From 1afe7dc50917a771ce8a06e418ea4e9681d26632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 31 May 2024 17:30:15 +0400 Subject: [PATCH 001/461] LineaTransaction class This class contains peripheral information of the transaction required for the tracing. --- .../zktracer/module/blockdata/Blockdata.java | 3 +- .../linea/zktracer/module/hub/Hub.java | 54 +- .../linea/zktracer/module/hub/Trace.java | 3660 ++++++++--------- .../hub/fragment/TransactionFragment.java | 99 +- .../zktracer/module/hub/transients/Block.java | 2 +- .../zktracer/types/LineaTransaction.java | 160 + 6 files changed, 1974 insertions(+), 2004 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/LineaTransaction.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java index 7d953927c7..a5feea7048 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java @@ -23,6 +23,7 @@ import java.util.Deque; import java.util.List; +import lombok.Getter; import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.rlptxn.RlpTxn; @@ -36,7 +37,7 @@ public class Blockdata implements Module { private final Wcp wcp; private final TxnData txnData; private final RlpTxn rlpTxn; - private final Deque operations = new ArrayDeque<>(); + @Getter final Deque operations = new ArrayDeque<>(); private boolean batchUnderConstruction; private final int TIMESTAMP_BYTESIZE = 4; private int previousTimestamp = 0; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 61eb832f07..edebd1bff7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -96,10 +96,7 @@ import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.runtime.stack.StackContext; import net.consensys.linea.zktracer.runtime.stack.StackLine; -import net.consensys.linea.zktracer.types.Bytecode; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.Precompile; -import net.consensys.linea.zktracer.types.TxState; +import net.consensys.linea.zktracer.types.*; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; @@ -149,6 +146,11 @@ public class Hub implements Module { /** stores all data related to failure states & module activation */ @Getter private final PlatformController pch; + @Getter private ProcessableBlockHeader currentBlockHeader; + + /** LineaTransaction is an enhanced Besu transaction */ + @Getter private LineaTransaction currentTransaction; + @Override public String moduleKey() { return "HUB"; @@ -618,17 +620,7 @@ void processStateInit(WorldView world) { ? preInitToSnapshot.deploy(value, initBytecode) : preInitToSnapshot.credit(value, true); - final TransactionFragment txFragment = - TransactionFragment.prepare( - this.transients.conflation().number(), - this.transients.block().minerAddress(), - tx.besuTx(), - true, - ((org.hyperledger.besu.ethereum.core.Transaction) tx.besuTx()) - .getEffectiveGasPrice(Optional.ofNullable(this.transients().block().baseFee())), - this.transients.block().baseFee(), - 0 // TODO: find getInitialGas - ); + final TransactionFragment txFragment = TransactionFragment.prepare(this.currentTransaction); this.defers.postTx(txFragment); final AccountFragment.AccountFragmentFactory accountFragmentFactory = @@ -793,14 +785,7 @@ void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { this, accountFragmentFactory.make(preFinalFromSnapshot, postFinalFromSnapshot), accountFragmentFactory.make(preFinalCoinbaseSnapshot, postFinalCoinbaseSnapshot), - TransactionFragment.prepare( - this.transients.conflation().number(), - this.transients.block().minerAddress(), - tx, - true, - this.transients.tx().gasPrice(), - this.transients.block().baseFee(), - this.transients.tx().initialGas()))); + TransactionFragment.prepare(this.currentTransaction))); } else { // Trace the exceptions of a transaction that could not even start // TODO: integrate with PCH @@ -845,6 +830,15 @@ public void traceStartTx(final WorldView world, final Transaction tx) { this.pch.reset(); this.state.enter(); + this.currentTransaction = + new LineaTransaction( + world, + this.transients.block().blockNumber(), + this.transients.block().minerAddress(), + this.transients.block().baseFee(), + txnData, + tx); + this.defers.postTx(this.state.currentTxTrace()); this.txStack.enterTransaction(tx, requiresEvmExecution(world, tx)); @@ -863,6 +857,7 @@ public void traceStartTx(final WorldView world, final Transaction tx) { } for (Module m : this.modules) { + // TODO: should use a LineaTransaction as its argument m.traceStartTx(world, tx); } } @@ -1177,7 +1172,7 @@ private void handleCreate(Address target) { @Override public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { - this.transients.block().update(processableBlockHeader); + this.transients.block().blockUpdate(processableBlockHeader); for (Module m : this.modules) { m.traceStartBlock(processableBlockHeader); } @@ -1344,16 +1339,7 @@ void traceOperation(MessageFrame frame) { this.addTraceSection(copySection); } case TRANSACTION -> this.addTraceSection( - new TransactionSection( - this, - TransactionFragment.prepare( - this.transients.conflation().number(), - frame.getMiningBeneficiary(), - this.transients.tx().besuTx(), - true, - frame.getGasPrice(), - frame.getBlockValues().getBaseFee().orElse(Wei.ZERO), - this.transients.tx().initialGas()))); + new TransactionSection(this, TransactionFragment.prepare(this.currentTransaction))); case STACK_RAM -> { switch (this.currentFrame().opCode()) { case CALLDATALOAD -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index fe05ffe5f6..8ec4061892 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -20,6 +20,7 @@ import java.util.List; import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; /** @@ -37,54 +38,56 @@ public class Trace { private final MappedByteBuffer accFinal; private final MappedByteBuffer accFirst; private final MappedByteBuffer - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee; + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum; private final MappedByteBuffer - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum; + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer alpha; private final MappedByteBuffer - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi; + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; private final MappedByteBuffer - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize; + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer batchNumber; + private final MappedByteBuffer callDataOffsetXorMmuSize; + private final MappedByteBuffer callDataSizeXorMmuSrcId; + private final MappedByteBuffer callStackDepth; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; private final MappedByteBuffer - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo; + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize; + private final MappedByteBuffer codeHashHiNewXorExpData5XorValueCurrLoXorValue; private final MappedByteBuffer - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo; + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorValueNextLo; + private final MappedByteBuffer codeHashLoXorMmuLimb1XorValueNextHi; private final MappedByteBuffer - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi; + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; private final MappedByteBuffer - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover; - private final MappedByteBuffer - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable; - private final MappedByteBuffer - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice; - private final MappedByteBuffer - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit; + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; private final MappedByteBuffer conAgain; private final MappedByteBuffer conFirst; private final MappedByteBuffer contextGetsReverted; private final MappedByteBuffer contextMayChange; private final MappedByteBuffer contextNumber; private final MappedByteBuffer contextNumberNew; + private final MappedByteBuffer contextNumberXorMmuTgtId; private final MappedByteBuffer contextRevertStamp; private final MappedByteBuffer contextSelfReverts; private final MappedByteBuffer contextWillRevert; private final MappedByteBuffer counterNsr; private final MappedByteBuffer counterTli; - private final MappedByteBuffer createFailureConditionWillRevertXorHashInfoFlag; private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; + private final MappedByteBuffer delta; private final MappedByteBuffer - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize; + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; private final MappedByteBuffer - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce; + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; private final MappedByteBuffer - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance; + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; private final MappedByteBuffer deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; private final MappedByteBuffer @@ -97,13 +100,14 @@ public class Trace { existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; private final MappedByteBuffer existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; - private final MappedByteBuffer expInstXorPrcCalleeGas; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; + private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; + private final MappedByteBuffer gasPrice; private final MappedByteBuffer - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; private final MappedByteBuffer hashInfoStamp; @@ -111,37 +115,37 @@ public class Trace { private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; + private final MappedByteBuffer instruction; private final MappedByteBuffer - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; private final MappedByteBuffer logInfoStamp; private final MappedByteBuffer - markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2; + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; private final MappedByteBuffer - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; - private final MappedByteBuffer mmuAuxIdXorPrcCallerGas; - private final MappedByteBuffer mmuExoSumXorPrcCdo; - private final MappedByteBuffer mmuInstXorPrcCds; - private final MappedByteBuffer mmuLimb1; - private final MappedByteBuffer mmuLimb2; - private final MappedByteBuffer mmuPhaseXorPrcRac; - private final MappedByteBuffer mmuRefOffsetXorPrcRao; - private final MappedByteBuffer mmuRefSizeXorPrcReturnGas; - private final MappedByteBuffer mmuSize; - private final MappedByteBuffer mmuSrcId; - private final MappedByteBuffer mmuSrcOffsetHi; - private final MappedByteBuffer mmuSrcOffsetLo; + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; private final MappedByteBuffer mmuStamp; - private final MappedByteBuffer mmuTgtId; - private final MappedByteBuffer mmuTgtOffsetLo; + private final MappedByteBuffer mxpOffset2Hi; + private final MappedByteBuffer mxpOffset2Lo; + private final MappedByteBuffer mxpSize1Hi; + private final MappedByteBuffer mxpSize1Lo; + private final MappedByteBuffer mxpSize2Hi; + private final MappedByteBuffer mxpSize2Lo; private final MappedByteBuffer mxpStamp; + private final MappedByteBuffer mxpWords; + private final MappedByteBuffer nbAdded; + private final MappedByteBuffer nbRemoved; private final MappedByteBuffer nonStackRows; - private final MappedByteBuffer - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity; - private final MappedByteBuffer - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas; - private final MappedByteBuffer oobData7XorStackItemValueLo3; - private final MappedByteBuffer oobData8XorStackItemValueLo4; - private final MappedByteBuffer oobInst; + private final MappedByteBuffer nonce; + private final MappedByteBuffer nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable; + private final MappedByteBuffer nonceXorStpGasMxpXorBasefee; + private final MappedByteBuffer oobData1; + private final MappedByteBuffer oobData2; + private final MappedByteBuffer oobData3; + private final MappedByteBuffer oobData4; + private final MappedByteBuffer oobData5; + private final MappedByteBuffer oobData6; + private final MappedByteBuffer oobData7; + private final MappedByteBuffer oobData8; private final MappedByteBuffer peekAtAccount; private final MappedByteBuffer peekAtContext; private final MappedByteBuffer peekAtMiscellaneous; @@ -162,10 +166,18 @@ public class Trace { private final MappedByteBuffer prcSha2256XorOpcx; private final MappedByteBuffer prcSuccessWillRevertXorPushpopFlag; private final MappedByteBuffer prcSuccessWontRevertXorRdcx; + private final MappedByteBuffer priorityFeePerGas; private final MappedByteBuffer programCounter; private final MappedByteBuffer programCounterNew; private final MappedByteBuffer refundCounter; + private final MappedByteBuffer refundCounterInfinity; private final MappedByteBuffer refundCounterNew; + private final MappedByteBuffer refundEffective; + private final MappedByteBuffer returnAtCapacityXorMxpInst; + private final MappedByteBuffer returnAtOffsetXorOobInst; + private final MappedByteBuffer returnDataContextNumberXorStpGasStipend; + private final MappedByteBuffer returnDataOffsetXorStpInstruction; + private final MappedByteBuffer returnDataSize; private final MappedByteBuffer returnExceptionXorShfFlag; private final MappedByteBuffer returnFromDeploymentEmptyCodeWillRevertXorSox; private final MappedByteBuffer returnFromDeploymentEmptyCodeWontRevertXorSstorex; @@ -173,40 +185,48 @@ public class Trace { private final MappedByteBuffer returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1; private final MappedByteBuffer returnFromMessageCallWillTouchRamXorStackItemPop2; private final MappedByteBuffer returnFromMessageCallWontTouchRamXorStackItemPop3; - private final MappedByteBuffer - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective; - private final MappedByteBuffer - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi; - private final MappedByteBuffer rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3; - private final MappedByteBuffer - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo; - private final MappedByteBuffer - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue; - private final MappedByteBuffer rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3; - private final MappedByteBuffer rlpaddrSaltHiXorOobData4XorStackItemValueHi4; - private final MappedByteBuffer rlpaddrSaltLoXorOobData5XorStackItemValueLo1; - private final MappedByteBuffer romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4; + private final MappedByteBuffer rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize; + private final MappedByteBuffer rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi; + private final MappedByteBuffer rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3; + private final MappedByteBuffer rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo; + private final MappedByteBuffer rlpaddrKecLoXorMmuTgtOffsetLo; + private final MappedByteBuffer rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4; + private final MappedByteBuffer rlpaddrSaltHiXorMxpGasMxp; + private final MappedByteBuffer rlpaddrSaltLoXorMxpOffset1Hi; + private final MappedByteBuffer romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag; private final MappedByteBuffer selfdestructExceptionXorStackItemPop4; private final MappedByteBuffer selfdestructWillRevertXorStaticx; private final MappedByteBuffer selfdestructWontRevertAlreadyMarkedXorStaticFlag; private final MappedByteBuffer selfdestructWontRevertNotYetMarkedXorStoFlag; + private final MappedByteBuffer stackItemHeight1; + private final MappedByteBuffer stackItemHeight2; + private final MappedByteBuffer stackItemHeight3; + private final MappedByteBuffer stackItemHeight4; + private final MappedByteBuffer stackItemStamp1; + private final MappedByteBuffer stackItemStamp2; + private final MappedByteBuffer stackItemStamp3; + private final MappedByteBuffer stackItemStamp4; + private final MappedByteBuffer stackItemValueHi1; + private final MappedByteBuffer stackItemValueHi2; + private final MappedByteBuffer stackItemValueHi3; + private final MappedByteBuffer stackItemValueHi4; + private final MappedByteBuffer stackItemValueLo1; + private final MappedByteBuffer stackItemValueLo2; + private final MappedByteBuffer stackItemValueLo3; + private final MappedByteBuffer stackItemValueLo4; private final MappedByteBuffer stoFinal; private final MappedByteBuffer stoFirst; - private final MappedByteBuffer stpGasHiXorStaticGas; + private final MappedByteBuffer stpGasHi; private final MappedByteBuffer stpGasLo; - private final MappedByteBuffer stpGasMxp; - private final MappedByteBuffer stpGasPaidOutOfPocket; - private final MappedByteBuffer stpGasStipend; - private final MappedByteBuffer stpGasUpfrontGasCost; - private final MappedByteBuffer stpInstruction; - private final MappedByteBuffer stpValHi; - private final MappedByteBuffer stpValLo; + private final MappedByteBuffer stpGasUpfrontGasCostXorGasLeftover; + private final MappedByteBuffer stpValueHi; + private final MappedByteBuffer stpValueLo; private final MappedByteBuffer subStamp; private final MappedByteBuffer sux; private final MappedByteBuffer swapFlag; private final MappedByteBuffer transactionReverts; - private final MappedByteBuffer trmFlagXorCreateEmptyInitCodeWillRevertXorDupFlag; - private final MappedByteBuffer trmRawAddressHiXorOobData6XorStackItemValueLo2; + private final MappedByteBuffer trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag; + private final MappedByteBuffer trmRawAddressHiXorMxpOffset1Lo; private final MappedByteBuffer twoLineInstruction; private final MappedByteBuffer txExec; private final MappedByteBuffer txFinl; @@ -214,74 +234,70 @@ public class Trace { private final MappedByteBuffer txSkip; private final MappedByteBuffer txWarm; private final MappedByteBuffer txnFlag; - private final MappedByteBuffer warmthNewXorCreateExceptionXorHaltFlag; - private final MappedByteBuffer warmthXorCreateEmptyInitCodeWontRevertXorExtFlag; + private final MappedByteBuffer warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag; + private final MappedByteBuffer warmthXorCreateExceptionXorHaltFlag; private final MappedByteBuffer wcpFlag; static List headers(int length) { return List.of( - new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 32, length), + new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), new ColumnHeader( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_ALPHA_xor_ADDRESS_HI_xor_BASEFEE", - 32, - length), - new ColumnHeader( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_DELTA_xor_ADDRESS_LO_xor_BATCH_NUM", - 32, - length), - new ColumnHeader( - "hub.BALANCE_NEW_xor_BYTE_CODE_ADDRESS_HI_xor_EXP_DATA_3_xor_HASH_INFO_KECCAK_LO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", - 32, + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_HASH_INFO_SIZE_xor_ADDRESS_HI_xor_BATCH_NUM", + 8, length), new ColumnHeader( - "hub.BALANCE_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_HI_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 32, length), - new ColumnHeader("hub.BATCH_NUMBER", 32, length), - new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 32, length), - new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 32, length), + new ColumnHeader("hub.ALPHA", 1, length), new ColumnHeader( - "hub.CODE_FRAGMENT_INDEX_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_4_xor_HASH_INFO_SIZE_xor_STORAGE_KEY_HI_xor_COINBASE_ADDRESS_LO", + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 32, length), new ColumnHeader( - "hub.CODE_HASH_HI_NEW_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MXP_GAS_MXP_xor_NB_ADDED_xor_VALUE_CURR_HI_xor_FROM_ADDRESS_LO", + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 32, length), + new ColumnHeader("hub.BATCH_NUMBER", 4, length), + new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), + new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), + new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), + new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), + new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), new ColumnHeader( - "hub.CODE_HASH_HI_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_EXP_DATA_5_xor_INSTRUCTION_xor_STORAGE_KEY_LO_xor_FROM_ADDRESS_HI", - 32, + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_STATIC_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", + 8, length), new ColumnHeader( - "hub.CODE_HASH_LO_NEW_xor_CALLER_ADDRESS_HI_xor_MXP_MTNTOP_xor_PUSH_VALUE_HI_xor_VALUE_NEXT_HI_xor_GAS_LEFTOVER", - 32, - length), + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), new ColumnHeader( - "hub.CODE_HASH_LO_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MXP_INST_xor_NB_REMOVED_xor_VALUE_CURR_LO_xor_GAS_INITIALLY_AVAILABLE", + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 32, length), + new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), + new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), new ColumnHeader( - "hub.CODE_SIZE_NEW_xor_CALL_DATA_CONTEXT_NUMBER_xor_MXP_OFFSET_1_LO_xor_STACK_ITEM_HEIGHT_1_xor_VALUE_ORIG_HI_xor_GAS_PRICE", - 32, + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", + 8, length), new ColumnHeader( - "hub.CODE_SIZE_xor_CALLER_ADDRESS_LO_xor_MXP_OFFSET_1_HI_xor_PUSH_VALUE_LO_xor_VALUE_NEXT_LO_xor_GAS_LIMIT", - 32, + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", + 8, length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), new ColumnHeader("hub.CONTEXT_MAY_CHANGE", 1, length), - new ColumnHeader("hub.CONTEXT_NUMBER", 32, length), - new ColumnHeader("hub.CONTEXT_NUMBER_NEW", 32, length), - new ColumnHeader("hub.CONTEXT_REVERT_STAMP", 32, length), + new ColumnHeader("hub.CONTEXT_NUMBER", 8, length), + new ColumnHeader("hub.CONTEXT_NUMBER_NEW", 8, length), + new ColumnHeader("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID", 8, length), + new ColumnHeader("hub.CONTEXT_REVERT_STAMP", 8, length), new ColumnHeader("hub.CONTEXT_SELF_REVERTS", 1, length), new ColumnHeader("hub.CONTEXT_WILL_REVERT", 1, length), - new ColumnHeader("hub.COUNTER_NSR", 32, length), + new ColumnHeader("hub.COUNTER_NSR", 2, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), - new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), new ColumnHeader( "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), @@ -292,17 +308,18 @@ static List headers(int length) { length), new ColumnHeader( "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader("hub.DELTA", 1, length), new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_CALL_DATA_SIZE_xor_MXP_OFFSET_2_LO_xor_STACK_ITEM_HEIGHT_3_xor_INIT_CODE_SIZE", - 32, + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", + 8, length), new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALL_STACK_DEPTH_xor_MXP_SIZE_1_HI_xor_STACK_ITEM_HEIGHT_4_xor_NONCE", - 32, + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", + 8, length), new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_xor_CALL_DATA_OFFSET_xor_MXP_OFFSET_2_HI_xor_STACK_ITEM_HEIGHT_2_xor_VALUE_ORIG_LO_xor_INITIAL_BALANCE", - 32, + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", + 8, length), new ColumnHeader( "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", @@ -316,7 +333,7 @@ static List headers(int length) { "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", 1, length), - new ColumnHeader("hub.DOM_STAMP", 32, length), + new ColumnHeader("hub.DOM_STAMP", 8, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), new ColumnHeader( "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", @@ -326,65 +343,63 @@ static List headers(int length) { "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", 1, length), - new ColumnHeader("hub.EXP_INST_xor_PRC_CALLEE_GAS", 8, length), - new ColumnHeader("hub.GAS_ACTUAL", 32, length), + new ColumnHeader("hub.GAS_ACTUAL", 8, length), new ColumnHeader("hub.GAS_COST", 32, length), - new ColumnHeader("hub.GAS_EXPECTED", 32, length), - new ColumnHeader("hub.GAS_NEXT", 32, length), + new ColumnHeader("hub.GAS_EXPECTED", 8, length), + new ColumnHeader("hub.GAS_LIMIT", 32, length), + new ColumnHeader("hub.GAS_NEXT", 8, length), + new ColumnHeader("hub.GAS_PRICE", 32, length), new ColumnHeader( - "hub.HAS_CODE_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", 1, length), new ColumnHeader( "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), - new ColumnHeader("hub.HASH_INFO_STAMP", 32, length), - new ColumnHeader("hub.HEIGHT", 32, length), - new ColumnHeader("hub.HEIGHT_NEW", 32, length), - new ColumnHeader("hub.HUB_STAMP", 32, length), - new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 32, length), + new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), + new ColumnHeader("hub.HEIGHT", 2, length), + new ColumnHeader("hub.HEIGHT_NEW", 2, length), + new ColumnHeader("hub.HUB_STAMP", 8, length), + new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), + new ColumnHeader("hub.INSTRUCTION", 32, length), new ColumnHeader( - "hub.IS_PRECOMPILE_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", 1, length), - new ColumnHeader("hub.LOG_INFO_STAMP", 32, length), + new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", 1, length), new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_xor_STP_EXISTS_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", 1, length), - new ColumnHeader("hub.MMU_AUX_ID_xor_PRC_CALLER_GAS", 8, length), - new ColumnHeader("hub.MMU_EXO_SUM_xor_PRC_CDO", 8, length), - new ColumnHeader("hub.MMU_INST_xor_PRC_CDS", 8, length), - new ColumnHeader("hub.MMU_LIMB_1", 32, length), - new ColumnHeader("hub.MMU_LIMB_2", 32, length), - new ColumnHeader("hub.MMU_PHASE_xor_PRC_RAC", 8, length), - new ColumnHeader("hub.MMU_REF_OFFSET_xor_PRC_RAO", 8, length), - new ColumnHeader("hub.MMU_REF_SIZE_xor_PRC_RETURN_GAS", 8, length), - new ColumnHeader("hub.MMU_SIZE", 8, length), - new ColumnHeader("hub.MMU_SRC_ID", 8, length), - new ColumnHeader("hub.MMU_SRC_OFFSET_HI", 32, length), - new ColumnHeader("hub.MMU_SRC_OFFSET_LO", 32, length), - new ColumnHeader("hub.MMU_STAMP", 32, length), - new ColumnHeader("hub.MMU_TGT_ID", 8, length), - new ColumnHeader("hub.MMU_TGT_OFFSET_LO", 32, length), - new ColumnHeader("hub.MXP_STAMP", 32, length), - new ColumnHeader("hub.NON_STACK_ROWS", 32, length), + new ColumnHeader("hub.MMU_STAMP", 8, length), + new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), + new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), + new ColumnHeader("hub.MXP_SIZE_1_HI", 32, length), + new ColumnHeader("hub.MXP_SIZE_1_LO", 32, length), + new ColumnHeader("hub.MXP_SIZE_2_HI", 32, length), + new ColumnHeader("hub.MXP_SIZE_2_LO", 32, length), + new ColumnHeader("hub.MXP_STAMP", 8, length), + new ColumnHeader("hub.MXP_WORDS", 32, length), + new ColumnHeader("hub.NB_ADDED", 1, length), + new ColumnHeader("hub.NB_REMOVED", 1, length), + new ColumnHeader("hub.NON_STACK_ROWS", 2, length), + new ColumnHeader("hub.NONCE", 32, length), new ColumnHeader( - "hub.NONCE_NEW_xor_CONTEXT_NUMBER_xor_MXP_SIZE_2_HI_xor_STACK_ITEM_STAMP_2_xor_REFUND_COUNTER_INFINITY", - 32, - length), - new ColumnHeader( - "hub.NONCE_xor_CALL_VALUE_xor_MXP_SIZE_1_LO_xor_STACK_ITEM_STAMP_1_xor_PRIORITY_FEE_PER_GAS", - 32, - length), - new ColumnHeader("hub.OOB_DATA_7_xor_STACK_ITEM_VALUE_LO_3", 32, length), - new ColumnHeader("hub.OOB_DATA_8_xor_STACK_ITEM_VALUE_LO_4", 32, length), - new ColumnHeader("hub.OOB_INST", 8, length), + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), + new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), + new ColumnHeader("hub.OOB_DATA_1", 32, length), + new ColumnHeader("hub.OOB_DATA_2", 32, length), + new ColumnHeader("hub.OOB_DATA_3", 32, length), + new ColumnHeader("hub.OOB_DATA_4", 32, length), + new ColumnHeader("hub.OOB_DATA_5", 32, length), + new ColumnHeader("hub.OOB_DATA_6", 32, length), + new ColumnHeader("hub.OOB_DATA_7", 32, length), + new ColumnHeader("hub.OOB_DATA_8", 32, length), new ColumnHeader("hub.PEEK_AT_ACCOUNT", 1, length), new ColumnHeader("hub.PEEK_AT_CONTEXT", 1, length), new ColumnHeader("hub.PEEK_AT_MISCELLANEOUS", 1, length), @@ -405,10 +420,18 @@ static List headers(int length) { new ColumnHeader("hub.PRC_SHA2-256_xor_OPCX", 1, length), new ColumnHeader("hub.PRC_SUCCESS_WILL_REVERT_xor_PUSHPOP_FLAG", 1, length), new ColumnHeader("hub.PRC_SUCCESS_WONT_REVERT_xor_RDCX", 1, length), - new ColumnHeader("hub.PROGRAM_COUNTER", 32, length), - new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 32, length), - new ColumnHeader("hub.REFUND_COUNTER", 32, length), - new ColumnHeader("hub.REFUND_COUNTER_NEW", 32, length), + new ColumnHeader("hub.PRIORITY_FEE_PER_GAS", 32, length), + new ColumnHeader("hub.PROGRAM_COUNTER", 8, length), + new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 8, length), + new ColumnHeader("hub.REFUND_COUNTER", 8, length), + new ColumnHeader("hub.REFUND_COUNTER_INFINITY", 32, length), + new ColumnHeader("hub.REFUND_COUNTER_NEW", 8, length), + new ColumnHeader("hub.REFUND_EFFECTIVE", 32, length), + new ColumnHeader("hub.RETURN_AT_CAPACITY_xor_MXP_INST", 8, length), + new ColumnHeader("hub.RETURN_AT_OFFSET_xor_OOB_INST", 8, length), + new ColumnHeader("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND", 8, length), + new ColumnHeader("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION", 8, length), + new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), new ColumnHeader( @@ -422,58 +445,57 @@ static List headers(int length) { new ColumnHeader( "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_HI_xor_RETURN_AT_CAPACITY_xor_MXP_SIZE_2_LO_xor_STACK_ITEM_STAMP_3_xor_REFUND_EFFECTIVE", - 32, - length), + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_LO_xor_RETURN_AT_OFFSET_xor_MXP_WORDS_xor_STACK_ITEM_STAMP_4_xor_TO_ADDRESS_HI", - 32, - length), + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), new ColumnHeader( - "hub.RLPADDR_FLAG_xor_STP_OOGX_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", 1, length), + new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), + new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), new ColumnHeader( - "hub.RLPADDR_KEC_HI_xor_RETURN_DATA_CONTEXT_NUMBER_xor_OOB_DATA_1_xor_STACK_ITEM_VALUE_HI_1_xor_TO_ADDRESS_LO", - 32, - length), - new ColumnHeader( - "hub.RLPADDR_KEC_LO_xor_RETURN_DATA_OFFSET_xor_OOB_DATA_2_xor_STACK_ITEM_VALUE_HI_2_xor_VALUE", - 32, - length), + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), + new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), new ColumnHeader( - "hub.RLPADDR_RECIPE_xor_RETURN_DATA_SIZE_xor_OOB_DATA_3_xor_STACK_ITEM_VALUE_HI_3", - 32, + "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", + 1, length), - new ColumnHeader( - "hub.RLPADDR_SALT_HI_xor_OOB_DATA_4_xor_STACK_ITEM_VALUE_HI_4", 32, length), - new ColumnHeader( - "hub.RLPADDR_SALT_LO_xor_OOB_DATA_5_xor_STACK_ITEM_VALUE_LO_1", 32, length), - new ColumnHeader( - "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG", 1, length), + new ColumnHeader("hub.STACK_ITEM_HEIGHT_1", 32, length), + new ColumnHeader("hub.STACK_ITEM_HEIGHT_2", 32, length), + new ColumnHeader("hub.STACK_ITEM_HEIGHT_3", 32, length), + new ColumnHeader("hub.STACK_ITEM_HEIGHT_4", 32, length), + new ColumnHeader("hub.STACK_ITEM_STAMP_1", 32, length), + new ColumnHeader("hub.STACK_ITEM_STAMP_2", 32, length), + new ColumnHeader("hub.STACK_ITEM_STAMP_3", 32, length), + new ColumnHeader("hub.STACK_ITEM_STAMP_4", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_HI_1", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_HI_2", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_HI_3", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_HI_4", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_LO_1", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_LO_2", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_LO_3", 32, length), + new ColumnHeader("hub.STACK_ITEM_VALUE_LO_4", 32, length), new ColumnHeader("hub.sto_FINAL", 1, length), new ColumnHeader("hub.sto_FIRST", 1, length), - new ColumnHeader("hub.STP_GAS_HI_xor_STATIC_GAS", 32, length), + new ColumnHeader("hub.STP_GAS_HI", 32, length), new ColumnHeader("hub.STP_GAS_LO", 32, length), - new ColumnHeader("hub.STP_GAS_MXP", 32, length), - new ColumnHeader("hub.STP_GAS_PAID_OUT_OF_POCKET", 32, length), - new ColumnHeader("hub.STP_GAS_STIPEND", 32, length), - new ColumnHeader("hub.STP_GAS_UPFRONT_GAS_COST", 32, length), - new ColumnHeader("hub.STP_INSTRUCTION", 32, length), - new ColumnHeader("hub.STP_VAL_HI", 32, length), - new ColumnHeader("hub.STP_VAL_LO", 32, length), - new ColumnHeader("hub.SUB_STAMP", 32, length), + new ColumnHeader("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER", 32, length), + new ColumnHeader("hub.STP_VALUE_HI", 32, length), + new ColumnHeader("hub.STP_VALUE_LO", 32, length), + new ColumnHeader("hub.SUB_STAMP", 8, length), new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), new ColumnHeader("hub.TRANSACTION_REVERTS", 1, length), new ColumnHeader( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), - new ColumnHeader( - "hub.TRM_RAW_ADDRESS_HI_xor_OOB_DATA_6_xor_STACK_ITEM_VALUE_LO_2", 32, length), + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), new ColumnHeader("hub.TX_FINL", 1, length), @@ -481,9 +503,11 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader( - "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", + 1, + length), + new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -491,192 +515,210 @@ public Trace(List buffers) { this.absoluteTransactionNumber = buffers.get(0); this.accFinal = buffers.get(1); this.accFirst = buffers.get(2); - this.addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee = buffers.get(3); - this.addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum = buffers.get(4); this - .balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi = - buffers.get(5); + .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum = + buffers.get(3); this - .balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize = + .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = + buffers.get(4); + this.alpha = buffers.get(5); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(6); - this.batchNumber = buffers.get(7); - this.callerContextNumber = buffers.get(8); - this.codeFragmentIndex = buffers.get(9); - this - .codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo = - buffers.get(10); - this - .codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo = - buffers.get(11); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = + buffers.get(7); + this.batchNumber = buffers.get(8); + this.callDataOffsetXorMmuSize = buffers.get(9); + this.callDataSizeXorMmuSrcId = buffers.get(10); + this.callStackDepth = buffers.get(11); + this.callerContextNumber = buffers.get(12); + this.codeFragmentIndex = buffers.get(13); this - .codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi = - buffers.get(12); - this.codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover = - buffers.get(13); - this - .codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable = + .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize = buffers.get(14); - this - .codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice = - buffers.get(15); - this.codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit = + this.codeHashHiNewXorExpData5XorValueCurrLoXorValue = buffers.get(15); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); - this.conAgain = buffers.get(17); - this.conFirst = buffers.get(18); - this.contextGetsReverted = buffers.get(19); - this.contextMayChange = buffers.get(20); - this.contextNumber = buffers.get(21); - this.contextNumberNew = buffers.get(22); - this.contextRevertStamp = buffers.get(23); - this.contextSelfReverts = buffers.get(24); - this.contextWillRevert = buffers.get(25); - this.counterNsr = buffers.get(26); - this.counterTli = buffers.get(27); - this.createFailureConditionWillRevertXorHashInfoFlag = buffers.get(28); - this.createFailureConditionWontRevertXorIcpx = buffers.get(29); - this.createNonemptyInitCodeFailureWillRevertXorInvalidFlag = buffers.get(30); - this.createNonemptyInitCodeFailureWontRevertXorJumpx = buffers.get(31); - this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(32); - this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(33); - this.deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize = - buffers.get(34); - this.deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce = - buffers.get(35); + this.codeHashLoNewXorMmuLimb2XorValueNextLo = buffers.get(17); + this.codeHashLoXorMmuLimb1XorValueNextHi = buffers.get(18); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = + buffers.get(19); this - .deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance = - buffers.get(36); + .codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = + buffers.get(20); + this.conAgain = buffers.get(21); + this.conFirst = buffers.get(22); + this.contextGetsReverted = buffers.get(23); + this.contextMayChange = buffers.get(24); + this.contextNumber = buffers.get(25); + this.contextNumberNew = buffers.get(26); + this.contextNumberXorMmuTgtId = buffers.get(27); + this.contextRevertStamp = buffers.get(28); + this.contextSelfReverts = buffers.get(29); + this.contextWillRevert = buffers.get(30); + this.counterNsr = buffers.get(31); + this.counterTli = buffers.get(32); + this.createFailureConditionWontRevertXorIcpx = buffers.get(33); + this.createNonemptyInitCodeFailureWillRevertXorInvalidFlag = buffers.get(34); + this.createNonemptyInitCodeFailureWontRevertXorJumpx = buffers.get(35); + this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); + this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); + this.delta = buffers.get(38); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = + buffers.get(39); + this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = + buffers.get(41); this .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = - buffers.get(37); + buffers.get(42); this .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = - buffers.get(38); + buffers.get(43); this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = - buffers.get(39); - this.domStamp = buffers.get(40); - this.exceptionAhoy = buffers.get(41); + buffers.get(44); + this.domStamp = buffers.get(45); + this.exceptionAhoy = buffers.get(46); this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = - buffers.get(42); + buffers.get(47); this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = - buffers.get(43); - this.expInstXorPrcCalleeGas = buffers.get(44); - this.gasActual = buffers.get(45); - this.gasCost = buffers.get(46); - this.gasExpected = buffers.get(47); - this.gasNext = buffers.get(48); - this.hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = - buffers.get(49); + buffers.get(48); + this.gasActual = buffers.get(49); + this.gasCost = buffers.get(50); + this.gasExpected = buffers.get(51); + this.gasLimit = buffers.get(52); + this.gasNext = buffers.get(53); + this.gasPrice = buffers.get(54); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = + buffers.get(55); this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = - buffers.get(50); - this.hashInfoStamp = buffers.get(51); - this.height = buffers.get(52); - this.heightNew = buffers.get(53); - this.hubStamp = buffers.get(54); - this.hubStampTransactionEnd = buffers.get(55); - this.isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = buffers.get(56); - this.logInfoStamp = buffers.get(57); - this.markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2 = - buffers.get(58); - this.markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = - buffers.get(59); - this.mmuAuxIdXorPrcCallerGas = buffers.get(60); - this.mmuExoSumXorPrcCdo = buffers.get(61); - this.mmuInstXorPrcCds = buffers.get(62); - this.mmuLimb1 = buffers.get(63); - this.mmuLimb2 = buffers.get(64); - this.mmuPhaseXorPrcRac = buffers.get(65); - this.mmuRefOffsetXorPrcRao = buffers.get(66); - this.mmuRefSizeXorPrcReturnGas = buffers.get(67); - this.mmuSize = buffers.get(68); - this.mmuSrcId = buffers.get(69); - this.mmuSrcOffsetHi = buffers.get(70); - this.mmuSrcOffsetLo = buffers.get(71); - this.mmuStamp = buffers.get(72); - this.mmuTgtId = buffers.get(73); - this.mmuTgtOffsetLo = buffers.get(74); - this.mxpStamp = buffers.get(75); - this.nonStackRows = buffers.get(76); - this.nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity = - buffers.get(77); - this.nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas = buffers.get(78); - this.oobData7XorStackItemValueLo3 = buffers.get(79); - this.oobData8XorStackItemValueLo4 = buffers.get(80); - this.oobInst = buffers.get(81); - this.peekAtAccount = buffers.get(82); - this.peekAtContext = buffers.get(83); - this.peekAtMiscellaneous = buffers.get(84); - this.peekAtScenario = buffers.get(85); - this.peekAtStack = buffers.get(86); - this.peekAtStorage = buffers.get(87); - this.peekAtTransaction = buffers.get(88); - this.prcBlake2FXorKecFlag = buffers.get(89); - this.prcEcaddXorLogFlag = buffers.get(90); - this.prcEcmulXorLogInfoFlag = buffers.get(91); - this.prcEcpairingXorMachineStateFlag = buffers.get(92); - this.prcEcrecoverXorMaxcsx = buffers.get(93); - this.prcFailureKnownToHubXorModFlag = buffers.get(94); - this.prcFailureKnownToRamXorMulFlag = buffers.get(95); - this.prcIdentityXorMxpx = buffers.get(96); - this.prcModexpXorMxpFlag = buffers.get(97); - this.prcRipemd160XorOogx = buffers.get(98); - this.prcSha2256XorOpcx = buffers.get(99); - this.prcSuccessWillRevertXorPushpopFlag = buffers.get(100); - this.prcSuccessWontRevertXorRdcx = buffers.get(101); - this.programCounter = buffers.get(102); - this.programCounterNew = buffers.get(103); - this.refundCounter = buffers.get(104); - this.refundCounterNew = buffers.get(105); - this.returnExceptionXorShfFlag = buffers.get(106); - this.returnFromDeploymentEmptyCodeWillRevertXorSox = buffers.get(107); - this.returnFromDeploymentEmptyCodeWontRevertXorSstorex = buffers.get(108); - this.returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag = buffers.get(109); - this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1 = buffers.get(110); - this.returnFromMessageCallWillTouchRamXorStackItemPop2 = buffers.get(111); - this.returnFromMessageCallWontTouchRamXorStackItemPop3 = buffers.get(112); - this.rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective = - buffers.get(113); - this.rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi = - buffers.get(114); - this.rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3 = buffers.get(115); - this.rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo = - buffers.get(116); - this.rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue = buffers.get(117); - this.rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3 = buffers.get(118); - this.rlpaddrSaltHiXorOobData4XorStackItemValueHi4 = buffers.get(119); - this.rlpaddrSaltLoXorOobData5XorStackItemValueLo1 = buffers.get(120); - this.romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4 = buffers.get(121); - this.selfdestructExceptionXorStackItemPop4 = buffers.get(122); - this.selfdestructWillRevertXorStaticx = buffers.get(123); - this.selfdestructWontRevertAlreadyMarkedXorStaticFlag = buffers.get(124); - this.selfdestructWontRevertNotYetMarkedXorStoFlag = buffers.get(125); - this.stoFinal = buffers.get(126); - this.stoFirst = buffers.get(127); - this.stpGasHiXorStaticGas = buffers.get(128); - this.stpGasLo = buffers.get(129); - this.stpGasMxp = buffers.get(130); - this.stpGasPaidOutOfPocket = buffers.get(131); - this.stpGasStipend = buffers.get(132); - this.stpGasUpfrontGasCost = buffers.get(133); - this.stpInstruction = buffers.get(134); - this.stpValHi = buffers.get(135); - this.stpValLo = buffers.get(136); - this.subStamp = buffers.get(137); - this.sux = buffers.get(138); - this.swapFlag = buffers.get(139); - this.transactionReverts = buffers.get(140); - this.trmFlagXorCreateEmptyInitCodeWillRevertXorDupFlag = buffers.get(141); - this.trmRawAddressHiXorOobData6XorStackItemValueLo2 = buffers.get(142); - this.twoLineInstruction = buffers.get(143); - this.txExec = buffers.get(144); - this.txFinl = buffers.get(145); - this.txInit = buffers.get(146); - this.txSkip = buffers.get(147); - this.txWarm = buffers.get(148); - this.txnFlag = buffers.get(149); - this.warmthNewXorCreateExceptionXorHaltFlag = buffers.get(150); - this.warmthXorCreateEmptyInitCodeWontRevertXorExtFlag = buffers.get(151); - this.wcpFlag = buffers.get(152); + this.hashInfoStamp = buffers.get(57); + this.height = buffers.get(58); + this.heightNew = buffers.get(59); + this.hubStamp = buffers.get(60); + this.hubStampTransactionEnd = buffers.get(61); + this.instruction = buffers.get(62); + this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = + buffers.get(63); + this.logInfoStamp = buffers.get(64); + this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = + buffers.get(65); + this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = + buffers.get(66); + this.mmuStamp = buffers.get(67); + this.mxpOffset2Hi = buffers.get(68); + this.mxpOffset2Lo = buffers.get(69); + this.mxpSize1Hi = buffers.get(70); + this.mxpSize1Lo = buffers.get(71); + this.mxpSize2Hi = buffers.get(72); + this.mxpSize2Lo = buffers.get(73); + this.mxpStamp = buffers.get(74); + this.mxpWords = buffers.get(75); + this.nbAdded = buffers.get(76); + this.nbRemoved = buffers.get(77); + this.nonStackRows = buffers.get(78); + this.nonce = buffers.get(79); + this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(80); + this.nonceXorStpGasMxpXorBasefee = buffers.get(81); + this.oobData1 = buffers.get(82); + this.oobData2 = buffers.get(83); + this.oobData3 = buffers.get(84); + this.oobData4 = buffers.get(85); + this.oobData5 = buffers.get(86); + this.oobData6 = buffers.get(87); + this.oobData7 = buffers.get(88); + this.oobData8 = buffers.get(89); + this.peekAtAccount = buffers.get(90); + this.peekAtContext = buffers.get(91); + this.peekAtMiscellaneous = buffers.get(92); + this.peekAtScenario = buffers.get(93); + this.peekAtStack = buffers.get(94); + this.peekAtStorage = buffers.get(95); + this.peekAtTransaction = buffers.get(96); + this.prcBlake2FXorKecFlag = buffers.get(97); + this.prcEcaddXorLogFlag = buffers.get(98); + this.prcEcmulXorLogInfoFlag = buffers.get(99); + this.prcEcpairingXorMachineStateFlag = buffers.get(100); + this.prcEcrecoverXorMaxcsx = buffers.get(101); + this.prcFailureKnownToHubXorModFlag = buffers.get(102); + this.prcFailureKnownToRamXorMulFlag = buffers.get(103); + this.prcIdentityXorMxpx = buffers.get(104); + this.prcModexpXorMxpFlag = buffers.get(105); + this.prcRipemd160XorOogx = buffers.get(106); + this.prcSha2256XorOpcx = buffers.get(107); + this.prcSuccessWillRevertXorPushpopFlag = buffers.get(108); + this.prcSuccessWontRevertXorRdcx = buffers.get(109); + this.priorityFeePerGas = buffers.get(110); + this.programCounter = buffers.get(111); + this.programCounterNew = buffers.get(112); + this.refundCounter = buffers.get(113); + this.refundCounterInfinity = buffers.get(114); + this.refundCounterNew = buffers.get(115); + this.refundEffective = buffers.get(116); + this.returnAtCapacityXorMxpInst = buffers.get(117); + this.returnAtOffsetXorOobInst = buffers.get(118); + this.returnDataContextNumberXorStpGasStipend = buffers.get(119); + this.returnDataOffsetXorStpInstruction = buffers.get(120); + this.returnDataSize = buffers.get(121); + this.returnExceptionXorShfFlag = buffers.get(122); + this.returnFromDeploymentEmptyCodeWillRevertXorSox = buffers.get(123); + this.returnFromDeploymentEmptyCodeWontRevertXorSstorex = buffers.get(124); + this.returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag = buffers.get(125); + this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1 = buffers.get(126); + this.returnFromMessageCallWillTouchRamXorStackItemPop2 = buffers.get(127); + this.returnFromMessageCallWontTouchRamXorStackItemPop3 = buffers.get(128); + this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(129); + this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi = buffers.get(130); + this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3 = buffers.get(131); + this.rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo = buffers.get(132); + this.rlpaddrKecLoXorMmuTgtOffsetLo = buffers.get(133); + this.rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4 = buffers.get(134); + this.rlpaddrSaltHiXorMxpGasMxp = buffers.get(135); + this.rlpaddrSaltLoXorMxpOffset1Hi = buffers.get(136); + this.romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag = buffers.get(137); + this.selfdestructExceptionXorStackItemPop4 = buffers.get(138); + this.selfdestructWillRevertXorStaticx = buffers.get(139); + this.selfdestructWontRevertAlreadyMarkedXorStaticFlag = buffers.get(140); + this.selfdestructWontRevertNotYetMarkedXorStoFlag = buffers.get(141); + this.stackItemHeight1 = buffers.get(142); + this.stackItemHeight2 = buffers.get(143); + this.stackItemHeight3 = buffers.get(144); + this.stackItemHeight4 = buffers.get(145); + this.stackItemStamp1 = buffers.get(146); + this.stackItemStamp2 = buffers.get(147); + this.stackItemStamp3 = buffers.get(148); + this.stackItemStamp4 = buffers.get(149); + this.stackItemValueHi1 = buffers.get(150); + this.stackItemValueHi2 = buffers.get(151); + this.stackItemValueHi3 = buffers.get(152); + this.stackItemValueHi4 = buffers.get(153); + this.stackItemValueLo1 = buffers.get(154); + this.stackItemValueLo2 = buffers.get(155); + this.stackItemValueLo3 = buffers.get(156); + this.stackItemValueLo4 = buffers.get(157); + this.stoFinal = buffers.get(158); + this.stoFirst = buffers.get(159); + this.stpGasHi = buffers.get(160); + this.stpGasLo = buffers.get(161); + this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(162); + this.stpValueHi = buffers.get(163); + this.stpValueLo = buffers.get(164); + this.subStamp = buffers.get(165); + this.sux = buffers.get(166); + this.swapFlag = buffers.get(167); + this.transactionReverts = buffers.get(168); + this.trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag = buffers.get(169); + this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(170); + this.twoLineInstruction = buffers.get(171); + this.txExec = buffers.get(172); + this.txFinl = buffers.get(173); + this.txInit = buffers.get(174); + this.txSkip = buffers.get(175); + this.txWarm = buffers.get(176); + this.txnFlag = buffers.get(177); + this.warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag = buffers.get(178); + this.warmthXorCreateExceptionXorHaltFlag = buffers.get(179); + this.wcpFlag = buffers.get(180); } public int size() { @@ -687,18 +729,14 @@ public int size() { return this.currentLine; } - public Trace absoluteTransactionNumber(final Bytes b) { + public Trace absoluteTransactionNumber(final int b) { if (filled.get(0)) { throw new IllegalStateException("hub.ABSOLUTE_TRANSACTION_NUMBER already set"); } else { filled.set(0); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - absoluteTransactionNumber.put((byte) 0); - } - absoluteTransactionNumber.put(b.toArrayUnsafe()); + absoluteTransactionNumber.putInt(b); return this; } @@ -727,50 +765,38 @@ public Trace accFirst(final Boolean b) { return this; } - public Trace batchNumber(final Bytes b) { + public Trace batchNumber(final int b) { if (filled.get(1)) { throw new IllegalStateException("hub.BATCH_NUMBER already set"); } else { filled.set(1); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - batchNumber.put((byte) 0); - } - batchNumber.put(b.toArrayUnsafe()); + batchNumber.putInt(b); return this; } - public Trace callerContextNumber(final Bytes b) { + public Trace callerContextNumber(final long b) { if (filled.get(2)) { throw new IllegalStateException("hub.CALLER_CONTEXT_NUMBER already set"); } else { filled.set(2); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - callerContextNumber.put((byte) 0); - } - callerContextNumber.put(b.toArrayUnsafe()); + callerContextNumber.putLong(b); return this; } - public Trace codeFragmentIndex(final Bytes b) { + public Trace codeFragmentIndex(final long b) { if (filled.get(3)) { throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX already set"); } else { filled.set(3); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndex.put((byte) 0); - } - codeFragmentIndex.put(b.toArrayUnsafe()); + codeFragmentIndex.putLong(b); return this; } @@ -823,50 +849,38 @@ public Trace contextMayChange(final Boolean b) { return this; } - public Trace contextNumber(final Bytes b) { + public Trace contextNumber(final long b) { if (filled.get(6)) { throw new IllegalStateException("hub.CONTEXT_NUMBER already set"); } else { filled.set(6); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - contextNumber.put((byte) 0); - } - contextNumber.put(b.toArrayUnsafe()); + contextNumber.putLong(b); return this; } - public Trace contextNumberNew(final Bytes b) { + public Trace contextNumberNew(final long b) { if (filled.get(7)) { throw new IllegalStateException("hub.CONTEXT_NUMBER_NEW already set"); } else { filled.set(7); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - contextNumberNew.put((byte) 0); - } - contextNumberNew.put(b.toArrayUnsafe()); + contextNumberNew.putLong(b); return this; } - public Trace contextRevertStamp(final Bytes b) { + public Trace contextRevertStamp(final long b) { if (filled.get(8)) { throw new IllegalStateException("hub.CONTEXT_REVERT_STAMP already set"); } else { filled.set(8); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - contextRevertStamp.put((byte) 0); - } - contextRevertStamp.put(b.toArrayUnsafe()); + contextRevertStamp.putLong(b); return this; } @@ -895,18 +909,14 @@ public Trace contextWillRevert(final Boolean b) { return this; } - public Trace counterNsr(final Bytes b) { + public Trace counterNsr(final short b) { if (filled.get(11)) { throw new IllegalStateException("hub.COUNTER_NSR already set"); } else { filled.set(11); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - counterNsr.put((byte) 0); - } - counterNsr.put(b.toArrayUnsafe()); + counterNsr.putShort(b); return this; } @@ -923,18 +933,14 @@ public Trace counterTli(final Boolean b) { return this; } - public Trace domStamp(final Bytes b) { + public Trace domStamp(final long b) { if (filled.get(13)) { throw new IllegalStateException("hub.DOM_STAMP already set"); } else { filled.set(13); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - domStamp.put((byte) 0); - } - domStamp.put(b.toArrayUnsafe()); + domStamp.putLong(b); return this; } @@ -951,18 +957,14 @@ public Trace exceptionAhoy(final Boolean b) { return this; } - public Trace gasActual(final Bytes b) { + public Trace gasActual(final long b) { if (filled.get(15)) { throw new IllegalStateException("hub.GAS_ACTUAL already set"); } else { filled.set(15); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasActual.put((byte) 0); - } - gasActual.put(b.toArrayUnsafe()); + gasActual.putLong(b); return this; } @@ -983,425 +985,340 @@ public Trace gasCost(final Bytes b) { return this; } - public Trace gasExpected(final Bytes b) { + public Trace gasExpected(final long b) { if (filled.get(17)) { throw new IllegalStateException("hub.GAS_EXPECTED already set"); } else { filled.set(17); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasExpected.put((byte) 0); - } - gasExpected.put(b.toArrayUnsafe()); + gasExpected.putLong(b); return this; } - public Trace gasNext(final Bytes b) { + public Trace gasNext(final long b) { if (filled.get(18)) { throw new IllegalStateException("hub.GAS_NEXT already set"); } else { filled.set(18); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - gasNext.put((byte) 0); - } - gasNext.put(b.toArrayUnsafe()); + gasNext.putLong(b); return this; } - public Trace hashInfoStamp(final Bytes b) { + public Trace hashInfoStamp(final long b) { if (filled.get(19)) { throw new IllegalStateException("hub.HASH_INFO_STAMP already set"); } else { filled.set(19); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - hashInfoStamp.put((byte) 0); - } - hashInfoStamp.put(b.toArrayUnsafe()); + hashInfoStamp.putLong(b); return this; } - public Trace height(final Bytes b) { + public Trace height(final short b) { if (filled.get(20)) { throw new IllegalStateException("hub.HEIGHT already set"); } else { filled.set(20); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - height.put((byte) 0); - } - height.put(b.toArrayUnsafe()); + height.putShort(b); return this; } - public Trace heightNew(final Bytes b) { + public Trace heightNew(final short b) { if (filled.get(21)) { throw new IllegalStateException("hub.HEIGHT_NEW already set"); } else { filled.set(21); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - heightNew.put((byte) 0); - } - heightNew.put(b.toArrayUnsafe()); + heightNew.putShort(b); return this; } - public Trace hubStamp(final Bytes b) { + public Trace hubStamp(final long b) { if (filled.get(22)) { throw new IllegalStateException("hub.HUB_STAMP already set"); } else { filled.set(22); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - hubStamp.put((byte) 0); - } - hubStamp.put(b.toArrayUnsafe()); + hubStamp.putLong(b); return this; } - public Trace hubStampTransactionEnd(final Bytes b) { + public Trace hubStampTransactionEnd(final long b) { if (filled.get(23)) { throw new IllegalStateException("hub.HUB_STAMP_TRANSACTION_END already set"); } else { filled.set(23); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - hubStampTransactionEnd.put((byte) 0); - } - hubStampTransactionEnd.put(b.toArrayUnsafe()); + hubStampTransactionEnd.putLong(b); return this; } - public Trace logInfoStamp(final Bytes b) { + public Trace logInfoStamp(final long b) { if (filled.get(24)) { throw new IllegalStateException("hub.LOG_INFO_STAMP already set"); } else { filled.set(24); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - logInfoStamp.put((byte) 0); - } - logInfoStamp.put(b.toArrayUnsafe()); + logInfoStamp.putLong(b); return this; } - public Trace mmuStamp(final Bytes b) { + public Trace mmuStamp(final long b) { if (filled.get(25)) { throw new IllegalStateException("hub.MMU_STAMP already set"); } else { filled.set(25); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mmuStamp.put((byte) 0); - } - mmuStamp.put(b.toArrayUnsafe()); + mmuStamp.putLong(b); return this; } - public Trace mxpStamp(final Bytes b) { + public Trace mxpStamp(final long b) { if (filled.get(26)) { throw new IllegalStateException("hub.MXP_STAMP already set"); } else { filled.set(26); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - mxpStamp.put((byte) 0); - } - mxpStamp.put(b.toArrayUnsafe()); + mxpStamp.putLong(b); return this; } - public Trace nonStackRows(final Bytes b) { + public Trace nonStackRows(final short b) { if (filled.get(27)) { throw new IllegalStateException("hub.NON_STACK_ROWS already set"); } else { filled.set(27); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonStackRows.put((byte) 0); - } - nonStackRows.put(b.toArrayUnsafe()); + nonStackRows.putShort(b); return this; } - public Trace pAccountAddressHi(final Bytes b) { - if (filled.get(118)) { + public Trace pAccountAddressHi(final long b) { + if (filled.get(107)) { throw new IllegalStateException("hub.account/ADDRESS_HI already set"); } else { - filled.set(118); + filled.set(107); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put((byte) 0); - } - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put(b.toArrayUnsafe()); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .putLong(b); return this; } public Trace pAccountAddressLo(final Bytes b) { - if (filled.get(119)) { + if (filled.get(132)) { throw new IllegalStateException("hub.account/ADDRESS_LO already set"); } else { - filled.set(119); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pAccountBalance(final Bytes b) { - if (filled.get(120)) { + if (filled.get(133)) { throw new IllegalStateException("hub.account/BALANCE already set"); } else { - filled.set(120); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pAccountBalanceNew(final Bytes b) { - if (filled.get(121)) { + if (filled.get(134)) { throw new IllegalStateException("hub.account/BALANCE_NEW already set"); } else { - filled.set(121); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } - public Trace pAccountCodeFragmentIndex(final Bytes b) { - if (filled.get(122)) { + public Trace pAccountCodeFragmentIndex(final long b) { + if (filled.get(108)) { throw new IllegalStateException("hub.account/CODE_FRAGMENT_INDEX already set"); } else { - filled.set(122); + filled.set(108); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put(b.toArrayUnsafe()); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } public Trace pAccountCodeHashHi(final Bytes b) { - if (filled.get(123)) { + if (filled.get(135)) { throw new IllegalStateException("hub.account/CODE_HASH_HI already set"); } else { - filled.set(123); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put((byte) 0); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pAccountCodeHashHiNew(final Bytes b) { - if (filled.get(124)) { + if (filled.get(136)) { throw new IllegalStateException("hub.account/CODE_HASH_HI_NEW already set"); } else { - filled.set(124); + filled.set(136); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put((byte) 0); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put(b.toArrayUnsafe()); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); return this; } public Trace pAccountCodeHashLo(final Bytes b) { - if (filled.get(125)) { + if (filled.get(137)) { throw new IllegalStateException("hub.account/CODE_HASH_LO already set"); } else { - filled.set(125); + filled.set(137); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put((byte) 0); + codeHashLoXorMmuLimb1XorValueNextHi.put((byte) 0); } - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put(b.toArrayUnsafe()); + codeHashLoXorMmuLimb1XorValueNextHi.put(b.toArrayUnsafe()); return this; } public Trace pAccountCodeHashLoNew(final Bytes b) { - if (filled.get(126)) { + if (filled.get(138)) { throw new IllegalStateException("hub.account/CODE_HASH_LO_NEW already set"); } else { - filled.set(126); + filled.set(138); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - (byte) 0); + codeHashLoNewXorMmuLimb2XorValueNextLo.put((byte) 0); } - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - b.toArrayUnsafe()); + codeHashLoNewXorMmuLimb2XorValueNextLo.put(b.toArrayUnsafe()); return this; } - public Trace pAccountCodeSize(final Bytes b) { - if (filled.get(127)) { + public Trace pAccountCodeSize(final long b) { + if (filled.get(109)) { throw new IllegalStateException("hub.account/CODE_SIZE already set"); } else { - filled.set(127); + filled.set(109); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - (byte) 0); - } - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - b.toArrayUnsafe()); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } - public Trace pAccountCodeSizeNew(final Bytes b) { - if (filled.get(128)) { + public Trace pAccountCodeSizeNew(final long b) { + if (filled.get(110)) { throw new IllegalStateException("hub.account/CODE_SIZE_NEW already set"); } else { - filled.set(128); + filled.set(110); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put((byte) 0); - } - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put(b.toArrayUnsafe()); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); return this; } - public Trace pAccountDeploymentNumber(final Bytes b) { - if (filled.get(129)) { + public Trace pAccountDeploymentNumber(final long b) { + if (filled.get(111)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER already set"); } else { - filled.set(129); + filled.set(111); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); return this; } - public Trace pAccountDeploymentNumberInfty(final Bytes b) { - if (filled.get(130)) { + public Trace pAccountDeploymentNumberInfty(final long b) { + if (filled.get(112)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(130); + filled.set(112); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - (byte) 0); - } - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - b.toArrayUnsafe()); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); return this; } - public Trace pAccountDeploymentNumberNew(final Bytes b) { - if (filled.get(131)) { + public Trace pAccountDeploymentNumberNew(final long b) { + if (filled.get(113)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_NEW already set"); } else { - filled.set(131); + filled.set(113); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put((byte) 0); - } - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put( - b.toArrayUnsafe()); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); return this; } @@ -1491,7 +1408,7 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( (byte) (b ? 1 : 0)); return this; @@ -1504,7 +1421,7 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(60); } - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -1517,7 +1434,7 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(61); } - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; @@ -1530,76 +1447,68 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( (byte) (b ? 1 : 0)); return this; } public Trace pAccountNonce(final Bytes b) { - if (filled.get(132)) { + if (filled.get(123)) { throw new IllegalStateException("hub.account/NONCE already set"); } else { - filled.set(132); + filled.set(123); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put((byte) 0); + nonceXorStpGasMxpXorBasefee.put((byte) 0); } - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put(b.toArrayUnsafe()); + nonceXorStpGasMxpXorBasefee.put(b.toArrayUnsafe()); return this; } public Trace pAccountNonceNew(final Bytes b) { - if (filled.get(133)) { + if (filled.get(124)) { throw new IllegalStateException("hub.account/NONCE_NEW already set"); } else { - filled.set(133); + filled.set(124); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put((byte) 0); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put( - b.toArrayUnsafe()); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(b.toArrayUnsafe()); return this; } - public Trace pAccountRlpaddrDepAddrHi(final Bytes b) { - if (filled.get(134)) { + public Trace pAccountRlpaddrDepAddrHi(final long b) { + if (filled.get(114)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_HI already set"); } else { - filled.set(134); + filled.set(114); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - (byte) 0); - } - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - b.toArrayUnsafe()); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); return this; } public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { - if (filled.get(135)) { + if (filled.get(139)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_LO already set"); } else { - filled.set(135); + filled.set(139); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put((byte) 0); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put((byte) 0); } - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put( - b.toArrayUnsafe()); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(b.toArrayUnsafe()); return this; } @@ -1611,433 +1520,365 @@ public Trace pAccountRlpaddrFlag(final Boolean b) { filled.set(63); } - rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountRlpaddrKecHi(final Bytes b) { - if (filled.get(136)) { + if (filled.get(140)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_HI already set"); } else { - filled.set(136); + filled.set(140); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - (byte) 0); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put((byte) 0); } - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - b.toArrayUnsafe()); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(b.toArrayUnsafe()); return this; } public Trace pAccountRlpaddrKecLo(final Bytes b) { - if (filled.get(137)) { + if (filled.get(141)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_LO already set"); } else { - filled.set(137); + filled.set(141); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put((byte) 0); + rlpaddrKecLoXorMmuTgtOffsetLo.put((byte) 0); } - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put(b.toArrayUnsafe()); + rlpaddrKecLoXorMmuTgtOffsetLo.put(b.toArrayUnsafe()); return this; } - public Trace pAccountRlpaddrRecipe(final Bytes b) { - if (filled.get(138)) { + public Trace pAccountRlpaddrRecipe(final Boolean b) { + if (filled.get(64)) { throw new IllegalStateException("hub.account/RLPADDR_RECIPE already set"); } else { - filled.set(138); + filled.set(64); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put((byte) 0); - } - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put(b.toArrayUnsafe()); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountRlpaddrSaltHi(final Bytes b) { - if (filled.get(139)) { + if (filled.get(142)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_HI already set"); } else { - filled.set(139); + filled.set(142); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.put((byte) 0); + rlpaddrSaltHiXorMxpGasMxp.put((byte) 0); } - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.put(b.toArrayUnsafe()); + rlpaddrSaltHiXorMxpGasMxp.put(b.toArrayUnsafe()); return this; } public Trace pAccountRlpaddrSaltLo(final Bytes b) { - if (filled.get(140)) { + if (filled.get(143)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_LO already set"); } else { - filled.set(140); + filled.set(143); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.put((byte) 0); + rlpaddrSaltLoXorMxpOffset1Hi.put((byte) 0); } - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.put(b.toArrayUnsafe()); + rlpaddrSaltLoXorMxpOffset1Hi.put(b.toArrayUnsafe()); return this; } public Trace pAccountRomLexFlag(final Boolean b) { - if (filled.get(64)) { + if (filled.get(65)) { throw new IllegalStateException("hub.account/ROM_LEX_FLAG already set"); } else { - filled.set(64); + filled.set(65); } - romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountTrmFlag(final Boolean b) { - if (filled.get(65)) { + if (filled.get(66)) { throw new IllegalStateException("hub.account/TRM_FLAG already set"); } else { - filled.set(65); + filled.set(66); } - trmFlagXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountTrmRawAddressHi(final Bytes b) { - if (filled.get(141)) { + if (filled.get(144)) { throw new IllegalStateException("hub.account/TRM_RAW_ADDRESS_HI already set"); } else { - filled.set(141); + filled.set(144); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - trmRawAddressHiXorOobData6XorStackItemValueLo2.put((byte) 0); + trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); } - trmRawAddressHiXorOobData6XorStackItemValueLo2.put(b.toArrayUnsafe()); + trmRawAddressHiXorMxpOffset1Lo.put(b.toArrayUnsafe()); return this; } public Trace pAccountWarmth(final Boolean b) { - if (filled.get(66)) { + if (filled.get(67)) { throw new IllegalStateException("hub.account/WARMTH already set"); } else { - filled.set(66); + filled.set(67); } - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountWarmthNew(final Boolean b) { - if (filled.get(67)) { + if (filled.get(68)) { throw new IllegalStateException("hub.account/WARMTH_NEW already set"); } else { - filled.set(67); + filled.set(68); } - warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); return this; } - public Trace pContextAccountAddressHi(final Bytes b) { - if (filled.get(118)) { + public Trace pContextAccountAddressHi(final long b) { + if (filled.get(107)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_HI already set"); } else { - filled.set(118); + filled.set(107); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put((byte) 0); - } - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put(b.toArrayUnsafe()); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .putLong(b); return this; } public Trace pContextAccountAddressLo(final Bytes b) { - if (filled.get(119)) { + if (filled.get(132)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_LO already set"); } else { - filled.set(119); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } - public Trace pContextAccountDeploymentNumber(final Bytes b) { - if (filled.get(120)) { + public Trace pContextAccountDeploymentNumber(final long b) { + if (filled.get(108)) { throw new IllegalStateException("hub.context/ACCOUNT_DEPLOYMENT_NUMBER already set"); } else { - filled.set(120); + filled.set(108); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put(b.toArrayUnsafe()); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } - public Trace pContextByteCodeAddressHi(final Bytes b) { - if (filled.get(121)) { + public Trace pContextByteCodeAddressHi(final long b) { + if (filled.get(109)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_HI already set"); } else { - filled.set(121); + filled.set(109); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } public Trace pContextByteCodeAddressLo(final Bytes b) { - if (filled.get(122)) { + if (filled.get(133)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_LO already set"); } else { - filled.set(122); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } - public Trace pContextByteCodeCodeFragmentIndex(final Bytes b) { - if (filled.get(123)) { + public Trace pContextByteCodeCodeFragmentIndex(final long b) { + if (filled.get(110)) { throw new IllegalStateException("hub.context/BYTE_CODE_CODE_FRAGMENT_INDEX already set"); } else { - filled.set(123); + filled.set(110); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put((byte) 0); - } - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put(b.toArrayUnsafe()); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); return this; } - public Trace pContextByteCodeDeploymentNumber(final Bytes b) { - if (filled.get(124)) { + public Trace pContextByteCodeDeploymentNumber(final long b) { + if (filled.get(111)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_NUMBER already set"); } else { - filled.set(124); + filled.set(111); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put(b.toArrayUnsafe()); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); return this; } - public Trace pContextByteCodeDeploymentStatus(final Bytes b) { - if (filled.get(125)) { + public Trace pContextByteCodeDeploymentStatus(final long b) { + if (filled.get(112)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_STATUS already set"); } else { - filled.set(125); + filled.set(112); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put((byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put(b.toArrayUnsafe()); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); return this; } - public Trace pContextCallDataContextNumber(final Bytes b) { - if (filled.get(128)) { + public Trace pContextCallDataContextNumber(final long b) { + if (filled.get(114)) { throw new IllegalStateException("hub.context/CALL_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(128); + filled.set(114); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put((byte) 0); - } - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put(b.toArrayUnsafe()); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); return this; } - public Trace pContextCallDataOffset(final Bytes b) { - if (filled.get(129)) { + public Trace pContextCallDataOffset(final long b) { + if (filled.get(115)) { throw new IllegalStateException("hub.context/CALL_DATA_OFFSET already set"); } else { - filled.set(129); + filled.set(115); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put((byte) 0); - } - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); + callDataOffsetXorMmuSize.putLong(b); return this; } - public Trace pContextCallDataSize(final Bytes b) { - if (filled.get(130)) { + public Trace pContextCallDataSize(final long b) { + if (filled.get(116)) { throw new IllegalStateException("hub.context/CALL_DATA_SIZE already set"); } else { - filled.set(130); + filled.set(116); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - (byte) 0); - } - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - b.toArrayUnsafe()); + callDataSizeXorMmuSrcId.putLong(b); return this; } - public Trace pContextCallStackDepth(final Bytes b) { - if (filled.get(131)) { + public Trace pContextCallStackDepth(final short b) { + if (filled.get(106)) { throw new IllegalStateException("hub.context/CALL_STACK_DEPTH already set"); } else { - filled.set(131); + filled.set(106); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put((byte) 0); - } - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put( - b.toArrayUnsafe()); + callStackDepth.putShort(b); return this; } public Trace pContextCallValue(final Bytes b) { - if (filled.get(132)) { + if (filled.get(135)) { throw new IllegalStateException("hub.context/CALL_VALUE already set"); } else { - filled.set(132); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put((byte) 0); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } - public Trace pContextCallerAddressHi(final Bytes b) { - if (filled.get(126)) { + public Trace pContextCallerAddressHi(final long b) { + if (filled.get(113)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_HI already set"); } else { - filled.set(126); + filled.set(113); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - (byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - b.toArrayUnsafe()); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); return this; } public Trace pContextCallerAddressLo(final Bytes b) { - if (filled.get(127)) { + if (filled.get(134)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_LO already set"); } else { - filled.set(127); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( b.toArrayUnsafe()); return this; } - public Trace pContextContextNumber(final Bytes b) { - if (filled.get(133)) { + public Trace pContextContextNumber(final long b) { + if (filled.get(117)) { throw new IllegalStateException("hub.context/CONTEXT_NUMBER already set"); } else { - filled.set(133); + filled.set(117); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put((byte) 0); - } - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put( - b.toArrayUnsafe()); + contextNumberXorMmuTgtId.putLong(b); return this; } @@ -2068,87 +1909,62 @@ public Trace pContextIsStatic(final Boolean b) { return this; } - public Trace pContextReturnAtCapacity(final Bytes b) { - if (filled.get(134)) { + public Trace pContextReturnAtCapacity(final long b) { + if (filled.get(118)) { throw new IllegalStateException("hub.context/RETURN_AT_CAPACITY already set"); } else { - filled.set(134); + filled.set(118); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - (byte) 0); - } - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - b.toArrayUnsafe()); + returnAtCapacityXorMxpInst.putLong(b); return this; } - public Trace pContextReturnAtOffset(final Bytes b) { - if (filled.get(135)) { + public Trace pContextReturnAtOffset(final long b) { + if (filled.get(119)) { throw new IllegalStateException("hub.context/RETURN_AT_OFFSET already set"); } else { - filled.set(135); + filled.set(119); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put((byte) 0); - } - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put( - b.toArrayUnsafe()); + returnAtOffsetXorOobInst.putLong(b); return this; } - public Trace pContextReturnDataContextNumber(final Bytes b) { - if (filled.get(136)) { + public Trace pContextReturnDataContextNumber(final long b) { + if (filled.get(120)) { throw new IllegalStateException("hub.context/RETURN_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(136); + filled.set(120); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - (byte) 0); - } - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - b.toArrayUnsafe()); + returnDataContextNumberXorStpGasStipend.putLong(b); return this; } - public Trace pContextReturnDataOffset(final Bytes b) { - if (filled.get(137)) { + public Trace pContextReturnDataOffset(final long b) { + if (filled.get(121)) { throw new IllegalStateException("hub.context/RETURN_DATA_OFFSET already set"); } else { - filled.set(137); + filled.set(121); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put((byte) 0); - } - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put(b.toArrayUnsafe()); + returnDataOffsetXorStpInstruction.putLong(b); return this; } - public Trace pContextReturnDataSize(final Bytes b) { - if (filled.get(138)) { + public Trace pContextReturnDataSize(final long b) { + if (filled.get(122)) { throw new IllegalStateException("hub.context/RETURN_DATA_SIZE already set"); } else { - filled.set(138); + filled.set(122); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put((byte) 0); - } - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put(b.toArrayUnsafe()); + returnDataSize.putLong(b); return this; } @@ -2166,18 +1982,15 @@ public Trace pContextUpdate(final Boolean b) { return this; } - public Trace pMiscCcrsStamp(final Bytes b) { - if (filled.get(118)) { + public Trace pMiscCcrsStamp(final long b) { + if (filled.get(107)) { throw new IllegalStateException("hub.misc/CCRS_STAMP already set"); } else { - filled.set(118); + filled.set(107); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put((byte) 0); - } - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put(b.toArrayUnsafe()); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -2196,89 +2009,88 @@ public Trace pMiscCcsrFlag(final Boolean b) { } public Trace pMiscExpData1(final Bytes b) { - if (filled.get(119)) { + if (filled.get(132)) { throw new IllegalStateException("hub.misc/EXP_DATA_1 already set"); } else { - filled.set(119); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pMiscExpData2(final Bytes b) { - if (filled.get(120)) { + if (filled.get(133)) { throw new IllegalStateException("hub.misc/EXP_DATA_2 already set"); } else { - filled.set(120); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pMiscExpData3(final Bytes b) { - if (filled.get(121)) { + if (filled.get(134)) { throw new IllegalStateException("hub.misc/EXP_DATA_3 already set"); } else { - filled.set(121); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } public Trace pMiscExpData4(final Bytes b) { - if (filled.get(122)) { + if (filled.get(135)) { throw new IllegalStateException("hub.misc/EXP_DATA_4 already set"); } else { - filled.set(122); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pMiscExpData5(final Bytes b) { - if (filled.get(123)) { + if (filled.get(136)) { throw new IllegalStateException("hub.misc/EXP_DATA_5 already set"); } else { - filled.set(123); + filled.set(136); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put((byte) 0); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put(b.toArrayUnsafe()); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); return this; } @@ -2297,37 +2109,39 @@ public Trace pMiscExpFlag(final Boolean b) { } public Trace pMiscExpInst(final long b) { - if (filled.get(102)) { + if (filled.get(108)) { throw new IllegalStateException("hub.misc/EXP_INST already set"); } else { - filled.set(102); + filled.set(108); } - expInstXorPrcCalleeGas.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } public Trace pMiscMmuAuxId(final long b) { - if (filled.get(103)) { + if (filled.get(109)) { throw new IllegalStateException("hub.misc/MMU_AUX_ID already set"); } else { - filled.set(103); + filled.set(109); } - mmuAuxIdXorPrcCallerGas.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } public Trace pMiscMmuExoSum(final long b) { - if (filled.get(104)) { + if (filled.get(110)) { throw new IllegalStateException("hub.misc/MMU_EXO_SUM already set"); } else { - filled.set(104); + filled.set(110); } - mmuExoSumXorPrcCdo.putLong(b); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); return this; } @@ -2346,137 +2160,137 @@ public Trace pMiscMmuFlag(final Boolean b) { } public Trace pMiscMmuInst(final long b) { - if (filled.get(105)) { + if (filled.get(111)) { throw new IllegalStateException("hub.misc/MMU_INST already set"); } else { - filled.set(105); + filled.set(111); } - mmuInstXorPrcCds.putLong(b); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); return this; } public Trace pMiscMmuLimb1(final Bytes b) { - if (filled.get(113)) { + if (filled.get(137)) { throw new IllegalStateException("hub.misc/MMU_LIMB_1 already set"); } else { - filled.set(113); + filled.set(137); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - mmuLimb1.put((byte) 0); + codeHashLoXorMmuLimb1XorValueNextHi.put((byte) 0); } - mmuLimb1.put(b.toArrayUnsafe()); + codeHashLoXorMmuLimb1XorValueNextHi.put(b.toArrayUnsafe()); return this; } public Trace pMiscMmuLimb2(final Bytes b) { - if (filled.get(114)) { + if (filled.get(138)) { throw new IllegalStateException("hub.misc/MMU_LIMB_2 already set"); } else { - filled.set(114); + filled.set(138); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - mmuLimb2.put((byte) 0); + codeHashLoNewXorMmuLimb2XorValueNextLo.put((byte) 0); } - mmuLimb2.put(b.toArrayUnsafe()); + codeHashLoNewXorMmuLimb2XorValueNextLo.put(b.toArrayUnsafe()); return this; } public Trace pMiscMmuPhase(final long b) { - if (filled.get(106)) { + if (filled.get(112)) { throw new IllegalStateException("hub.misc/MMU_PHASE already set"); } else { - filled.set(106); + filled.set(112); } - mmuPhaseXorPrcRac.putLong(b); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); return this; } public Trace pMiscMmuRefOffset(final long b) { - if (filled.get(107)) { + if (filled.get(113)) { throw new IllegalStateException("hub.misc/MMU_REF_OFFSET already set"); } else { - filled.set(107); + filled.set(113); } - mmuRefOffsetXorPrcRao.putLong(b); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); return this; } public Trace pMiscMmuRefSize(final long b) { - if (filled.get(108)) { + if (filled.get(114)) { throw new IllegalStateException("hub.misc/MMU_REF_SIZE already set"); } else { - filled.set(108); + filled.set(114); } - mmuRefSizeXorPrcReturnGas.putLong(b); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); return this; } public Trace pMiscMmuSize(final long b) { - if (filled.get(109)) { + if (filled.get(115)) { throw new IllegalStateException("hub.misc/MMU_SIZE already set"); } else { - filled.set(109); + filled.set(115); } - mmuSize.putLong(b); + callDataOffsetXorMmuSize.putLong(b); return this; } public Trace pMiscMmuSrcId(final long b) { - if (filled.get(110)) { + if (filled.get(116)) { throw new IllegalStateException("hub.misc/MMU_SRC_ID already set"); } else { - filled.set(110); + filled.set(116); } - mmuSrcId.putLong(b); + callDataSizeXorMmuSrcId.putLong(b); return this; } public Trace pMiscMmuSrcOffsetHi(final Bytes b) { - if (filled.get(115)) { + if (filled.get(139)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_HI already set"); } else { - filled.set(115); + filled.set(139); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - mmuSrcOffsetHi.put((byte) 0); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put((byte) 0); } - mmuSrcOffsetHi.put(b.toArrayUnsafe()); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(b.toArrayUnsafe()); return this; } public Trace pMiscMmuSrcOffsetLo(final Bytes b) { - if (filled.get(116)) { + if (filled.get(140)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_LO already set"); } else { - filled.set(116); + filled.set(140); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - mmuSrcOffsetLo.put((byte) 0); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put((byte) 0); } - mmuSrcOffsetLo.put(b.toArrayUnsafe()); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(b.toArrayUnsafe()); return this; } @@ -2495,29 +2309,29 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { } public Trace pMiscMmuTgtId(final long b) { - if (filled.get(111)) { + if (filled.get(117)) { throw new IllegalStateException("hub.misc/MMU_TGT_ID already set"); } else { - filled.set(111); + filled.set(117); } - mmuTgtId.putLong(b); + contextNumberXorMmuTgtId.putLong(b); return this; } public Trace pMiscMmuTgtOffsetLo(final Bytes b) { - if (filled.get(117)) { + if (filled.get(141)) { throw new IllegalStateException("hub.misc/MMU_TGT_OFFSET_LO already set"); } else { - filled.set(117); + filled.set(141); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - mmuTgtOffsetLo.put((byte) 0); + rlpaddrKecLoXorMmuTgtOffsetLo.put((byte) 0); } - mmuTgtOffsetLo.put(b.toArrayUnsafe()); + rlpaddrKecLoXorMmuTgtOffsetLo.put(b.toArrayUnsafe()); return this; } @@ -2549,431 +2363,402 @@ public Trace pMiscMxpFlag(final Boolean b) { } public Trace pMiscMxpGasMxp(final Bytes b) { - if (filled.get(124)) { + if (filled.get(142)) { throw new IllegalStateException("hub.misc/MXP_GAS_MXP already set"); } else { - filled.set(124); + filled.set(142); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put((byte) 0); + rlpaddrSaltHiXorMxpGasMxp.put((byte) 0); } - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put(b.toArrayUnsafe()); + rlpaddrSaltHiXorMxpGasMxp.put(b.toArrayUnsafe()); return this; } - public Trace pMiscMxpInst(final Bytes b) { - if (filled.get(125)) { + public Trace pMiscMxpInst(final long b) { + if (filled.get(118)) { throw new IllegalStateException("hub.misc/MXP_INST already set"); } else { - filled.set(125); + filled.set(118); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put((byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put(b.toArrayUnsafe()); + returnAtCapacityXorMxpInst.putLong(b); return this; } - public Trace pMiscMxpMtntop(final Bytes b) { - if (filled.get(126)) { + public Trace pMiscMxpMtntop(final Boolean b) { + if (filled.get(59)) { throw new IllegalStateException("hub.misc/MXP_MTNTOP already set"); } else { - filled.set(126); + filled.set(59); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - (byte) 0); - } - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - b.toArrayUnsafe()); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpMxpx(final Boolean b) { - if (filled.get(59)) { + if (filled.get(60)) { throw new IllegalStateException("hub.misc/MXP_MXPX already set"); } else { - filled.set(59); + filled.set(60); } - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( (byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpOffset1Hi(final Bytes b) { - if (filled.get(127)) { + if (filled.get(143)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_HI already set"); } else { - filled.set(127); + filled.set(143); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - (byte) 0); + rlpaddrSaltLoXorMxpOffset1Hi.put((byte) 0); } - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - b.toArrayUnsafe()); + rlpaddrSaltLoXorMxpOffset1Hi.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpOffset1Lo(final Bytes b) { - if (filled.get(128)) { + if (filled.get(144)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_LO already set"); } else { - filled.set(128); + filled.set(144); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put((byte) 0); + trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); } - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put(b.toArrayUnsafe()); + trmRawAddressHiXorMxpOffset1Lo.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpOffset2Hi(final Bytes b) { - if (filled.get(129)) { + if (filled.get(145)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_HI already set"); } else { - filled.set(129); + filled.set(145); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put((byte) 0); + mxpOffset2Hi.put((byte) 0); } - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); + mxpOffset2Hi.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpOffset2Lo(final Bytes b) { - if (filled.get(130)) { + if (filled.get(146)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_LO already set"); } else { - filled.set(130); + filled.set(146); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - (byte) 0); + mxpOffset2Lo.put((byte) 0); } - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - b.toArrayUnsafe()); + mxpOffset2Lo.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpSize1Hi(final Bytes b) { - if (filled.get(131)) { + if (filled.get(147)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_HI already set"); } else { - filled.set(131); + filled.set(147); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put((byte) 0); + mxpSize1Hi.put((byte) 0); } - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put( - b.toArrayUnsafe()); + mxpSize1Hi.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpSize1Lo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(148)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_LO already set"); } else { - filled.set(132); + filled.set(148); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put((byte) 0); + mxpSize1Lo.put((byte) 0); } - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put(b.toArrayUnsafe()); + mxpSize1Lo.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpSize2Hi(final Bytes b) { - if (filled.get(133)) { + if (filled.get(149)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_HI already set"); } else { - filled.set(133); + filled.set(149); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put((byte) 0); + mxpSize2Hi.put((byte) 0); } - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put( - b.toArrayUnsafe()); + mxpSize2Hi.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpSize2Lo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(150)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_LO already set"); } else { - filled.set(134); + filled.set(150); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - (byte) 0); + mxpSize2Lo.put((byte) 0); } - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - b.toArrayUnsafe()); + mxpSize2Lo.put(b.toArrayUnsafe()); return this; } public Trace pMiscMxpWords(final Bytes b) { - if (filled.get(135)) { + if (filled.get(151)) { throw new IllegalStateException("hub.misc/MXP_WORDS already set"); } else { - filled.set(135); + filled.set(151); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put((byte) 0); + mxpWords.put((byte) 0); } - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put( - b.toArrayUnsafe()); + mxpWords.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData1(final Bytes b) { - if (filled.get(136)) { + if (filled.get(152)) { throw new IllegalStateException("hub.misc/OOB_DATA_1 already set"); } else { - filled.set(136); + filled.set(152); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - (byte) 0); + oobData1.put((byte) 0); } - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - b.toArrayUnsafe()); + oobData1.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData2(final Bytes b) { - if (filled.get(137)) { + if (filled.get(153)) { throw new IllegalStateException("hub.misc/OOB_DATA_2 already set"); } else { - filled.set(137); + filled.set(153); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put((byte) 0); + oobData2.put((byte) 0); } - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put(b.toArrayUnsafe()); + oobData2.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData3(final Bytes b) { - if (filled.get(138)) { + if (filled.get(154)) { throw new IllegalStateException("hub.misc/OOB_DATA_3 already set"); } else { - filled.set(138); + filled.set(154); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put((byte) 0); + oobData3.put((byte) 0); } - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put(b.toArrayUnsafe()); + oobData3.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData4(final Bytes b) { - if (filled.get(139)) { + if (filled.get(155)) { throw new IllegalStateException("hub.misc/OOB_DATA_4 already set"); } else { - filled.set(139); + filled.set(155); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.put((byte) 0); + oobData4.put((byte) 0); } - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.put(b.toArrayUnsafe()); + oobData4.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData5(final Bytes b) { - if (filled.get(140)) { + if (filled.get(156)) { throw new IllegalStateException("hub.misc/OOB_DATA_5 already set"); } else { - filled.set(140); + filled.set(156); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.put((byte) 0); + oobData5.put((byte) 0); } - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.put(b.toArrayUnsafe()); + oobData5.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData6(final Bytes b) { - if (filled.get(141)) { + if (filled.get(157)) { throw new IllegalStateException("hub.misc/OOB_DATA_6 already set"); } else { - filled.set(141); + filled.set(157); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - trmRawAddressHiXorOobData6XorStackItemValueLo2.put((byte) 0); + oobData6.put((byte) 0); } - trmRawAddressHiXorOobData6XorStackItemValueLo2.put(b.toArrayUnsafe()); + oobData6.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData7(final Bytes b) { - if (filled.get(142)) { + if (filled.get(158)) { throw new IllegalStateException("hub.misc/OOB_DATA_7 already set"); } else { - filled.set(142); + filled.set(158); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - oobData7XorStackItemValueLo3.put((byte) 0); + oobData7.put((byte) 0); } - oobData7XorStackItemValueLo3.put(b.toArrayUnsafe()); + oobData7.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobData8(final Bytes b) { - if (filled.get(143)) { + if (filled.get(159)) { throw new IllegalStateException("hub.misc/OOB_DATA_8 already set"); } else { - filled.set(143); + filled.set(159); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - oobData8XorStackItemValueLo4.put((byte) 0); + oobData8.put((byte) 0); } - oobData8XorStackItemValueLo4.put(b.toArrayUnsafe()); + oobData8.put(b.toArrayUnsafe()); return this; } public Trace pMiscOobFlag(final Boolean b) { - if (filled.get(60)) { + if (filled.get(61)) { throw new IllegalStateException("hub.misc/OOB_FLAG already set"); } else { - filled.set(60); + filled.set(61); } - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; } public Trace pMiscOobInst(final long b) { - if (filled.get(112)) { + if (filled.get(119)) { throw new IllegalStateException("hub.misc/OOB_INST already set"); } else { - filled.set(112); + filled.set(119); } - oobInst.putLong(b); + returnAtOffsetXorOobInst.putLong(b); return this; } public Trace pMiscStpExists(final Boolean b) { - if (filled.get(61)) { + if (filled.get(62)) { throw new IllegalStateException("hub.misc/STP_EXISTS already set"); } else { - filled.set(61); + filled.set(62); } - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( (byte) (b ? 1 : 0)); return this; } public Trace pMiscStpFlag(final Boolean b) { - if (filled.get(62)) { + if (filled.get(63)) { throw new IllegalStateException("hub.misc/STP_FLAG already set"); } else { - filled.set(62); + filled.set(63); } - markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscStpGasHi(final Bytes b) { - if (filled.get(144)) { + if (filled.get(160)) { throw new IllegalStateException("hub.misc/STP_GAS_HI already set"); } else { - filled.set(144); + filled.set(160); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - stpGasHiXorStaticGas.put((byte) 0); + stpGasHi.put((byte) 0); } - stpGasHiXorStaticGas.put(b.toArrayUnsafe()); + stpGasHi.put(b.toArrayUnsafe()); return this; } public Trace pMiscStpGasLo(final Bytes b) { - if (filled.get(145)) { + if (filled.get(161)) { throw new IllegalStateException("hub.misc/STP_GAS_LO already set"); } else { - filled.set(145); + filled.set(161); } final byte[] bs = b.toArrayUnsafe(); @@ -2986,137 +2771,129 @@ public Trace pMiscStpGasLo(final Bytes b) { } public Trace pMiscStpGasMxp(final Bytes b) { - if (filled.get(146)) { + if (filled.get(123)) { throw new IllegalStateException("hub.misc/STP_GAS_MXP already set"); } else { - filled.set(146); + filled.set(123); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - stpGasMxp.put((byte) 0); + nonceXorStpGasMxpXorBasefee.put((byte) 0); } - stpGasMxp.put(b.toArrayUnsafe()); + nonceXorStpGasMxpXorBasefee.put(b.toArrayUnsafe()); return this; } public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { - if (filled.get(147)) { + if (filled.get(124)) { throw new IllegalStateException("hub.misc/STP_GAS_PAID_OUT_OF_POCKET already set"); } else { - filled.set(147); + filled.set(124); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - stpGasPaidOutOfPocket.put((byte) 0); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } - stpGasPaidOutOfPocket.put(b.toArrayUnsafe()); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(b.toArrayUnsafe()); return this; } - public Trace pMiscStpGasStipend(final Bytes b) { - if (filled.get(148)) { + public Trace pMiscStpGasStipend(final long b) { + if (filled.get(120)) { throw new IllegalStateException("hub.misc/STP_GAS_STIPEND already set"); } else { - filled.set(148); + filled.set(120); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpGasStipend.put((byte) 0); - } - stpGasStipend.put(b.toArrayUnsafe()); + returnDataContextNumberXorStpGasStipend.putLong(b); return this; } public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { - if (filled.get(149)) { + if (filled.get(125)) { throw new IllegalStateException("hub.misc/STP_GAS_UPFRONT_GAS_COST already set"); } else { - filled.set(149); + filled.set(125); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - stpGasUpfrontGasCost.put((byte) 0); + stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); } - stpGasUpfrontGasCost.put(b.toArrayUnsafe()); + stpGasUpfrontGasCostXorGasLeftover.put(b.toArrayUnsafe()); return this; } - public Trace pMiscStpInstruction(final Bytes b) { - if (filled.get(150)) { + public Trace pMiscStpInstruction(final long b) { + if (filled.get(121)) { throw new IllegalStateException("hub.misc/STP_INSTRUCTION already set"); } else { - filled.set(150); + filled.set(121); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpInstruction.put((byte) 0); - } - stpInstruction.put(b.toArrayUnsafe()); + returnDataOffsetXorStpInstruction.putLong(b); return this; } public Trace pMiscStpOogx(final Boolean b) { - if (filled.get(63)) { + if (filled.get(64)) { throw new IllegalStateException("hub.misc/STP_OOGX already set"); } else { - filled.set(63); + filled.set(64); } - rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } - public Trace pMiscStpValHi(final Bytes b) { - if (filled.get(151)) { - throw new IllegalStateException("hub.misc/STP_VAL_HI already set"); + public Trace pMiscStpValueHi(final Bytes b) { + if (filled.get(162)) { + throw new IllegalStateException("hub.misc/STP_VALUE_HI already set"); } else { - filled.set(151); + filled.set(162); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - stpValHi.put((byte) 0); + stpValueHi.put((byte) 0); } - stpValHi.put(b.toArrayUnsafe()); + stpValueHi.put(b.toArrayUnsafe()); return this; } - public Trace pMiscStpValLo(final Bytes b) { - if (filled.get(152)) { - throw new IllegalStateException("hub.misc/STP_VAL_LO already set"); + public Trace pMiscStpValueLo(final Bytes b) { + if (filled.get(163)) { + throw new IllegalStateException("hub.misc/STP_VALUE_LO already set"); } else { - filled.set(152); + filled.set(163); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - stpValLo.put((byte) 0); + stpValueLo.put((byte) 0); } - stpValLo.put(b.toArrayUnsafe()); + stpValueLo.put(b.toArrayUnsafe()); return this; } public Trace pMiscStpWarmth(final Boolean b) { - if (filled.get(64)) { + if (filled.get(65)) { throw new IllegalStateException("hub.misc/STP_WARMTH already set"); } else { - filled.set(64); + filled.set(65); } - romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3210,7 +2987,7 @@ public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( (byte) (b ? 1 : 0)); return this; @@ -3224,7 +3001,7 @@ public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { filled.set(60); } - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -3238,7 +3015,7 @@ public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { filled.set(61); } - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; @@ -3252,7 +3029,7 @@ public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( (byte) (b ? 1 : 0)); return this; @@ -3266,7 +3043,7 @@ public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { filled.set(63); } - rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); return this; } @@ -3278,7 +3055,7 @@ public Trace pScenarioCreateAbort(final Boolean b) { filled.set(64); } - romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } @@ -3291,7 +3068,7 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { filled.set(65); } - trmFlagXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3304,7 +3081,7 @@ public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { filled.set(66); } - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3316,7 +3093,7 @@ public Trace pScenarioCreateException(final Boolean b) { filled.set(67); } - warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3329,7 +3106,7 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { filled.set(68); } - createFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3413,49 +3190,52 @@ public Trace pScenarioPrcBlake2F(final Boolean b) { } public Trace pScenarioPrcCalleeGas(final long b) { - if (filled.get(102)) { + if (filled.get(107)) { throw new IllegalStateException("hub.scenario/PRC_CALLEE_GAS already set"); } else { - filled.set(102); + filled.set(107); } - expInstXorPrcCalleeGas.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .putLong(b); return this; } public Trace pScenarioPrcCallerGas(final long b) { - if (filled.get(103)) { + if (filled.get(108)) { throw new IllegalStateException("hub.scenario/PRC_CALLER_GAS already set"); } else { - filled.set(103); + filled.set(108); } - mmuAuxIdXorPrcCallerGas.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } public Trace pScenarioPrcCdo(final long b) { - if (filled.get(104)) { + if (filled.get(109)) { throw new IllegalStateException("hub.scenario/PRC_CDO already set"); } else { - filled.set(104); + filled.set(109); } - mmuExoSumXorPrcCdo.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } public Trace pScenarioPrcCds(final long b) { - if (filled.get(105)) { + if (filled.get(110)) { throw new IllegalStateException("hub.scenario/PRC_CDS already set"); } else { - filled.set(105); + filled.set(110); } - mmuInstXorPrcCds.putLong(b); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); return this; } @@ -3557,37 +3337,37 @@ public Trace pScenarioPrcModexp(final Boolean b) { } public Trace pScenarioPrcRac(final long b) { - if (filled.get(106)) { + if (filled.get(111)) { throw new IllegalStateException("hub.scenario/PRC_RAC already set"); } else { - filled.set(106); + filled.set(111); } - mmuPhaseXorPrcRac.putLong(b); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); return this; } public Trace pScenarioPrcRao(final long b) { - if (filled.get(107)) { + if (filled.get(112)) { throw new IllegalStateException("hub.scenario/PRC_RAO already set"); } else { - filled.set(107); + filled.set(112); } - mmuRefOffsetXorPrcRao.putLong(b); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); return this; } public Trace pScenarioPrcReturnGas(final long b) { - if (filled.get(108)) { + if (filled.get(113)) { throw new IllegalStateException("hub.scenario/PRC_RETURN_GAS already set"); } else { - filled.set(108); + filled.set(113); } - mmuRefSizeXorPrcReturnGas.putLong(b); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); return this; } @@ -3806,18 +3586,14 @@ public Trace pStackAddFlag(final Boolean b) { return this; } - public Trace pStackAlpha(final Bytes b) { - if (filled.get(118)) { + public Trace pStackAlpha(final UnsignedByte b) { + if (filled.get(102)) { throw new IllegalStateException("hub.stack/ALPHA already set"); } else { - filled.set(118); + filled.set(102); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put((byte) 0); - } - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put(b.toArrayUnsafe()); + alpha.put(b.toByte()); return this; } @@ -3881,7 +3657,7 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( (byte) (b ? 1 : 0)); return this; @@ -3894,7 +3670,7 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(60); } - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -3907,7 +3683,7 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(61); } - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; @@ -3920,7 +3696,7 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( (byte) (b ? 1 : 0)); return this; @@ -3933,7 +3709,7 @@ public Trace pStackDecFlag3(final Boolean b) { filled.set(63); } - rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); return this; } @@ -3945,23 +3721,19 @@ public Trace pStackDecFlag4(final Boolean b) { filled.set(64); } - romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } - public Trace pStackDelta(final Bytes b) { - if (filled.get(119)) { + public Trace pStackDelta(final UnsignedByte b) { + if (filled.get(103)) { throw new IllegalStateException("hub.stack/DELTA already set"); } else { - filled.set(119); + filled.set(103); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put((byte) 0); - } - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put(b.toArrayUnsafe()); + delta.put(b.toByte()); return this; } @@ -3973,7 +3745,7 @@ public Trace pStackDupFlag(final Boolean b) { filled.set(65); } - trmFlagXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3985,7 +3757,7 @@ public Trace pStackExtFlag(final Boolean b) { filled.set(66); } - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3997,7 +3769,7 @@ public Trace pStackHaltFlag(final Boolean b) { filled.set(67); } - warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4009,61 +3781,56 @@ public Trace pStackHashInfoFlag(final Boolean b) { filled.set(68); } - createFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pStackHashInfoKeccakHi(final Bytes b) { - if (filled.get(120)) { + if (filled.get(132)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_HI already set"); } else { - filled.set(120); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pStackHashInfoKeccakLo(final Bytes b) { - if (filled.get(121)) { + if (filled.get(133)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_LO already set"); } else { - filled.set(121); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } - public Trace pStackHashInfoSize(final Bytes b) { - if (filled.get(122)) { + public Trace pStackHashInfoSize(final long b) { + if (filled.get(107)) { throw new IllegalStateException("hub.stack/HASH_INFO_SIZE already set"); } else { - filled.set(122); + filled.set(107); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); - } - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put(b.toArrayUnsafe()); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4081,19 +3848,17 @@ public Trace pStackIcpx(final Boolean b) { } public Trace pStackInstruction(final Bytes b) { - if (filled.get(123)) { + if (filled.get(164)) { throw new IllegalStateException("hub.stack/INSTRUCTION already set"); } else { - filled.set(123); + filled.set(164); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put((byte) 0); + instruction.put((byte) 0); } - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put(b.toArrayUnsafe()); + instruction.put(b.toArrayUnsafe()); return this; } @@ -4255,38 +4020,26 @@ public Trace pStackMxpx(final Boolean b) { return this; } - public Trace pStackNbAdded(final Bytes b) { - if (filled.get(124)) { + public Trace pStackNbAdded(final UnsignedByte b) { + if (filled.get(104)) { throw new IllegalStateException("hub.stack/NB_ADDED already set"); } else { - filled.set(124); + filled.set(104); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put((byte) 0); - } - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put(b.toArrayUnsafe()); + nbAdded.put(b.toByte()); return this; } - public Trace pStackNbRemoved(final Bytes b) { - if (filled.get(125)) { + public Trace pStackNbRemoved(final UnsignedByte b) { + if (filled.get(105)) { throw new IllegalStateException("hub.stack/NB_REMOVED already set"); } else { - filled.set(125); + filled.set(105); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put((byte) 0); - } - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put(b.toArrayUnsafe()); + nbRemoved.put(b.toByte()); return this; } @@ -4316,36 +4069,35 @@ public Trace pStackOpcx(final Boolean b) { } public Trace pStackPushValueHi(final Bytes b) { - if (filled.get(126)) { + if (filled.get(134)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_HI already set"); } else { - filled.set(126); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( b.toArrayUnsafe()); return this; } public Trace pStackPushValueLo(final Bytes b) { - if (filled.get(127)) { + if (filled.get(135)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_LO already set"); } else { - filled.set(127); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - (byte) 0); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( b.toArrayUnsafe()); return this; @@ -4412,72 +4164,65 @@ public Trace pStackSstorex(final Boolean b) { } public Trace pStackStackItemHeight1(final Bytes b) { - if (filled.get(128)) { + if (filled.get(165)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_1 already set"); } else { - filled.set(128); + filled.set(165); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put((byte) 0); + stackItemHeight1.put((byte) 0); } - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put(b.toArrayUnsafe()); + stackItemHeight1.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemHeight2(final Bytes b) { - if (filled.get(129)) { + if (filled.get(166)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_2 already set"); } else { - filled.set(129); + filled.set(166); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put((byte) 0); + stackItemHeight2.put((byte) 0); } - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); + stackItemHeight2.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemHeight3(final Bytes b) { - if (filled.get(130)) { + if (filled.get(167)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_3 already set"); } else { - filled.set(130); + filled.set(167); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - (byte) 0); + stackItemHeight3.put((byte) 0); } - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - b.toArrayUnsafe()); + stackItemHeight3.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemHeight4(final Bytes b) { - if (filled.get(131)) { + if (filled.get(168)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_4 already set"); } else { - filled.set(131); + filled.set(168); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put((byte) 0); + stackItemHeight4.put((byte) 0); } - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put( - b.toArrayUnsafe()); + stackItemHeight4.put(b.toArrayUnsafe()); return this; } @@ -4531,199 +4276,193 @@ public Trace pStackStackItemPop4(final Boolean b) { } public Trace pStackStackItemStamp1(final Bytes b) { - if (filled.get(132)) { + if (filled.get(169)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_1 already set"); } else { - filled.set(132); + filled.set(169); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put((byte) 0); + stackItemStamp1.put((byte) 0); } - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put(b.toArrayUnsafe()); + stackItemStamp1.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemStamp2(final Bytes b) { - if (filled.get(133)) { + if (filled.get(170)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_2 already set"); } else { - filled.set(133); + filled.set(170); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put((byte) 0); + stackItemStamp2.put((byte) 0); } - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put( - b.toArrayUnsafe()); + stackItemStamp2.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemStamp3(final Bytes b) { - if (filled.get(134)) { + if (filled.get(171)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_3 already set"); } else { - filled.set(134); + filled.set(171); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - (byte) 0); + stackItemStamp3.put((byte) 0); } - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - b.toArrayUnsafe()); + stackItemStamp3.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemStamp4(final Bytes b) { - if (filled.get(135)) { + if (filled.get(172)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_4 already set"); } else { - filled.set(135); + filled.set(172); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put((byte) 0); + stackItemStamp4.put((byte) 0); } - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put( - b.toArrayUnsafe()); + stackItemStamp4.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueHi1(final Bytes b) { - if (filled.get(136)) { + if (filled.get(173)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_1 already set"); } else { - filled.set(136); + filled.set(173); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - (byte) 0); + stackItemValueHi1.put((byte) 0); } - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - b.toArrayUnsafe()); + stackItemValueHi1.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueHi2(final Bytes b) { - if (filled.get(137)) { + if (filled.get(174)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_2 already set"); } else { - filled.set(137); + filled.set(174); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put((byte) 0); + stackItemValueHi2.put((byte) 0); } - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put(b.toArrayUnsafe()); + stackItemValueHi2.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueHi3(final Bytes b) { - if (filled.get(138)) { + if (filled.get(175)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_3 already set"); } else { - filled.set(138); + filled.set(175); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put((byte) 0); + stackItemValueHi3.put((byte) 0); } - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.put(b.toArrayUnsafe()); + stackItemValueHi3.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueHi4(final Bytes b) { - if (filled.get(139)) { + if (filled.get(176)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_4 already set"); } else { - filled.set(139); + filled.set(176); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.put((byte) 0); + stackItemValueHi4.put((byte) 0); } - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.put(b.toArrayUnsafe()); + stackItemValueHi4.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueLo1(final Bytes b) { - if (filled.get(140)) { + if (filled.get(177)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_1 already set"); } else { - filled.set(140); + filled.set(177); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.put((byte) 0); + stackItemValueLo1.put((byte) 0); } - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.put(b.toArrayUnsafe()); + stackItemValueLo1.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueLo2(final Bytes b) { - if (filled.get(141)) { + if (filled.get(178)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_2 already set"); } else { - filled.set(141); + filled.set(178); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - trmRawAddressHiXorOobData6XorStackItemValueLo2.put((byte) 0); + stackItemValueLo2.put((byte) 0); } - trmRawAddressHiXorOobData6XorStackItemValueLo2.put(b.toArrayUnsafe()); + stackItemValueLo2.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueLo3(final Bytes b) { - if (filled.get(142)) { + if (filled.get(179)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_3 already set"); } else { - filled.set(142); + filled.set(179); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - oobData7XorStackItemValueLo3.put((byte) 0); + stackItemValueLo3.put((byte) 0); } - oobData7XorStackItemValueLo3.put(b.toArrayUnsafe()); + stackItemValueLo3.put(b.toArrayUnsafe()); return this; } public Trace pStackStackItemValueLo4(final Bytes b) { - if (filled.get(143)) { + if (filled.get(180)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_4 already set"); } else { - filled.set(143); + filled.set(180); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - oobData8XorStackItemValueLo4.put((byte) 0); + stackItemValueLo4.put((byte) 0); } - oobData8XorStackItemValueLo4.put(b.toArrayUnsafe()); + stackItemValueLo4.put(b.toArrayUnsafe()); return this; } @@ -4752,18 +4491,15 @@ public Trace pStackStaticFlag(final Boolean b) { return this; } - public Trace pStackStaticGas(final Bytes b) { - if (filled.get(144)) { + public Trace pStackStaticGas(final long b) { + if (filled.get(108)) { throw new IllegalStateException("hub.stack/STATIC_GAS already set"); } else { - filled.set(144); + filled.set(108); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - stpGasHiXorStaticGas.put((byte) 0); - } - stpGasHiXorStaticGas.put(b.toArrayUnsafe()); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -4840,106 +4576,95 @@ public Trace pStackWcpFlag(final Boolean b) { return this; } - public Trace pStorageAddressHi(final Bytes b) { - if (filled.get(118)) { + public Trace pStorageAddressHi(final long b) { + if (filled.get(107)) { throw new IllegalStateException("hub.storage/ADDRESS_HI already set"); } else { - filled.set(118); + filled.set(107); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put((byte) 0); - } - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put(b.toArrayUnsafe()); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .putLong(b); return this; } public Trace pStorageAddressLo(final Bytes b) { - if (filled.get(119)) { + if (filled.get(132)) { throw new IllegalStateException("hub.storage/ADDRESS_LO already set"); } else { - filled.set(119); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } - public Trace pStorageDeploymentNumber(final Bytes b) { - if (filled.get(120)) { + public Trace pStorageDeploymentNumber(final long b) { + if (filled.get(108)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER already set"); } else { - filled.set(120); + filled.set(108); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put(b.toArrayUnsafe()); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } - public Trace pStorageDeploymentNumberInfty(final Bytes b) { - if (filled.get(121)) { + public Trace pStorageDeploymentNumberInfty(final long b) { + if (filled.get(109)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(121); + filled.set(109); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } public Trace pStorageStorageKeyHi(final Bytes b) { - if (filled.get(122)) { + if (filled.get(133)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_HI already set"); } else { - filled.set(122); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pStorageStorageKeyLo(final Bytes b) { - if (filled.get(123)) { + if (filled.get(134)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_LO already set"); } else { - filled.set(123); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -4958,19 +4683,18 @@ public Trace pStorageValueCurrChanges(final Boolean b) { } public Trace pStorageValueCurrHi(final Bytes b) { - if (filled.get(124)) { + if (filled.get(135)) { throw new IllegalStateException("hub.storage/VALUE_CURR_HI already set"); } else { - filled.set(124); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put((byte) 0); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -5002,37 +4726,33 @@ public Trace pStorageValueCurrIsZero(final Boolean b) { } public Trace pStorageValueCurrLo(final Bytes b) { - if (filled.get(125)) { + if (filled.get(136)) { throw new IllegalStateException("hub.storage/VALUE_CURR_LO already set"); } else { - filled.set(125); + filled.set(136); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put((byte) 0); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put(b.toArrayUnsafe()); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); return this; } public Trace pStorageValueNextHi(final Bytes b) { - if (filled.get(126)) { + if (filled.get(137)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_HI already set"); } else { - filled.set(126); + filled.set(137); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - (byte) 0); + codeHashLoXorMmuLimb1XorValueNextHi.put((byte) 0); } - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - b.toArrayUnsafe()); + codeHashLoXorMmuLimb1XorValueNextHi.put(b.toArrayUnsafe()); return this; } @@ -5077,37 +4797,33 @@ public Trace pStorageValueNextIsZero(final Boolean b) { } public Trace pStorageValueNextLo(final Bytes b) { - if (filled.get(127)) { + if (filled.get(138)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_LO already set"); } else { - filled.set(127); + filled.set(138); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - (byte) 0); + codeHashLoNewXorMmuLimb2XorValueNextLo.put((byte) 0); } - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - b.toArrayUnsafe()); + codeHashLoNewXorMmuLimb2XorValueNextLo.put(b.toArrayUnsafe()); return this; } public Trace pStorageValueOrigHi(final Bytes b) { - if (filled.get(128)) { + if (filled.get(139)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_HI already set"); } else { - filled.set(128); + filled.set(139); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put((byte) 0); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put((byte) 0); } - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put(b.toArrayUnsafe()); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(b.toArrayUnsafe()); return this; } @@ -5119,26 +4835,24 @@ public Trace pStorageValueOrigIsZero(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( (byte) (b ? 1 : 0)); return this; } public Trace pStorageValueOrigLo(final Bytes b) { - if (filled.get(129)) { + if (filled.get(140)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_LO already set"); } else { - filled.set(129); + filled.set(140); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put((byte) 0); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put((byte) 0); } - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(b.toArrayUnsafe()); return this; } @@ -5150,7 +4864,7 @@ public Trace pStorageWarmth(final Boolean b) { filled.set(60); } - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -5163,94 +4877,81 @@ public Trace pStorageWarmthNew(final Boolean b) { filled.set(61); } - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; } public Trace pTransactionBasefee(final Bytes b) { - if (filled.get(118)) { + if (filled.get(123)) { throw new IllegalStateException("hub.transaction/BASEFEE already set"); } else { - filled.set(118); + filled.set(123); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put((byte) 0); + nonceXorStpGasMxpXorBasefee.put((byte) 0); } - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.put(b.toArrayUnsafe()); + nonceXorStpGasMxpXorBasefee.put(b.toArrayUnsafe()); return this; } - public Trace pTransactionBatchNum(final Bytes b) { - if (filled.get(119)) { + public Trace pTransactionBatchNum(final long b) { + if (filled.get(107)) { throw new IllegalStateException("hub.transaction/BATCH_NUM already set"); } else { - filled.set(119); + filled.set(107); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put((byte) 0); - } - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.put(b.toArrayUnsafe()); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .putLong(b); return this; } - public Trace pTransactionCallDataSize(final Bytes b) { - if (filled.get(120)) { + public Trace pTransactionCallDataSize(final long b) { + if (filled.get(108)) { throw new IllegalStateException("hub.transaction/CALL_DATA_SIZE already set"); } else { - filled.set(120); + filled.set(108); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put((byte) 0); - } - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize - .put(b.toArrayUnsafe()); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } - public Trace pTransactionCoinbaseAddressHi(final Bytes b) { - if (filled.get(121)) { + public Trace pTransactionCoinbaseAddressHi(final long b) { + if (filled.get(109)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_HI already set"); } else { - filled.set(121); + filled.set(109); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put((byte) 0); - } - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi - .put(b.toArrayUnsafe()); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } public Trace pTransactionCoinbaseAddressLo(final Bytes b) { - if (filled.get(122)) { + if (filled.get(132)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_LO already set"); } else { - filled.set(122); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo - .put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -5268,146 +4969,126 @@ public Trace pTransactionCopyTxcd(final Boolean b) { return this; } - public Trace pTransactionFromAddressHi(final Bytes b) { - if (filled.get(123)) { + public Trace pTransactionFromAddressHi(final long b) { + if (filled.get(110)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_HI already set"); } else { - filled.set(123); + filled.set(110); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put((byte) 0); - } - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .put(b.toArrayUnsafe()); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); return this; } public Trace pTransactionFromAddressLo(final Bytes b) { - if (filled.get(124)) { + if (filled.get(133)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_LO already set"); } else { - filled.set(124); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } public Trace pTransactionGasInitiallyAvailable(final Bytes b) { - if (filled.get(125)) { + if (filled.get(124)) { throw new IllegalStateException("hub.transaction/GAS_INITIALLY_AVAILABLE already set"); } else { - filled.set(125); + filled.set(124); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put((byte) 0); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .put(b.toArrayUnsafe()); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(b.toArrayUnsafe()); return this; } public Trace pTransactionGasLeftover(final Bytes b) { - if (filled.get(126)) { + if (filled.get(125)) { throw new IllegalStateException("hub.transaction/GAS_LEFTOVER already set"); } else { - filled.set(126); + filled.set(125); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - (byte) 0); + stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); } - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover.put( - b.toArrayUnsafe()); + stpGasUpfrontGasCostXorGasLeftover.put(b.toArrayUnsafe()); return this; } public Trace pTransactionGasLimit(final Bytes b) { - if (filled.get(127)) { + if (filled.get(126)) { throw new IllegalStateException("hub.transaction/GAS_LIMIT already set"); } else { - filled.set(127); + filled.set(126); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - (byte) 0); + gasLimit.put((byte) 0); } - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.put( - b.toArrayUnsafe()); + gasLimit.put(b.toArrayUnsafe()); return this; } public Trace pTransactionGasPrice(final Bytes b) { - if (filled.get(128)) { + if (filled.get(127)) { throw new IllegalStateException("hub.transaction/GAS_PRICE already set"); } else { - filled.set(128); + filled.set(127); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put((byte) 0); + gasPrice.put((byte) 0); } - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .put(b.toArrayUnsafe()); + gasPrice.put(b.toArrayUnsafe()); return this; } - public Trace pTransactionInitCodeSize(final Bytes b) { - if (filled.get(130)) { + public Trace pTransactionInitCodeSize(final long b) { + if (filled.get(111)) { throw new IllegalStateException("hub.transaction/INIT_CODE_SIZE already set"); } else { - filled.set(130); + filled.set(111); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - (byte) 0); - } - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize.put( - b.toArrayUnsafe()); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); return this; } public Trace pTransactionInitialBalance(final Bytes b) { - if (filled.get(129)) { + if (filled.get(134)) { throw new IllegalStateException("hub.transaction/INITIAL_BALANCE already set"); } else { - filled.set(129); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -5439,69 +5120,65 @@ public Trace pTransactionIsType2(final Boolean b) { } public Trace pTransactionNonce(final Bytes b) { - if (filled.get(131)) { + if (filled.get(128)) { throw new IllegalStateException("hub.transaction/NONCE already set"); } else { - filled.set(131); + filled.set(128); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put((byte) 0); + nonce.put((byte) 0); } - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.put( - b.toArrayUnsafe()); + nonce.put(b.toArrayUnsafe()); return this; } public Trace pTransactionPriorityFeePerGas(final Bytes b) { - if (filled.get(132)) { + if (filled.get(129)) { throw new IllegalStateException("hub.transaction/PRIORITY_FEE_PER_GAS already set"); } else { - filled.set(132); + filled.set(129); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put((byte) 0); + priorityFeePerGas.put((byte) 0); } - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.put(b.toArrayUnsafe()); + priorityFeePerGas.put(b.toArrayUnsafe()); return this; } public Trace pTransactionRefundCounterInfinity(final Bytes b) { - if (filled.get(133)) { + if (filled.get(130)) { throw new IllegalStateException("hub.transaction/REFUND_COUNTER_INFINITY already set"); } else { - filled.set(133); + filled.set(130); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put((byte) 0); + refundCounterInfinity.put((byte) 0); } - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.put( - b.toArrayUnsafe()); + refundCounterInfinity.put(b.toArrayUnsafe()); return this; } public Trace pTransactionRefundEffective(final Bytes b) { - if (filled.get(134)) { + if (filled.get(131)) { throw new IllegalStateException("hub.transaction/REFUND_EFFECTIVE already set"); } else { - filled.set(134); + filled.set(131); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - (byte) 0); + refundEffective.put((byte) 0); } - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.put( - b.toArrayUnsafe()); + refundEffective.put(b.toArrayUnsafe()); return this; } @@ -5532,53 +5209,47 @@ public Trace pTransactionStatusCode(final Boolean b) { return this; } - public Trace pTransactionToAddressHi(final Bytes b) { - if (filled.get(135)) { + public Trace pTransactionToAddressHi(final long b) { + if (filled.get(112)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_HI already set"); } else { - filled.set(135); + filled.set(112); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put((byte) 0); - } - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.put( - b.toArrayUnsafe()); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); return this; } public Trace pTransactionToAddressLo(final Bytes b) { - if (filled.get(136)) { + if (filled.get(135)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_LO already set"); } else { - filled.set(136); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( - (byte) 0); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.put( + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( b.toArrayUnsafe()); return this; } public Trace pTransactionValue(final Bytes b) { - if (filled.get(137)) { + if (filled.get(136)) { throw new IllegalStateException("hub.transaction/VALUE already set"); } else { - filled.set(137); + filled.set(136); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put((byte) 0); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.put(b.toArrayUnsafe()); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); return this; } @@ -5667,66 +5338,50 @@ public Trace peekAtTransaction(final Boolean b) { return this; } - public Trace programCounter(final Bytes b) { + public Trace programCounter(final long b) { if (filled.get(35)) { throw new IllegalStateException("hub.PROGRAM_COUNTER already set"); } else { filled.set(35); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - programCounter.put((byte) 0); - } - programCounter.put(b.toArrayUnsafe()); + programCounter.putLong(b); return this; } - public Trace programCounterNew(final Bytes b) { + public Trace programCounterNew(final long b) { if (filled.get(36)) { throw new IllegalStateException("hub.PROGRAM_COUNTER_NEW already set"); } else { filled.set(36); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - programCounterNew.put((byte) 0); - } - programCounterNew.put(b.toArrayUnsafe()); + programCounterNew.putLong(b); return this; } - public Trace refundCounter(final Bytes b) { + public Trace refundCounter(final long b) { if (filled.get(37)) { throw new IllegalStateException("hub.REFUND_COUNTER already set"); } else { filled.set(37); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - refundCounter.put((byte) 0); - } - refundCounter.put(b.toArrayUnsafe()); + refundCounter.putLong(b); return this; } - public Trace refundCounterNew(final Bytes b) { + public Trace refundCounterNew(final long b) { if (filled.get(38)) { throw new IllegalStateException("hub.REFUND_COUNTER_NEW already set"); } else { filled.set(38); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - refundCounterNew.put((byte) 0); - } - refundCounterNew.put(b.toArrayUnsafe()); + refundCounterNew.putLong(b); return this; } @@ -5755,18 +5410,14 @@ public Trace stoFirst(final Boolean b) { return this; } - public Trace subStamp(final Bytes b) { + public Trace subStamp(final long b) { if (filled.get(39)) { throw new IllegalStateException("hub.SUB_STAMP already set"); } else { filled.set(39); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - subStamp.put((byte) 0); - } - subStamp.put(b.toArrayUnsafe()); + subStamp.putLong(b); return this; } @@ -5868,30 +5519,46 @@ public Trace validateRow() { throw new IllegalStateException("hub.acc_FIRST has not been filled"); } - if (!filled.get(118)) { + if (!filled.get(107)) { throw new IllegalStateException( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_ALPHA_xor_ADDRESS_HI_xor_BASEFEE has not been filled"); + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_HASH_INFO_SIZE_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } - if (!filled.get(119)) { + if (!filled.get(132)) { throw new IllegalStateException( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_DELTA_xor_ADDRESS_LO_xor_BATCH_NUM has not been filled"); + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } - if (!filled.get(121)) { + if (!filled.get(102)) { + throw new IllegalStateException("hub.ALPHA has not been filled"); + } + + if (!filled.get(134)) { throw new IllegalStateException( - "hub.BALANCE_NEW_xor_BYTE_CODE_ADDRESS_HI_xor_EXP_DATA_3_xor_HASH_INFO_KECCAK_LO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } - if (!filled.get(120)) { + if (!filled.get(133)) { throw new IllegalStateException( - "hub.BALANCE_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_HI_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } if (!filled.get(1)) { throw new IllegalStateException("hub.BATCH_NUMBER has not been filled"); } + if (!filled.get(115)) { + throw new IllegalStateException("hub.CALL_DATA_OFFSET_xor_MMU_SIZE has not been filled"); + } + + if (!filled.get(116)) { + throw new IllegalStateException("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID has not been filled"); + } + + if (!filled.get(106)) { + throw new IllegalStateException("hub.CALL_STACK_DEPTH has not been filled"); + } + if (!filled.get(2)) { throw new IllegalStateException("hub.CALLER_CONTEXT_NUMBER has not been filled"); } @@ -5900,39 +5567,39 @@ public Trace validateRow() { throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX has not been filled"); } - if (!filled.get(122)) { + if (!filled.get(108)) { throw new IllegalStateException( - "hub.CODE_FRAGMENT_INDEX_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_4_xor_HASH_INFO_SIZE_xor_STORAGE_KEY_HI_xor_COINBASE_ADDRESS_LO has not been filled"); + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_STATIC_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } - if (!filled.get(124)) { + if (!filled.get(136)) { throw new IllegalStateException( - "hub.CODE_HASH_HI_NEW_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MXP_GAS_MXP_xor_NB_ADDED_xor_VALUE_CURR_HI_xor_FROM_ADDRESS_LO has not been filled"); + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } - if (!filled.get(123)) { + if (!filled.get(135)) { throw new IllegalStateException( - "hub.CODE_HASH_HI_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_EXP_DATA_5_xor_INSTRUCTION_xor_STORAGE_KEY_LO_xor_FROM_ADDRESS_HI has not been filled"); + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } - if (!filled.get(126)) { + if (!filled.get(138)) { throw new IllegalStateException( - "hub.CODE_HASH_LO_NEW_xor_CALLER_ADDRESS_HI_xor_MXP_MTNTOP_xor_PUSH_VALUE_HI_xor_VALUE_NEXT_HI_xor_GAS_LEFTOVER has not been filled"); + "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } - if (!filled.get(125)) { + if (!filled.get(137)) { throw new IllegalStateException( - "hub.CODE_HASH_LO_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MXP_INST_xor_NB_REMOVED_xor_VALUE_CURR_LO_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } - if (!filled.get(128)) { + if (!filled.get(110)) { throw new IllegalStateException( - "hub.CODE_SIZE_NEW_xor_CALL_DATA_CONTEXT_NUMBER_xor_MXP_OFFSET_1_LO_xor_STACK_ITEM_HEIGHT_1_xor_VALUE_ORIG_HI_xor_GAS_PRICE has not been filled"); + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } - if (!filled.get(127)) { + if (!filled.get(109)) { throw new IllegalStateException( - "hub.CODE_SIZE_xor_CALLER_ADDRESS_LO_xor_MXP_OFFSET_1_HI_xor_PUSH_VALUE_LO_xor_VALUE_NEXT_LO_xor_GAS_LIMIT has not been filled"); + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); } if (!filled.get(49)) { @@ -5959,6 +5626,10 @@ public Trace validateRow() { throw new IllegalStateException("hub.CONTEXT_NUMBER_NEW has not been filled"); } + if (!filled.get(117)) { + throw new IllegalStateException("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID has not been filled"); + } + if (!filled.get(8)) { throw new IllegalStateException("hub.CONTEXT_REVERT_STAMP has not been filled"); } @@ -5979,11 +5650,6 @@ public Trace validateRow() { throw new IllegalStateException("hub.COUNTER_TLI has not been filled"); } - if (!filled.get(68)) { - throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); - } - if (!filled.get(69)) { throw new IllegalStateException( "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); @@ -6009,19 +5675,23 @@ public Trace validateRow() { "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); } - if (!filled.get(130)) { + if (!filled.get(103)) { + throw new IllegalStateException("hub.DELTA has not been filled"); + } + + if (!filled.get(112)) { throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_CALL_DATA_SIZE_xor_MXP_OFFSET_2_LO_xor_STACK_ITEM_HEIGHT_3_xor_INIT_CODE_SIZE has not been filled"); + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } - if (!filled.get(131)) { + if (!filled.get(113)) { throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALL_STACK_DEPTH_xor_MXP_SIZE_1_HI_xor_STACK_ITEM_HEIGHT_4_xor_NONCE has not been filled"); + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } - if (!filled.get(129)) { + if (!filled.get(111)) { throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_xor_CALL_DATA_OFFSET_xor_MXP_OFFSET_2_HI_xor_STACK_ITEM_HEIGHT_2_xor_VALUE_ORIG_LO_xor_INITIAL_BALANCE has not been filled"); + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } if (!filled.get(54)) { @@ -6057,10 +5727,6 @@ public Trace validateRow() { "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); } - if (!filled.get(102)) { - throw new IllegalStateException("hub.EXP_INST_xor_PRC_CALLEE_GAS has not been filled"); - } - if (!filled.get(15)) { throw new IllegalStateException("hub.GAS_ACTUAL has not been filled"); } @@ -6073,13 +5739,21 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_EXPECTED has not been filled"); } + if (!filled.get(126)) { + throw new IllegalStateException("hub.GAS_LIMIT has not been filled"); + } + if (!filled.get(18)) { throw new IllegalStateException("hub.GAS_NEXT has not been filled"); } + if (!filled.get(127)) { + throw new IllegalStateException("hub.GAS_PRICE has not been filled"); + } + if (!filled.get(59)) { throw new IllegalStateException( - "hub.HAS_CODE_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(58)) { @@ -6107,9 +5781,13 @@ public Trace validateRow() { throw new IllegalStateException("hub.HUB_STAMP_TRANSACTION_END has not been filled"); } + if (!filled.get(164)) { + throw new IllegalStateException("hub.INSTRUCTION has not been filled"); + } + if (!filled.get(60)) { throw new IllegalStateException( - "hub.IS_PRECOMPILE_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); } if (!filled.get(24)) { @@ -6118,104 +5796,105 @@ public Trace validateRow() { if (!filled.get(62)) { throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); } if (!filled.get(61)) { throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_xor_STP_EXISTS_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); } - if (!filled.get(103)) { - throw new IllegalStateException("hub.MMU_AUX_ID_xor_PRC_CALLER_GAS has not been filled"); + if (!filled.get(25)) { + throw new IllegalStateException("hub.MMU_STAMP has not been filled"); } - if (!filled.get(104)) { - throw new IllegalStateException("hub.MMU_EXO_SUM_xor_PRC_CDO has not been filled"); + if (!filled.get(145)) { + throw new IllegalStateException("hub.MXP_OFFSET_2_HI has not been filled"); } - if (!filled.get(105)) { - throw new IllegalStateException("hub.MMU_INST_xor_PRC_CDS has not been filled"); + if (!filled.get(146)) { + throw new IllegalStateException("hub.MXP_OFFSET_2_LO has not been filled"); } - if (!filled.get(113)) { - throw new IllegalStateException("hub.MMU_LIMB_1 has not been filled"); + if (!filled.get(147)) { + throw new IllegalStateException("hub.MXP_SIZE_1_HI has not been filled"); } - if (!filled.get(114)) { - throw new IllegalStateException("hub.MMU_LIMB_2 has not been filled"); + if (!filled.get(148)) { + throw new IllegalStateException("hub.MXP_SIZE_1_LO has not been filled"); } - if (!filled.get(106)) { - throw new IllegalStateException("hub.MMU_PHASE_xor_PRC_RAC has not been filled"); + if (!filled.get(149)) { + throw new IllegalStateException("hub.MXP_SIZE_2_HI has not been filled"); } - if (!filled.get(107)) { - throw new IllegalStateException("hub.MMU_REF_OFFSET_xor_PRC_RAO has not been filled"); + if (!filled.get(150)) { + throw new IllegalStateException("hub.MXP_SIZE_2_LO has not been filled"); } - if (!filled.get(108)) { - throw new IllegalStateException("hub.MMU_REF_SIZE_xor_PRC_RETURN_GAS has not been filled"); + if (!filled.get(26)) { + throw new IllegalStateException("hub.MXP_STAMP has not been filled"); } - if (!filled.get(109)) { - throw new IllegalStateException("hub.MMU_SIZE has not been filled"); + if (!filled.get(151)) { + throw new IllegalStateException("hub.MXP_WORDS has not been filled"); } - if (!filled.get(110)) { - throw new IllegalStateException("hub.MMU_SRC_ID has not been filled"); + if (!filled.get(104)) { + throw new IllegalStateException("hub.NB_ADDED has not been filled"); } - if (!filled.get(115)) { - throw new IllegalStateException("hub.MMU_SRC_OFFSET_HI has not been filled"); + if (!filled.get(105)) { + throw new IllegalStateException("hub.NB_REMOVED has not been filled"); } - if (!filled.get(116)) { - throw new IllegalStateException("hub.MMU_SRC_OFFSET_LO has not been filled"); + if (!filled.get(27)) { + throw new IllegalStateException("hub.NON_STACK_ROWS has not been filled"); } - if (!filled.get(25)) { - throw new IllegalStateException("hub.MMU_STAMP has not been filled"); + if (!filled.get(128)) { + throw new IllegalStateException("hub.NONCE has not been filled"); } - if (!filled.get(111)) { - throw new IllegalStateException("hub.MMU_TGT_ID has not been filled"); + if (!filled.get(124)) { + throw new IllegalStateException( + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } - if (!filled.get(117)) { - throw new IllegalStateException("hub.MMU_TGT_OFFSET_LO has not been filled"); + if (!filled.get(123)) { + throw new IllegalStateException("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE has not been filled"); } - if (!filled.get(26)) { - throw new IllegalStateException("hub.MXP_STAMP has not been filled"); + if (!filled.get(152)) { + throw new IllegalStateException("hub.OOB_DATA_1 has not been filled"); } - if (!filled.get(27)) { - throw new IllegalStateException("hub.NON_STACK_ROWS has not been filled"); + if (!filled.get(153)) { + throw new IllegalStateException("hub.OOB_DATA_2 has not been filled"); } - if (!filled.get(133)) { - throw new IllegalStateException( - "hub.NONCE_NEW_xor_CONTEXT_NUMBER_xor_MXP_SIZE_2_HI_xor_STACK_ITEM_STAMP_2_xor_REFUND_COUNTER_INFINITY has not been filled"); + if (!filled.get(154)) { + throw new IllegalStateException("hub.OOB_DATA_3 has not been filled"); } - if (!filled.get(132)) { - throw new IllegalStateException( - "hub.NONCE_xor_CALL_VALUE_xor_MXP_SIZE_1_LO_xor_STACK_ITEM_STAMP_1_xor_PRIORITY_FEE_PER_GAS has not been filled"); + if (!filled.get(155)) { + throw new IllegalStateException("hub.OOB_DATA_4 has not been filled"); } - if (!filled.get(142)) { - throw new IllegalStateException( - "hub.OOB_DATA_7_xor_STACK_ITEM_VALUE_LO_3 has not been filled"); + if (!filled.get(156)) { + throw new IllegalStateException("hub.OOB_DATA_5 has not been filled"); } - if (!filled.get(143)) { - throw new IllegalStateException( - "hub.OOB_DATA_8_xor_STACK_ITEM_VALUE_LO_4 has not been filled"); + if (!filled.get(157)) { + throw new IllegalStateException("hub.OOB_DATA_6 has not been filled"); } - if (!filled.get(112)) { - throw new IllegalStateException("hub.OOB_INST has not been filled"); + if (!filled.get(158)) { + throw new IllegalStateException("hub.OOB_DATA_7 has not been filled"); + } + + if (!filled.get(159)) { + throw new IllegalStateException("hub.OOB_DATA_8 has not been filled"); } if (!filled.get(28)) { @@ -6302,6 +5981,10 @@ public Trace validateRow() { throw new IllegalStateException("hub.PRC_SUCCESS_WONT_REVERT_xor_RDCX has not been filled"); } + if (!filled.get(129)) { + throw new IllegalStateException("hub.PRIORITY_FEE_PER_GAS has not been filled"); + } + if (!filled.get(35)) { throw new IllegalStateException("hub.PROGRAM_COUNTER has not been filled"); } @@ -6314,10 +5997,40 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER has not been filled"); } + if (!filled.get(130)) { + throw new IllegalStateException("hub.REFUND_COUNTER_INFINITY has not been filled"); + } + if (!filled.get(38)) { throw new IllegalStateException("hub.REFUND_COUNTER_NEW has not been filled"); } + if (!filled.get(131)) { + throw new IllegalStateException("hub.REFUND_EFFECTIVE has not been filled"); + } + + if (!filled.get(118)) { + throw new IllegalStateException("hub.RETURN_AT_CAPACITY_xor_MXP_INST has not been filled"); + } + + if (!filled.get(119)) { + throw new IllegalStateException("hub.RETURN_AT_OFFSET_xor_OOB_INST has not been filled"); + } + + if (!filled.get(120)) { + throw new IllegalStateException( + "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + } + + if (!filled.get(121)) { + throw new IllegalStateException( + "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + } + + if (!filled.get(122)) { + throw new IllegalStateException("hub.RETURN_DATA_SIZE has not been filled"); + } + if (!filled.get(87)) { throw new IllegalStateException("hub.RETURN_EXCEPTION_xor_SHF_FLAG has not been filled"); } @@ -6352,49 +6065,48 @@ public Trace validateRow() { "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } - if (!filled.get(134)) { + if (!filled.get(114)) { throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_HI_xor_RETURN_AT_CAPACITY_xor_MXP_SIZE_2_LO_xor_STACK_ITEM_STAMP_3_xor_REFUND_EFFECTIVE has not been filled"); + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } - if (!filled.get(135)) { + if (!filled.get(139)) { throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_LO_xor_RETURN_AT_OFFSET_xor_MXP_WORDS_xor_STACK_ITEM_STAMP_4_xor_TO_ADDRESS_HI has not been filled"); + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } if (!filled.get(63)) { throw new IllegalStateException( - "hub.RLPADDR_FLAG_xor_STP_OOGX_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); } - if (!filled.get(136)) { + if (!filled.get(140)) { throw new IllegalStateException( - "hub.RLPADDR_KEC_HI_xor_RETURN_DATA_CONTEXT_NUMBER_xor_OOB_DATA_1_xor_STACK_ITEM_VALUE_HI_1_xor_TO_ADDRESS_LO has not been filled"); + "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } - if (!filled.get(137)) { + if (!filled.get(141)) { throw new IllegalStateException( - "hub.RLPADDR_KEC_LO_xor_RETURN_DATA_OFFSET_xor_OOB_DATA_2_xor_STACK_ITEM_VALUE_HI_2_xor_VALUE has not been filled"); + "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } - if (!filled.get(138)) { + if (!filled.get(64)) { throw new IllegalStateException( - "hub.RLPADDR_RECIPE_xor_RETURN_DATA_SIZE_xor_OOB_DATA_3_xor_STACK_ITEM_VALUE_HI_3 has not been filled"); + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } - if (!filled.get(139)) { - throw new IllegalStateException( - "hub.RLPADDR_SALT_HI_xor_OOB_DATA_4_xor_STACK_ITEM_VALUE_HI_4 has not been filled"); + if (!filled.get(142)) { + throw new IllegalStateException("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP has not been filled"); } - if (!filled.get(140)) { + if (!filled.get(143)) { throw new IllegalStateException( - "hub.RLPADDR_SALT_LO_xor_OOB_DATA_5_xor_STACK_ITEM_VALUE_LO_1 has not been filled"); + "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } - if (!filled.get(64)) { + if (!filled.get(65)) { throw new IllegalStateException( - "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } if (!filled.get(94)) { @@ -6417,48 +6129,97 @@ public Trace validateRow() { "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } - if (!filled.get(51)) { - throw new IllegalStateException("hub.sto_FINAL has not been filled"); + if (!filled.get(165)) { + throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_1 has not been filled"); } - if (!filled.get(52)) { - throw new IllegalStateException("hub.sto_FIRST has not been filled"); + if (!filled.get(166)) { + throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_2 has not been filled"); } - if (!filled.get(144)) { - throw new IllegalStateException("hub.STP_GAS_HI_xor_STATIC_GAS has not been filled"); + if (!filled.get(167)) { + throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_3 has not been filled"); } - if (!filled.get(145)) { - throw new IllegalStateException("hub.STP_GAS_LO has not been filled"); + if (!filled.get(168)) { + throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_4 has not been filled"); + } + + if (!filled.get(169)) { + throw new IllegalStateException("hub.STACK_ITEM_STAMP_1 has not been filled"); + } + + if (!filled.get(170)) { + throw new IllegalStateException("hub.STACK_ITEM_STAMP_2 has not been filled"); + } + + if (!filled.get(171)) { + throw new IllegalStateException("hub.STACK_ITEM_STAMP_3 has not been filled"); + } + + if (!filled.get(172)) { + throw new IllegalStateException("hub.STACK_ITEM_STAMP_4 has not been filled"); + } + + if (!filled.get(173)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_1 has not been filled"); + } + + if (!filled.get(174)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_2 has not been filled"); + } + + if (!filled.get(175)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_3 has not been filled"); + } + + if (!filled.get(176)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_4 has not been filled"); + } + + if (!filled.get(177)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_1 has not been filled"); + } + + if (!filled.get(178)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_2 has not been filled"); + } + + if (!filled.get(179)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_3 has not been filled"); + } + + if (!filled.get(180)) { + throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_4 has not been filled"); } - if (!filled.get(146)) { - throw new IllegalStateException("hub.STP_GAS_MXP has not been filled"); + if (!filled.get(51)) { + throw new IllegalStateException("hub.sto_FINAL has not been filled"); } - if (!filled.get(147)) { - throw new IllegalStateException("hub.STP_GAS_PAID_OUT_OF_POCKET has not been filled"); + if (!filled.get(52)) { + throw new IllegalStateException("hub.sto_FIRST has not been filled"); } - if (!filled.get(148)) { - throw new IllegalStateException("hub.STP_GAS_STIPEND has not been filled"); + if (!filled.get(160)) { + throw new IllegalStateException("hub.STP_GAS_HI has not been filled"); } - if (!filled.get(149)) { - throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST has not been filled"); + if (!filled.get(161)) { + throw new IllegalStateException("hub.STP_GAS_LO has not been filled"); } - if (!filled.get(150)) { - throw new IllegalStateException("hub.STP_INSTRUCTION has not been filled"); + if (!filled.get(125)) { + throw new IllegalStateException( + "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } - if (!filled.get(151)) { - throw new IllegalStateException("hub.STP_VAL_HI has not been filled"); + if (!filled.get(162)) { + throw new IllegalStateException("hub.STP_VALUE_HI has not been filled"); } - if (!filled.get(152)) { - throw new IllegalStateException("hub.STP_VAL_LO has not been filled"); + if (!filled.get(163)) { + throw new IllegalStateException("hub.STP_VALUE_LO has not been filled"); } if (!filled.get(39)) { @@ -6477,14 +6238,14 @@ public Trace validateRow() { throw new IllegalStateException("hub.TRANSACTION_REVERTS has not been filled"); } - if (!filled.get(65)) { + if (!filled.get(66)) { throw new IllegalStateException( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } - if (!filled.get(141)) { + if (!filled.get(144)) { throw new IllegalStateException( - "hub.TRM_RAW_ADDRESS_HI_xor_OOB_DATA_6_xor_STACK_ITEM_VALUE_LO_2 has not been filled"); + "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } if (!filled.get(41)) { @@ -6515,14 +6276,14 @@ public Trace validateRow() { throw new IllegalStateException("hub.TXN_FLAG has not been filled"); } - if (!filled.get(67)) { + if (!filled.get(68)) { throw new IllegalStateException( - "hub.WARMTH_NEW_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); } - if (!filled.get(66)) { + if (!filled.get(67)) { throw new IllegalStateException( - "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } if (!filled.get(101)) { @@ -6537,7 +6298,7 @@ public Trace validateRow() { public Trace fillAndValidateRow() { if (!filled.get(0)) { - absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 32); + absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 4); } if (!filled.get(47)) { @@ -6548,97 +6309,107 @@ public Trace fillAndValidateRow() { accFirst.position(accFirst.position() + 1); } - if (!filled.get(118)) { - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.position( - addressHiXorAccountAddressHiXorCcrsStampXorAlphaXorAddressHiXorBasefee.position() + 32); + if (!filled.get(107)) { + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .position( + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum + .position() + + 8); } - if (!filled.get(119)) { - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.position( - addressLoXorAccountAddressLoXorExpData1XorDeltaXorAddressLoXorBatchNum.position() + 32); + if (!filled.get(132)) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position( + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position() + + 32); } - if (!filled.get(121)) { - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi + if (!filled.get(102)) { + alpha.position(alpha.position() + 1); + } + + if (!filled.get(134)) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance .position( - balanceNewXorByteCodeAddressHiXorExpData3XorHashInfoKeccakLoXorDeploymentNumberInftyXorCoinbaseAddressHi + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance .position() + 32); } - if (!filled.get(120)) { - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize + if (!filled.get(133)) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo .position( - balanceXorAccountDeploymentNumberXorExpData2XorHashInfoKeccakHiXorDeploymentNumberXorCallDataSize + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo .position() + 32); } if (!filled.get(1)) { - batchNumber.position(batchNumber.position() + 32); + batchNumber.position(batchNumber.position() + 4); + } + + if (!filled.get(115)) { + callDataOffsetXorMmuSize.position(callDataOffsetXorMmuSize.position() + 8); + } + + if (!filled.get(116)) { + callDataSizeXorMmuSrcId.position(callDataSizeXorMmuSrcId.position() + 8); + } + + if (!filled.get(106)) { + callStackDepth.position(callStackDepth.position() + 2); } if (!filled.get(2)) { - callerContextNumber.position(callerContextNumber.position() + 32); + callerContextNumber.position(callerContextNumber.position() + 8); } if (!filled.get(3)) { - codeFragmentIndex.position(codeFragmentIndex.position() + 32); + codeFragmentIndex.position(codeFragmentIndex.position() + 8); } - if (!filled.get(122)) { - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo + if (!filled.get(108)) { + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize .position( - codeFragmentIndexXorByteCodeAddressLoXorExpData4XorHashInfoSizeXorStorageKeyHiXorCoinbaseAddressLo + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize .position() - + 32); + + 8); } - if (!filled.get(124)) { - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .position( - codeHashHiNewXorByteCodeDeploymentNumberXorMxpGasMxpXorNbAddedXorValueCurrHiXorFromAddressLo - .position() - + 32); + if (!filled.get(136)) { + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); } - if (!filled.get(123)) { - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .position( - codeHashHiXorByteCodeCodeFragmentIndexXorExpData5XorInstructionXorStorageKeyLoXorFromAddressHi - .position() - + 32); + if (!filled.get(135)) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + + 32); } - if (!filled.get(126)) { - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover - .position( - codeHashLoNewXorCallerAddressHiXorMxpMtntopXorPushValueHiXorValueNextHiXorGasLeftover - .position() - + 32); + if (!filled.get(138)) { + codeHashLoNewXorMmuLimb2XorValueNextLo.position( + codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); } - if (!filled.get(125)) { - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .position( - codeHashLoXorByteCodeDeploymentStatusXorMxpInstXorNbRemovedXorValueCurrLoXorGasInitiallyAvailable - .position() - + 32); + if (!filled.get(137)) { + codeHashLoXorMmuLimb1XorValueNextHi.position( + codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); } - if (!filled.get(128)) { - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .position( - codeSizeNewXorCallDataContextNumberXorMxpOffset1LoXorStackItemHeight1XorValueOrigHiXorGasPrice - .position() - + 32); + if (!filled.get(110)) { + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + + 8); } - if (!filled.get(127)) { - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit.position( - codeSizeXorCallerAddressLoXorMxpOffset1HiXorPushValueLoXorValueNextLoXorGasLimit - .position() - + 32); + if (!filled.get(109)) { + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position( + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position() + + 8); } if (!filled.get(49)) { @@ -6658,15 +6429,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(6)) { - contextNumber.position(contextNumber.position() + 32); + contextNumber.position(contextNumber.position() + 8); } if (!filled.get(7)) { - contextNumberNew.position(contextNumberNew.position() + 32); + contextNumberNew.position(contextNumberNew.position() + 8); + } + + if (!filled.get(117)) { + contextNumberXorMmuTgtId.position(contextNumberXorMmuTgtId.position() + 8); } if (!filled.get(8)) { - contextRevertStamp.position(contextRevertStamp.position() + 32); + contextRevertStamp.position(contextRevertStamp.position() + 8); } if (!filled.get(9)) { @@ -6678,18 +6453,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(11)) { - counterNsr.position(counterNsr.position() + 32); + counterNsr.position(counterNsr.position() + 2); } if (!filled.get(12)) { counterTli.position(counterTli.position() + 1); } - if (!filled.get(68)) { - createFailureConditionWillRevertXorHashInfoFlag.position( - createFailureConditionWillRevertXorHashInfoFlag.position() + 1); - } - if (!filled.get(69)) { createFailureConditionWontRevertXorIcpx.position( createFailureConditionWontRevertXorIcpx.position() + 1); @@ -6715,26 +6485,26 @@ public Trace fillAndValidateRow() { createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); } - if (!filled.get(130)) { - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize - .position( - deploymentNumberInftyXorCallDataSizeXorMxpOffset2LoXorStackItemHeight3XorInitCodeSize - .position() - + 32); + if (!filled.get(103)) { + delta.position(delta.position() + 1); } - if (!filled.get(131)) { - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.position( - deploymentNumberNewXorCallStackDepthXorMxpSize1HiXorStackItemHeight4XorNonce.position() - + 32); + if (!filled.get(112)) { + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi + .position() + + 8); } - if (!filled.get(129)) { - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .position( - deploymentNumberXorCallDataOffsetXorMxpOffset2HiXorStackItemHeight2XorValueOrigLoXorInitialBalance - .position() - + 32); + if (!filled.get(113)) { + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + } + + if (!filled.get(111)) { + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + + 8); } if (!filled.get(54)) { @@ -6762,7 +6532,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(13)) { - domStamp.position(domStamp.position() + 32); + domStamp.position(domStamp.position() + 8); } if (!filled.get(14)) { @@ -6784,12 +6554,8 @@ public Trace fillAndValidateRow() { + 1); } - if (!filled.get(102)) { - expInstXorPrcCalleeGas.position(expInstXorPrcCalleeGas.position() + 8); - } - if (!filled.get(15)) { - gasActual.position(gasActual.position() + 32); + gasActual.position(gasActual.position() + 8); } if (!filled.get(16)) { @@ -6797,16 +6563,24 @@ public Trace fillAndValidateRow() { } if (!filled.get(17)) { - gasExpected.position(gasExpected.position() + 32); + gasExpected.position(gasExpected.position() + 8); + } + + if (!filled.get(126)) { + gasLimit.position(gasLimit.position() + 32); } if (!filled.get(18)) { - gasNext.position(gasNext.position() + 32); + gasNext.position(gasNext.position() + 8); + } + + if (!filled.get(127)) { + gasPrice.position(gasPrice.position() + 32); } if (!filled.get(59)) { - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position( - hasCodeNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero .position() + 1); } @@ -6818,138 +6592,145 @@ public Trace fillAndValidateRow() { } if (!filled.get(19)) { - hashInfoStamp.position(hashInfoStamp.position() + 32); + hashInfoStamp.position(hashInfoStamp.position() + 8); } if (!filled.get(20)) { - height.position(height.position() + 32); + height.position(height.position() + 2); } if (!filled.get(21)) { - heightNew.position(heightNew.position() + 32); + heightNew.position(heightNew.position() + 2); } if (!filled.get(22)) { - hubStamp.position(hubStamp.position() + 32); + hubStamp.position(hubStamp.position() + 8); } if (!filled.get(23)) { - hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 32); + hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 8); + } + + if (!filled.get(164)) { + instruction.position(instruction.position() + 32); } if (!filled.get(60)) { - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position( - isPrecompileXorOobFlagXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + 1); } if (!filled.get(24)) { - logInfoStamp.position(logInfoStamp.position() + 32); + logInfoStamp.position(logInfoStamp.position() + 8); } if (!filled.get(62)) { - markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2.position( - markedForSelfdestructNewXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag2.position() + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 + .position() + 1); } if (!filled.get(61)) { - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew .position( - markedForSelfdestructXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew .position() + 1); } - if (!filled.get(103)) { - mmuAuxIdXorPrcCallerGas.position(mmuAuxIdXorPrcCallerGas.position() + 8); + if (!filled.get(25)) { + mmuStamp.position(mmuStamp.position() + 8); } - if (!filled.get(104)) { - mmuExoSumXorPrcCdo.position(mmuExoSumXorPrcCdo.position() + 8); + if (!filled.get(145)) { + mxpOffset2Hi.position(mxpOffset2Hi.position() + 32); } - if (!filled.get(105)) { - mmuInstXorPrcCds.position(mmuInstXorPrcCds.position() + 8); + if (!filled.get(146)) { + mxpOffset2Lo.position(mxpOffset2Lo.position() + 32); } - if (!filled.get(113)) { - mmuLimb1.position(mmuLimb1.position() + 32); + if (!filled.get(147)) { + mxpSize1Hi.position(mxpSize1Hi.position() + 32); } - if (!filled.get(114)) { - mmuLimb2.position(mmuLimb2.position() + 32); + if (!filled.get(148)) { + mxpSize1Lo.position(mxpSize1Lo.position() + 32); } - if (!filled.get(106)) { - mmuPhaseXorPrcRac.position(mmuPhaseXorPrcRac.position() + 8); + if (!filled.get(149)) { + mxpSize2Hi.position(mxpSize2Hi.position() + 32); } - if (!filled.get(107)) { - mmuRefOffsetXorPrcRao.position(mmuRefOffsetXorPrcRao.position() + 8); + if (!filled.get(150)) { + mxpSize2Lo.position(mxpSize2Lo.position() + 32); } - if (!filled.get(108)) { - mmuRefSizeXorPrcReturnGas.position(mmuRefSizeXorPrcReturnGas.position() + 8); + if (!filled.get(26)) { + mxpStamp.position(mxpStamp.position() + 8); } - if (!filled.get(109)) { - mmuSize.position(mmuSize.position() + 8); + if (!filled.get(151)) { + mxpWords.position(mxpWords.position() + 32); } - if (!filled.get(110)) { - mmuSrcId.position(mmuSrcId.position() + 8); + if (!filled.get(104)) { + nbAdded.position(nbAdded.position() + 1); } - if (!filled.get(115)) { - mmuSrcOffsetHi.position(mmuSrcOffsetHi.position() + 32); + if (!filled.get(105)) { + nbRemoved.position(nbRemoved.position() + 1); } - if (!filled.get(116)) { - mmuSrcOffsetLo.position(mmuSrcOffsetLo.position() + 32); + if (!filled.get(27)) { + nonStackRows.position(nonStackRows.position() + 2); } - if (!filled.get(25)) { - mmuStamp.position(mmuStamp.position() + 32); + if (!filled.get(128)) { + nonce.position(nonce.position() + 32); } - if (!filled.get(111)) { - mmuTgtId.position(mmuTgtId.position() + 8); + if (!filled.get(124)) { + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); } - if (!filled.get(117)) { - mmuTgtOffsetLo.position(mmuTgtOffsetLo.position() + 32); + if (!filled.get(123)) { + nonceXorStpGasMxpXorBasefee.position(nonceXorStpGasMxpXorBasefee.position() + 32); } - if (!filled.get(26)) { - mxpStamp.position(mxpStamp.position() + 32); + if (!filled.get(152)) { + oobData1.position(oobData1.position() + 32); } - if (!filled.get(27)) { - nonStackRows.position(nonStackRows.position() + 32); + if (!filled.get(153)) { + oobData2.position(oobData2.position() + 32); } - if (!filled.get(133)) { - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.position( - nonceNewXorContextNumberXorMxpSize2HiXorStackItemStamp2XorRefundCounterInfinity.position() - + 32); + if (!filled.get(154)) { + oobData3.position(oobData3.position() + 32); } - if (!filled.get(132)) { - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.position( - nonceXorCallValueXorMxpSize1LoXorStackItemStamp1XorPriorityFeePerGas.position() + 32); + if (!filled.get(155)) { + oobData4.position(oobData4.position() + 32); } - if (!filled.get(142)) { - oobData7XorStackItemValueLo3.position(oobData7XorStackItemValueLo3.position() + 32); + if (!filled.get(156)) { + oobData5.position(oobData5.position() + 32); } - if (!filled.get(143)) { - oobData8XorStackItemValueLo4.position(oobData8XorStackItemValueLo4.position() + 32); + if (!filled.get(157)) { + oobData6.position(oobData6.position() + 32); } - if (!filled.get(112)) { - oobInst.position(oobInst.position() + 8); + if (!filled.get(158)) { + oobData7.position(oobData7.position() + 32); + } + + if (!filled.get(159)) { + oobData8.position(oobData8.position() + 32); } if (!filled.get(28)) { @@ -7033,20 +6814,53 @@ public Trace fillAndValidateRow() { prcSuccessWontRevertXorRdcx.position(prcSuccessWontRevertXorRdcx.position() + 1); } + if (!filled.get(129)) { + priorityFeePerGas.position(priorityFeePerGas.position() + 32); + } + if (!filled.get(35)) { - programCounter.position(programCounter.position() + 32); + programCounter.position(programCounter.position() + 8); } if (!filled.get(36)) { - programCounterNew.position(programCounterNew.position() + 32); + programCounterNew.position(programCounterNew.position() + 8); } if (!filled.get(37)) { - refundCounter.position(refundCounter.position() + 32); + refundCounter.position(refundCounter.position() + 8); + } + + if (!filled.get(130)) { + refundCounterInfinity.position(refundCounterInfinity.position() + 32); } if (!filled.get(38)) { - refundCounterNew.position(refundCounterNew.position() + 32); + refundCounterNew.position(refundCounterNew.position() + 8); + } + + if (!filled.get(131)) { + refundEffective.position(refundEffective.position() + 32); + } + + if (!filled.get(118)) { + returnAtCapacityXorMxpInst.position(returnAtCapacityXorMxpInst.position() + 8); + } + + if (!filled.get(119)) { + returnAtOffsetXorOobInst.position(returnAtOffsetXorOobInst.position() + 8); + } + + if (!filled.get(120)) { + returnDataContextNumberXorStpGasStipend.position( + returnDataContextNumberXorStpGasStipend.position() + 8); + } + + if (!filled.get(121)) { + returnDataOffsetXorStpInstruction.position(returnDataOffsetXorStpInstruction.position() + 8); + } + + if (!filled.get(122)) { + returnDataSize.position(returnDataSize.position() + 8); } if (!filled.get(87)) { @@ -7083,54 +6897,46 @@ public Trace fillAndValidateRow() { returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } - if (!filled.get(134)) { - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective.position( - rlpaddrDepAddrHiXorReturnAtCapacityXorMxpSize2LoXorStackItemStamp3XorRefundEffective - .position() - + 32); + if (!filled.get(114)) { + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); } - if (!filled.get(135)) { - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.position( - rlpaddrDepAddrLoXorReturnAtOffsetXorMxpWordsXorStackItemStamp4XorToAddressHi.position() - + 32); + if (!filled.get(139)) { + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); } if (!filled.get(63)) { - rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3.position( - rlpaddrFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); } - if (!filled.get(136)) { - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo.position( - rlpaddrKecHiXorReturnDataContextNumberXorOobData1XorStackItemValueHi1XorToAddressLo - .position() - + 32); + if (!filled.get(140)) { + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); } - if (!filled.get(137)) { - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.position( - rlpaddrKecLoXorReturnDataOffsetXorOobData2XorStackItemValueHi2XorValue.position() + 32); + if (!filled.get(141)) { + rlpaddrKecLoXorMmuTgtOffsetLo.position(rlpaddrKecLoXorMmuTgtOffsetLo.position() + 32); } - if (!filled.get(138)) { - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.position( - rlpaddrRecipeXorReturnDataSizeXorOobData3XorStackItemValueHi3.position() + 32); + if (!filled.get(64)) { + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } - if (!filled.get(139)) { - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.position( - rlpaddrSaltHiXorOobData4XorStackItemValueHi4.position() + 32); + if (!filled.get(142)) { + rlpaddrSaltHiXorMxpGasMxp.position(rlpaddrSaltHiXorMxpGasMxp.position() + 32); } - if (!filled.get(140)) { - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.position( - rlpaddrSaltLoXorOobData5XorStackItemValueLo1.position() + 32); + if (!filled.get(143)) { + rlpaddrSaltLoXorMxpOffset1Hi.position(rlpaddrSaltLoXorMxpOffset1Hi.position() + 32); } - if (!filled.get(64)) { - romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4.position( - romLexFlagXorStpWarmthXorCreateAbortXorDecFlag4.position() + 1); + if (!filled.get(65)) { + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } if (!filled.get(94)) { @@ -7152,52 +6958,101 @@ public Trace fillAndValidateRow() { selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } - if (!filled.get(51)) { - stoFinal.position(stoFinal.position() + 1); + if (!filled.get(165)) { + stackItemHeight1.position(stackItemHeight1.position() + 32); } - if (!filled.get(52)) { - stoFirst.position(stoFirst.position() + 1); + if (!filled.get(166)) { + stackItemHeight2.position(stackItemHeight2.position() + 32); } - if (!filled.get(144)) { - stpGasHiXorStaticGas.position(stpGasHiXorStaticGas.position() + 32); + if (!filled.get(167)) { + stackItemHeight3.position(stackItemHeight3.position() + 32); } - if (!filled.get(145)) { - stpGasLo.position(stpGasLo.position() + 32); + if (!filled.get(168)) { + stackItemHeight4.position(stackItemHeight4.position() + 32); } - if (!filled.get(146)) { - stpGasMxp.position(stpGasMxp.position() + 32); + if (!filled.get(169)) { + stackItemStamp1.position(stackItemStamp1.position() + 32); } - if (!filled.get(147)) { - stpGasPaidOutOfPocket.position(stpGasPaidOutOfPocket.position() + 32); + if (!filled.get(170)) { + stackItemStamp2.position(stackItemStamp2.position() + 32); } - if (!filled.get(148)) { - stpGasStipend.position(stpGasStipend.position() + 32); + if (!filled.get(171)) { + stackItemStamp3.position(stackItemStamp3.position() + 32); } - if (!filled.get(149)) { - stpGasUpfrontGasCost.position(stpGasUpfrontGasCost.position() + 32); + if (!filled.get(172)) { + stackItemStamp4.position(stackItemStamp4.position() + 32); } - if (!filled.get(150)) { - stpInstruction.position(stpInstruction.position() + 32); + if (!filled.get(173)) { + stackItemValueHi1.position(stackItemValueHi1.position() + 32); } - if (!filled.get(151)) { - stpValHi.position(stpValHi.position() + 32); + if (!filled.get(174)) { + stackItemValueHi2.position(stackItemValueHi2.position() + 32); } - if (!filled.get(152)) { - stpValLo.position(stpValLo.position() + 32); + if (!filled.get(175)) { + stackItemValueHi3.position(stackItemValueHi3.position() + 32); + } + + if (!filled.get(176)) { + stackItemValueHi4.position(stackItemValueHi4.position() + 32); + } + + if (!filled.get(177)) { + stackItemValueLo1.position(stackItemValueLo1.position() + 32); + } + + if (!filled.get(178)) { + stackItemValueLo2.position(stackItemValueLo2.position() + 32); + } + + if (!filled.get(179)) { + stackItemValueLo3.position(stackItemValueLo3.position() + 32); + } + + if (!filled.get(180)) { + stackItemValueLo4.position(stackItemValueLo4.position() + 32); + } + + if (!filled.get(51)) { + stoFinal.position(stoFinal.position() + 1); + } + + if (!filled.get(52)) { + stoFirst.position(stoFirst.position() + 1); + } + + if (!filled.get(160)) { + stpGasHi.position(stpGasHi.position() + 32); + } + + if (!filled.get(161)) { + stpGasLo.position(stpGasLo.position() + 32); + } + + if (!filled.get(125)) { + stpGasUpfrontGasCostXorGasLeftover.position( + stpGasUpfrontGasCostXorGasLeftover.position() + 32); + } + + if (!filled.get(162)) { + stpValueHi.position(stpValueHi.position() + 32); + } + + if (!filled.get(163)) { + stpValueLo.position(stpValueLo.position() + 32); } if (!filled.get(39)) { - subStamp.position(subStamp.position() + 32); + subStamp.position(subStamp.position() + 8); } if (!filled.get(98)) { @@ -7212,14 +7067,13 @@ public Trace fillAndValidateRow() { transactionReverts.position(transactionReverts.position() + 1); } - if (!filled.get(65)) { - trmFlagXorCreateEmptyInitCodeWillRevertXorDupFlag.position( - trmFlagXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + if (!filled.get(66)) { + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } - if (!filled.get(141)) { - trmRawAddressHiXorOobData6XorStackItemValueLo2.position( - trmRawAddressHiXorOobData6XorStackItemValueLo2.position() + 32); + if (!filled.get(144)) { + trmRawAddressHiXorMxpOffset1Lo.position(trmRawAddressHiXorMxpOffset1Lo.position() + 32); } if (!filled.get(41)) { @@ -7250,14 +7104,14 @@ public Trace fillAndValidateRow() { txnFlag.position(txnFlag.position() + 1); } - if (!filled.get(67)) { - warmthNewXorCreateExceptionXorHaltFlag.position( - warmthNewXorCreateExceptionXorHaltFlag.position() + 1); + if (!filled.get(68)) { + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); } - if (!filled.get(66)) { - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.position( - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + if (!filled.get(67)) { + warmthXorCreateExceptionXorHaltFlag.position( + warmthXorCreateExceptionXorHaltFlag.position() + 1); } if (!filled.get(101)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index bb1ee037bd..2dda24a53f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -15,99 +15,68 @@ package net.consensys.linea.zktracer.module.hub.fragment; -import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.TransactionStack; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.LineaTransaction; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.evm.worldstate.WorldView; public final class TransactionFragment implements TraceFragment, PostTransactionDefer { + private final LineaTransaction lineaTransaction; @Setter private TraceSection parentSection; - private final int batchNumber; - private final Address minerAddress; - private final Transaction tx; - private final boolean evmExecutes; - private final Wei gasPrice; - private final Wei baseFee; - private boolean txSuccess; - private final long initialGas; - private TransactionFragment( - int batchNumber, - Address minerAddress, - Transaction tx, - boolean evmExecutes, - Wei gasPrice, - Wei baseFee, - boolean txSuccess, - long initialGas) { - this.batchNumber = batchNumber; - this.minerAddress = minerAddress; - this.tx = tx; - this.evmExecutes = evmExecutes; - this.gasPrice = gasPrice; - this.baseFee = baseFee; - this.txSuccess = txSuccess; - this.initialGas = initialGas; + private TransactionFragment(LineaTransaction lineaTransaction) { + this.lineaTransaction = lineaTransaction; } - public static TransactionFragment prepare( - int batchNumber, - Address minerAddress, - Transaction tx, - boolean evmExecutes, - Wei gasPrice, - Wei baseFee, - long initialGas) { - return new TransactionFragment( - batchNumber, minerAddress, tx, evmExecutes, gasPrice, baseFee, false, initialGas); + public static TransactionFragment prepare(LineaTransaction lineaTransaction) { + return new TransactionFragment(lineaTransaction); } @Override public Trace trace(Trace trace) { - final EWord to = EWord.of(effectiveToAddress(tx)); - final EWord from = EWord.of(tx.getSender()); - final EWord miner = EWord.of(minerAddress); - long gasRefundAmount = this.parentSection.parentTrace().refundedGas(); - long leftoverGas = this.parentSection.parentTrace().leftoverGas(); - long gasRefundFinalCounter = this.parentSection.parentTrace().gasRefundFinalCounter(); + final Transaction tx = lineaTransaction.besuTransaction(); + final EWord to = EWord.of(lineaTransaction.effectiveTo()); + final EWord from = EWord.of(lineaTransaction.getSender()); + final EWord miner = EWord.of(lineaTransaction.coinbase()); return trace .peekAtTransaction(true) - .pTransactionNonce(Bytes.ofUnsignedLong(tx.getNonce())) - .pTransactionIsDeployment(tx.getTo().isEmpty()) - .pTransactionFromAddressHi(from.hi()) + .pTransactionBatchNum(lineaTransaction.relativeBlockNumber()) + .pTransactionFromAddressHi(from.hi().toLong()) .pTransactionFromAddressLo(from.lo()) - .pTransactionToAddressHi(to.hi()) + .pTransactionNonce(Bytes.ofUnsignedLong(tx.getNonce())) + .pTransactionInitialBalance(bigIntegerToBytes(lineaTransaction.initialBalance())) + .pTransactionValue(bigIntegerToBytes(tx.getValue().getAsBigInteger())) + .pTransactionToAddressHi(to.hi().toLong()) .pTransactionToAddressLo(to.lo()) - .pTransactionGasPrice(gasPrice) - .pTransactionBasefee(baseFee) + .pTransactionRequiresEvmExecution(lineaTransaction.requiresEvmExecution()) + .pTransactionCopyTxcd(lineaTransaction.copyTransactionCallData()) + .pTransactionIsDeployment(tx.getTo().isEmpty()) + .pTransactionIsType2(tx.getType() == TransactionType.EIP1559) + .pTransactionGasLimit(Bytes.minimalBytes(tx.getGasLimit())) .pTransactionGasInitiallyAvailable( - Bytes.ofUnsignedLong(TransactionStack.computeInitGas(tx))) - .pTransactionInitialBalance(Bytes.ofUnsignedLong(initialGas)) - .pTransactionValue(bigIntegerToBytes(tx.getValue().getAsBigInteger())) - .pTransactionCoinbaseAddressHi(miner.hi()) - .pTransactionCoinbaseAddressLo(miner.lo()) - .pTransactionCallDataSize(Bytes.ofUnsignedInt(tx.getData().map(Bytes::size).orElse(0))) - .pTransactionRequiresEvmExecution(evmExecutes) - .pTransactionGasLeftover(Bytes.ofUnsignedLong(leftoverGas)) - .pTransactionRefundCounterInfinity(Bytes.ofUnsignedLong(gasRefundFinalCounter)) - .pTransactionRefundEffective(Bytes.ofUnsignedLong(gasRefundAmount)) - .pTransactionStatusCode(txSuccess); + Bytes.minimalBytes(lineaTransaction.initiallyAvailableGas())) + .pTransactionGasPrice(Bytes.minimalBytes(lineaTransaction.effectiveGasPrice())) + .pTransactionBasefee(Bytes.minimalBytes(lineaTransaction.baseFee())) + .pTransactionCallDataSize(tx.getData().map(Bytes::size).orElse(0)) + .pTransactionInitCodeSize(tx.getInit().map(Bytes::size).orElse(0)) + .pTransactionStatusCode(lineaTransaction.statusCode()) + .pTransactionGasLeftover(Bytes.minimalBytes(lineaTransaction.leftoverGas())) + .pTransactionRefundCounterInfinity(Bytes.minimalBytes(lineaTransaction.refundCounterMax())) + .pTransactionRefundEffective(Bytes.minimalBytes(lineaTransaction.refundEffective())) + .pTransactionCoinbaseAddressHi(miner.hi().toLong()) + .pTransactionCoinbaseAddressLo(miner.lo()); } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - this.txSuccess = isSuccessful; - } + public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Block.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Block.java index 9c6b577d11..d7b8084aa4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Block.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Block.java @@ -34,7 +34,7 @@ public class Block { * * @param processableBlockHeader the processable block header */ - public void update(final ProcessableBlockHeader processableBlockHeader) { + public void blockUpdate(final ProcessableBlockHeader processableBlockHeader) { this.blockNumber++; this.minerAddress = processableBlockHeader.getCoinbase(); this.baseFee = Wei.fromQuantity(processableBlockHeader.getBaseFee().orElseThrow()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/LineaTransaction.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/LineaTransaction.java new file mode 100644 index 0000000000..6522c7a036 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/LineaTransaction.java @@ -0,0 +1,160 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.types; + +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.*; +import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; + +import java.math.BigInteger; +import java.util.Optional; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.ZkTracer; +import net.consensys.linea.zktracer.module.txndata.TxnData; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.worldstate.WorldView; + +@Accessors(fluent = true) +@Getter +public class LineaTransaction { + final int relativeBlockNumber; + + final Transaction besuTransaction; + final int relativeTransactionNumber; + final Address coinbase; + final long baseFee; + + final boolean isDeployment; + final boolean requiresEvmExecution; + final boolean copyTransactionCallData; + + final BigInteger initialBalance; + + final long dataCost; + final long accessListCost; + final long initiallyAvailableGas; + + final Address effectiveTo; + + final long effectiveGasPrice; + + @Setter long refundCounterMax; + @Setter long refundEffective; + @Setter long leftoverGas; + @Setter boolean statusCode; + + public LineaTransaction( + WorldView world, + int relativeBlockNumber, + Address coinbase, + Wei baseFee, + TxnData txnData, + Transaction transaction) { + this.relativeBlockNumber = relativeBlockNumber; + this.coinbase = coinbase; + this.baseFee = baseFee.toLong(); + + this.besuTransaction = transaction; + this.relativeTransactionNumber = txnData.currentBlock().getTxs().size() + 1; + + this.isDeployment = transaction.getTo().isEmpty(); + this.requiresEvmExecution = computeRequiresEvmExecution(world); + this.copyTransactionCallData = computeCopyCallData(); + + this.initialBalance = getInitialBalance(world); + + this.dataCost = + ZkTracer.gasCalculator.transactionIntrinsicGasCost( + besuTransaction.getPayload(), isDeployment); + this.accessListCost = + besuTransaction.getAccessList().map(ZkTracer.gasCalculator::accessListGasCost).orElse(0L); + this.initiallyAvailableGas = getInitiallyAvailableGas(); + + this.effectiveTo = effectiveToAddress(besuTransaction); + + this.effectiveGasPrice = getEffectiveGasPrice(); + } + + private boolean computeCopyCallData() { + return requiresEvmExecution && !isDeployment && !besuTransaction.getData().get().isEmpty(); + } + + private boolean computeRequiresEvmExecution(WorldView world) { + if (!isDeployment) { + return Optional.ofNullable(world.get(this.besuTransaction.getTo().get())) + .map(a -> !a.getCode().isEmpty()) + .orElse(false); + } + + return !this.besuTransaction.getInit().get().isEmpty(); + } + + private BigInteger getInitialBalance(WorldView world) { + final Address sender = besuTransaction.getSender(); + return world.get(sender).getBalance().getAsBigInteger(); + } + + public long getUpfrontGasCost() { + return dataCost + + (isDeployment ? GAS_CONST_G_CREATE : 0) + + GAS_CONST_G_TRANSACTION + + accessListCost; + } + + public long getInitiallyAvailableGas() { + return besuTransaction.getGasLimit() - getUpfrontGasCost(); + } + + public void completeLineaTransaction( + boolean statusCode, long leftoverGas, long refundCounterMax) { + this.refundCounterMax = refundCounterMax; + this.leftoverGas = leftoverGas; + this.statusCode = statusCode; + this.refundEffective = getRefundEffective(); + } + + private long getRefundEffective() { + final long consumedGas = besuTransaction.getGasLimit() - leftoverGas; + final long maxRefundableAmount = consumedGas / MAX_REFUND_QUOTIENT; + return Math.min(maxRefundableAmount, refundCounterMax); + } + + private long getEffectiveGasPrice() { + + final Transaction tx = besuTransaction; + switch (tx.getType()) { + case FRONTIER, ACCESS_LIST -> { + return tx.getGasPrice().get().getAsBigInteger().longValueExact(); + } + case EIP1559 -> { + final long baseFee = baseFee(); + final long maxPriorityFee = + tx.getMaxPriorityFeePerGas().get().getAsBigInteger().longValue(); + final long maxFeePerGas = tx.getMaxFeePerGas().get().getAsBigInteger().longValueExact(); + return Math.min(baseFee + maxPriorityFee, maxFeePerGas); + } + default -> throw new IllegalArgumentException("Transaction type not supported"); + } + } + + public Address getSender() { + return besuTransaction.getSender(); + } +} From 88a2ae3f78994437de1704a64b6427071dff7f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 31 May 2024 21:59:43 +0400 Subject: [PATCH 002/461] feat(hub): CommonFragment partial implementation --- .../linea/zktracer/module/hub/Hub.java | 6 +- .../linea/zktracer/module/hub/State.java | 5 +- .../linea/zktracer/module/hub/TxTrace.java | 12 +- .../module/hub/fragment/CommonFragment.java | 198 +++++++++++------- .../module/hub/section/TraceSection.java | 4 +- 5 files changed, 140 insertions(+), 85 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index edebd1bff7..03ed58cb55 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -125,7 +125,7 @@ public class Hub implements Module { public static final GasProjector GAS_PROJECTOR = new GasProjector(); /** accumulate the trace information for the Hub */ - @Getter private final State state = new State(); + @Getter public final State state = new State(); /** contain the factories for trace segments that need complex initialization */ @Getter private final Factories factories; @@ -879,6 +879,8 @@ public void traceEndTx( Bytes output, List logs, long gasUsed) { + final long leftoverGas = currentTransaction.besuTransaction().getGasLimit() - gasUsed; + this.currentTransaction.completeLineaTransaction(isSuccessful, leftoverGas, this.refundedGas()); this.txStack.exitTransaction(this, isSuccessful); if (this.transients.tx().state() != TxState.TX_SKIP) { this.processStateFinal(world, tx, isSuccessful); @@ -1203,7 +1205,7 @@ public void traceEndConflation(final WorldView state) { } public long refundedGas() { - return this.state.currentTxTrace().refundedGas(); + return this.state.currentTxTrace().refundCounter(); } public long remainingGas() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index 0ed1f507cc..c0bb35b4e7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -91,7 +91,7 @@ public void pop() { /** Describes the Hub state during a given transaction. */ @Accessors(fluent = true) @Getter - static class TxState { + public static class TxState { Stamps stamps; TxTrace txTrace; @@ -116,7 +116,8 @@ public static class Stamps { private int hub = 0; private int mmu = 0; private int mxp = 0; - private int hashInfo = 0; + private int hashInfo = 0; // TODO: doesn't exist anymore + private int log = 0; // TODO: implement this public Stamps() {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 4f0416e853..6e432fbc4a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -36,7 +36,7 @@ public class TxTrace implements PostTransactionDefer { /** A cache for the line count of this transaction */ private int cachedLineCount = 0; - private long refundedGas = -1; + private long refundCounter = -1; @Getter private long leftoverGas = -1; @Getter private long gasRefundFinalCounter = 0; // TODO: @@ -70,17 +70,17 @@ public void add(TraceSection section) { this.trace.add(section); } - public long refundedGas() { - if (this.refundedGas == -1) { - this.refundedGas = 0; + public long refundCounter() { + if (this.refundCounter == -1) { + this.refundCounter = 0; for (TraceSection section : this.trace) { if (!section.hasReverted()) { - this.refundedGas += section.refundDelta(); + this.refundCounter += section.refundDelta(); } } } - return this.refundedGas; + return this.refundCounter; } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index d5f98b365e..1d111f1f76 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -20,15 +20,18 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.TransactionStack; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.InstructionFamily; +import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TxState; import org.apache.tuweni.bytes.Bytes; +import java.math.BigInteger; + @Accessors(fluent = true, chain = false) @Builder public final class CommonFragment implements TraceFragment { @@ -36,16 +39,17 @@ public final class CommonFragment implements TraceFragment { private final int txId; private final int batchNumber; private final TxState txState; - private final int stamp; + private final State.TxState.Stamps stamps; private final InstructionFamily instructionFamily; private final Exceptions exceptions; private final int callFrameId; @Getter private final int contextNumber; - @Setter private int newContextNumber; + @Setter private int contextNumberNew; private final int revertStamp; + @Getter final short height; + @Getter final short heightNew; @Getter private final int pc; - @Setter private int newPc; - private final EWord codeAddress; + @Setter private int pcNew; private int codeDeploymentNumber; private final boolean codeDeploymentStatus; private final int callerContextNumber; @@ -55,39 +59,88 @@ public final class CommonFragment implements TraceFragment { private final long gasNext; @Getter private final long refundDelta; @Setter private long gasRefund; - @Getter @Setter private boolean twoLinesInstruction; - @Getter @Setter private boolean twoLinesInstructionCounter; + @Getter @Setter private boolean twoLineInstruction; + @Getter @Setter private boolean twoLineInstructionCounter; @Getter @Setter private int numberOfNonStackRows; @Getter @Setter private int nonStackRowsCounter; public static CommonFragment fromHub( - final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowsCounter) { + final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowsCounter) { long refund = 0; - if (hub.pch().exceptions().noStackException()) { + + boolean noStackException = hub.pch().exceptions().noStackException(); + + if (noStackException) { refund = Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).refund(); } + int height = hub.currentFrame().stack().getHeight(); + int heightNew = (noStackException + ? height - hub.opCode().getData().stackSettings().delta() + hub.opCode().getData().stackSettings().alpha() + : 0); + + final int pc = frame.pc(); + final int pcNew = !noStackException + ? computePcNew(hub, pc) + : 0; + return CommonFragment.builder() - .hub(hub) - .txId(hub.transients().tx().id()) - .batchNumber(hub.transients().conflation().number()) - .txState(hub.transients().tx().state()) - .stamp(hub.stamp()) - .instructionFamily(hub.opCodeData().instructionFamily()) - .exceptions(hub.pch().exceptions().snapshot()) - .callFrameId(frame.id()) - .contextNumber(frame.contextNumber()) - .newContextNumber(frame.contextNumber()) - .pc(frame.pc()) - .codeAddress(frame.addressAsEWord()) - .codeDeploymentNumber(frame.codeDeploymentNumber()) - .codeDeploymentStatus(frame.underDeployment()) - .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) - .refundDelta(refund) - .twoLinesInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) - .twoLinesInstructionCounter(tliCounter) - .nonStackRowsCounter(nonStackRowsCounter) - .build(); + .hub(hub) + .txId(hub.transients().tx().id()) + .batchNumber(hub.transients().conflation().number()) + .txState(hub.transients().tx().state()) + .stamps(hub.state.stamps()) + .instructionFamily(hub.opCodeData().instructionFamily()) + .exceptions(hub.pch().exceptions().snapshot()) + .callFrameId(frame.id()) + .contextNumber(frame.contextNumber()) + .contextNumberNew(frame.contextNumber()) // TODO + .pc(pc) + .pcNew(pcNew) + .height((short) height) + .heightNew((short) heightNew) + .codeDeploymentNumber(frame.codeDeploymentNumber()) + .codeDeploymentStatus(frame.underDeployment()) + .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) + .refundDelta(refund) + .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) + .twoLineInstructionCounter(tliCounter) + .nonStackRowsCounter(nonStackRowsCounter) + .build(); + } + + private static int computePcNew(final Hub hub, final int pc) { + OpCode opCode = hub.opCode(); + + if (opCode.getData().isPush()) { + return pc + opCode.byteValue() - OpCode.PUSH1.byteValue() + 2; + } + + if (opCode.getData().instructionFamily().equals(InstructionFamily.JUMP)) { + BigInteger prospectivePcNew = hub.currentFrame().frame().getStackItem(0).toBigInteger(); + BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); + + final int attemptedPcNew = codeSize.compareTo(prospectivePcNew) > 0 + ? prospectivePcNew.intValueExact() + : 0; + + if (opCode.equals(OpCode.JUMP)) { + return attemptedPcNew; + } + + if (opCode.equals(OpCode.JUMPI)) { + BigInteger condition = hub.currentFrame().frame().getStackItem(1).toBigInteger(); + if (!condition.equals(BigInteger.ZERO)) { + return attemptedPcNew; + } + } + } + + return pc + 1; + } + + private static int computeContextNumberNew(final Hub hub) { + return 0; // TODO } public boolean txReverts() { @@ -116,50 +169,49 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); + return trace - .codeFragmentIndex(Bytes.ofUnsignedInt(codeFragmentIndex)) - .absoluteTransactionNumber(Bytes.ofUnsignedInt(tx.absNumber())) - .height(Bytes.ofUnsignedShort(stackHeight)) - .heightNew(Bytes.ofUnsignedShort(stackHeightNew)) - .batchNumber(Bytes.ofUnsignedInt(this.batchNumber)) - .txSkip(this.txState == TxState.TX_SKIP) - .txWarm(this.txState == TxState.TX_WARM) - .txInit(this.txState == TxState.TX_INIT) - .txExec(this.txState == TxState.TX_EXEC) - .txFinl(this.txState == TxState.TX_FINAL) - .hubStamp(Bytes.ofUnsignedInt(this.stamp)) - .hubStampTransactionEnd(Bytes.ofUnsignedLong(tx.endStamp())) - .transactionReverts(tx.status()) - .contextMayChange( - this.txState == TxState.TX_EXEC - && ((instructionFamily == InstructionFamily.CALL - || instructionFamily == InstructionFamily.CREATE - || instructionFamily == InstructionFamily.HALT - || instructionFamily == InstructionFamily.INVALID) - || exceptions.any())) - .exceptionAhoy(exceptions.any()) - - // Context data - .contextNumber(Bytes.ofUnsignedInt(contextNumber)) - .contextNumberNew(Bytes.ofUnsignedInt(newContextNumber)) - .contextRevertStamp(Bytes.ofUnsignedInt(revertStamp)) - .contextWillRevert(getsReverted || selfReverts) - .contextGetsReverted(getsReverted) - .contextSelfReverts(selfReverts) - .programCounter(Bytes.ofUnsignedInt(pc)) - .programCounterNew(Bytes.ofUnsignedInt(newPc)) - - // Bytecode metadata - .callerContextNumber(Bytes.ofUnsignedInt(callerContextNumber)) - .gasExpected(Bytes.ofUnsignedLong(gasExpected)) - .gasActual(Bytes.ofUnsignedLong(gasActual)) - .gasCost(Bytes.ofUnsignedLong(gasCost)) - .gasNext(Bytes.ofUnsignedLong(gasNext)) - .refundCounter(Bytes.ofUnsignedInt(gasRefund)) - .refundCounterNew(Bytes.EMPTY) - .twoLineInstruction(twoLinesInstruction) - .counterTli(twoLinesInstructionCounter) - .nonStackRows(Bytes.ofUnsignedShort(numberOfNonStackRows)) - .counterNsr(Bytes.ofUnsignedShort(nonStackRowsCounter)); + .absoluteTransactionNumber(tx.absNumber()) + .batchNumber(this.batchNumber) + .txSkip(this.txState == TxState.TX_SKIP) + .txWarm(this.txState == TxState.TX_WARM) + .txInit(this.txState == TxState.TX_INIT) + .txExec(this.txState == TxState.TX_EXEC) + .txFinl(this.txState == TxState.TX_FINAL) + .hubStamp(this.stamps.hub()) + .hubStampTransactionEnd(tx.endStamp()) + .contextMayChange( + this.txState == TxState.TX_EXEC + && ((instructionFamily == InstructionFamily.CALL + || instructionFamily == InstructionFamily.CREATE + || instructionFamily == InstructionFamily.HALT + || instructionFamily == InstructionFamily.INVALID) + || exceptions.any())) + .exceptionAhoy(exceptions.any()) + .logInfoStamp(this.stamps.log()) + .mmuStamp(this.stamps.mmu()) + .mxpStamp(this.stamps.mxp()) + .contextNumber(contextNumber) + .contextNumberNew(contextNumberNew) // TODO + .callerContextNumber(callerContextNumber) + .contextWillRevert(getsReverted || selfReverts) + .contextGetsReverted(getsReverted) + .contextSelfReverts(selfReverts) + .contextRevertStamp(revertStamp) + .codeFragmentIndex(codeFragmentIndex) + .programCounter(pc) + .programCounterNew(pcNew) + .height((short) stackHeight) + .heightNew((short) stackHeightNew) + .gasExpected(gasExpected) + .gasActual(gasActual) + .gasCost(Bytes.ofUnsignedLong(gasCost)) + .gasNext(gasNext) + .refundCounter(gasRefund) + .refundCounterNew(gasRefund + refundDelta) + .twoLineInstruction(twoLineInstruction) + .counterTli(twoLineInstructionCounter) + .nonStackRows((short) numberOfNonStackRows) + .counterNsr((short) nonStackRowsCounter); } } 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 cd90c34029..65ab7ff329 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 @@ -202,8 +202,8 @@ public void seal(Hub hub) { nonStackLineCounter++; line.common.nonStackRowsCounter(nonStackLineCounter); } - line.common.newPc(hub.lastPc()); - line.common.newContextNumber(hub.lastContextNumber()); + line.common.pcNew(hub.lastPc()); + line.common.contextNumberNew(hub.lastContextNumber()); line.common.numberOfNonStackRows(nonStackLineNumbers); } } From c5d5eb4cd77fa446c87fe12f451b68cd9a677d50 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 00:40:38 +0530 Subject: [PATCH 003/461] fix(gub): trace all columns --- .../linea/zktracer/module/hub/Trace.java | 1122 +++++------------ .../module/hub/fragment/AccountFragment.java | 36 +- .../module/hub/fragment/ContextFragment.java | 39 +- .../module/hub/fragment/StackFragment.java | 112 +- .../module/hub/fragment/StorageFragment.java | 11 +- zkevm-constraints | 2 +- 6 files changed, 432 insertions(+), 890 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 8ec4061892..e1b80c1d9b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub; +import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -37,32 +38,24 @@ public class Trace { private final MappedByteBuffer absoluteTransactionNumber; private final MappedByteBuffer accFinal; private final MappedByteBuffer accFirst; - private final MappedByteBuffer - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum; - private final MappedByteBuffer - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; + private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; private final MappedByteBuffer alpha; - private final MappedByteBuffer - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; - private final MappedByteBuffer - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; + private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; + private final MappedByteBuffer balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer batchNumber; private final MappedByteBuffer callDataOffsetXorMmuSize; private final MappedByteBuffer callDataSizeXorMmuSrcId; private final MappedByteBuffer callStackDepth; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize; + private final MappedByteBuffer codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; private final MappedByteBuffer codeHashHiNewXorExpData5XorValueCurrLoXorValue; - private final MappedByteBuffer - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorValueNextLo; private final MappedByteBuffer codeHashLoXorMmuLimb1XorValueNextHi; - private final MappedByteBuffer - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; - private final MappedByteBuffer - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; + private final MappedByteBuffer codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; + private final MappedByteBuffer codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; private final MappedByteBuffer conAgain; private final MappedByteBuffer conFirst; private final MappedByteBuffer contextGetsReverted; @@ -78,51 +71,37 @@ public class Trace { private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; - private final MappedByteBuffer - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; private final MappedByteBuffer delta; - private final MappedByteBuffer - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; - private final MappedByteBuffer - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; - private final MappedByteBuffer - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; - private final MappedByteBuffer - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; - private final MappedByteBuffer - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; - private final MappedByteBuffer - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; + private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; + private final MappedByteBuffer deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; + private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; + private final MappedByteBuffer deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; + private final MappedByteBuffer deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; + private final MappedByteBuffer deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; - private final MappedByteBuffer - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; - private final MappedByteBuffer - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; + private final MappedByteBuffer existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; + private final MappedByteBuffer existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; - private final MappedByteBuffer - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; - private final MappedByteBuffer - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; + private final MappedByteBuffer hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; + private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; private final MappedByteBuffer hashInfoStamp; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; - private final MappedByteBuffer - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; + private final MappedByteBuffer isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; private final MappedByteBuffer logInfoStamp; - private final MappedByteBuffer - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; - private final MappedByteBuffer - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; + private final MappedByteBuffer markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; + private final MappedByteBuffer markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -243,49 +222,24 @@ static List headers(int length) { new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), - new ColumnHeader( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_HASH_INFO_SIZE_xor_ADDRESS_HI_xor_BATCH_NUM", - 8, - length), - new ColumnHeader( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", 8, length), + new ColumnHeader("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 32, length), new ColumnHeader("hub.ALPHA", 1, length), - new ColumnHeader( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", - 32, - length), - new ColumnHeader( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 32, length), + new ColumnHeader("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 32, length), new ColumnHeader("hub.BATCH_NUMBER", 4, length), new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), - new ColumnHeader( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_STATIC_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", - 8, - length), - new ColumnHeader( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), - new ColumnHeader( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", 8, length), + new ColumnHeader("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), + new ColumnHeader("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), - new ColumnHeader( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", - 8, - length), - new ColumnHeader( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", - 8, - length), + new ColumnHeader("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", 8, length), + new ColumnHeader("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", 8, length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), @@ -299,83 +253,39 @@ static List headers(int length) { new ColumnHeader("hub.COUNTER_NSR", 2, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX", 1, length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", - 1, - length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), new ColumnHeader("hub.DELTA", 1, length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", - 1, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", - 1, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", - 1, - length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", 8, length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", 8, length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", 8, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", 1, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", 1, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", 1, length), new ColumnHeader("hub.DOM_STAMP", 8, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), - new ColumnHeader( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", - 1, - length), - new ColumnHeader( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", - 1, - length), + new ColumnHeader("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", 1, length), + new ColumnHeader("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", 1, length), new ColumnHeader("hub.GAS_ACTUAL", 8, length), new ColumnHeader("hub.GAS_COST", 32, length), new ColumnHeader("hub.GAS_EXPECTED", 8, length), new ColumnHeader("hub.GAS_LIMIT", 32, length), new ColumnHeader("hub.GAS_NEXT", 8, length), new ColumnHeader("hub.GAS_PRICE", 32, length), - new ColumnHeader( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", - 1, - length), - new ColumnHeader( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", - 1, - length), + new ColumnHeader("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", 1, length), + new ColumnHeader("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), new ColumnHeader("hub.HEIGHT", 2, length), new ColumnHeader("hub.HEIGHT_NEW", 2, length), new ColumnHeader("hub.HUB_STAMP", 8, length), new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), new ColumnHeader("hub.INSTRUCTION", 32, length), - new ColumnHeader( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", - 1, - length), + new ColumnHeader("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", 1, length), new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", - 1, - length), - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", - 1, - length), + new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", 1, length), + new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", 1, length), new ColumnHeader("hub.MMU_STAMP", 8, length), new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), @@ -389,8 +299,7 @@ static List headers(int length) { new ColumnHeader("hub.NB_REMOVED", 1, length), new ColumnHeader("hub.NON_STACK_ROWS", 2, length), new ColumnHeader("hub.NONCE", 32, length), - new ColumnHeader( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), + new ColumnHeader("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), new ColumnHeader("hub.OOB_DATA_1", 32, length), new ColumnHeader("hub.OOB_DATA_2", 32, length), @@ -434,34 +343,20 @@ static List headers(int length) { new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), - new ColumnHeader( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", - 1, - length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), + new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), + new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + new ColumnHeader("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), + new ColumnHeader("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), + new ColumnHeader("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", 1, length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), - new ColumnHeader( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), - new ColumnHeader( - "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", - 1, - length), + new ColumnHeader("hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), @@ -493,8 +388,7 @@ static List headers(int length) { new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), new ColumnHeader("hub.TRANSACTION_REVERTS", 1, length), - new ColumnHeader( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + new ColumnHeader("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -503,10 +397,7 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", - 1, - length), + new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -515,36 +406,24 @@ public Trace(List buffers) { this.absoluteTransactionNumber = buffers.get(0); this.accFinal = buffers.get(1); this.accFirst = buffers.get(2); - this - .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum = - buffers.get(3); - this - .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = - buffers.get(4); + this.addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = buffers.get(3); + this.addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(4); this.alpha = buffers.get(5); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = - buffers.get(6); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = - buffers.get(7); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(6); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = buffers.get(7); this.batchNumber = buffers.get(8); this.callDataOffsetXorMmuSize = buffers.get(9); this.callDataSizeXorMmuSrcId = buffers.get(10); this.callStackDepth = buffers.get(11); this.callerContextNumber = buffers.get(12); this.codeFragmentIndex = buffers.get(13); - this - .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize = - buffers.get(14); + this.codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = buffers.get(14); this.codeHashHiNewXorExpData5XorValueCurrLoXorValue = buffers.get(15); - this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = - buffers.get(16); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); this.codeHashLoNewXorMmuLimb2XorValueNextLo = buffers.get(17); this.codeHashLoXorMmuLimb1XorValueNextHi = buffers.get(18); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = - buffers.get(19); - this - .codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = - buffers.get(20); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = buffers.get(19); + this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = buffers.get(20); this.conAgain = buffers.get(21); this.conFirst = buffers.get(22); this.contextGetsReverted = buffers.get(23); @@ -563,48 +442,34 @@ public Trace(List buffers) { this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); this.delta = buffers.get(38); - this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = - buffers.get(39); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = buffers.get(39); this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); - this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = - buffers.get(41); - this - .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = - buffers.get(42); - this - .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = - buffers.get(43); - this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = - buffers.get(44); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = buffers.get(41); + this.deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = buffers.get(42); + this.deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = buffers.get(43); + this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = buffers.get(44); this.domStamp = buffers.get(45); this.exceptionAhoy = buffers.get(46); - this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = - buffers.get(47); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = - buffers.get(48); + this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = buffers.get(47); + this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = buffers.get(48); this.gasActual = buffers.get(49); this.gasCost = buffers.get(50); this.gasExpected = buffers.get(51); this.gasLimit = buffers.get(52); this.gasNext = buffers.get(53); this.gasPrice = buffers.get(54); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = - buffers.get(55); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = - buffers.get(56); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = buffers.get(55); + this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = buffers.get(56); this.hashInfoStamp = buffers.get(57); this.height = buffers.get(58); this.heightNew = buffers.get(59); this.hubStamp = buffers.get(60); this.hubStampTransactionEnd = buffers.get(61); this.instruction = buffers.get(62); - this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = - buffers.get(63); + this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = buffers.get(63); this.logInfoStamp = buffers.get(64); - this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = - buffers.get(65); - this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = - buffers.get(66); + this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = buffers.get(65); + this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = buffers.get(66); this.mmuStamp = buffers.get(67); this.mxpOffset2Hi = buffers.get(68); this.mxpOffset2Lo = buffers.get(69); @@ -1124,8 +989,7 @@ public Trace pAccountAddressHi(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -1139,11 +1003,9 @@ public Trace pAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1157,11 +1019,9 @@ public Trace pAccountBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1175,11 +1035,9 @@ public Trace pAccountBalanceNew(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -1191,8 +1049,7 @@ public Trace pAccountCodeFragmentIndex(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -1208,8 +1065,7 @@ public Trace pAccountCodeHashHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1269,8 +1125,7 @@ public Trace pAccountCodeSize(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -1330,8 +1185,7 @@ public Trace pAccountDeploymentStatus(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -1343,8 +1197,7 @@ public Trace pAccountDeploymentStatusInfty(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -1356,8 +1209,7 @@ public Trace pAccountDeploymentStatusNew(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -1369,8 +1221,7 @@ public Trace pAccountExists(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -1382,8 +1233,7 @@ public Trace pAccountExistsNew(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -1395,8 +1245,7 @@ public Trace pAccountHasCode(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -1408,8 +1257,7 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -1421,8 +1269,7 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } @@ -1434,8 +1281,7 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -1447,8 +1293,7 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } @@ -1672,8 +1517,7 @@ public Trace pContextAccountAddressHi(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -1687,11 +1531,9 @@ public Trace pContextAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1703,8 +1545,7 @@ public Trace pContextAccountDeploymentNumber(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -1716,8 +1557,7 @@ public Trace pContextByteCodeAddressHi(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -1731,11 +1571,9 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1835,8 +1673,7 @@ public Trace pContextCallValue(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1862,11 +1699,9 @@ public Trace pContextCallerAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -1890,8 +1725,7 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -1903,8 +1737,7 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -1976,8 +1809,7 @@ public Trace pContextUpdate(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -1989,8 +1821,7 @@ public Trace pMiscCcrsStamp(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -2002,8 +1833,7 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -2017,11 +1847,9 @@ public Trace pMiscExpData1(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -2035,11 +1863,9 @@ public Trace pMiscExpData2(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -2053,11 +1879,9 @@ public Trace pMiscExpData3(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -2073,8 +1897,7 @@ public Trace pMiscExpData4(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -2102,8 +1925,7 @@ public Trace pMiscExpFlag(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -2115,8 +1937,7 @@ public Trace pMiscExpInst(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -2128,8 +1949,7 @@ public Trace pMiscMmuAuxId(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -2153,8 +1973,7 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -2302,8 +2121,7 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -2343,8 +2161,7 @@ public Trace pMiscMxpDeploys(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -2356,8 +2173,7 @@ public Trace pMiscMxpFlag(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -2397,8 +2213,7 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -2410,8 +2225,7 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } @@ -2695,8 +2509,7 @@ public Trace pMiscOobFlag(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -2720,8 +2533,7 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } @@ -2905,36 +2717,31 @@ public Trace pScenarioCallAbort(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { if (filled.get(54)) { - throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { if (filled.get(55)) { - throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -2946,8 +2753,7 @@ public Trace pScenarioCallException(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -2959,86 +2765,74 @@ public Trace pScenarioCallPrcFailure(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { if (filled.get(58)) { - throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { if (filled.get(59)) { - throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { if (filled.get(60)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); } else { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { if (filled.get(61)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); } else { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { if (filled.get(62)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { if (filled.get(63)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(63); } @@ -3062,8 +2856,7 @@ public Trace pScenarioCreateAbort(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { if (filled.get(65)) { - throw new IllegalStateException( - "hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); } else { filled.set(65); } @@ -3075,8 +2868,7 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { if (filled.get(66)) { - throw new IllegalStateException( - "hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); } else { filled.set(66); } @@ -3100,8 +2892,7 @@ public Trace pScenarioCreateException(final Boolean b) { public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { if (filled.get(68)) { - throw new IllegalStateException( - "hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); } else { filled.set(68); } @@ -3113,8 +2904,7 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { if (filled.get(69)) { - throw new IllegalStateException( - "hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); } else { filled.set(69); } @@ -3126,8 +2916,7 @@ public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { if (filled.get(70)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); } else { filled.set(70); } @@ -3139,8 +2928,7 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { if (filled.get(71)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); } else { filled.set(71); } @@ -3152,22 +2940,19 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { if (filled.get(72)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); } else { filled.set(72); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { if (filled.get(73)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); } else { filled.set(73); } @@ -3196,8 +2981,7 @@ public Trace pScenarioPrcCalleeGas(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -3209,8 +2993,7 @@ public Trace pScenarioPrcCallerGas(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -3222,8 +3005,7 @@ public Trace pScenarioPrcCdo(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -3434,8 +3216,7 @@ public Trace pScenarioReturnException(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { if (filled.get(88)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { filled.set(88); } @@ -3447,8 +3228,7 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { if (filled.get(89)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { filled.set(89); } @@ -3460,8 +3240,7 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { if (filled.get(90)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { filled.set(90); } @@ -3473,8 +3252,7 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { if (filled.get(91)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { filled.set(91); } @@ -3486,8 +3264,7 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { if (filled.get(92)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { filled.set(92); } @@ -3499,8 +3276,7 @@ public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { if (filled.get(93)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { filled.set(93); } @@ -3536,8 +3312,7 @@ public Trace pScenarioSelfdestructWillRevert(final Boolean b) { public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { if (filled.get(96)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { filled.set(96); } @@ -3549,8 +3324,7 @@ public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { if (filled.get(97)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { filled.set(97); } @@ -3567,8 +3341,7 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -3580,8 +3353,7 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -3605,8 +3377,7 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -3618,8 +3389,7 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -3631,8 +3401,7 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -3644,8 +3413,7 @@ public Trace pStackConFlag(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -3657,8 +3425,7 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -3670,8 +3437,7 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } @@ -3683,8 +3449,7 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -3696,8 +3461,7 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } @@ -3795,11 +3559,9 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -3813,24 +3575,9 @@ public Trace pStackHashInfoKeccakLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); - - return this; - } - - public Trace pStackHashInfoSize(final long b) { - if (filled.get(107)) { - throw new IllegalStateException("hub.stack/HASH_INFO_SIZE already set"); - } else { - filled.set(107); - } - - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .putLong(b); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -3882,8 +3629,7 @@ public Trace pStackJumpDestinationVettingRequired(final Boolean b) { filled.set(72); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); return this; } @@ -4077,11 +3823,9 @@ public Trace pStackPushValueHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -4097,8 +3841,7 @@ public Trace pStackPushValueLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4492,14 +4235,13 @@ public Trace pStackStaticFlag(final Boolean b) { } public Trace pStackStaticGas(final long b) { - if (filled.get(108)) { + if (filled.get(107)) { throw new IllegalStateException("hub.stack/STATIC_GAS already set"); } else { - filled.set(108); + filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -4583,8 +4325,7 @@ public Trace pStorageAddressHi(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -4598,11 +4339,9 @@ public Trace pStorageAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4614,8 +4353,7 @@ public Trace pStorageDeploymentNumber(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -4627,8 +4365,7 @@ public Trace pStorageDeploymentNumberInfty(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -4642,11 +4379,9 @@ public Trace pStorageStorageKeyHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4660,11 +4395,9 @@ public Trace pStorageStorageKeyLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -4676,8 +4409,7 @@ public Trace pStorageValueCurrChanges(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -4693,8 +4425,7 @@ public Trace pStorageValueCurrHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4706,8 +4437,7 @@ public Trace pStorageValueCurrIsOrig(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -4719,8 +4449,7 @@ public Trace pStorageValueCurrIsZero(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -4764,8 +4493,7 @@ public Trace pStorageValueNextIsCurr(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -4777,8 +4505,7 @@ public Trace pStorageValueNextIsOrig(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -4790,8 +4517,7 @@ public Trace pStorageValueNextIsZero(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -4835,8 +4561,7 @@ public Trace pStorageValueOrigIsZero(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -4864,8 +4589,7 @@ public Trace pStorageWarmth(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } @@ -4877,8 +4601,7 @@ public Trace pStorageWarmthNew(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -4906,8 +4629,7 @@ public Trace pTransactionBatchNum(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -4919,8 +4641,7 @@ public Trace pTransactionCallDataSize(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -4932,8 +4653,7 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -4947,11 +4667,9 @@ public Trace pTransactionCoinbaseAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4963,8 +4681,7 @@ public Trace pTransactionCopyTxcd(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -4990,11 +4707,9 @@ public Trace pTransactionFromAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -5084,11 +4799,9 @@ public Trace pTransactionInitialBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -5100,8 +4813,7 @@ public Trace pTransactionIsDeployment(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -5113,8 +4825,7 @@ public Trace pTransactionIsType2(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -5190,8 +4901,7 @@ public Trace pTransactionRequiresEvmExecution(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -5203,8 +4913,7 @@ public Trace pTransactionStatusCode(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -5232,8 +4941,7 @@ public Trace pTransactionToAddressLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -5520,13 +5228,11 @@ public Trace validateRow() { } if (!filled.get(107)) { - throw new IllegalStateException( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_HASH_INFO_SIZE_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); + throw new IllegalStateException("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } if (!filled.get(132)) { - throw new IllegalStateException( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); + throw new IllegalStateException("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } if (!filled.get(102)) { @@ -5534,13 +5240,11 @@ public Trace validateRow() { } if (!filled.get(134)) { - throw new IllegalStateException( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); + throw new IllegalStateException("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } if (!filled.get(133)) { - throw new IllegalStateException( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); + throw new IllegalStateException("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } if (!filled.get(1)) { @@ -5568,38 +5272,31 @@ public Trace validateRow() { } if (!filled.get(108)) { - throw new IllegalStateException( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_STATIC_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); + throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } if (!filled.get(136)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } if (!filled.get(135)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } if (!filled.get(138)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } if (!filled.get(137)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } if (!filled.get(110)) { - throw new IllegalStateException( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } if (!filled.get(109)) { - throw new IllegalStateException( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); } if (!filled.get(49)) { @@ -5651,28 +5348,23 @@ public Trace validateRow() { } if (!filled.get(69)) { - throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + throw new IllegalStateException("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); } if (!filled.get(70)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); } if (!filled.get(71)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); } if (!filled.get(72)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); } if (!filled.get(73)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); } if (!filled.get(103)) { @@ -5680,33 +5372,27 @@ public Trace validateRow() { } if (!filled.get(112)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } if (!filled.get(113)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } if (!filled.get(111)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } if (!filled.get(54)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(55)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); } if (!filled.get(53)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); } if (!filled.get(13)) { @@ -5718,13 +5404,11 @@ public Trace validateRow() { } if (!filled.get(57)) { - throw new IllegalStateException( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); + throw new IllegalStateException("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); } if (!filled.get(56)) { - throw new IllegalStateException( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); + throw new IllegalStateException("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(15)) { @@ -5752,13 +5436,11 @@ public Trace validateRow() { } if (!filled.get(59)) { - throw new IllegalStateException( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); + throw new IllegalStateException("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(58)) { - throw new IllegalStateException( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + throw new IllegalStateException("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(19)) { @@ -5786,8 +5468,7 @@ public Trace validateRow() { } if (!filled.get(60)) { - throw new IllegalStateException( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); + throw new IllegalStateException("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); } if (!filled.get(24)) { @@ -5795,13 +5476,11 @@ public Trace validateRow() { } if (!filled.get(62)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); } if (!filled.get(61)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); } if (!filled.get(25)) { @@ -5857,8 +5536,7 @@ public Trace validateRow() { } if (!filled.get(124)) { - throw new IllegalStateException( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + throw new IllegalStateException("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } if (!filled.get(123)) { @@ -5938,8 +5616,7 @@ public Trace validateRow() { } if (!filled.get(77)) { - throw new IllegalStateException( - "hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); } if (!filled.get(78)) { @@ -5947,13 +5624,11 @@ public Trace validateRow() { } if (!filled.get(79)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); } if (!filled.get(80)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); } if (!filled.get(81)) { @@ -5973,8 +5648,7 @@ public Trace validateRow() { } if (!filled.get(85)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_SUCCESS_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(86)) { @@ -6018,13 +5692,11 @@ public Trace validateRow() { } if (!filled.get(120)) { - throw new IllegalStateException( - "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + throw new IllegalStateException("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } if (!filled.get(121)) { - throw new IllegalStateException( - "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + throw new IllegalStateException("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } if (!filled.get(122)) { @@ -6036,63 +5708,51 @@ public Trace validateRow() { } if (!filled.get(88)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); } if (!filled.get(89)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(90)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(91)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(92)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(93)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } if (!filled.get(114)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } if (!filled.get(139)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } if (!filled.get(63)) { - throw new IllegalStateException( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); + throw new IllegalStateException("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); } if (!filled.get(140)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); + throw new IllegalStateException("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } if (!filled.get(141)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); + throw new IllegalStateException("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } if (!filled.get(64)) { - throw new IllegalStateException( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + throw new IllegalStateException("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } if (!filled.get(142)) { @@ -6100,33 +5760,27 @@ public Trace validateRow() { } if (!filled.get(143)) { - throw new IllegalStateException( - "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); + throw new IllegalStateException("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } if (!filled.get(65)) { - throw new IllegalStateException( - "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + throw new IllegalStateException("hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } if (!filled.get(94)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); } if (!filled.get(95)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); } if (!filled.get(96)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); } if (!filled.get(97)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } if (!filled.get(165)) { @@ -6210,8 +5864,7 @@ public Trace validateRow() { } if (!filled.get(125)) { - throw new IllegalStateException( - "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); + throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } if (!filled.get(162)) { @@ -6239,13 +5892,11 @@ public Trace validateRow() { } if (!filled.get(66)) { - throw new IllegalStateException( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + throw new IllegalStateException("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } if (!filled.get(144)) { - throw new IllegalStateException( - "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); + throw new IllegalStateException("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } if (!filled.get(41)) { @@ -6277,13 +5928,11 @@ public Trace validateRow() { } if (!filled.get(68)) { - throw new IllegalStateException( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + throw new IllegalStateException("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); } if (!filled.get(67)) { - throw new IllegalStateException( - "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + throw new IllegalStateException("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } if (!filled.get(101)) { @@ -6310,19 +5959,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(107)) { - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .position( - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorHashInfoSizeXorAddressHiXorBatchNum - .position() - + 8); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position(addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position() + 8); } if (!filled.get(132)) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position( - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position() - + 32); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position(addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position() + 32); } if (!filled.get(102)) { @@ -6330,19 +5971,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(134)) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position( - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position() - + 32); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position(balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position() + 32); } if (!filled.get(133)) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position( - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position() - + 32); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position(balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position() + 32); } if (!filled.get(1)) { @@ -6370,46 +6003,31 @@ public Trace fillAndValidateRow() { } if (!filled.get(108)) { - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .position( - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorStaticGasXorDeploymentNumberXorCallDataSize - .position() - + 8); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position(codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position() + 8); } if (!filled.get(136)) { - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position(codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); } if (!filled.get(135)) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() - + 32); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position(codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 32); } if (!filled.get(138)) { - codeHashLoNewXorMmuLimb2XorValueNextLo.position( - codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); + codeHashLoNewXorMmuLimb2XorValueNextLo.position(codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); } if (!filled.get(137)) { - codeHashLoXorMmuLimb1XorValueNextHi.position( - codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); + codeHashLoXorMmuLimb1XorValueNextHi.position(codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); } if (!filled.get(110)) { - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() - + 8); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position(codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + 8); } if (!filled.get(109)) { - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .position( - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .position() - + 8); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position(codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position() + 8); } if (!filled.get(49)) { @@ -6461,28 +6079,23 @@ public Trace fillAndValidateRow() { } if (!filled.get(69)) { - createFailureConditionWontRevertXorIcpx.position( - createFailureConditionWontRevertXorIcpx.position() + 1); + createFailureConditionWontRevertXorIcpx.position(createFailureConditionWontRevertXorIcpx.position() + 1); } if (!filled.get(70)) { - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position( - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position(createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); } if (!filled.get(71)) { - createNonemptyInitCodeFailureWontRevertXorJumpx.position( - createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); + createNonemptyInitCodeFailureWontRevertXorJumpx.position(createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); } if (!filled.get(72)) { - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position( - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position(createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); } if (!filled.get(73)) { - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position( - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position(createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); } if (!filled.get(103)) { @@ -6490,45 +6103,27 @@ public Trace fillAndValidateRow() { } if (!filled.get(112)) { - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi - .position() - + 8); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position(deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position() + 8); } if (!filled.get(113)) { - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position(deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); } if (!filled.get(111)) { - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() - + 8); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position(deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + 8); } if (!filled.get(54)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .position( - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .position() - + 1); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position(deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position() + 1); } if (!filled.get(55)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .position( - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .position() - + 1); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position(deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position() + 1); } if (!filled.get(53)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd - .position( - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd - .position() - + 1); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position(deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position() + 1); } if (!filled.get(13)) { @@ -6540,18 +6135,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(57)) { - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position( - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode - .position() - + 1); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position(existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position() + 1); } if (!filled.get(56)) { - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution - .position( - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution - .position() - + 1); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position(existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position() + 1); } if (!filled.get(15)) { @@ -6579,16 +6167,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(59)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position( - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero - .position() - + 1); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position(hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position() + 1); } if (!filled.get(58)) { - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position( - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() - + 1); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position(hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() + 1); } if (!filled.get(19)) { @@ -6616,9 +6199,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(60)) { - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position( - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() - + 1); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position(isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + 1); } if (!filled.get(24)) { @@ -6626,18 +6207,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(62)) { - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position( - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 - .position() - + 1); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position(markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position() + 1); } if (!filled.get(61)) { - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew - .position( - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew - .position() - + 1); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position(markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position() + 1); } if (!filled.get(25)) { @@ -6693,8 +6267,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(124)) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position(nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); } if (!filled.get(123)) { @@ -6806,8 +6379,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(85)) { - prcSuccessWillRevertXorPushpopFlag.position( - prcSuccessWillRevertXorPushpopFlag.position() + 1); + prcSuccessWillRevertXorPushpopFlag.position(prcSuccessWillRevertXorPushpopFlag.position() + 1); } if (!filled.get(86)) { @@ -6851,8 +6423,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(120)) { - returnDataContextNumberXorStpGasStipend.position( - returnDataContextNumberXorStpGasStipend.position() + 8); + returnDataContextNumberXorStpGasStipend.position(returnDataContextNumberXorStpGasStipend.position() + 8); } if (!filled.get(121)) { @@ -6868,53 +6439,43 @@ public Trace fillAndValidateRow() { } if (!filled.get(88)) { - returnFromDeploymentEmptyCodeWillRevertXorSox.position( - returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + returnFromDeploymentEmptyCodeWillRevertXorSox.position(returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); } if (!filled.get(89)) { - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position( - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position(returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); } if (!filled.get(90)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position( - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position(returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); } if (!filled.get(91)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position( - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position(returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); } if (!filled.get(92)) { - returnFromMessageCallWillTouchRamXorStackItemPop2.position( - returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop2.position(returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); } if (!filled.get(93)) { - returnFromMessageCallWontTouchRamXorStackItemPop3.position( - returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); + returnFromMessageCallWontTouchRamXorStackItemPop3.position(returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } if (!filled.get(114)) { - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position(rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); } if (!filled.get(139)) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position(rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); } if (!filled.get(63)) { - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position( - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position(rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); } if (!filled.get(140)) { - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position(rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); } if (!filled.get(141)) { @@ -6922,8 +6483,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(64)) { - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position(rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } if (!filled.get(142)) { @@ -6935,13 +6495,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(65)) { - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position(romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } if (!filled.get(94)) { - selfdestructExceptionXorStackItemPop4.position( - selfdestructExceptionXorStackItemPop4.position() + 1); + selfdestructExceptionXorStackItemPop4.position(selfdestructExceptionXorStackItemPop4.position() + 1); } if (!filled.get(95)) { @@ -6949,13 +6507,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(96)) { - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position( - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position(selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); } if (!filled.get(97)) { - selfdestructWontRevertNotYetMarkedXorStoFlag.position( - selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); + selfdestructWontRevertNotYetMarkedXorStoFlag.position(selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } if (!filled.get(165)) { @@ -7039,8 +6595,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(125)) { - stpGasUpfrontGasCostXorGasLeftover.position( - stpGasUpfrontGasCostXorGasLeftover.position() + 32); + stpGasUpfrontGasCostXorGasLeftover.position(stpGasUpfrontGasCostXorGasLeftover.position() + 32); } if (!filled.get(162)) { @@ -7068,8 +6623,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(66)) { - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position(trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } if (!filled.get(144)) { @@ -7105,13 +6659,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(68)) { - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position(warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); } if (!filled.get(67)) { - warmthXorCreateExceptionXorHaltFlag.position( - warmthXorCreateExceptionXorHaltFlag.position() + 1); + warmthXorCreateExceptionXorHaltFlag.position(warmthXorCreateExceptionXorHaltFlag.position() + 1); } if (!filled.get(101)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java index 584acb09df..0e624dfe99 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java @@ -95,24 +95,22 @@ public Trace trace(Trace trace) { return trace .peekAtAccount(true) - .pAccountTrmFlag(this.addressToTrim.isPresent()) - .pAccountTrmRawAddressHi(this.addressToTrim.map(a -> EWord.of(a).hi()).orElse(Bytes.EMPTY)) - .pAccountAddressHi(eWho.hi()) + .pAccountAddressHi(eWho.hi().toLong()) .pAccountAddressLo(eWho.lo()) - .pAccountIsPrecompile(isPrecompile(who)) .pAccountNonce(Bytes.ofUnsignedLong(oldState.nonce())) .pAccountNonceNew(Bytes.ofUnsignedLong(newState.nonce())) .pAccountBalance(oldState.balance()) .pAccountBalanceNew(newState.balance()) - .pAccountCodeSize(Bytes.ofUnsignedInt(oldState.code().getSize())) - .pAccountCodeSizeNew(Bytes.ofUnsignedInt(newState.code().getSize())) + .pAccountCodeSize(oldState.code().getSize()) + .pAccountCodeSizeNew(newState.code().getSize()) .pAccountCodeHashHi(eCodeHash.hi()) - .pAccountCodeHashLo(eCodeHash.lo()) .pAccountCodeHashHiNew(eCodeHashNew.hi()) + .pAccountCodeHashLo(eCodeHash.lo()) .pAccountCodeHashLoNew(eCodeHashNew.lo()) .pAccountHasCode(oldState.code().getCodeHash() != Hash.EMPTY) .pAccountHasCodeNew(newState.code().getCodeHash() != Hash.EMPTY) - .pAccountCodeFragmentIndex(Bytes.of(this.codeFragmentIndex)) + .pAccountCodeFragmentIndex(this.codeFragmentIndex) + .pAccountRomLexFlag(false) // TODO .pAccountExists( oldState.nonce() > 0 || oldState.code().getCodeHash() != Hash.EMPTY @@ -123,12 +121,26 @@ public Trace trace(Trace trace) { || !newState.balance().isZero()) .pAccountWarmth(oldState.isWarm()) .pAccountWarmthNew(newState.isWarm()) - .pAccountDeploymentNumber(Bytes.ofUnsignedInt(oldState.deploymentNumber())) - .pAccountDeploymentNumberNew(Bytes.ofUnsignedInt(newState.deploymentNumber())) - .pAccountDeploymentNumberInfty(Bytes.ofUnsignedInt(deploymentNumberInfinity)) + .pAccountMarkedForSelfdestruct(false) // TODO: + .pAccountMarkedForSelfdestructNew(false) // TODO + .pAccountDeploymentNumber(oldState.deploymentNumber()) + .pAccountDeploymentNumberNew(newState.deploymentNumber()) .pAccountDeploymentStatus(oldState.deploymentStatus()) .pAccountDeploymentStatusNew(newState.deploymentStatus()) - .pAccountDeploymentStatusInfty(existsInfinity); + .pAccountDeploymentNumberInfty(deploymentNumberInfinity) + .pAccountDeploymentStatusInfty(existsInfinity) + .pAccountTrmFlag(this.addressToTrim.isPresent()) + .pAccountTrmRawAddressHi(this.addressToTrim.map(a -> EWord.of(a).hi()).orElse(Bytes.EMPTY)) + .pAccountIsPrecompile(isPrecompile(who)) + .pAccountRlpaddrFlag(false) // TODO + .pAccountRlpaddrRecipe(false) // TODO + .pAccountRlpaddrDepAddrHi(0) // TODO + .pAccountRlpaddrDepAddrLo(Bytes.EMPTY) // TODO + .pAccountRlpaddrSaltHi(Bytes.EMPTY) // TODO + .pAccountRlpaddrSaltLo(Bytes.EMPTY) // TODO + .pAccountRlpaddrKecHi(Bytes.EMPTY) // TODO + .pAccountRlpaddrKecLo(Bytes.EMPTY) // TODO + ; } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index d6812edf0a..83ab486544 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -91,35 +91,32 @@ public Trace trace(Trace trace) { final EWord eAddress = callFrame.addressAsEWord(); final EWord eCodeAddress = callFrame.codeAddressAsEWord(); final EWord parentAddress = parent.addressAsEWord(); - return trace .peekAtContext(true) - .pContextContextNumber(Bytes.ofUnsignedInt(callFrame.contextNumber())) - .pContextCallStackDepth(Bytes.ofUnsignedInt(callFrame.depth())) + .pContextContextNumber(callFrame.contextNumber()) + .pContextCallStackDepth((short) callFrame.depth()) + .pContextIsRoot(callFrame.isRoot()) .pContextIsStatic(callFrame.type().isStatic()) - .pContextAccountAddressHi(eAddress.hi()) + .pContextAccountAddressHi(eAddress.hi().toLong()) .pContextAccountAddressLo(eAddress.lo()) - .pContextByteCodeAddressHi(eCodeAddress.hi()) + .pContextAccountDeploymentNumber(callFrame.accountDeploymentNumber()) + .pContextByteCodeAddressHi(eCodeAddress.hi().toLong()) .pContextByteCodeAddressLo(eCodeAddress.lo()) - .pContextAccountDeploymentNumber(Bytes.ofUnsignedInt(callFrame.accountDeploymentNumber())) - .pContextByteCodeDeploymentNumber(Bytes.ofUnsignedInt(callFrame.codeDeploymentNumber())) - .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? Bytes.of(1) : Bytes.EMPTY) - .pContextCallDataContextNumber(Bytes.ofUnsignedInt(parent.contextNumber())) - .pContextCallerAddressHi(parentAddress.hi()) + .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) + .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) + .pContextByteCodeCodeFragmentIndex(0) // TODO + .pContextCallerAddressHi(parentAddress.hi().toLong()) .pContextCallerAddressLo(parentAddress.lo()) .pContextCallValue(callFrame.value()) - .pContextCallDataOffset( - Bytes.ofUnsignedLong(callFrame.callDataInfo().memorySpan().offset())) - .pContextCallDataSize(Bytes.ofUnsignedLong(callFrame.callDataInfo().memorySpan().length())) - .pContextReturnAtOffset( - Bytes.ofUnsignedLong(callFrame.requestedReturnDataTarget().offset())) - .pContextReturnAtCapacity( - Bytes.ofUnsignedLong(callFrame.requestedReturnDataTarget().length())) + .pContextCallDataContextNumber(parent.contextNumber()) + .pContextCallDataOffset(callFrame.callDataInfo().memorySpan().offset()) + .pContextCallDataSize(callFrame.callDataInfo().memorySpan().length()) + .pContextReturnAtOffset(callFrame.requestedReturnDataTarget().offset()) + .pContextReturnAtCapacity(callFrame.requestedReturnDataTarget().length()) .pContextUpdate(updateCallerReturndata) .pContextReturnDataContextNumber( - Bytes.ofUnsignedInt( - callFrame.lastCallee().map(c -> callStack.getById(c).contextNumber()).orElse(0))) - .pContextReturnDataOffset(Bytes.ofUnsignedLong(returnDataSegment.offset())) - .pContextReturnDataSize(Bytes.ofUnsignedLong(returnDataSegment.length())); + callFrame.lastCallee().map(c -> callStack.getById(c).contextNumber()).orElse(0)) + .pContextReturnDataOffset(returnDataSegment.offset()) + .pContextReturnDataSize(returnDataSegment.length()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 94e1c7b93b..5d9841422a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -35,6 +35,7 @@ import net.consensys.linea.zktracer.runtime.stack.Stack; import net.consensys.linea.zktracer.runtime.stack.StackOperation; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; @@ -181,93 +182,74 @@ public Trace trace(Trace trace) { stampTracers.get(i).apply(Bytes.ofUnsignedLong(op.stackStamp())); } + final InstructionFamily currentInstFamily = + this.stack.getCurrentOpcodeData().instructionFamily(); + return trace .peekAtStack(true) // Instruction details - .pStackAlpha(Bytes.ofUnsignedInt(this.stack.getCurrentOpcodeData().stackSettings().alpha())) - .pStackDelta(Bytes.ofUnsignedInt(this.stack.getCurrentOpcodeData().stackSettings().delta())) - .pStackNbAdded( - Bytes.ofUnsignedInt(this.stack.getCurrentOpcodeData().stackSettings().nbAdded())) + .pStackAlpha(UnsignedByte.of(this.stack.getCurrentOpcodeData().stackSettings().alpha())) + .pStackDelta(UnsignedByte.of(this.stack.getCurrentOpcodeData().stackSettings().delta())) + .pStackNbAdded(UnsignedByte.of(this.stack.getCurrentOpcodeData().stackSettings().nbAdded())) .pStackNbRemoved( - Bytes.ofUnsignedInt(this.stack.getCurrentOpcodeData().stackSettings().nbRemoved())) + UnsignedByte.of(this.stack.getCurrentOpcodeData().stackSettings().nbRemoved())) .pStackInstruction(Bytes.of(this.stack.getCurrentOpcodeData().value())) - .pStackStaticGas(Bytes.ofUnsignedInt(staticGas)) - .pStackPushValueHi(pushValue.hi()) - .pStackPushValueLo(pushValue.lo()) + .pStackStaticGas(staticGas) + // Opcode families + .pStackAccFlag(currentInstFamily == InstructionFamily.ACCOUNT) + .pStackAddFlag(currentInstFamily == InstructionFamily.ADD) + .pStackBinFlag(currentInstFamily == InstructionFamily.BIN) + .pStackBtcFlag(currentInstFamily == InstructionFamily.BATCH) + .pStackCallFlag(currentInstFamily == InstructionFamily.CALL) + .pStackConFlag(currentInstFamily == InstructionFamily.CONTEXT) + .pStackCopyFlag(currentInstFamily == InstructionFamily.COPY) + .pStackCreateFlag(currentInstFamily == InstructionFamily.CREATE) + .pStackDupFlag(currentInstFamily == InstructionFamily.DUP) + .pStackExtFlag(currentInstFamily == InstructionFamily.EXT) + .pStackHaltFlag(currentInstFamily == InstructionFamily.HALT) + .pStackInvalidFlag(currentInstFamily == InstructionFamily.INVALID) + .pStackJumpFlag(currentInstFamily == InstructionFamily.JUMP) + .pStackKecFlag(currentInstFamily == InstructionFamily.KEC) + .pStackLogFlag(currentInstFamily == InstructionFamily.LOG) + .pStackMachineStateFlag(currentInstFamily == InstructionFamily.MACHINE_STATE) + .pStackModFlag(currentInstFamily == InstructionFamily.MOD) + .pStackMulFlag(currentInstFamily == InstructionFamily.MUL) + .pStackPushpopFlag(currentInstFamily == InstructionFamily.PUSH_POP) + .pStackShfFlag(currentInstFamily == InstructionFamily.SHF) + .pStackStackramFlag(currentInstFamily == InstructionFamily.STACK_RAM) + .pStackStoFlag(currentInstFamily == InstructionFamily.STORAGE) + .pStackSwapFlag(currentInstFamily == InstructionFamily.SWAP) + .pStackTxnFlag(currentInstFamily == InstructionFamily.TRANSACTION) + .pStackWcpFlag(currentInstFamily == InstructionFamily.WCP) .pStackDecFlag1(this.stack.getCurrentOpcodeData().stackSettings().flag1()) .pStackDecFlag2(this.stack.getCurrentOpcodeData().stackSettings().flag2()) .pStackDecFlag3(this.stack.getCurrentOpcodeData().stackSettings().flag3()) .pStackDecFlag4(this.stack.getCurrentOpcodeData().stackSettings().flag4()) + .pStackMxpFlag( + Optional.ofNullable(this.stack.getCurrentOpcodeData().billing()) + .map(b -> b.type() != MxpType.NONE) + .orElse(false)) + .pStackStaticFlag(this.stack.getCurrentOpcodeData().stackSettings().forbiddenInStatic()) + .pStackPushValueHi(pushValue.hi()) + .pStackPushValueLo(pushValue.lo()) + .pStackJumpDestinationVettingRequired(false) // TODO // Exception flag .pStackOpcx(exceptions.invalidOpcode()) .pStackSux(exceptions.stackUnderflow()) .pStackSox(exceptions.stackOverflow()) - .pStackOogx(exceptions.outOfGas()) .pStackMxpx(exceptions.outOfMemoryExpansion()) + .pStackOogx(exceptions.outOfGas()) .pStackRdcx(exceptions.returnDataCopyFault()) .pStackJumpx(exceptions.jumpFault()) .pStackStaticx(exceptions.staticFault()) .pStackSstorex(exceptions.outOfSStore()) .pStackIcpx(contextExceptions.invalidCodePrefix()) .pStackMaxcsx(contextExceptions.codeSizeOverflow()) - // Opcode families - .pStackAddFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.ADD) - .pStackModFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.MOD) - .pStackMulFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.MUL) - .pStackExtFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.EXT) - .pStackWcpFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.WCP) - .pStackBinFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.BIN) - .pStackShfFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.SHF) - .pStackKecFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.KEC) - .pStackConFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.CONTEXT) - .pStackAccFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.ACCOUNT) - .pStackCopyFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.COPY) - .pStackTxnFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.TRANSACTION) - .pStackBtcFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.BATCH) - .pStackStackramFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.STACK_RAM) - .pStackStoFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.STORAGE) - .pStackJumpFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.JUMP) - .pStackPushpopFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.PUSH_POP) - .pStackDupFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.DUP) - .pStackSwapFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.SWAP) - .pStackLogFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.LOG) - .pStackCreateFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.CREATE) - .pStackCallFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.CALL) - .pStackHaltFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.HALT) - .pStackInvalidFlag( - this.stack.getCurrentOpcodeData().instructionFamily() == InstructionFamily.INVALID) - .pStackMxpFlag( - Optional.ofNullable(this.stack.getCurrentOpcodeData().billing()) - .map(b -> b.type() != MxpType.NONE) - .orElse(false)) - .pStackStaticFlag(this.stack.getCurrentOpcodeData().stackSettings().forbiddenInStatic()) // Hash data - .pStackHashInfoSize(Bytes.ofUnsignedInt(hashInfoSize)) + .pStackHashInfoFlag(this.hashInfoFlag) .pStackHashInfoKeccakHi(this.hashInfoKeccak.hi()) .pStackHashInfoKeccakLo(this.hashInfoKeccak.lo()) - .pStackHashInfoFlag(this.hashInfoFlag); + .pStackLogInfoFlag(false) // TODO + ; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java index 8fa83caca9..6dba76deac 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java @@ -17,7 +17,6 @@ import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; /** @@ -40,12 +39,11 @@ public record StorageFragment( @Override public Trace trace(Trace trace) { final EWord eAddress = EWord.of(address); - return trace .peekAtStorage(true) - .pStorageAddressHi(eAddress.hi()) + .pStorageAddressHi(eAddress.hi().toLong()) .pStorageAddressLo(eAddress.lo()) - .pStorageDeploymentNumber(Bytes.ofUnsignedInt(deploymentNumber)) + .pStorageDeploymentNumber(deploymentNumber) .pStorageStorageKeyHi(key.hi()) .pStorageStorageKeyLo(key.lo()) .pStorageValueOrigHi(valOrig.hi()) @@ -57,9 +55,10 @@ public Trace trace(Trace trace) { .pStorageWarmth(oldWarmth) .pStorageWarmthNew(newWarmth) .pStorageValueOrigIsZero(valOrig.isZero()) + .pStorageValueCurrIsOrig(valCurr.equals(valOrig)) .pStorageValueCurrIsZero(valCurr.isZero()) + .pStorageValueNextIsCurr(valNext == valOrig) .pStorageValueNextIsZero(valNext.isZero()) - .pStorageValueNextIsOrig(valNext == valOrig) - .pStorageValueNextIsCurr(valNext == valOrig); + .pStorageValueNextIsOrig(valNext == valOrig); } } diff --git a/zkevm-constraints b/zkevm-constraints index 42ebec79c5..5e42309d55 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 42ebec79c56ba2aac16c843062baa1f61c5b07bf +Subproject commit 5e42309d551c8dda4c1eb1824bdb66ecd08eb744 From 3a3079c82ed19fdc8e8e8e9141603d0bb20725f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 31 May 2024 23:26:17 +0400 Subject: [PATCH 004/461] feat(hub): more stuff in CommonFragment Added several items in the CommonFragment class WARNING: wip and TraceSection now contains a worldview that isn't set anywhere. --- .../linea/zktracer/module/hub/Hub.java | 37 ++++++++++++++- .../module/hub/fragment/CommonFragment.java | 45 ++++++++++++++++--- .../module/hub/fragment/imc/ImcFragment.java | 6 +-- .../fragment/scenario/ScenarioFragment.java | 8 ++-- .../module/hub/section/CreateSection.java | 8 ++-- .../module/hub/section/TraceSection.java | 8 ++-- .../hub/signals/AbortingConditions.java | 6 +-- .../hub/signals/PlatformController.java | 18 ++++---- .../zktracer/module/hub/signals/Signals.java | 10 ++--- .../linea/zktracer/module/limits/Keccak.java | 2 +- 10 files changed, 107 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 03ed58cb55..f142c4cfbb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -647,6 +647,39 @@ public CallFrame currentFrame() { return this.callStack.current(); } + public int contextNumberNew(WorldView world) { + OpCode opCode = this.opCode(); + if (pch.exceptions().any() + || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) + || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)){ + return this.callStack().caller().contextNumber(); + } + + final int currentContextNumber = this.callStack().current().contextNumber(); + + if (opCode.isCall()) { + if (pch().abortingConditions().any()) { + return currentContextNumber; + } + Address calleeAddress = Address.extract((Bytes32) this.currentFrame().frame().getStackItem(1)); + if (world.get(calleeAddress).hasCode()) { + return 1 + stamp(); + } + } + + if (opCode.isCreate()) { + if (pch().abortingConditions().any() || pch().failureConditions().any()) { + return currentContextNumber; + } + final int initCodeSize = this.currentFrame().frame().getStackItem(2).toInt(); + if (initCodeSize != 0) { + return 1 + stamp(); + } + } + + return currentContextNumber; + } + public MessageFrame messageFrame() { return this.callStack.current().frame(); } @@ -656,7 +689,7 @@ private void handleStack(MessageFrame frame) { } void triggerModules(MessageFrame frame) { - if (this.pch.exceptions().none() && this.pch.aborts().none()) { + if (this.pch.exceptions().none() && this.pch.abortingConditions().none()) { for (Module precompileLimit : this.precompileLimitModules) { precompileLimit.tracePreOpcode(frame); } @@ -1475,7 +1508,7 @@ void traceOperation(MessageFrame frame) { .makeWithTrm( calledAccountSnapshot, calledAccountSnapshot, rawCalledAddress))); } - } else if (this.pch.aborts().any()) { + } else if (this.pch.abortingConditions().any()) { // // THERE IS AN ABORT // diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 1d111f1f76..19bc4c3c44 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -23,12 +23,17 @@ import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.TransactionStack; +import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.TxState; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.worldstate.WorldView; import java.math.BigInteger; @@ -42,7 +47,10 @@ public final class CommonFragment implements TraceFragment { private final State.TxState.Stamps stamps; private final InstructionFamily instructionFamily; private final Exceptions exceptions; + private final AbortingConditions abortingConditions; + private final FailureConditions failureConditions; private final int callFrameId; + private final int callerContextNumber; @Getter private final int contextNumber; @Setter private int contextNumberNew; private final int revertStamp; @@ -52,7 +60,6 @@ public final class CommonFragment implements TraceFragment { @Setter private int pcNew; private int codeDeploymentNumber; private final boolean codeDeploymentStatus; - private final int callerContextNumber; private final long gasExpected; private final long gasActual; private final long gasCost; @@ -64,10 +71,8 @@ public final class CommonFragment implements TraceFragment { @Getter @Setter private int numberOfNonStackRows; @Getter @Setter private int nonStackRowsCounter; - public static CommonFragment fromHub( - final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowsCounter) { + public static CommonFragment fromHub(WorldView world, final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowsCounter) { long refund = 0; - boolean noStackException = hub.pch().exceptions().noStackException(); if (noStackException) { @@ -92,9 +97,11 @@ public static CommonFragment fromHub( .stamps(hub.state.stamps()) .instructionFamily(hub.opCodeData().instructionFamily()) .exceptions(hub.pch().exceptions().snapshot()) + .abortingConditions(hub.pch().abortingConditions().snapshot()) + .failureConditions(hub.pch().failureConditions().snapshot()) .callFrameId(frame.id()) .contextNumber(frame.contextNumber()) - .contextNumberNew(frame.contextNumber()) // TODO + .contextNumberNew(hub.contextNumberNew(world)) .pc(pc) .pcNew(pcNew) .height((short) height) @@ -139,8 +146,32 @@ private static int computePcNew(final Hub hub, final int pc) { return pc + 1; } - private static int computeContextNumberNew(final Hub hub) { - return 0; // TODO + private int computeContextNumberNew(WorldView world, final Hub hub) { + OpCode opCode = hub.opCode(); + if (exceptions.any() + || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) + || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)){ + return callerContextNumber; + } + + if (opCode.isCall()) { + // If abortingConditions Then contextNumberNew <-- contextNumber + Address calleeAddress = Address.extract((Bytes32) hub.currentFrame().frame().getStackItem(1)); + if (world.get(calleeAddress).hasCode()) { + return 1 + hub.stamp(); + } + } + + if (opCode.isCreate()) { + // If (abortingConditions ∨ failureConditions) Then contextNumberNew <-- contextNumber + final int initCodeSize = hub.currentFrame().frame().getStackItem(2).toInt(); + if (initCodeSize != 0) { + return 1 + hub.stamp(); + } + } + + return contextNumber; + } public boolean txReverts() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index b10b2448d0..547f2f0476 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -129,7 +129,7 @@ public static ImcFragment forCall( EWord.of(hub.messageFrame().getStackItem(2)), EWord.of(callerAccount.getBalance()), hub.callStack().depth(), - hub.pch().aborts().any())); + hub.pch().abortingConditions().any())); } } default -> throw new IllegalArgumentException("unexpected opcode for IMC/CALL"); @@ -220,7 +220,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { .map(AccountState::getBalance) .orElse(Wei.ZERO)), hub.callStack().depth(), - hub.pch().aborts().any())); + hub.pch().abortingConditions().any())); } case DELEGATECALL, STATICCALL -> { r.callOob( @@ -231,7 +231,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { .map(AccountState::getBalance) .orElse(Wei.ZERO)), hub.callStack().depth(), - hub.pch().aborts().any())); + hub.pch().abortingConditions().any())); } case RETURN -> { if (hub.currentFrame().underDeployment()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 5fd1342d86..03631e044f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -93,8 +93,8 @@ public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { hub.currentFrame().id(), hub.callStack().futureId(), hub.pch().exceptions().any(), - hub.pch().aborts().any(), - hub.pch().failures().any(), + hub.pch().abortingConditions().any(), + hub.pch().failureConditions().any(), hub.pch().exceptions().invalidCodePrefix()); hub.defers().postTx(r); return r; @@ -108,8 +108,8 @@ public static ScenarioFragment forCreate(final Hub hub, boolean targetHasCode) { hub.currentFrame().id(), hub.callStack().futureId(), hub.pch().exceptions().any(), - hub.pch().aborts().any(), - hub.pch().failures().any(), + hub.pch().abortingConditions().any(), + hub.pch().failureConditions().any(), hub.pch().exceptions().invalidCodePrefix()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index d742a1c751..1693e89878 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -79,9 +79,9 @@ public CreateSection( this.opCode = hub.opCode(); this.emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); this.initialGas = hub.messageFrame().getRemainingGas(); - this.aborts = hub.pch().aborts().snapshot(); + this.aborts = hub.pch().abortingConditions().snapshot(); this.exceptions = hub.pch().exceptions().snapshot(); - this.failures = hub.pch().failures().snapshot(); + this.failures = hub.pch().failureConditions().snapshot(); this.oldCreatorSnapshot = oldCreatorSnapshot; this.oldCreatedSnapshot = oldCreatedSnapshot; @@ -157,8 +157,8 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces ImcFragment.empty(hub) .callOob( new Create( - hub.pch().aborts().any(), - hub.pch().failures().any(), + hub.pch().abortingConditions().any(), + hub.pch().failureConditions().any(), EWord.of(hub.messageFrame().getStackItem(0)), EWord.of(oldCreatedSnapshot.balance()), oldCreatedSnapshot.nonce(), 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 65ab7ff329..7c572882a4 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 @@ -32,10 +32,12 @@ import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.stack.StackLine; +import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true) /** A TraceSection gather the trace lines linked to a single operation */ public abstract class TraceSection { + private WorldView world; @Getter private int stackHeight = 0; @Getter private int stackHeightNew = 0; @@ -79,7 +81,7 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { * @return a {@link CommonFragment} representing the shared columns */ private CommonFragment traceCommon(Hub hub, CallFrame frame) { - return CommonFragment.fromHub(hub, frame, this.stackRowsCounter == 2, this.nonStackRowsCounter); + return CommonFragment.fromHub(world, hub, frame, this.stackRowsCounter == 2, this.nonStackRowsCounter); } /** Default creator for an empty section. */ @@ -251,7 +253,7 @@ private List makeStackFragments(final Hub hub, CallFrame f) { f.stack().snapshot(), new StackLine().asStackOperations(), hub.pch().exceptions().snapshot(), - hub.pch().aborts().snapshot(), + hub.pch().abortingConditions().snapshot(), Hub.GAS_PROJECTOR.of(f.frame(), f.opCode()), f.underDeployment())); } @@ -263,7 +265,7 @@ private List makeStackFragments(final Hub hub, CallFrame f) { f.stack().snapshot(), line.asStackOperations(), hub.pch().exceptions().snapshot(), - hub.pch().aborts().snapshot(), + hub.pch().abortingConditions().snapshot(), Hub.GAS_PROJECTOR.of(f.frame(), f.opCode()), f.underDeployment())); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java index 0860845c89..fb5e33ac7b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java @@ -33,11 +33,11 @@ public final class AbortingConditions { /** * @param callStackOverflow too many nested contexts - * @param balanceTooLow trying to give more ETH than the caller has + * @param insufficientBalance trying to give more ETH than the caller has */ - public AbortingConditions(boolean callStackOverflow, boolean balanceTooLow) { + public AbortingConditions(boolean callStackOverflow, boolean insufficientBalance) { this.callStackOverflow = callStackOverflow; - this.balanceTooLow = balanceTooLow; + this.balanceTooLow = insufficientBalance; } public static AbortingConditions of(Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java index ad8211d90b..3337911ce2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java @@ -32,24 +32,24 @@ public class PlatformController { /** The exceptions raised during the execution of the current operation */ @Getter private final Exceptions exceptions; /** The aborting conditions raised during the execution of the current operation */ - @Getter private final AbortingConditions aborts; + @Getter private final AbortingConditions abortingConditions; - @Getter private final FailureConditions failures; + @Getter private final FailureConditions failureConditions; public PlatformController(final Hub hub) { this.hub = hub; this.exceptions = new Exceptions(hub); - this.aborts = new AbortingConditions(); + this.abortingConditions = new AbortingConditions(); this.signals = new Signals(this); - this.failures = new FailureConditions(hub); + this.failureConditions = new FailureConditions(hub); } /** Reset all information */ public void reset() { this.signals.reset(); this.exceptions.reset(); - this.aborts.reset(); - this.failures.reset(); + this.abortingConditions.reset(); + this.failureConditions.reset(); } /** @@ -63,9 +63,9 @@ public void setup(MessageFrame frame) { this.exceptions.prepare(frame, Hub.GAS_PROJECTOR); if (this.exceptions.none()) { - this.aborts.prepare(hub); - if (aborts.none()) { - this.failures.prepare(frame); + this.abortingConditions.prepare(hub); + if (abortingConditions.none()) { + this.failureConditions.prepare(frame); } } this.signals.prepare(frame, this, this.hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index a65cd49ad3..aa8365bdf7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -185,7 +185,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H this.trm = ex.outOfGas() || ex.none(); final boolean triggersAbortingCondition = - ex.none() && this.platformController.aborts().any(); + ex.none() && this.platformController.abortingConditions().any(); final Address target = Words.toAddress(frame.getStackItem(1)); final boolean targetAddressHasNonEmptyCode = @@ -196,15 +196,15 @@ public void prepare(MessageFrame frame, PlatformController platformController, H this.romLex = ex.none() && !triggersAbortingCondition && targetAddressHasNonEmptyCode; this.ecData = ex.none() && EC_PRECOMPILES.contains(target); this.exp = - ex.none() && this.platformController.aborts().none() && target.equals(Address.MODEXP); + ex.none() && this.platformController.abortingConditions().none() && target.equals(Address.MODEXP); } case CREATE, CREATE2 -> { - boolean triggersAbortingCondition = ex.none() && this.platformController.aborts().any(); + boolean triggersAbortingCondition = ex.none() && this.platformController.abortingConditions().any(); boolean triggersFailureCondition = false; - if (ex.none() && this.platformController.aborts().none()) { - triggersFailureCondition = this.platformController.failures().any(); + if (ex.none() && this.platformController.abortingConditions().none()) { + triggersFailureCondition = this.platformController.failureConditions().any(); } final boolean nonzeroSize = !frame.getStackItem(2).isZero(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java index 9e752e05aa..2fe7b9e1b1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java @@ -99,7 +99,7 @@ public void tracePreOpcode(final MessageFrame frame) { callShakira(frame, 0, 1, this.deployedCodeSizes); } - if (opCode == OpCode.CREATE2 && pch.aborts().none()) { + if (opCode == OpCode.CREATE2 && pch.abortingConditions().none()) { callShakira(frame, 1, 2, this.create2Sizes); } } From d62e623a0633ebfb107dddfd4ac1866aa251a191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 1 Jun 2024 01:14:17 +0400 Subject: [PATCH 005/461] correct REFGAS_NEW in the common section --- .../module/hub/fragment/CommonFragment.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 19bc4c3c44..afc9e684d4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -71,18 +71,19 @@ public final class CommonFragment implements TraceFragment { @Getter @Setter private int numberOfNonStackRows; @Getter @Setter private int nonStackRowsCounter; - public static CommonFragment fromHub(WorldView world, final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowsCounter) { - long refund = 0; + public static CommonFragment fromHub(WorldView world, final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowCounter) { + long refundDelta = 0; boolean noStackException = hub.pch().exceptions().noStackException(); if (noStackException) { - refund = Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).refund(); + refundDelta = Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).refund(); } int height = hub.currentFrame().stack().getHeight(); - int heightNew = (noStackException - ? height - hub.opCode().getData().stackSettings().delta() + hub.opCode().getData().stackSettings().alpha() - : 0); + int heightNew = + (noStackException + ? height - hub.opCode().getData().stackSettings().delta() + hub.opCode().getData().stackSettings().alpha() + : 0); final int pc = frame.pc(); final int pcNew = !noStackException @@ -109,10 +110,10 @@ public static CommonFragment fromHub(WorldView world, final Hub hub, final CallF .codeDeploymentNumber(frame.codeDeploymentNumber()) .codeDeploymentStatus(frame.underDeployment()) .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) - .refundDelta(refund) + .refundDelta(refundDelta) .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) .twoLineInstructionCounter(tliCounter) - .nonStackRowsCounter(nonStackRowsCounter) + .nonStackRowsCounter(nonStackRowCounter) .build(); } @@ -123,9 +124,9 @@ private static int computePcNew(final Hub hub, final int pc) { return pc + opCode.byteValue() - OpCode.PUSH1.byteValue() + 2; } - if (opCode.getData().instructionFamily().equals(InstructionFamily.JUMP)) { - BigInteger prospectivePcNew = hub.currentFrame().frame().getStackItem(0).toBigInteger(); - BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); + if (opCode.isJump()) { + final BigInteger prospectivePcNew = hub.currentFrame().frame().getStackItem(0).toBigInteger(); + final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); final int attemptedPcNew = codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() @@ -199,7 +200,7 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { // frame.underDeployment())); final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); - + final boolean willRevert = frame.willRevert(); return trace .absoluteTransactionNumber(tx.absNumber()) @@ -223,9 +224,9 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .mmuStamp(this.stamps.mmu()) .mxpStamp(this.stamps.mxp()) .contextNumber(contextNumber) - .contextNumberNew(contextNumberNew) // TODO + .contextNumberNew(contextNumberNew) .callerContextNumber(callerContextNumber) - .contextWillRevert(getsReverted || selfReverts) + .contextWillRevert(willRevert) .contextGetsReverted(getsReverted) .contextSelfReverts(selfReverts) .contextRevertStamp(revertStamp) @@ -239,7 +240,7 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .gasCost(Bytes.ofUnsignedLong(gasCost)) .gasNext(gasNext) .refundCounter(gasRefund) - .refundCounterNew(gasRefund + refundDelta) + .refundCounterNew(gasRefund + (willRevert ? 0 : refundDelta)) .twoLineInstruction(twoLineInstruction) .counterTli(twoLineInstructionCounter) .nonStackRows((short) numberOfNonStackRows) From 716f320417dfc155295925164dee8dc16137dd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 1 Jun 2024 01:19:12 +0400 Subject: [PATCH 006/461] various - hashInfoKeccak in all cases - jumpDestinationVettingRequired computation - introduced willRevert for - logInfoFlag - refundCounterNew --- .../module/hub/fragment/StackFragment.java | 65 +++++++++++++++---- .../module/hub/section/TraceSection.java | 9 ++- .../linea/zktracer/opcode/OpCode.java | 11 ++++ .../zktracer/runtime/callstack/CallFrame.java | 4 ++ 4 files changed, 75 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 5d9841422a..8827a61e85 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment; +import java.math.BigInteger; import java.util.List; import java.util.Optional; import java.util.function.Function; @@ -50,9 +51,10 @@ public final class StackFragment implements TraceFragment { @Setter private DeploymentExceptions contextExceptions; private final long staticGas; private EWord hashInfoKeccak = EWord.ZERO; - private final long hashInfoSize; private final boolean hashInfoFlag; @Getter private final OpCode opCode; + private final boolean jumpDestinationVettingRequired; + private final boolean willRevert; private StackFragment( final Hub hub, @@ -62,7 +64,8 @@ private StackFragment( AbortingConditions aborts, DeploymentExceptions contextExceptions, GasProjection gp, - boolean isDeploying) { + boolean isDeploying, + boolean willRevert) { this.stack = stack; this.stackOps = stackOps; this.exceptions = exceptions; @@ -78,12 +81,44 @@ private StackFragment( && gp.messageSize() > 0; default -> false; }; - this.hashInfoSize = this.hashInfoFlag ? gp.messageSize() : 0; + if (this.hashInfoFlag) { + Bytes memorySegmentToHash; + switch (this.opCode) { + case SHA3, RETURN -> { + long offset = hub.currentFrame().frame().getStackItem(0).toLong(); + long size = hub.currentFrame().frame().getStackItem(1).toLong(); + memorySegmentToHash = hub.messageFrame().shadowReadMemory(offset, size); + } + case CREATE2 -> { + long offset = hub.currentFrame().frame().getStackItem(1).toLong(); + long size = hub.currentFrame().frame().getStackItem(2).toLong(); + memorySegmentToHash = hub.messageFrame().shadowReadMemory(offset, size); + } + default -> + throw new UnsupportedOperationException("Hash was attempted by the following opcode: " + this.opCode().toString()); + } + this.hashInfoKeccak = EWord.of(memorySegmentToHash); + } + this.staticGas = gp.staticGas(); - if (this.opCode == OpCode.RETURN && exceptions.none()) { - this.hashInfoKeccak = - EWord.of(org.hyperledger.besu.crypto.Hash.keccak256(hub.transients().op().returnData())); + + if (opCode.isJump() && !exceptions.stackException()) { + final BigInteger prospectivePcNew = hub.currentFrame().frame().getStackItem(0).toBigInteger(); + final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); + + boolean prospectivePcNewIsInBounds = codeSize.compareTo(prospectivePcNew) > 0; + + if (opCode.equals(OpCode.JUMPI)) { + boolean nonzeroJumpCondition = !hub.currentFrame().frame().getStackItem(1).toBigInteger().equals(BigInteger.ZERO); + prospectivePcNewIsInBounds = prospectivePcNewIsInBounds && nonzeroJumpCondition; + } + + jumpDestinationVettingRequired = prospectivePcNewIsInBounds; + } else { + jumpDestinationVettingRequired = false; } + + this.willRevert = willRevert; } public static StackFragment prepare( @@ -93,7 +128,8 @@ public static StackFragment prepare( final Exceptions exceptions, final AbortingConditions aborts, final GasProjection gp, - boolean isDeploying) { + boolean isDeploying, + boolean willRevert) { return new StackFragment( hub, stack, @@ -102,7 +138,8 @@ public static StackFragment prepare( aborts, DeploymentExceptions.empty(), gp, - isDeploying); + isDeploying, + willRevert); } public void feedHashedValue(MessageFrame frame) { @@ -128,6 +165,12 @@ public void feedHashedValue(MessageFrame frame) { } } + private boolean traceLog() { + return this.opCode.isLog() + && this.exceptions.none() // TODO: should be redundant (exceptions trigger reverts) --- this could be asserted + && !this.willRevert; + } + @Override public Trace trace(Trace trace) { final List> valHiTracers = @@ -232,7 +275,7 @@ public Trace trace(Trace trace) { .pStackStaticFlag(this.stack.getCurrentOpcodeData().stackSettings().forbiddenInStatic()) .pStackPushValueHi(pushValue.hi()) .pStackPushValueLo(pushValue.lo()) - .pStackJumpDestinationVettingRequired(false) // TODO + .pStackJumpDestinationVettingRequired(this.jumpDestinationVettingRequired) // TODO: confirm this // Exception flag .pStackOpcx(exceptions.invalidOpcode()) .pStackSux(exceptions.stackUnderflow()) @@ -249,7 +292,7 @@ public Trace trace(Trace trace) { .pStackHashInfoFlag(this.hashInfoFlag) .pStackHashInfoKeccakHi(this.hashInfoKeccak.hi()) .pStackHashInfoKeccakLo(this.hashInfoKeccak.lo()) - .pStackLogInfoFlag(false) // TODO - ; + .pStackLogInfoFlag(this.traceLog()) // TODO: confirm this + ; } } 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 7c572882a4..2f7820f20d 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 @@ -81,7 +81,8 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { * @return a {@link CommonFragment} representing the shared columns */ private CommonFragment traceCommon(Hub hub, CallFrame frame) { - return CommonFragment.fromHub(world, hub, frame, this.stackRowsCounter == 2, this.nonStackRowsCounter); + return CommonFragment.fromHub( + world, hub, frame, this.stackRowsCounter == 2, this.nonStackRowsCounter); } /** Default creator for an empty section. */ @@ -255,7 +256,8 @@ private List makeStackFragments(final Hub hub, CallFrame f) { hub.pch().exceptions().snapshot(), hub.pch().abortingConditions().snapshot(), Hub.GAS_PROJECTOR.of(f.frame(), f.opCode()), - f.underDeployment())); + f.underDeployment(), + f.willRevert())); } } else { for (StackLine line : f.pending().lines()) { @@ -267,7 +269,8 @@ private List makeStackFragments(final Hub hub, CallFrame f) { hub.pch().exceptions().snapshot(), hub.pch().abortingConditions().snapshot(), Hub.GAS_PROJECTOR.of(f.frame(), f.opCode()), - f.underDeployment())); + f.underDeployment(), + f.willRevert())); } } return r; 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 bf27a1e088..dbdeb59bbd 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 @@ -210,6 +210,17 @@ public UnsignedByte unsignedByteValue() { return UnsignedByte.of(byteValue()); } + /** Returns true for JUMP-type instructions*/ + public boolean isJump() { return this == OpCode.JUMP || this == OpCode.JUMPI; } + + public boolean isLog() { + return this == OpCode.LOG0 + || this == OpCode.LOG1 + || this == OpCode.LOG2 + || this == OpCode.LOG3 + || this == OpCode.LOG4; + } + /** Returns whether the {@link OpCode} entails a contract creation. */ public boolean isCreate() { return this == OpCode.CREATE || this == OpCode.CREATE2; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 56506999e1..cf97905a67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -277,6 +277,10 @@ public boolean getsReverted() { return this.getsRevertedAt > 0; } + public boolean willRevert() { + return selfReverts() || getsReverted(); + } + public boolean hasReverted() { return (this.selfRevertsAt > 0) || (this.getsRevertedAt > 0); } From 272815bbe034812ec46de5a75fd71d05453aa29f Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 09:11:08 +0530 Subject: [PATCH 007/461] fix(hub): make it buil --- .../linea/zktracer/module/hub/Hub.java | 7 +- .../linea/zktracer/module/hub/Trace.java | 1105 ++++++++++++----- .../defer/SkippedPostTransactionDefer.java | 9 +- .../module/hub/fragment/CommonFragment.java | 165 +-- .../module/hub/fragment/StackFragment.java | 18 +- .../module/hub/fragment/imc/call/MxpCall.java | 2 +- .../module/hub/fragment/imc/call/StpCall.java | 8 +- .../zktracer/module/hub/signals/Signals.java | 7 +- .../linea/zktracer/opcode/OpCode.java | 14 +- 9 files changed, 888 insertions(+), 447 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f142c4cfbb..d21512b27a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -650,8 +650,8 @@ public CallFrame currentFrame() { public int contextNumberNew(WorldView world) { OpCode opCode = this.opCode(); if (pch.exceptions().any() - || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) - || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)){ + || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) + || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { return this.callStack().caller().contextNumber(); } @@ -661,7 +661,8 @@ public int contextNumberNew(WorldView world) { if (pch().abortingConditions().any()) { return currentContextNumber; } - Address calleeAddress = Address.extract((Bytes32) this.currentFrame().frame().getStackItem(1)); + Address calleeAddress = + Address.extract((Bytes32) this.currentFrame().frame().getStackItem(1)); if (world.get(calleeAddress).hasCode()) { return 1 + stamp(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index e1b80c1d9b..6af8e288f2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.hub; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -38,24 +37,32 @@ public class Trace { private final MappedByteBuffer absoluteTransactionNumber; private final MappedByteBuffer accFinal; private final MappedByteBuffer accFirst; - private final MappedByteBuffer addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; - private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; + private final MappedByteBuffer + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; private final MappedByteBuffer alpha; - private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; - private final MappedByteBuffer balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; + private final MappedByteBuffer + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; + private final MappedByteBuffer + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer batchNumber; private final MappedByteBuffer callDataOffsetXorMmuSize; private final MappedByteBuffer callDataSizeXorMmuSrcId; private final MappedByteBuffer callStackDepth; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; + private final MappedByteBuffer + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; private final MappedByteBuffer codeHashHiNewXorExpData5XorValueCurrLoXorValue; - private final MappedByteBuffer codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorValueNextLo; private final MappedByteBuffer codeHashLoXorMmuLimb1XorValueNextHi; - private final MappedByteBuffer codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; - private final MappedByteBuffer codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; + private final MappedByteBuffer + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; + private final MappedByteBuffer + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; private final MappedByteBuffer conAgain; private final MappedByteBuffer conFirst; private final MappedByteBuffer contextGetsReverted; @@ -71,37 +78,51 @@ public class Trace { private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; - private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; private final MappedByteBuffer delta; - private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; - private final MappedByteBuffer deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; - private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; - private final MappedByteBuffer deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; - private final MappedByteBuffer deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; - private final MappedByteBuffer deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; + private final MappedByteBuffer + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; + private final MappedByteBuffer + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; + private final MappedByteBuffer + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; + private final MappedByteBuffer + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; + private final MappedByteBuffer + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; + private final MappedByteBuffer + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; - private final MappedByteBuffer existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; - private final MappedByteBuffer existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; + private final MappedByteBuffer + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; + private final MappedByteBuffer + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; - private final MappedByteBuffer hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; - private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; + private final MappedByteBuffer + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; + private final MappedByteBuffer + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; private final MappedByteBuffer hashInfoStamp; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; - private final MappedByteBuffer isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; + private final MappedByteBuffer + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; private final MappedByteBuffer logInfoStamp; - private final MappedByteBuffer markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; - private final MappedByteBuffer markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; + private final MappedByteBuffer + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; + private final MappedByteBuffer + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -222,24 +243,49 @@ static List headers(int length) { new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), - new ColumnHeader("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", 8, length), - new ColumnHeader("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", + 8, + length), + new ColumnHeader( + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.ALPHA", 1, length), - new ColumnHeader("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 32, length), - new ColumnHeader("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", + 32, + length), + new ColumnHeader( + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.BATCH_NUMBER", 4, length), new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), - new ColumnHeader("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", 8, length), - new ColumnHeader("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), - new ColumnHeader("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", + 8, + length), + new ColumnHeader( + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), + new ColumnHeader( + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), - new ColumnHeader("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", 8, length), - new ColumnHeader("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", 8, length), + new ColumnHeader( + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", + 8, + length), + new ColumnHeader( + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", + 8, + length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), @@ -253,39 +299,83 @@ static List headers(int length) { new ColumnHeader("hub.COUNTER_NSR", 2, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", + 1, + length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), new ColumnHeader("hub.DELTA", 1, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", 8, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", 8, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", 8, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", 1, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", 1, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", 1, length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", + 1, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", + 1, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", + 1, + length), new ColumnHeader("hub.DOM_STAMP", 8, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), - new ColumnHeader("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", 1, length), - new ColumnHeader("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", 1, length), + new ColumnHeader( + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", + 1, + length), + new ColumnHeader( + "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", + 1, + length), new ColumnHeader("hub.GAS_ACTUAL", 8, length), new ColumnHeader("hub.GAS_COST", 32, length), new ColumnHeader("hub.GAS_EXPECTED", 8, length), new ColumnHeader("hub.GAS_LIMIT", 32, length), new ColumnHeader("hub.GAS_NEXT", 8, length), new ColumnHeader("hub.GAS_PRICE", 32, length), - new ColumnHeader("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", 1, length), - new ColumnHeader("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), + new ColumnHeader( + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", + 1, + length), + new ColumnHeader( + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", + 1, + length), new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), new ColumnHeader("hub.HEIGHT", 2, length), new ColumnHeader("hub.HEIGHT_NEW", 2, length), new ColumnHeader("hub.HUB_STAMP", 8, length), new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), new ColumnHeader("hub.INSTRUCTION", 32, length), - new ColumnHeader("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", 1, length), + new ColumnHeader( + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", + 1, + length), new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), - new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", 1, length), - new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", 1, length), + new ColumnHeader( + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", + 1, + length), + new ColumnHeader( + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", + 1, + length), new ColumnHeader("hub.MMU_STAMP", 8, length), new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), @@ -299,7 +389,8 @@ static List headers(int length) { new ColumnHeader("hub.NB_REMOVED", 1, length), new ColumnHeader("hub.NON_STACK_ROWS", 2, length), new ColumnHeader("hub.NONCE", 32, length), - new ColumnHeader("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), + new ColumnHeader( + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), new ColumnHeader("hub.OOB_DATA_1", 32, length), new ColumnHeader("hub.OOB_DATA_2", 32, length), @@ -343,20 +434,34 @@ static List headers(int length) { new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), - new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), - new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), - new ColumnHeader("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), - new ColumnHeader("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), - new ColumnHeader("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + new ColumnHeader( + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), + new ColumnHeader( + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), + new ColumnHeader( + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", + 1, + length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), - new ColumnHeader("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader( + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), - new ColumnHeader("hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), + new ColumnHeader( + "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", + 1, + length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), @@ -388,7 +493,8 @@ static List headers(int length) { new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), new ColumnHeader("hub.TRANSACTION_REVERTS", 1, length), - new ColumnHeader("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + new ColumnHeader( + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -397,7 +503,10 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), + new ColumnHeader( + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", + 1, + length), new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -406,24 +515,36 @@ public Trace(List buffers) { this.absoluteTransactionNumber = buffers.get(0); this.accFinal = buffers.get(1); this.accFirst = buffers.get(2); - this.addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = buffers.get(3); - this.addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(4); + this + .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = + buffers.get(3); + this + .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = + buffers.get(4); this.alpha = buffers.get(5); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(6); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = buffers.get(7); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = + buffers.get(6); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = + buffers.get(7); this.batchNumber = buffers.get(8); this.callDataOffsetXorMmuSize = buffers.get(9); this.callDataSizeXorMmuSrcId = buffers.get(10); this.callStackDepth = buffers.get(11); this.callerContextNumber = buffers.get(12); this.codeFragmentIndex = buffers.get(13); - this.codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = buffers.get(14); + this + .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = + buffers.get(14); this.codeHashHiNewXorExpData5XorValueCurrLoXorValue = buffers.get(15); - this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = + buffers.get(16); this.codeHashLoNewXorMmuLimb2XorValueNextLo = buffers.get(17); this.codeHashLoXorMmuLimb1XorValueNextHi = buffers.get(18); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = buffers.get(19); - this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = buffers.get(20); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = + buffers.get(19); + this + .codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = + buffers.get(20); this.conAgain = buffers.get(21); this.conFirst = buffers.get(22); this.contextGetsReverted = buffers.get(23); @@ -442,34 +563,48 @@ public Trace(List buffers) { this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); this.delta = buffers.get(38); - this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = buffers.get(39); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = + buffers.get(39); this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); - this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = buffers.get(41); - this.deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = buffers.get(42); - this.deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = buffers.get(43); - this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = buffers.get(44); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = + buffers.get(41); + this + .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = + buffers.get(42); + this + .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = + buffers.get(43); + this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = + buffers.get(44); this.domStamp = buffers.get(45); this.exceptionAhoy = buffers.get(46); - this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = buffers.get(47); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = buffers.get(48); + this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = + buffers.get(47); + this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = + buffers.get(48); this.gasActual = buffers.get(49); this.gasCost = buffers.get(50); this.gasExpected = buffers.get(51); this.gasLimit = buffers.get(52); this.gasNext = buffers.get(53); this.gasPrice = buffers.get(54); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = buffers.get(55); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = buffers.get(56); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = + buffers.get(55); + this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = + buffers.get(56); this.hashInfoStamp = buffers.get(57); this.height = buffers.get(58); this.heightNew = buffers.get(59); this.hubStamp = buffers.get(60); this.hubStampTransactionEnd = buffers.get(61); this.instruction = buffers.get(62); - this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = buffers.get(63); + this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = + buffers.get(63); this.logInfoStamp = buffers.get(64); - this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = buffers.get(65); - this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = buffers.get(66); + this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = + buffers.get(65); + this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = + buffers.get(66); this.mmuStamp = buffers.get(67); this.mxpOffset2Hi = buffers.get(68); this.mxpOffset2Lo = buffers.get(69); @@ -989,7 +1124,8 @@ public Trace pAccountAddressHi(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1003,9 +1139,11 @@ public Trace pAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1019,9 +1157,11 @@ public Trace pAccountBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1035,9 +1175,11 @@ public Trace pAccountBalanceNew(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1049,7 +1191,8 @@ public Trace pAccountCodeFragmentIndex(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1065,7 +1208,8 @@ public Trace pAccountCodeHashHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1125,7 +1269,8 @@ public Trace pAccountCodeSize(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1185,7 +1330,8 @@ public Trace pAccountDeploymentStatus(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1197,7 +1343,8 @@ public Trace pAccountDeploymentStatusInfty(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1209,7 +1356,8 @@ public Trace pAccountDeploymentStatusNew(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -1221,7 +1369,8 @@ public Trace pAccountExists(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -1233,7 +1382,8 @@ public Trace pAccountExistsNew(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -1245,7 +1395,8 @@ public Trace pAccountHasCode(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -1257,7 +1408,8 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -1269,7 +1421,8 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -1281,7 +1434,8 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -1293,7 +1447,8 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } @@ -1517,7 +1672,8 @@ public Trace pContextAccountAddressHi(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1531,9 +1687,11 @@ public Trace pContextAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1545,7 +1703,8 @@ public Trace pContextAccountDeploymentNumber(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1557,7 +1716,8 @@ public Trace pContextByteCodeAddressHi(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1571,9 +1731,11 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1673,7 +1835,8 @@ public Trace pContextCallValue(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1699,9 +1862,11 @@ public Trace pContextCallerAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1725,7 +1890,8 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1737,7 +1903,8 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1809,7 +1976,8 @@ public Trace pContextUpdate(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -1821,7 +1989,8 @@ public Trace pMiscCcrsStamp(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1833,7 +2002,8 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1847,9 +2017,11 @@ public Trace pMiscExpData1(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1863,9 +2035,11 @@ public Trace pMiscExpData2(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1879,9 +2053,11 @@ public Trace pMiscExpData3(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1897,7 +2073,8 @@ public Trace pMiscExpData4(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1925,7 +2102,8 @@ public Trace pMiscExpFlag(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1937,7 +2115,8 @@ public Trace pMiscExpInst(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1949,7 +2128,8 @@ public Trace pMiscMmuAuxId(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1973,7 +2153,8 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -2121,7 +2302,8 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -2161,7 +2343,8 @@ public Trace pMiscMxpDeploys(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -2173,7 +2356,8 @@ public Trace pMiscMxpFlag(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -2213,7 +2397,8 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -2225,7 +2410,8 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -2509,7 +2695,8 @@ public Trace pMiscOobFlag(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -2533,7 +2720,8 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } @@ -2717,31 +2905,36 @@ public Trace pScenarioCallAbort(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { if (filled.get(54)) { - throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { if (filled.get(55)) { - throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -2753,7 +2946,8 @@ public Trace pScenarioCallException(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -2765,74 +2959,86 @@ public Trace pScenarioCallPrcFailure(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { if (filled.get(58)) { - throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { if (filled.get(59)) { - throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { if (filled.get(60)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); } else { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { if (filled.get(61)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); } else { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { if (filled.get(62)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { if (filled.get(63)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(63); } @@ -2856,7 +3062,8 @@ public Trace pScenarioCreateAbort(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { if (filled.get(65)) { - throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); } else { filled.set(65); } @@ -2868,7 +3075,8 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { if (filled.get(66)) { - throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); } else { filled.set(66); } @@ -2892,7 +3100,8 @@ public Trace pScenarioCreateException(final Boolean b) { public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { if (filled.get(68)) { - throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); } else { filled.set(68); } @@ -2904,7 +3113,8 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { if (filled.get(69)) { - throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); } else { filled.set(69); } @@ -2916,7 +3126,8 @@ public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { if (filled.get(70)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); } else { filled.set(70); } @@ -2928,7 +3139,8 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { if (filled.get(71)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); } else { filled.set(71); } @@ -2940,19 +3152,22 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { if (filled.get(72)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); } else { filled.set(72); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { if (filled.get(73)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); } else { filled.set(73); } @@ -2981,7 +3196,8 @@ public Trace pScenarioPrcCalleeGas(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -2993,7 +3209,8 @@ public Trace pScenarioPrcCallerGas(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -3005,7 +3222,8 @@ public Trace pScenarioPrcCdo(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -3216,7 +3434,8 @@ public Trace pScenarioReturnException(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { if (filled.get(88)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { filled.set(88); } @@ -3228,7 +3447,8 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { if (filled.get(89)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { filled.set(89); } @@ -3240,7 +3460,8 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { if (filled.get(90)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { filled.set(90); } @@ -3252,7 +3473,8 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { if (filled.get(91)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { filled.set(91); } @@ -3264,7 +3486,8 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { if (filled.get(92)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { filled.set(92); } @@ -3276,7 +3499,8 @@ public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { if (filled.get(93)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { filled.set(93); } @@ -3312,7 +3536,8 @@ public Trace pScenarioSelfdestructWillRevert(final Boolean b) { public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { if (filled.get(96)) { - throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); + throw new IllegalStateException( + "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { filled.set(96); } @@ -3324,7 +3549,8 @@ public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { if (filled.get(97)) { - throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); + throw new IllegalStateException( + "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { filled.set(97); } @@ -3341,7 +3567,8 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -3353,7 +3580,8 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -3377,7 +3605,8 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -3389,7 +3618,8 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -3401,7 +3631,8 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -3413,7 +3644,8 @@ public Trace pStackConFlag(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -3425,7 +3657,8 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -3437,7 +3670,8 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -3449,7 +3683,8 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -3461,7 +3696,8 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(62); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } @@ -3559,9 +3795,11 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -3575,9 +3813,11 @@ public Trace pStackHashInfoKeccakLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -3629,7 +3869,8 @@ public Trace pStackJumpDestinationVettingRequired(final Boolean b) { filled.set(72); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( + (byte) (b ? 1 : 0)); return this; } @@ -3823,9 +4064,11 @@ public Trace pStackPushValueHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -3841,7 +4084,8 @@ public Trace pStackPushValueLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4241,7 +4485,8 @@ public Trace pStackStaticGas(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4325,7 +4570,8 @@ public Trace pStorageAddressHi(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4339,9 +4585,11 @@ public Trace pStorageAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4353,7 +4601,8 @@ public Trace pStorageDeploymentNumber(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -4365,7 +4614,8 @@ public Trace pStorageDeploymentNumberInfty(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -4379,9 +4629,11 @@ public Trace pStorageStorageKeyHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4395,9 +4647,11 @@ public Trace pStorageStorageKeyLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -4409,7 +4663,8 @@ public Trace pStorageValueCurrChanges(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4425,7 +4680,8 @@ public Trace pStorageValueCurrHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4437,7 +4693,8 @@ public Trace pStorageValueCurrIsOrig(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -4449,7 +4706,8 @@ public Trace pStorageValueCurrIsZero(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -4493,7 +4751,8 @@ public Trace pStorageValueNextIsCurr(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -4505,7 +4764,8 @@ public Trace pStorageValueNextIsOrig(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -4517,7 +4777,8 @@ public Trace pStorageValueNextIsZero(final Boolean b) { filled.set(58); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4561,7 +4822,8 @@ public Trace pStorageValueOrigIsZero(final Boolean b) { filled.set(59); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4589,7 +4851,8 @@ public Trace pStorageWarmth(final Boolean b) { filled.set(60); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -4601,7 +4864,8 @@ public Trace pStorageWarmthNew(final Boolean b) { filled.set(61); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -4629,7 +4893,8 @@ public Trace pTransactionBatchNum(final long b) { filled.set(107); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4641,7 +4906,8 @@ public Trace pTransactionCallDataSize(final long b) { filled.set(108); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -4653,7 +4919,8 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { filled.set(109); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -4667,9 +4934,11 @@ public Trace pTransactionCoinbaseAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4681,7 +4950,8 @@ public Trace pTransactionCopyTxcd(final Boolean b) { filled.set(53); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4707,9 +4977,11 @@ public Trace pTransactionFromAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4799,9 +5071,11 @@ public Trace pTransactionInitialBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -4813,7 +5087,8 @@ public Trace pTransactionIsDeployment(final Boolean b) { filled.set(54); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -4825,7 +5100,8 @@ public Trace pTransactionIsType2(final Boolean b) { filled.set(55); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -4901,7 +5177,8 @@ public Trace pTransactionRequiresEvmExecution(final Boolean b) { filled.set(56); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -4913,7 +5190,8 @@ public Trace pTransactionStatusCode(final Boolean b) { filled.set(57); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -4941,7 +5219,8 @@ public Trace pTransactionToAddressLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -5228,11 +5507,13 @@ public Trace validateRow() { } if (!filled.get(107)) { - throw new IllegalStateException("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); + throw new IllegalStateException( + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } if (!filled.get(132)) { - throw new IllegalStateException("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } if (!filled.get(102)) { @@ -5240,11 +5521,13 @@ public Trace validateRow() { } if (!filled.get(134)) { - throw new IllegalStateException("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); + throw new IllegalStateException( + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } if (!filled.get(133)) { - throw new IllegalStateException("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } if (!filled.get(1)) { @@ -5272,31 +5555,38 @@ public Trace validateRow() { } if (!filled.get(108)) { - throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); + throw new IllegalStateException( + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } if (!filled.get(136)) { - throw new IllegalStateException("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } if (!filled.get(135)) { - throw new IllegalStateException("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } if (!filled.get(138)) { - throw new IllegalStateException("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } if (!filled.get(137)) { - throw new IllegalStateException("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } if (!filled.get(110)) { - throw new IllegalStateException("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } if (!filled.get(109)) { - throw new IllegalStateException("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); } if (!filled.get(49)) { @@ -5348,23 +5638,28 @@ public Trace validateRow() { } if (!filled.get(69)) { - throw new IllegalStateException("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + throw new IllegalStateException( + "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); } if (!filled.get(70)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); } if (!filled.get(71)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); } if (!filled.get(72)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); } if (!filled.get(73)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); } if (!filled.get(103)) { @@ -5372,27 +5667,33 @@ public Trace validateRow() { } if (!filled.get(112)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } if (!filled.get(113)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } if (!filled.get(111)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } if (!filled.get(54)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(55)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); } if (!filled.get(53)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); } if (!filled.get(13)) { @@ -5404,11 +5705,13 @@ public Trace validateRow() { } if (!filled.get(57)) { - throw new IllegalStateException("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); + throw new IllegalStateException( + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); } if (!filled.get(56)) { - throw new IllegalStateException("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); + throw new IllegalStateException( + "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(15)) { @@ -5436,11 +5739,13 @@ public Trace validateRow() { } if (!filled.get(59)) { - throw new IllegalStateException("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); + throw new IllegalStateException( + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(58)) { - throw new IllegalStateException("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + throw new IllegalStateException( + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(19)) { @@ -5468,7 +5773,8 @@ public Trace validateRow() { } if (!filled.get(60)) { - throw new IllegalStateException("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); + throw new IllegalStateException( + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); } if (!filled.get(24)) { @@ -5476,11 +5782,13 @@ public Trace validateRow() { } if (!filled.get(62)) { - throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); + throw new IllegalStateException( + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); } if (!filled.get(61)) { - throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); + throw new IllegalStateException( + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); } if (!filled.get(25)) { @@ -5536,7 +5844,8 @@ public Trace validateRow() { } if (!filled.get(124)) { - throw new IllegalStateException("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + throw new IllegalStateException( + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } if (!filled.get(123)) { @@ -5616,7 +5925,8 @@ public Trace validateRow() { } if (!filled.get(77)) { - throw new IllegalStateException("hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); } if (!filled.get(78)) { @@ -5624,11 +5934,13 @@ public Trace validateRow() { } if (!filled.get(79)) { - throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); } if (!filled.get(80)) { - throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); } if (!filled.get(81)) { @@ -5648,7 +5960,8 @@ public Trace validateRow() { } if (!filled.get(85)) { - throw new IllegalStateException("hub.PRC_SUCCESS_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_SUCCESS_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(86)) { @@ -5692,11 +6005,13 @@ public Trace validateRow() { } if (!filled.get(120)) { - throw new IllegalStateException("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + throw new IllegalStateException( + "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } if (!filled.get(121)) { - throw new IllegalStateException("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + throw new IllegalStateException( + "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } if (!filled.get(122)) { @@ -5708,51 +6023,63 @@ public Trace validateRow() { } if (!filled.get(88)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); } if (!filled.get(89)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(90)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(91)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(92)) { - throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(93)) { - throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } if (!filled.get(114)) { - throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } if (!filled.get(139)) { - throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } if (!filled.get(63)) { - throw new IllegalStateException("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); } if (!filled.get(140)) { - throw new IllegalStateException("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } if (!filled.get(141)) { - throw new IllegalStateException("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } if (!filled.get(64)) { - throw new IllegalStateException("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } if (!filled.get(142)) { @@ -5760,27 +6087,33 @@ public Trace validateRow() { } if (!filled.get(143)) { - throw new IllegalStateException("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } if (!filled.get(65)) { - throw new IllegalStateException("hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } if (!filled.get(94)) { - throw new IllegalStateException("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); } if (!filled.get(95)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); } if (!filled.get(96)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); } if (!filled.get(97)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } if (!filled.get(165)) { @@ -5864,7 +6197,8 @@ public Trace validateRow() { } if (!filled.get(125)) { - throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); + throw new IllegalStateException( + "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } if (!filled.get(162)) { @@ -5892,11 +6226,13 @@ public Trace validateRow() { } if (!filled.get(66)) { - throw new IllegalStateException("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + throw new IllegalStateException( + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } if (!filled.get(144)) { - throw new IllegalStateException("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); + throw new IllegalStateException( + "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } if (!filled.get(41)) { @@ -5928,11 +6264,13 @@ public Trace validateRow() { } if (!filled.get(68)) { - throw new IllegalStateException("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + throw new IllegalStateException( + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); } if (!filled.get(67)) { - throw new IllegalStateException("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + throw new IllegalStateException( + "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } if (!filled.get(101)) { @@ -5959,11 +6297,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(107)) { - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position(addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position() + 8); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .position( + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .position() + + 8); } if (!filled.get(132)) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position(addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position() + 32); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position( + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position() + + 32); } if (!filled.get(102)) { @@ -5971,11 +6317,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(134)) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position(balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position() + 32); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance + .position( + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance + .position() + + 32); } if (!filled.get(133)) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position(balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position() + 32); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo + .position( + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo + .position() + + 32); } if (!filled.get(1)) { @@ -6003,31 +6357,46 @@ public Trace fillAndValidateRow() { } if (!filled.get(108)) { - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position(codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position() + 8); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .position( + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .position() + + 8); } if (!filled.get(136)) { - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position(codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); } if (!filled.get(135)) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position(codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 32); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + + 32); } if (!filled.get(138)) { - codeHashLoNewXorMmuLimb2XorValueNextLo.position(codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); + codeHashLoNewXorMmuLimb2XorValueNextLo.position( + codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); } if (!filled.get(137)) { - codeHashLoXorMmuLimb1XorValueNextHi.position(codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); + codeHashLoXorMmuLimb1XorValueNextHi.position( + codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); } if (!filled.get(110)) { - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position(codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + 8); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + + 8); } if (!filled.get(109)) { - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position(codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position() + 8); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position( + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position() + + 8); } if (!filled.get(49)) { @@ -6079,23 +6448,28 @@ public Trace fillAndValidateRow() { } if (!filled.get(69)) { - createFailureConditionWontRevertXorIcpx.position(createFailureConditionWontRevertXorIcpx.position() + 1); + createFailureConditionWontRevertXorIcpx.position( + createFailureConditionWontRevertXorIcpx.position() + 1); } if (!filled.get(70)) { - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position(createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position( + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); } if (!filled.get(71)) { - createNonemptyInitCodeFailureWontRevertXorJumpx.position(createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); + createNonemptyInitCodeFailureWontRevertXorJumpx.position( + createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); } if (!filled.get(72)) { - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position(createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position( + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); } if (!filled.get(73)) { - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position(createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position( + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); } if (!filled.get(103)) { @@ -6103,27 +6477,45 @@ public Trace fillAndValidateRow() { } if (!filled.get(112)) { - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position(deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position() + 8); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi + .position() + + 8); } if (!filled.get(113)) { - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position(deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); } if (!filled.get(111)) { - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position(deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + 8); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + + 8); } if (!filled.get(54)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position(deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position() + 1); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .position( + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .position() + + 1); } if (!filled.get(55)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position(deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position() + 1); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .position( + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .position() + + 1); } if (!filled.get(53)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position(deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position() + 1); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd + .position( + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd + .position() + + 1); } if (!filled.get(13)) { @@ -6135,11 +6527,18 @@ public Trace fillAndValidateRow() { } if (!filled.get(57)) { - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position(existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position() + 1); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position( + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode + .position() + + 1); } if (!filled.get(56)) { - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position(existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position() + 1); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution + .position( + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution + .position() + + 1); } if (!filled.get(15)) { @@ -6167,11 +6566,16 @@ public Trace fillAndValidateRow() { } if (!filled.get(59)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position(hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position() + 1); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero + .position() + + 1); } if (!filled.get(58)) { - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position(hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() + 1); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position( + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() + + 1); } if (!filled.get(19)) { @@ -6199,7 +6603,9 @@ public Trace fillAndValidateRow() { } if (!filled.get(60)) { - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position(isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + 1); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + + 1); } if (!filled.get(24)) { @@ -6207,11 +6613,18 @@ public Trace fillAndValidateRow() { } if (!filled.get(62)) { - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position(markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position() + 1); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 + .position() + + 1); } if (!filled.get(61)) { - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position(markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position() + 1); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew + .position( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew + .position() + + 1); } if (!filled.get(25)) { @@ -6267,7 +6680,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(124)) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position(nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); } if (!filled.get(123)) { @@ -6379,7 +6793,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(85)) { - prcSuccessWillRevertXorPushpopFlag.position(prcSuccessWillRevertXorPushpopFlag.position() + 1); + prcSuccessWillRevertXorPushpopFlag.position( + prcSuccessWillRevertXorPushpopFlag.position() + 1); } if (!filled.get(86)) { @@ -6423,7 +6838,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(120)) { - returnDataContextNumberXorStpGasStipend.position(returnDataContextNumberXorStpGasStipend.position() + 8); + returnDataContextNumberXorStpGasStipend.position( + returnDataContextNumberXorStpGasStipend.position() + 8); } if (!filled.get(121)) { @@ -6439,43 +6855,53 @@ public Trace fillAndValidateRow() { } if (!filled.get(88)) { - returnFromDeploymentEmptyCodeWillRevertXorSox.position(returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + returnFromDeploymentEmptyCodeWillRevertXorSox.position( + returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); } if (!filled.get(89)) { - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position(returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position( + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); } if (!filled.get(90)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position(returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position( + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); } if (!filled.get(91)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position(returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position( + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); } if (!filled.get(92)) { - returnFromMessageCallWillTouchRamXorStackItemPop2.position(returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop2.position( + returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); } if (!filled.get(93)) { - returnFromMessageCallWontTouchRamXorStackItemPop3.position(returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); + returnFromMessageCallWontTouchRamXorStackItemPop3.position( + returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } if (!filled.get(114)) { - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position(rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); } if (!filled.get(139)) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position(rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); } if (!filled.get(63)) { - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position(rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); } if (!filled.get(140)) { - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position(rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); } if (!filled.get(141)) { @@ -6483,7 +6909,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(64)) { - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position(rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } if (!filled.get(142)) { @@ -6495,11 +6922,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(65)) { - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position(romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( + romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } if (!filled.get(94)) { - selfdestructExceptionXorStackItemPop4.position(selfdestructExceptionXorStackItemPop4.position() + 1); + selfdestructExceptionXorStackItemPop4.position( + selfdestructExceptionXorStackItemPop4.position() + 1); } if (!filled.get(95)) { @@ -6507,11 +6936,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(96)) { - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position(selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position( + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); } if (!filled.get(97)) { - selfdestructWontRevertNotYetMarkedXorStoFlag.position(selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); + selfdestructWontRevertNotYetMarkedXorStoFlag.position( + selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } if (!filled.get(165)) { @@ -6595,7 +7026,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(125)) { - stpGasUpfrontGasCostXorGasLeftover.position(stpGasUpfrontGasCostXorGasLeftover.position() + 32); + stpGasUpfrontGasCostXorGasLeftover.position( + stpGasUpfrontGasCostXorGasLeftover.position() + 32); } if (!filled.get(162)) { @@ -6623,7 +7055,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(66)) { - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position(trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } if (!filled.get(144)) { @@ -6659,11 +7092,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(68)) { - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position(warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); } if (!filled.get(67)) { - warmthXorCreateExceptionXorHaltFlag.position(warmthXorCreateExceptionXorHaltFlag.position() + 1); + warmthXorCreateExceptionXorHaltFlag.position( + warmthXorCreateExceptionXorHaltFlag.position() + 1); } if (!filled.get(101)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java index cab82eb200..e08d5e47a2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java @@ -81,13 +81,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub.factories().accountFragment().make(oldMinerAccount, newMinerAccount), // 1 line -- transaction data - TransactionFragment.prepare( - hub.transients().conflation().number(), - minerAddress, - tx, - false, - gasPrice, - baseFee, - hub.transients().tx().initialGas()))); + TransactionFragment.prepare(hub.currentTransaction()))); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index afc9e684d4..5045d1dbaa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.fragment; +import java.math.BigInteger; + import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -35,8 +37,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.worldstate.WorldView; -import java.math.BigInteger; - @Accessors(fluent = true, chain = false) @Builder public final class CommonFragment implements TraceFragment { @@ -71,7 +71,12 @@ public final class CommonFragment implements TraceFragment { @Getter @Setter private int numberOfNonStackRows; @Getter @Setter private int nonStackRowsCounter; - public static CommonFragment fromHub(WorldView world, final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowCounter) { + public static CommonFragment fromHub( + WorldView world, + final Hub hub, + final CallFrame frame, + boolean tliCounter, + int nonStackRowCounter) { long refundDelta = 0; boolean noStackException = hub.pch().exceptions().noStackException(); @@ -81,40 +86,40 @@ public static CommonFragment fromHub(WorldView world, final Hub hub, final CallF int height = hub.currentFrame().stack().getHeight(); int heightNew = - (noStackException - ? height - hub.opCode().getData().stackSettings().delta() + hub.opCode().getData().stackSettings().alpha() - : 0); + (noStackException + ? height + - hub.opCode().getData().stackSettings().delta() + + hub.opCode().getData().stackSettings().alpha() + : 0); final int pc = frame.pc(); - final int pcNew = !noStackException - ? computePcNew(hub, pc) - : 0; + final int pcNew = !noStackException ? computePcNew(hub, pc) : 0; return CommonFragment.builder() - .hub(hub) - .txId(hub.transients().tx().id()) - .batchNumber(hub.transients().conflation().number()) - .txState(hub.transients().tx().state()) - .stamps(hub.state.stamps()) - .instructionFamily(hub.opCodeData().instructionFamily()) - .exceptions(hub.pch().exceptions().snapshot()) - .abortingConditions(hub.pch().abortingConditions().snapshot()) - .failureConditions(hub.pch().failureConditions().snapshot()) - .callFrameId(frame.id()) - .contextNumber(frame.contextNumber()) - .contextNumberNew(hub.contextNumberNew(world)) - .pc(pc) - .pcNew(pcNew) - .height((short) height) - .heightNew((short) heightNew) - .codeDeploymentNumber(frame.codeDeploymentNumber()) - .codeDeploymentStatus(frame.underDeployment()) - .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) - .refundDelta(refundDelta) - .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) - .twoLineInstructionCounter(tliCounter) - .nonStackRowsCounter(nonStackRowCounter) - .build(); + .hub(hub) + .txId(hub.transients().tx().id()) + .batchNumber(hub.transients().conflation().number()) + .txState(hub.transients().tx().state()) + .stamps(hub.state.stamps()) + .instructionFamily(hub.opCodeData().instructionFamily()) + .exceptions(hub.pch().exceptions().snapshot()) + .abortingConditions(hub.pch().abortingConditions().snapshot()) + .failureConditions(hub.pch().failureConditions().snapshot()) + .callFrameId(frame.id()) + .contextNumber(frame.contextNumber()) + .contextNumberNew(hub.contextNumberNew(world)) + .pc(pc) + .pcNew(pcNew) + .height((short) height) + .heightNew((short) heightNew) + .codeDeploymentNumber(frame.codeDeploymentNumber()) + .codeDeploymentStatus(frame.underDeployment()) + .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) + .refundDelta(refundDelta) + .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) + .twoLineInstructionCounter(tliCounter) + .nonStackRowsCounter(nonStackRowCounter) + .build(); } private static int computePcNew(final Hub hub, final int pc) { @@ -128,9 +133,8 @@ private static int computePcNew(final Hub hub, final int pc) { final BigInteger prospectivePcNew = hub.currentFrame().frame().getStackItem(0).toBigInteger(); final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); - final int attemptedPcNew = codeSize.compareTo(prospectivePcNew) > 0 - ? prospectivePcNew.intValueExact() - : 0; + final int attemptedPcNew = + codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() : 0; if (opCode.equals(OpCode.JUMP)) { return attemptedPcNew; @@ -150,8 +154,8 @@ private static int computePcNew(final Hub hub, final int pc) { private int computeContextNumberNew(WorldView world, final Hub hub) { OpCode opCode = hub.opCode(); if (exceptions.any() - || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) - || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)){ + || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) + || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { return callerContextNumber; } @@ -172,7 +176,6 @@ private int computeContextNumberNew(WorldView world, final Hub hub) { } return contextNumber; - } public boolean txReverts() { @@ -203,47 +206,47 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final boolean willRevert = frame.willRevert(); return trace - .absoluteTransactionNumber(tx.absNumber()) - .batchNumber(this.batchNumber) - .txSkip(this.txState == TxState.TX_SKIP) - .txWarm(this.txState == TxState.TX_WARM) - .txInit(this.txState == TxState.TX_INIT) - .txExec(this.txState == TxState.TX_EXEC) - .txFinl(this.txState == TxState.TX_FINAL) - .hubStamp(this.stamps.hub()) - .hubStampTransactionEnd(tx.endStamp()) - .contextMayChange( - this.txState == TxState.TX_EXEC - && ((instructionFamily == InstructionFamily.CALL - || instructionFamily == InstructionFamily.CREATE - || instructionFamily == InstructionFamily.HALT - || instructionFamily == InstructionFamily.INVALID) - || exceptions.any())) - .exceptionAhoy(exceptions.any()) - .logInfoStamp(this.stamps.log()) - .mmuStamp(this.stamps.mmu()) - .mxpStamp(this.stamps.mxp()) - .contextNumber(contextNumber) - .contextNumberNew(contextNumberNew) - .callerContextNumber(callerContextNumber) - .contextWillRevert(willRevert) - .contextGetsReverted(getsReverted) - .contextSelfReverts(selfReverts) - .contextRevertStamp(revertStamp) - .codeFragmentIndex(codeFragmentIndex) - .programCounter(pc) - .programCounterNew(pcNew) - .height((short) stackHeight) - .heightNew((short) stackHeightNew) - .gasExpected(gasExpected) - .gasActual(gasActual) - .gasCost(Bytes.ofUnsignedLong(gasCost)) - .gasNext(gasNext) - .refundCounter(gasRefund) - .refundCounterNew(gasRefund + (willRevert ? 0 : refundDelta)) - .twoLineInstruction(twoLineInstruction) - .counterTli(twoLineInstructionCounter) - .nonStackRows((short) numberOfNonStackRows) - .counterNsr((short) nonStackRowsCounter); + .absoluteTransactionNumber(tx.absNumber()) + .batchNumber(this.batchNumber) + .txSkip(this.txState == TxState.TX_SKIP) + .txWarm(this.txState == TxState.TX_WARM) + .txInit(this.txState == TxState.TX_INIT) + .txExec(this.txState == TxState.TX_EXEC) + .txFinl(this.txState == TxState.TX_FINAL) + .hubStamp(this.stamps.hub()) + .hubStampTransactionEnd(tx.endStamp()) + .contextMayChange( + this.txState == TxState.TX_EXEC + && ((instructionFamily == InstructionFamily.CALL + || instructionFamily == InstructionFamily.CREATE + || instructionFamily == InstructionFamily.HALT + || instructionFamily == InstructionFamily.INVALID) + || exceptions.any())) + .exceptionAhoy(exceptions.any()) + .logInfoStamp(this.stamps.log()) + .mmuStamp(this.stamps.mmu()) + .mxpStamp(this.stamps.mxp()) + .contextNumber(contextNumber) + .contextNumberNew(contextNumberNew) + .callerContextNumber(callerContextNumber) + .contextWillRevert(willRevert) + .contextGetsReverted(getsReverted) + .contextSelfReverts(selfReverts) + .contextRevertStamp(revertStamp) + .codeFragmentIndex(codeFragmentIndex) + .programCounter(pc) + .programCounterNew(pcNew) + .height((short) stackHeight) + .heightNew((short) stackHeightNew) + .gasExpected(gasExpected) + .gasActual(gasActual) + .gasCost(Bytes.ofUnsignedLong(gasCost)) + .gasNext(gasNext) + .refundCounter(gasRefund) + .refundCounterNew(gasRefund + (willRevert ? 0 : refundDelta)) + .twoLineInstruction(twoLineInstruction) + .counterTli(twoLineInstructionCounter) + .nonStackRows((short) numberOfNonStackRows) + .counterNsr((short) nonStackRowsCounter); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 8827a61e85..03c0996a81 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -94,8 +94,8 @@ private StackFragment( long size = hub.currentFrame().frame().getStackItem(2).toLong(); memorySegmentToHash = hub.messageFrame().shadowReadMemory(offset, size); } - default -> - throw new UnsupportedOperationException("Hash was attempted by the following opcode: " + this.opCode().toString()); + default -> throw new UnsupportedOperationException( + "Hash was attempted by the following opcode: " + this.opCode().toString()); } this.hashInfoKeccak = EWord.of(memorySegmentToHash); } @@ -109,7 +109,8 @@ private StackFragment( boolean prospectivePcNewIsInBounds = codeSize.compareTo(prospectivePcNew) > 0; if (opCode.equals(OpCode.JUMPI)) { - boolean nonzeroJumpCondition = !hub.currentFrame().frame().getStackItem(1).toBigInteger().equals(BigInteger.ZERO); + boolean nonzeroJumpCondition = + !hub.currentFrame().frame().getStackItem(1).toBigInteger().equals(BigInteger.ZERO); prospectivePcNewIsInBounds = prospectivePcNewIsInBounds && nonzeroJumpCondition; } @@ -167,8 +168,10 @@ public void feedHashedValue(MessageFrame frame) { private boolean traceLog() { return this.opCode.isLog() - && this.exceptions.none() // TODO: should be redundant (exceptions trigger reverts) --- this could be asserted - && !this.willRevert; + && this.exceptions + .none() // TODO: should be redundant (exceptions trigger reverts) --- this could be + // asserted + && !this.willRevert; } @Override @@ -275,7 +278,8 @@ public Trace trace(Trace trace) { .pStackStaticFlag(this.stack.getCurrentOpcodeData().stackSettings().forbiddenInStatic()) .pStackPushValueHi(pushValue.hi()) .pStackPushValueLo(pushValue.lo()) - .pStackJumpDestinationVettingRequired(this.jumpDestinationVettingRequired) // TODO: confirm this + .pStackJumpDestinationVettingRequired( + this.jumpDestinationVettingRequired) // TODO: confirm this // Exception flag .pStackOpcx(exceptions.invalidOpcode()) .pStackSux(exceptions.stackUnderflow()) @@ -293,6 +297,6 @@ public Trace trace(Trace trace) { .pStackHashInfoKeccakHi(this.hashInfoKeccak.hi()) .pStackHashInfoKeccakLo(this.hashInfoKeccak.lo()) .pStackLogInfoFlag(this.traceLog()) // TODO: confirm this - ; + ; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index a60c452a1c..65796cc230 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -62,7 +62,7 @@ public Trace trace(Trace trace) { return trace .pMiscMxpFlag(true) .pMiscMxpMxpx(this.mxpException) - .pMiscMxpInst(Bytes.ofUnsignedInt(this.opCode)) + .pMiscMxpInst(this.opCode) .pMiscMxpDeploys(this.deploys) .pMiscMxpWords(Bytes.ofUnsignedLong(this.memorySize)) .pMiscMxpGasMxp(Bytes.ofUnsignedLong(this.gasMxp)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java index fc200e1556..25709625a3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java @@ -35,16 +35,16 @@ public record StpCall( public Trace trace(Trace trace) { return trace .pMiscStpFlag(true) - .pMiscStpInstruction(Bytes.of(opCode)) + .pMiscStpInstruction(opCode) .pMiscStpGasHi(gas.hi()) .pMiscStpGasLo(gas.lo()) - .pMiscStpValHi(value.hi()) - .pMiscStpValLo(value.lo()) + .pMiscStpValueHi(value.hi()) + .pMiscStpValueLo(value.lo()) .pMiscStpExists(exists) .pMiscStpWarmth(warm) .pMiscStpOogx(outOfGasException) .pMiscStpGasUpfrontGasCost(Bytes.ofUnsignedLong(upfront)) .pMiscStpGasPaidOutOfPocket(Bytes.ofUnsignedLong(outOfPocket)) - .pMiscStpGasStipend(Bytes.ofUnsignedLong(stipend)); + .pMiscStpGasStipend(stipend); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index aa8365bdf7..8e7f575fed 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -196,11 +196,14 @@ public void prepare(MessageFrame frame, PlatformController platformController, H this.romLex = ex.none() && !triggersAbortingCondition && targetAddressHasNonEmptyCode; this.ecData = ex.none() && EC_PRECOMPILES.contains(target); this.exp = - ex.none() && this.platformController.abortingConditions().none() && target.equals(Address.MODEXP); + ex.none() + && this.platformController.abortingConditions().none() + && target.equals(Address.MODEXP); } case CREATE, CREATE2 -> { - boolean triggersAbortingCondition = ex.none() && this.platformController.abortingConditions().any(); + boolean triggersAbortingCondition = + ex.none() && this.platformController.abortingConditions().any(); boolean triggersFailureCondition = false; if (ex.none() && this.platformController.abortingConditions().none()) { 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 dbdeb59bbd..08efa6fefc 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 @@ -210,15 +210,17 @@ public UnsignedByte unsignedByteValue() { return UnsignedByte.of(byteValue()); } - /** Returns true for JUMP-type instructions*/ - public boolean isJump() { return this == OpCode.JUMP || this == OpCode.JUMPI; } + /** Returns true for JUMP-type instructions */ + public boolean isJump() { + return this == OpCode.JUMP || this == OpCode.JUMPI; + } public boolean isLog() { return this == OpCode.LOG0 - || this == OpCode.LOG1 - || this == OpCode.LOG2 - || this == OpCode.LOG3 - || this == OpCode.LOG4; + || this == OpCode.LOG1 + || this == OpCode.LOG2 + || this == OpCode.LOG3 + || this == OpCode.LOG4; } /** Returns whether the {@link OpCode} entails a contract creation. */ From ca7145424154c5318dc50543639a8da35d8b8e6e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 09:52:16 +0530 Subject: [PATCH 008/461] fix(hub): fix cnNew for root context --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index d21512b27a..fa06e0100f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -652,7 +652,7 @@ public int contextNumberNew(WorldView world) { if (pch.exceptions().any() || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { - return this.callStack().caller().contextNumber(); + return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); //TODO: when callStackDepth = 0 } final int currentContextNumber = this.callStack().current().contextNumber(); From 3da79c09d6367f6d08afdf8b4da27675262e17ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 1 Jun 2024 15:22:43 +0400 Subject: [PATCH 009/461] fixes - HubProcessingMetadata - HubProcessingPhase clean up + stuff ... --- .../linea/zktracer/module/hub/Hub.java | 159 ++++++++---------- .../linea/zktracer/module/hub/State.java | 6 +- .../zktracer/module/hub/TransactionStack.java | 45 ++--- .../module/hub/fragment/CommonFragment.java | 38 ++--- .../hub/fragment/TransactionFragment.java | 47 +++--- .../module/hub/signals/Exceptions.java | 2 +- .../module/hub/transients/Transients.java | 4 +- .../zktracer/module/hub/transients/Tx.java | 4 +- .../zktracer/module/txndata/TxnData.java | 2 +- .../{TxState.java => HubProcessingPhase.java} | 2 +- ...ava => TransactionProcessingMetadata.java} | 75 ++++++--- 11 files changed, 205 insertions(+), 179 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/types/{TxState.java => HubProcessingPhase.java} (95%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/types/{LineaTransaction.java => TransactionProcessingMetadata.java} (73%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index fa06e0100f..7a752d5ab3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -126,6 +126,7 @@ public class Hub implements Module { /** accumulate the trace information for the Hub */ @Getter public final State state = new State(); + /** contain the factories for trace segments that need complex initialization */ @Getter private final Factories factories; @@ -148,9 +149,6 @@ public class Hub implements Module { @Getter private ProcessableBlockHeader currentBlockHeader; - /** LineaTransaction is an enhanced Besu transaction */ - @Getter private LineaTransaction currentTransaction; - @Override public String moduleKey() { return "HUB"; @@ -423,14 +421,15 @@ public List getModulesToCount() { * @param world a view onto the state */ void processStateSkip(WorldView world) { + this.state.setProcessingPhase(HubProcessingPhase.TX_SKIP); this.state.stamps().incrementHubStamp(); - final boolean isDeployment = this.transients.tx().besuTx().getTo().isEmpty(); + final boolean isDeployment = this.txStack.current().getBesuTransaction().getTo().isEmpty(); // // 3 sections -- account changes // // From account information - final Address fromAddress = this.transients.tx().besuTx().getSender(); + final Address fromAddress = this.txStack.current().getBesuTransaction().getSender(); final AccountSnapshot oldFromAccount = AccountSnapshot.fromAccount( world.get(fromAddress), @@ -439,7 +438,7 @@ void processStateSkip(WorldView world) { false); // To account information - final Address toAddress = effectiveToAddress(this.transients.tx().besuTx()); + final Address toAddress = effectiveToAddress(this.txStack.current().getBesuTransaction()); if (isDeployment) { this.transients.conflation().deploymentInfo().deploy(toAddress); } @@ -469,7 +468,7 @@ void processStateSkip(WorldView world) { oldFromAccount, oldToAccount, oldMinerAccount, - this.transients.tx().gasPrice(), + Wei.of(this.txStack.current().getEffectiveGasPrice()), this.transients.block().baseFee())); } @@ -478,36 +477,22 @@ void processStateSkip(WorldView world) { * * @param world a view onto the state */ - void processStateWarm(WorldView world) { - this.transients - .tx() - .besuTx() + void processPrewarmingPhase(WorldView world) { + this.state.setProcessingPhase(HubProcessingPhase.TX_WARM); + this.txStack + .current() + .getBesuTransaction() .getAccessList() .ifPresent( - preWarmed -> { - if (!preWarmed.isEmpty()) { + accessList -> { + if (!accessList.isEmpty()) { Set
seenAddresses = new HashSet<>(precompileAddress); - this.state.stamps().incrementHubStamp(); - Map> seenKeys = new HashMap<>(); List fragments = new ArrayList<>(); - final TransactionStack.MetaTransaction tx = this.transients.tx(); - final Transaction besuTx = tx.besuTx(); - final Address senderAddress = besuTx.getSender(); - final Address receiverAddress = effectiveToAddress(besuTx); - - for (AccessListEntry entry : preWarmed) { + for (AccessListEntry entry : accessList) { this.state.stamps().incrementHubStamp(); - final Address address = entry.address(); - if (senderAddress.equals(address)) { - tx.isSenderPreWarmed(true); - } - - if (receiverAddress.equals(address)) { - tx.isReceiverPreWarmed(true); - } final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); @@ -559,10 +544,19 @@ void processStateWarm(WorldView world) { } } + final TransactionProcessingMetadata transactionProcessingMetadata = + this.txStack.current(); + final Transaction besuTx = transactionProcessingMetadata.getBesuTransaction(); + final Address senderAddress = besuTx.getSender(); + final Address receiverAddress = effectiveToAddress(besuTx); + transactionProcessingMetadata.isSenderPreWarmed( + seenAddresses.contains(senderAddress)); + transactionProcessingMetadata.isReceiverPreWarmed( + seenAddresses.contains(receiverAddress)); + this.addTraceSection(new WarmupSection(this, fragments)); } }); - this.transients.tx().state(TxState.TX_INIT); } /** @@ -571,13 +565,14 @@ void processStateWarm(WorldView world) { * @param world a view onto the state */ void processStateInit(WorldView world) { + this.state.setProcessingPhase(HubProcessingPhase.TX_INIT); this.state.stamps().incrementHubStamp(); - final TransactionStack.MetaTransaction tx = this.transients.tx(); - final boolean isDeployment = tx.besuTx().getTo().isEmpty(); - final Address toAddress = effectiveToAddress(tx.besuTx()); + final TransactionProcessingMetadata tx = this.transients.tx(); + final boolean isDeployment = tx.getBesuTransaction().getTo().isEmpty(); + final Address toAddress = effectiveToAddress(tx.getBesuTransaction()); final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); - final Address fromAddress = tx.besuTx().getSender(); + final Address fromAddress = tx.getBesuTransaction().getSender(); final Account fromAccount = world.get(fromAddress); final AccountSnapshot preInitFromSnapshot = AccountSnapshot.fromAccount( @@ -590,12 +585,12 @@ void processStateInit(WorldView world) { ZkTracer.feeMarket .getTransactionPriceCalculator() .price( - (org.hyperledger.besu.ethereum.core.Transaction) tx.besuTx(), + (org.hyperledger.besu.ethereum.core.Transaction) tx.getBesuTransaction(), Optional.of(this.transients.block().baseFee())); - final Wei value = (Wei) tx.besuTx().getValue(); + final Wei value = (Wei) tx.getBesuTransaction().getValue(); final AccountSnapshot postInitFromSnapshot = preInitFromSnapshot.debit( - transactionGasPrice.multiply(tx.besuTx().getGasLimit()).add(value), true); + transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value), true); final boolean isSelfCredit = toAddress.equals(fromAddress); @@ -614,13 +609,14 @@ void processStateInit(WorldView world) { deploymentInfo.deploy(toAddress); } - final Bytecode initBytecode = new Bytecode(tx.besuTx().getInit().orElse(Bytes.EMPTY)); + final Bytecode initBytecode = + new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); final AccountSnapshot postInitToSnapshot = isDeployment ? preInitToSnapshot.deploy(value, initBytecode) : preInitToSnapshot.credit(value, true); - final TransactionFragment txFragment = TransactionFragment.prepare(this.currentTransaction); + final TransactionFragment txFragment = TransactionFragment.prepare(this.txStack.current()); this.defers.postTx(txFragment); final AccountFragment.AccountFragmentFactory accountFragmentFactory = @@ -637,7 +633,7 @@ void processStateInit(WorldView world) { ContextFragment.initializeExecutionContext(this), txFragment)); - tx.state(TxState.TX_EXEC); + this.state.setProcessingPhase(HubProcessingPhase.TX_EXEC); } public CallFrame currentFrame() { @@ -652,7 +648,9 @@ public int contextNumberNew(WorldView world) { if (pch.exceptions().any() || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { - return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); //TODO: when callStackDepth = 0 + return this.callStack.depth() == 0 + ? 0 + : this.callStack().caller().contextNumber(); // TODO: when callStackDepth = 0 } final int currentContextNumber = this.callStack().current().contextNumber(); @@ -772,10 +770,10 @@ void processStateExec(MessageFrame frame) { } void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { - this.transients().tx().state(TxState.TX_FINAL); + this.state.setProcessingPhase(HubProcessingPhase.TX_FINAL); this.state.stamps().incrementHubStamp(); - final Address fromAddress = this.transients.tx().besuTx().getSender(); + final Address fromAddress = this.transients.tx().getBesuTransaction().getSender(); final Account fromAccount = worldView.get(fromAddress); final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); final AccountSnapshot preFinalFromSnapshot = @@ -819,7 +817,7 @@ void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { this, accountFragmentFactory.make(preFinalFromSnapshot, postFinalFromSnapshot), accountFragmentFactory.make(preFinalCoinbaseSnapshot, postFinalCoinbaseSnapshot), - TransactionFragment.prepare(this.currentTransaction))); + TransactionFragment.prepare(this.txStack.current()))); } else { // Trace the exceptions of a transaction that could not even start // TODO: integrate with PCH @@ -827,7 +825,7 @@ void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { // this.exceptions = Exceptions.fromOutOfGas(); // } // otherwise 4 account rows (sender, coinbase, sender, recipient) + 1 tx row - Address toAddress = this.transients.tx().besuTx().getSender(); + Address toAddress = this.transients.tx().getBesuTransaction().getSender(); Account toAccount = worldView.get(toAddress); AccountSnapshot preFinalToSnapshot = AccountSnapshot.fromAccount( @@ -863,30 +861,18 @@ public void enterTransaction() { public void traceStartTx(final WorldView world, final Transaction tx) { this.pch.reset(); this.state.enter(); - - this.currentTransaction = - new LineaTransaction( - world, - this.transients.block().blockNumber(), - this.transients.block().minerAddress(), - this.transients.block().baseFee(), - txnData, - tx); + this.txStack.enterTransaction(world, tx, transients.block()); this.defers.postTx(this.state.currentTxTrace()); - this.txStack.enterTransaction(tx, requiresEvmExecution(world, tx)); - this.enterTransaction(); - if (this.transients - .tx() - .shouldSkip(world)) /* TODO: should use requiresEvmExecution instead of recomputing it */ { - this.transients.tx().state(TxState.TX_SKIP); + if (!this.txStack.current().requiresEvmExecution()) { this.processStateSkip(world); } else { - this.transients.tx().state(TxState.TX_WARM); - this.processStateWarm(world); + if (this.txStack.current().requiresPrewarming()) { + this.processPrewarmingPhase(world); + } this.processStateInit(world); } @@ -913,10 +899,13 @@ public void traceEndTx( Bytes output, List logs, long gasUsed) { - final long leftoverGas = currentTransaction.besuTransaction().getGasLimit() - gasUsed; - this.currentTransaction.completeLineaTransaction(isSuccessful, leftoverGas, this.refundedGas()); + final long leftoverGas = txStack.current().getBesuTransaction().getGasLimit() - gasUsed; + txStack + .current() + .completeLineaTransaction( + isSuccessful, leftoverGas, this.accruedRefunds(), this.state.stamps().hub()); this.txStack.exitTransaction(this, isSuccessful); - if (this.transients.tx().state() != TxState.TX_SKIP) { + if (this.state.processingPhase != HubProcessingPhase.TX_SKIP) { this.processStateFinal(world, tx, isSuccessful); } @@ -970,9 +959,9 @@ public void traceContextEnter(MessageFrame frame) { if (frame.getDepth() == 0) { // Bedrock... - final TransactionStack.MetaTransaction currentTx = transients().tx(); - final Address toAddress = effectiveToAddress(currentTx.besuTx()); - final boolean isDeployment = this.transients.tx().besuTx().getTo().isEmpty(); + final TransactionProcessingMetadata currentTx = transients().tx(); + final Address toAddress = effectiveToAddress(currentTx.getBesuTransaction()); + final boolean isDeployment = this.transients.tx().getBesuTransaction().getTo().isEmpty(); final boolean shouldCopyTxCallData = !isDeployment && !frame.getInputData().isEmpty() && currentTx.requiresEvmExecution(); @@ -982,18 +971,18 @@ public void traceContextEnter(MessageFrame frame) { if (shouldCopyTxCallData) { this.callStack.newMantleAndBedrock( this.state.stamps().hub(), - this.transients.tx().besuTx().getSender(), + this.transients.tx().getBesuTransaction().getSender(), toAddress, CallFrameType.MANTLE, new Bytecode( toAddress == null - ? this.transients.tx().besuTx().getData().orElse(Bytes.EMPTY) + ? this.transients.tx().getBesuTransaction().getData().orElse(Bytes.EMPTY) : Optional.ofNullable(frame.getWorldUpdater().get(toAddress)) .map(AccountState::getCode) .orElse(Bytes.EMPTY)), - Wei.of(this.transients.tx().besuTx().getValue().getAsBigInteger()), - this.transients.tx().besuTx().getGasLimit(), - this.transients.tx().besuTx().getData().orElse(Bytes.EMPTY), + Wei.of(this.transients.tx().getBesuTransaction().getValue().getAsBigInteger()), + this.transients.tx().getBesuTransaction().getGasLimit(), + this.transients.tx().getBesuTransaction().getData().orElse(Bytes.EMPTY), this.transients.conflation().deploymentInfo().number(toAddress), toAddress.isEmpty() ? 0 @@ -1007,13 +996,13 @@ public void traceContextEnter(MessageFrame frame) { CallFrameType.BEDROCK, new Bytecode( toAddress == null - ? this.transients.tx().besuTx().getData().orElse(Bytes.EMPTY) + ? this.transients.tx().getBesuTransaction().getData().orElse(Bytes.EMPTY) : Optional.ofNullable(frame.getWorldUpdater().get(toAddress)) .map(AccountState::getCode) .orElse(Bytes.EMPTY)), - Wei.of(this.transients.tx().besuTx().getValue().getAsBigInteger()), - this.transients.tx().besuTx().getGasLimit(), - this.transients.tx().besuTx().getData().orElse(Bytes.EMPTY), + Wei.of(this.transients.tx().getBesuTransaction().getValue().getAsBigInteger()), + this.transients.tx().getBesuTransaction().getGasLimit(), + this.transients.tx().getBesuTransaction().getData().orElse(Bytes.EMPTY), this.transients.conflation().deploymentInfo().number(toAddress), toAddress.isEmpty() ? 0 @@ -1118,14 +1107,14 @@ public void traceContextExit(MessageFrame frame) { @Override public void tracePreOpcode(final MessageFrame frame) { - if (this.transients.tx().state() == TxState.TX_SKIP) { + if (this.state().processingPhase == HubProcessingPhase.TX_SKIP) { return; } this.processStateExec(frame); } public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { - if (this.transients.tx().state() == TxState.TX_SKIP) { + if (this.state.processingPhase == HubProcessingPhase.TX_SKIP) { return; } @@ -1209,6 +1198,7 @@ private void handleCreate(Address target) { @Override public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { this.transients.block().blockUpdate(processableBlockHeader); + this.txStack.resetBlock(); for (Module m : this.modules) { m.traceStartBlock(processableBlockHeader); } @@ -1238,7 +1228,7 @@ public void traceEndConflation(final WorldView state) { } } - public long refundedGas() { + public long accruedRefunds() { return this.state.currentTxTrace().refundCounter(); } @@ -1375,7 +1365,7 @@ void traceOperation(MessageFrame frame) { this.addTraceSection(copySection); } case TRANSACTION -> this.addTraceSection( - new TransactionSection(this, TransactionFragment.prepare(this.currentTransaction))); + new TransactionSection(this, TransactionFragment.prepare(this.txStack.current()))); case STACK_RAM -> { switch (this.currentFrame().opCode()) { case CALLDATALOAD -> { @@ -1403,10 +1393,7 @@ void traceOperation(MessageFrame frame) { address, this.currentFrame().accountDeploymentNumber(), key, - this.transients - .tx() - .storage() - .getOriginalValueOrUpdate(address, key, valNext), + this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), EWord.of(frame.getTransientStorageValue(address, key)), valNext, frame.isStorageWarm(address, key), @@ -1422,7 +1409,7 @@ void traceOperation(MessageFrame frame) { address, this.currentFrame().accountDeploymentNumber(), key, - this.transients.tx().storage().getOriginalValueOrUpdate(address, key), + this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), valCurrent, valCurrent, frame.isStorageWarm(address, key), diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index c0bb35b4e7..ced73559d2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -20,17 +20,19 @@ import java.util.Iterator; import lombok.Getter; +import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.State.TxState.Stamps; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; +import net.consensys.linea.zktracer.types.HubProcessingPhase; public class State implements StackedContainer { private final Deque state = new ArrayDeque<>(50); State() {} - private TxState current() { + public TxState current() { return this.state.peek(); } @@ -38,6 +40,8 @@ public Stamps stamps() { return this.current().stamps; } + @Getter @Setter HubProcessingPhase processingPhase; + /** * @return the current transaction trace elements */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index eee07b4d60..c0667d0550 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -28,28 +28,32 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.container.StackedContainer; +import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; -import net.consensys.linea.zktracer.types.TxState; +import net.consensys.linea.zktracer.types.HubProcessingPhase; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.worldstate.WorldView; public class TransactionStack implements StackedContainer { - private final List txs = new ArrayList<>(100); + private final List txs = new ArrayList<>(100); private int currentAbsNumber; + private int relativeBlockNumber; + private int relativeTransactionNumber; - public MetaTransaction current() { + public TransactionProcessingMetadata current() { return this.txs.get(this.txs.size() - 1); } - public MetaTransaction getById(int id) { + public TransactionProcessingMetadata getById(int id) { return this.txs.get(id); } - public MetaTransaction getByAbsNumber(int id) { - for (MetaTransaction tx : this.txs) { - if (tx.absNumber == id) { + public TransactionProcessingMetadata getByAbsNumber(int id) { + for (TransactionProcessingMetadata tx : this.txs) { + if (tx.getAbsoluteTransactionNumber() == id) { return tx; } } @@ -60,14 +64,20 @@ public MetaTransaction getByAbsNumber(int id) { @Override public void enter() { this.currentAbsNumber += 1; + this.relativeTransactionNumber += 1; } @Override public void pop() { this.currentAbsNumber -= 1; + this.relativeTransactionNumber -= 1; } - public void enterTransaction(final Transaction tx, final boolean requiresEvmExecution) { + public void resetBlock() { + this.relativeTransactionNumber = 0; + } + + public void enterTransaction(final WorldView world, final Transaction tx, Block block) { this.enter(); if (tx.getTo().isPresent() && isPrecompile(tx.getTo().get())) { throw new RuntimeException("Call to precompile forbidden"); @@ -75,22 +85,17 @@ public void enterTransaction(final Transaction tx, final boolean requiresEvmExec // this.number++; } - final MetaTransaction newTx = - MetaTransaction.builder() - .besuTx(tx) - .absNumber(currentAbsNumber) - .status(null) - .initialGas(tx.getGasLimit()) - .requiresEvmExecution(requiresEvmExecution) - .build(); + final TransactionProcessingMetadata newTx = + new TransactionProcessingMetadata( + world, tx, block, relativeTransactionNumber, currentAbsNumber); this.txs.add(newTx); } public void exitTransaction(final Hub hub, boolean isSuccessful) { - if (this.current().state() != TxState.TX_SKIP) { - this.current().state(TxState.TX_FINAL); + if (hub.state.processingPhase != HubProcessingPhase.TX_SKIP) { + hub.state.setProcessingPhase(HubProcessingPhase.TX_FINAL); } - this.current().status(!isSuccessful).endStamp(hub.stamp()); + this.current().setHubStampTransactionEnd(hub.stamp()); } public static long computeInitGas(Transaction tx) { @@ -106,7 +111,7 @@ public static class MetaTransaction { @Getter private int id; @Getter private Transaction besuTx; @Getter private int absNumber; - @Getter @Setter private TxState state; + @Getter @Setter private HubProcessingPhase state; @Setter @Builder.Default private Boolean status = null; @Getter private long initialGas; @Getter private final StorageInitialValues storage = new StorageInitialValues(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 5045d1dbaa..ffde876a2a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -24,14 +24,14 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.TransactionStack; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.TxState; +import net.consensys.linea.zktracer.types.HubProcessingPhase; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; @@ -41,9 +41,9 @@ @Builder public final class CommonFragment implements TraceFragment { private final Hub hub; - private final int txId; - private final int batchNumber; - private final TxState txState; + private final int absoluteTransactionNumber; + private final int relativeBlockNumber; + private final HubProcessingPhase hubProcessingPhase; private final State.TxState.Stamps stamps; private final InstructionFamily instructionFamily; private final Exceptions exceptions; @@ -97,9 +97,9 @@ public static CommonFragment fromHub( return CommonFragment.builder() .hub(hub) - .txId(hub.transients().tx().id()) - .batchNumber(hub.transients().conflation().number()) - .txState(hub.transients().tx().state()) + .absoluteTransactionNumber(hub.transients().tx().getAbsoluteTransactionNumber()) + .relativeBlockNumber(hub.transients().conflation().number()) + .hubProcessingPhase(hub.state.getProcessingPhase()) .stamps(hub.state.stamps()) .instructionFamily(hub.opCodeData().instructionFamily()) .exceptions(hub.pch().exceptions().snapshot()) @@ -179,7 +179,7 @@ private int computeContextNumberNew(WorldView world, final Hub hub) { } public boolean txReverts() { - return hub.txStack().getById(this.txId).status(); + return hub.txStack().getById(this.absoluteTransactionNumber).statusCode(); } @Override @@ -189,7 +189,7 @@ public Trace trace(Trace trace) { public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final CallFrame frame = this.hub.callStack().getById(this.callFrameId); - final TransactionStack.MetaTransaction tx = hub.txStack().getById(this.txId); + final TransactionProcessingMetadata tx = hub.txStack().getById(this.absoluteTransactionNumber); // TODO: after ROMLex merge final int codeFragmentIndex = 0; // frame.type() == CallFrameType.MANTLE @@ -206,17 +206,17 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final boolean willRevert = frame.willRevert(); return trace - .absoluteTransactionNumber(tx.absNumber()) - .batchNumber(this.batchNumber) - .txSkip(this.txState == TxState.TX_SKIP) - .txWarm(this.txState == TxState.TX_WARM) - .txInit(this.txState == TxState.TX_INIT) - .txExec(this.txState == TxState.TX_EXEC) - .txFinl(this.txState == TxState.TX_FINAL) + .absoluteTransactionNumber(tx.getAbsoluteTransactionNumber()) + .batchNumber(this.relativeBlockNumber) + .txSkip(this.hubProcessingPhase == HubProcessingPhase.TX_SKIP) + .txWarm(this.hubProcessingPhase == HubProcessingPhase.TX_WARM) + .txInit(this.hubProcessingPhase == HubProcessingPhase.TX_INIT) + .txExec(this.hubProcessingPhase == HubProcessingPhase.TX_EXEC) + .txFinl(this.hubProcessingPhase == HubProcessingPhase.TX_FINAL) .hubStamp(this.stamps.hub()) - .hubStampTransactionEnd(tx.endStamp()) + .hubStampTransactionEnd(tx.getHubStampTransactionEnd()) .contextMayChange( - this.txState == TxState.TX_EXEC + this.hubProcessingPhase == HubProcessingPhase.TX_EXEC && ((instructionFamily == InstructionFamily.CALL || instructionFamily == InstructionFamily.CREATE || instructionFamily == InstructionFamily.HALT diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index 2dda24a53f..75ae04cfb0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -23,56 +23,61 @@ import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.LineaTransaction; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.evm.worldstate.WorldView; public final class TransactionFragment implements TraceFragment, PostTransactionDefer { - private final LineaTransaction lineaTransaction; + private final TransactionProcessingMetadata transactionProcessingMetadata; @Setter private TraceSection parentSection; - private TransactionFragment(LineaTransaction lineaTransaction) { - this.lineaTransaction = lineaTransaction; + private TransactionFragment(TransactionProcessingMetadata transactionProcessingMetadata) { + this.transactionProcessingMetadata = transactionProcessingMetadata; } - public static TransactionFragment prepare(LineaTransaction lineaTransaction) { - return new TransactionFragment(lineaTransaction); + public static TransactionFragment prepare( + TransactionProcessingMetadata transactionProcessingMetadata) { + return new TransactionFragment(transactionProcessingMetadata); } @Override public Trace trace(Trace trace) { - final Transaction tx = lineaTransaction.besuTransaction(); - final EWord to = EWord.of(lineaTransaction.effectiveTo()); - final EWord from = EWord.of(lineaTransaction.getSender()); - final EWord miner = EWord.of(lineaTransaction.coinbase()); + final Transaction tx = transactionProcessingMetadata.getBesuTransaction(); + final EWord to = EWord.of(transactionProcessingMetadata.getEffectiveTo()); + final EWord from = EWord.of(transactionProcessingMetadata.getSender()); + final EWord miner = EWord.of(transactionProcessingMetadata.getCoinbase()); return trace .peekAtTransaction(true) - .pTransactionBatchNum(lineaTransaction.relativeBlockNumber()) + .pTransactionBatchNum(transactionProcessingMetadata.getRelativeBlockNumber()) .pTransactionFromAddressHi(from.hi().toLong()) .pTransactionFromAddressLo(from.lo()) .pTransactionNonce(Bytes.ofUnsignedLong(tx.getNonce())) - .pTransactionInitialBalance(bigIntegerToBytes(lineaTransaction.initialBalance())) + .pTransactionInitialBalance( + bigIntegerToBytes(transactionProcessingMetadata.getInitialBalance())) .pTransactionValue(bigIntegerToBytes(tx.getValue().getAsBigInteger())) .pTransactionToAddressHi(to.hi().toLong()) .pTransactionToAddressLo(to.lo()) - .pTransactionRequiresEvmExecution(lineaTransaction.requiresEvmExecution()) - .pTransactionCopyTxcd(lineaTransaction.copyTransactionCallData()) + .pTransactionRequiresEvmExecution(transactionProcessingMetadata.requiresEvmExecution()) + .pTransactionCopyTxcd(transactionProcessingMetadata.copyTransactionCallData()) .pTransactionIsDeployment(tx.getTo().isEmpty()) .pTransactionIsType2(tx.getType() == TransactionType.EIP1559) .pTransactionGasLimit(Bytes.minimalBytes(tx.getGasLimit())) .pTransactionGasInitiallyAvailable( - Bytes.minimalBytes(lineaTransaction.initiallyAvailableGas())) - .pTransactionGasPrice(Bytes.minimalBytes(lineaTransaction.effectiveGasPrice())) - .pTransactionBasefee(Bytes.minimalBytes(lineaTransaction.baseFee())) + Bytes.minimalBytes(transactionProcessingMetadata.getInitiallyAvailableGas())) + .pTransactionGasPrice( + Bytes.minimalBytes(transactionProcessingMetadata.getEffectiveGasPrice())) + .pTransactionBasefee(Bytes.minimalBytes(transactionProcessingMetadata.getBaseFee())) .pTransactionCallDataSize(tx.getData().map(Bytes::size).orElse(0)) .pTransactionInitCodeSize(tx.getInit().map(Bytes::size).orElse(0)) - .pTransactionStatusCode(lineaTransaction.statusCode()) - .pTransactionGasLeftover(Bytes.minimalBytes(lineaTransaction.leftoverGas())) - .pTransactionRefundCounterInfinity(Bytes.minimalBytes(lineaTransaction.refundCounterMax())) - .pTransactionRefundEffective(Bytes.minimalBytes(lineaTransaction.refundEffective())) + .pTransactionStatusCode(transactionProcessingMetadata.statusCode()) + .pTransactionGasLeftover(Bytes.minimalBytes(transactionProcessingMetadata.getLeftoverGas())) + .pTransactionRefundCounterInfinity( + Bytes.minimalBytes(transactionProcessingMetadata.getRefundCounterMax())) + .pTransactionRefundEffective( + Bytes.minimalBytes(transactionProcessingMetadata.getRefundEffective())) .pTransactionCoinbaseAddressHi(miner.hi().toLong()) .pTransactionCoinbaseAddressLo(miner.lo()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java index 90f8d82350..78853083ef 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java @@ -231,7 +231,7 @@ private static boolean isReturnDataCopyFault(final MessageFrame frame, final OpC } private static boolean isJumpFault(final MessageFrame frame, OpCode opCode) { - if (opCode == OpCode.JUMP || opCode == OpCode.JUMPI) { + if (opCode.isJump()) { final long target = Words.clampedToLong(frame.getStackItem(0)); final boolean invalidDestination = frame.getCode().isJumpDestInvalid((int) target); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java index 490a4cee82..b04a34488f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java @@ -18,7 +18,7 @@ import lombok.Getter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.TransactionStack; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; /** * This class stores data and provide information accessible through the {@link Hub} of various @@ -35,7 +35,7 @@ public class Transients { /** provides operation-related information */ final OperationAncillaries op; - public TransactionStack.MetaTransaction tx() { + public TransactionProcessingMetadata tx() { return this.hub.txStack().current(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java index de1a9ecc3d..1bbcf05d17 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java @@ -25,7 +25,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.container.StackedContainer; -import net.consensys.linea.zktracer.types.TxState; +import net.consensys.linea.zktracer.types.HubProcessingPhase; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Transaction; @@ -40,7 +40,7 @@ public class Tx implements StackedContainer { private int number = 0; private Transaction transaction; - @Setter private TxState state; + @Setter private HubProcessingPhase state; @Setter private Boolean status; private long initialGas; StorageInitialValues storage; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java index 015855c7fe..1da2524a67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java @@ -106,7 +106,7 @@ public void traceEndTx( List logs, long gasUsed) { final long leftoverGas = tx.getGasLimit() - gasUsed; - final long refundCounter = hub.refundedGas(); + final long refundCounter = hub.accruedRefunds(); this.currentBlock().endTx(leftoverGas, refundCounter, isSuccessful); final TransactionSnapshot currentTx = this.currentBlock().currentTx(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TxState.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/HubProcessingPhase.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/types/TxState.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/types/HubProcessingPhase.java index c27974f0d6..f851ab2df2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TxState.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/HubProcessingPhase.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.types; -public enum TxState { +public enum HubProcessingPhase { TX_EXEC, TX_FINAL, TX_INIT, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/LineaTransaction.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java similarity index 73% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/types/LineaTransaction.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 6522c7a036..2d36d99df8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/LineaTransaction.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -25,24 +25,29 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; -import net.consensys.linea.zktracer.module.txndata.TxnData; +import net.consensys.linea.zktracer.module.hub.transients.Block; +import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.worldstate.WorldView; -@Accessors(fluent = true) +@Accessors() @Getter -public class LineaTransaction { +public class TransactionProcessingMetadata { + final int absoluteTransactionNumber; + final int relativeTransactionNumber; final int relativeBlockNumber; final Transaction besuTransaction; - final int relativeTransactionNumber; final Address coinbase; final long baseFee; final boolean isDeployment; + + @Accessors(fluent = true) final boolean requiresEvmExecution; + + @Accessors(fluent = true) final boolean copyTransactionCallData; final BigInteger initialBalance; @@ -55,24 +60,39 @@ public class LineaTransaction { final long effectiveGasPrice; - @Setter long refundCounterMax; - @Setter long refundEffective; - @Setter long leftoverGas; - @Setter boolean statusCode; + @Setter long refundCounterMax = 0; + @Setter long refundEffective = 0; + @Setter long leftoverGas = 0; + + @Accessors(fluent = true) + @Setter + boolean statusCode = false; + + @Setter int hubStampTransactionEnd; - public LineaTransaction( + @Accessors(fluent = true) + @Setter + boolean isSenderPreWarmed = false; + + @Accessors(fluent = true) + @Setter + boolean isReceiverPreWarmed = false; + + final StorageInitialValues storage = new StorageInitialValues(); + + public TransactionProcessingMetadata( WorldView world, - int relativeBlockNumber, - Address coinbase, - Wei baseFee, - TxnData txnData, - Transaction transaction) { - this.relativeBlockNumber = relativeBlockNumber; - this.coinbase = coinbase; - this.baseFee = baseFee.toLong(); + Transaction transaction, + Block block, + int relativeTransactionNumber, + int absoluteTransactionNumber) { + this.absoluteTransactionNumber = absoluteTransactionNumber; + this.relativeBlockNumber = block.blockNumber(); + this.coinbase = block.minerAddress(); + this.baseFee = block.baseFee().toLong(); this.besuTransaction = transaction; - this.relativeTransactionNumber = txnData.currentBlock().getTxs().size() + 1; + this.relativeTransactionNumber = relativeTransactionNumber; this.isDeployment = transaction.getTo().isEmpty(); this.requiresEvmExecution = computeRequiresEvmExecution(world); @@ -89,7 +109,7 @@ public LineaTransaction( this.effectiveTo = effectiveToAddress(besuTransaction); - this.effectiveGasPrice = getEffectiveGasPrice(); + this.effectiveGasPrice = computeEffectiveGasPrice(); } private boolean computeCopyCallData() { @@ -123,20 +143,21 @@ public long getInitiallyAvailableGas() { } public void completeLineaTransaction( - boolean statusCode, long leftoverGas, long refundCounterMax) { + boolean statusCode, long leftoverGas, long refundCounterMax, int hubStampTransactionEnd) { this.refundCounterMax = refundCounterMax; this.leftoverGas = leftoverGas; this.statusCode = statusCode; - this.refundEffective = getRefundEffective(); + this.refundEffective = computeRefundEffective(); + this.hubStampTransactionEnd = hubStampTransactionEnd; } - private long getRefundEffective() { + private long computeRefundEffective() { final long consumedGas = besuTransaction.getGasLimit() - leftoverGas; final long maxRefundableAmount = consumedGas / MAX_REFUND_QUOTIENT; return Math.min(maxRefundableAmount, refundCounterMax); } - private long getEffectiveGasPrice() { + private long computeEffectiveGasPrice() { final Transaction tx = besuTransaction; switch (tx.getType()) { @@ -144,7 +165,7 @@ private long getEffectiveGasPrice() { return tx.getGasPrice().get().getAsBigInteger().longValueExact(); } case EIP1559 -> { - final long baseFee = baseFee(); + final long baseFee = this.baseFee; final long maxPriorityFee = tx.getMaxPriorityFeePerGas().get().getAsBigInteger().longValue(); final long maxFeePerGas = tx.getMaxFeePerGas().get().getAsBigInteger().longValueExact(); @@ -157,4 +178,8 @@ private long getEffectiveGasPrice() { public Address getSender() { return besuTransaction.getSender(); } + + public boolean requiresPrewarming() { + return requiresEvmExecution && (accessListCost != 0); + } } From 28c55edf911984c93869446d987f530c29063231 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 17:00:13 +0530 Subject: [PATCH 010/461] fix(hub): make it buil ? --- .../linea/zktracer/types/TransactionProcessingMetadata.java | 1 - 1 file changed, 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 2d36d99df8..376d3d8ee8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -31,7 +31,6 @@ import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; -@Accessors() @Getter public class TransactionProcessingMetadata { final int absoluteTransactionNumber; From 07721b93e58fb8afe6003c609163ae3259fb8e32 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 17:09:07 +0530 Subject: [PATCH 011/461] fix(hub): re make it compile ?? --- .../module/hub/defer/SkippedPostTransactionDefer.java | 2 +- .../zktracer/module/hub/fragment/ContextFragment.java | 2 +- .../zktracer/module/hub/fragment/imc/ImcFragment.java | 8 ++++---- .../module/hub/fragment/imc/call/mmu/MmuCall.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java index e08d5e47a2..51d5b75998 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java @@ -81,6 +81,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub.factories().accountFragment().make(oldMinerAccount, newMinerAccount), // 1 line -- transaction data - TransactionFragment.prepare(hub.currentTransaction()))); + TransactionFragment.prepare(hub.txStack().current()))); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 83ab486544..923a683b84 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -46,7 +46,7 @@ public static ContextFragment initializeExecutionContext(final Hub hub) { hub.callStack(), Either.right(hub.stamp() + 1), MemorySpan.fromStartEnd( - 0, hub.transients().tx().besuTx().getData().map(Bytes::size).orElse(0)), + 0, hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)), false); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 547f2f0476..be74764653 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -23,7 +23,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.TransactionStack; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -41,6 +40,7 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; @@ -87,10 +87,10 @@ public static ImcFragment empty(final Hub hub) { public static ImcFragment forTxInit(final Hub hub) { // isdeployment == false // non empty calldata - final TransactionStack.MetaTransaction currentTx = hub.transients().tx(); - final boolean isDeployment = currentTx.besuTx().getTo().isEmpty(); + final TransactionProcessingMetadata currentTx = hub.txStack().current(); + final boolean isDeployment = currentTx.getBesuTransaction().getTo().isEmpty(); - final Optional txData = currentTx.besuTx().getData(); + final Optional txData = currentTx.getBesuTransaction().getData(); final boolean shouldCopyTxCallData = !isDeployment && txData.isPresent() diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index f4f431aaa0..5e0fa9ba27 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -298,9 +298,9 @@ public static MmuCall revert(final Hub hub) { public static MmuCall txInit(final Hub hub) { return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(hub.transients().tx().absNumber()) + .sourceId(hub.txStack().current().getAbsoluteTransactionNumber()) .targetId(hub.stamp()) - .size(hub.transients().tx().besuTx().getData().map(Bytes::size).orElse(0)) + .size(hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)) .phase(RLP_TXN_PHASE_DATA) .setRlpTxn(); } From 773d4f93b31f641cf7d1cffdd6ff2567adb09e9b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 18:09:25 +0530 Subject: [PATCH 012/461] fix(hub): Victory, hub knows to trace 1+1=2 ! --- .../zktracer/module/hub/TransactionStack.java | 14 ++------------ .../module/hub/fragment/AccountFragment.java | 3 ++- .../module/hub/fragment/CommonFragment.java | 7 +++++-- .../module/hub/fragment/ContextFragment.java | 8 +++++--- .../module/hub/fragment/TransactionFragment.java | 7 ++++--- .../linea/zktracer/types/Conversions.java | 4 ++++ 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index c0667d0550..bd0540c98b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -47,18 +47,8 @@ public TransactionProcessingMetadata current() { return this.txs.get(this.txs.size() - 1); } - public TransactionProcessingMetadata getById(int id) { - return this.txs.get(id); - } - - public TransactionProcessingMetadata getByAbsNumber(int id) { - for (TransactionProcessingMetadata tx : this.txs) { - if (tx.getAbsoluteTransactionNumber() == id) { - return tx; - } - } - - throw new IndexOutOfBoundsException("unknown tx"); + public TransactionProcessingMetadata getByAbsoluteTransactionNumber(final int id) { + return this.txs.get(id - 1); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java index 0e624dfe99..17ed7b7974 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.module.hub.fragment; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; +import static net.consensys.linea.zktracer.types.Conversions.bytesToLong; import java.util.Optional; @@ -95,7 +96,7 @@ public Trace trace(Trace trace) { return trace .peekAtAccount(true) - .pAccountAddressHi(eWho.hi().toLong()) + .pAccountAddressHi(bytesToLong(eWho.hi())) .pAccountAddressLo(eWho.lo()) .pAccountNonce(Bytes.ofUnsignedLong(oldState.nonce())) .pAccountNonceNew(Bytes.ofUnsignedLong(newState.nonce())) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index ffde876a2a..ee79987071 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -179,7 +179,9 @@ private int computeContextNumberNew(WorldView world, final Hub hub) { } public boolean txReverts() { - return hub.txStack().getById(this.absoluteTransactionNumber).statusCode(); + return hub.txStack() + .getByAbsoluteTransactionNumber(this.absoluteTransactionNumber) + .statusCode(); } @Override @@ -189,7 +191,8 @@ public Trace trace(Trace trace) { public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final CallFrame frame = this.hub.callStack().getById(this.callFrameId); - final TransactionProcessingMetadata tx = hub.txStack().getById(this.absoluteTransactionNumber); + final TransactionProcessingMetadata tx = + hub.txStack().getByAbsoluteTransactionNumber(this.absoluteTransactionNumber); // TODO: after ROMLex merge final int codeFragmentIndex = 0; // frame.type() == CallFrameType.MANTLE diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 923a683b84..a815ace47f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.fragment; +import static net.consensys.linea.zktracer.types.Conversions.bytesToLong; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -97,15 +99,15 @@ public Trace trace(Trace trace) { .pContextCallStackDepth((short) callFrame.depth()) .pContextIsRoot(callFrame.isRoot()) .pContextIsStatic(callFrame.type().isStatic()) - .pContextAccountAddressHi(eAddress.hi().toLong()) + .pContextAccountAddressHi(bytesToLong(eAddress.hi())) .pContextAccountAddressLo(eAddress.lo()) .pContextAccountDeploymentNumber(callFrame.accountDeploymentNumber()) - .pContextByteCodeAddressHi(eCodeAddress.hi().toLong()) + .pContextByteCodeAddressHi(bytesToLong(eCodeAddress.hi())) .pContextByteCodeAddressLo(eCodeAddress.lo()) .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) .pContextByteCodeCodeFragmentIndex(0) // TODO - .pContextCallerAddressHi(parentAddress.hi().toLong()) + .pContextCallerAddressHi(bytesToLong(parentAddress.hi())) .pContextCallerAddressLo(parentAddress.lo()) .pContextCallValue(callFrame.value()) .pContextCallDataContextNumber(parent.contextNumber()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index 75ae04cfb0..177a7e3c20 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.module.hub.fragment; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import static net.consensys.linea.zktracer.types.Conversions.bytesToLong; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Hub; @@ -52,13 +53,13 @@ public Trace trace(Trace trace) { return trace .peekAtTransaction(true) .pTransactionBatchNum(transactionProcessingMetadata.getRelativeBlockNumber()) - .pTransactionFromAddressHi(from.hi().toLong()) + .pTransactionFromAddressHi(bytesToLong(from.hi())) .pTransactionFromAddressLo(from.lo()) .pTransactionNonce(Bytes.ofUnsignedLong(tx.getNonce())) .pTransactionInitialBalance( bigIntegerToBytes(transactionProcessingMetadata.getInitialBalance())) .pTransactionValue(bigIntegerToBytes(tx.getValue().getAsBigInteger())) - .pTransactionToAddressHi(to.hi().toLong()) + .pTransactionToAddressHi(bytesToLong(to.hi())) .pTransactionToAddressLo(to.lo()) .pTransactionRequiresEvmExecution(transactionProcessingMetadata.requiresEvmExecution()) .pTransactionCopyTxcd(transactionProcessingMetadata.copyTransactionCallData()) @@ -78,7 +79,7 @@ public Trace trace(Trace trace) { Bytes.minimalBytes(transactionProcessingMetadata.getRefundCounterMax())) .pTransactionRefundEffective( Bytes.minimalBytes(transactionProcessingMetadata.getRefundEffective())) - .pTransactionCoinbaseAddressHi(miner.hi().toLong()) + .pTransactionCoinbaseAddressHi(bytesToLong(miner.hi())) .pTransactionCoinbaseAddressLo(miner.lo()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java index 9904f4737e..8e6345b5f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java @@ -143,4 +143,8 @@ public static Bytes longToBytes(final long input) { public static Bytes booleanToBytes(boolean x) { return x ? ONE : Bytes.EMPTY; } + + public static long bytesToLong(final Bytes input) { + return input.trimLeadingZeros().toLong(); + } } From bce390cbe45418f8290c600f8aca16085476f035 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 19:06:36 +0530 Subject: [PATCH 013/461] fix(hub): snaphsot of stamps --- .../linea/zktracer/module/hub/Hub.java | 4 +-- .../linea/zktracer/module/hub/State.java | 6 ++-- .../module/hub/fragment/CommonFragment.java | 31 +------------------ 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 7a752d5ab3..8648fd96b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -648,9 +648,7 @@ public int contextNumberNew(WorldView world) { if (pch.exceptions().any() || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { - return this.callStack.depth() == 0 - ? 0 - : this.callStack().caller().contextNumber(); // TODO: when callStackDepth = 0 + return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); } final int currentContextNumber = this.callStack().current().contextNumber(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index ced73559d2..e33ce93ca9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -28,7 +28,7 @@ import net.consensys.linea.zktracer.types.HubProcessingPhase; public class State implements StackedContainer { - private final Deque state = new ArrayDeque<>(50); + private final Deque state = new ArrayDeque<>(); State() {} @@ -110,7 +110,7 @@ public TxState(Stamps stamps) { } TxState spinOff() { - return new TxState(this.stamps.spinOff()); + return new TxState(this.stamps.snapshot()); } /** Stores all the stamps associated to the tracing of a transaction. */ @@ -132,7 +132,7 @@ public Stamps(int hubStamp, int mmuStamp, int mxpStamp, int hashInfoStamp) { this.hashInfo = hashInfoStamp; } - Stamps spinOff() { + public Stamps snapshot() { return new Stamps(this.hub, this.mmu, this.mxp, this.hashInfo); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index ee79987071..e4341db36b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -33,8 +33,6 @@ import net.consensys.linea.zktracer.types.HubProcessingPhase; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true, chain = false) @@ -100,7 +98,7 @@ public static CommonFragment fromHub( .absoluteTransactionNumber(hub.transients().tx().getAbsoluteTransactionNumber()) .relativeBlockNumber(hub.transients().conflation().number()) .hubProcessingPhase(hub.state.getProcessingPhase()) - .stamps(hub.state.stamps()) + .stamps(hub.state.stamps().snapshot()) .instructionFamily(hub.opCodeData().instructionFamily()) .exceptions(hub.pch().exceptions().snapshot()) .abortingConditions(hub.pch().abortingConditions().snapshot()) @@ -151,33 +149,6 @@ private static int computePcNew(final Hub hub, final int pc) { return pc + 1; } - private int computeContextNumberNew(WorldView world, final Hub hub) { - OpCode opCode = hub.opCode(); - if (exceptions.any() - || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) - || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { - return callerContextNumber; - } - - if (opCode.isCall()) { - // If abortingConditions Then contextNumberNew <-- contextNumber - Address calleeAddress = Address.extract((Bytes32) hub.currentFrame().frame().getStackItem(1)); - if (world.get(calleeAddress).hasCode()) { - return 1 + hub.stamp(); - } - } - - if (opCode.isCreate()) { - // If (abortingConditions ∨ failureConditions) Then contextNumberNew <-- contextNumber - final int initCodeSize = hub.currentFrame().frame().getStackItem(2).toInt(); - if (initCodeSize != 0) { - return 1 + hub.stamp(); - } - } - - return contextNumber; - } - public boolean txReverts() { return hub.txStack() .getByAbsoluteTransactionNumber(this.absoluteTransactionNumber) From 2843ba34aff2061b13b0fe0a050134374cccf971 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 19:44:45 +0530 Subject: [PATCH 014/461] fix: cn_new, hubStampEndTx, update constraints --- .../linea/zktracer/module/hub/Hub.java | 65 ++++++++++++------- .../zktracer/module/hub/TransactionStack.java | 2 +- .../module/hub/fragment/CommonFragment.java | 2 +- .../module/hub/section/TraceSection.java | 2 +- 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 8648fd96b8..63850d1a76 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -644,37 +644,54 @@ public CallFrame currentFrame() { } public int contextNumberNew(WorldView world) { - OpCode opCode = this.opCode(); - if (pch.exceptions().any() - || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) - || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { - return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); - } - - final int currentContextNumber = this.callStack().current().contextNumber(); - - if (opCode.isCall()) { - if (pch().abortingConditions().any()) { - return currentContextNumber; + switch (this.state.getProcessingPhase()) { + case TX_SKIP, TX_WARM, TX_FINAL -> { + return 0; } - Address calleeAddress = - Address.extract((Bytes32) this.currentFrame().frame().getStackItem(1)); - if (world.get(calleeAddress).hasCode()) { - return 1 + stamp(); + case TX_INIT -> { + return this.state.stamps().hub() + 1; } - } + case TX_EXEC -> { + final OpCode opCode = this.opCode(); + + if (pch.exceptions().any() + || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) + || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { + return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); + } + + final int currentContextNumber = this.callStack().current().contextNumber(); + + if (opCode.isCall()) { + if (pch().abortingConditions().any()) { + return currentContextNumber; + } + Address calleeAddress = + Address.extract((Bytes32) this.currentFrame().frame().getStackItem(1)); + if (world.get(calleeAddress).hasCode()) { + return 1 + stamp(); + } + } + + if (opCode.isCreate()) { + if (pch().abortingConditions().any() || pch().failureConditions().any()) { + return currentContextNumber; + } + final int initCodeSize = this.currentFrame().frame().getStackItem(2).toInt(); + if (initCodeSize != 0) { + return 1 + stamp(); + } + } - if (opCode.isCreate()) { - if (pch().abortingConditions().any() || pch().failureConditions().any()) { return currentContextNumber; } - final int initCodeSize = this.currentFrame().frame().getStackItem(2).toInt(); - if (initCodeSize != 0) { - return 1 + stamp(); + default -> { + { + throw new IllegalStateException( + String.format("Hub can't be in the state %s", this.state.getProcessingPhase())); + } } } - - return currentContextNumber; } public MessageFrame messageFrame() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index bd0540c98b..8ca36d6b9f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -85,7 +85,7 @@ public void exitTransaction(final Hub hub, boolean isSuccessful) { if (hub.state.processingPhase != HubProcessingPhase.TX_SKIP) { hub.state.setProcessingPhase(HubProcessingPhase.TX_FINAL); } - this.current().setHubStampTransactionEnd(hub.stamp()); + this.current().setHubStampTransactionEnd(hub.stamp() + 1); } public static long computeInitGas(Transaction tx) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index e4341db36b..08fe4592f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -50,7 +50,7 @@ public final class CommonFragment implements TraceFragment { private final int callFrameId; private final int callerContextNumber; @Getter private final int contextNumber; - @Setter private int contextNumberNew; + private final int contextNumberNew; private final int revertStamp; @Getter final short height; @Getter final short heightNew; 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 2f7820f20d..da8becd114 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 @@ -206,7 +206,7 @@ public void seal(Hub hub) { line.common.nonStackRowsCounter(nonStackLineCounter); } line.common.pcNew(hub.lastPc()); - line.common.contextNumberNew(hub.lastContextNumber()); + // line.common.contextNumberNew(hub.lastContextNumber()); //TODO understand this line.common.numberOfNonStackRows(nonStackLineNumbers); } } From de0bcb19c1f791f34cb5894441c09ca8de2d9369 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 1 Jun 2024 22:23:54 +0530 Subject: [PATCH 015/461] fix(hub): pc and pc new --- .../module/hub/fragment/CommonFragment.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 08fe4592f0..c7f8c808d9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -75,23 +75,21 @@ public static CommonFragment fromHub( final CallFrame frame, boolean tliCounter, int nonStackRowCounter) { - long refundDelta = 0; - boolean noStackException = hub.pch().exceptions().noStackException(); - if (noStackException) { - refundDelta = Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).refund(); - } + final boolean noStackException = hub.pch().exceptions().noStackException(); + final long refundDelta = + noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).refund() : 0; - int height = hub.currentFrame().stack().getHeight(); - int heightNew = + final int height = hub.currentFrame().stack().getHeight(); + final int heightNew = (noStackException ? height - hub.opCode().getData().stackSettings().delta() + hub.opCode().getData().stackSettings().alpha() : 0); - - final int pc = frame.pc(); - final int pcNew = !noStackException ? computePcNew(hub, pc) : 0; + final boolean hubInExecPhase = hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC; + final int pc = hubInExecPhase ? frame.pc() : 0; + final int pcNew = noStackException && hubInExecPhase ? computePcNew(hub, pc) : 0; return CommonFragment.builder() .hub(hub) From 75593f5b08d1c8f18b70b0915571b1bae7aa2c28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 1 Jun 2024 21:53:25 +0400 Subject: [PATCH 016/461] updated instruction decoder --- .../src/main/resources/opcodes.yml | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml index f2574c8909..48459ac5be 100644 --- a/arithmetization/src/main/resources/opcodes.yml +++ b/arithmetization/src/main/resources/opcodes.yml @@ -30,6 +30,7 @@ opcodes: nbAdded: 1 nbRemoved: 2 staticGas: G_LOW + flag1: true - mnemonic: SUB value: 0x03 instructionFamily: ADD @@ -110,6 +111,7 @@ opcodes: nbAdded: 1 nbRemoved: 2 staticGas: G_EXP + flag2: true - mnemonic: SIGNEXTEND value: 0xb instructionFamily: BIN @@ -120,8 +122,8 @@ opcodes: nbAdded: 1 nbRemoved: 2 staticGas: G_VERY_LOW - # assigned SLT opcode for WCP module with value 0x0E. Change this value if Linéa/EVM uses this opcode. - # assigned SGT opcode for WCP module with value 0x0F. Change this value if Linéa/EVM uses this opcode. + # assigned LEQ opcode for WCP module with value 0x0E. Change this value if Linéa/EVM uses this opcode. + # assigned GEQ opcode for WCP module with value 0x0F. Change this value if Linéa/EVM uses this opcode. - mnemonic: LT value: 0x10 instructionFamily: WCP @@ -288,6 +290,7 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BASE + flag1: true - mnemonic: BALANCE value: 0x31 instructionFamily: ACCOUNT @@ -299,7 +302,7 @@ opcodes: nbRemoved: 1 staticGas: S_HUB addressTrimmingInstruction: true - flag4: true + flag1: true - mnemonic: ORIGIN value: 0x32 instructionFamily: TRANSACTION @@ -331,7 +334,7 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BASE - flag1: true + flag3: true - mnemonic: CALLDATALOAD value: 0x35 instructionFamily: STACK_RAM @@ -354,8 +357,7 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BASE - flag1: true - flag3: true + flag4: true - mnemonic: CALLDATACOPY value: 0x37 instructionFamily: COPY @@ -366,6 +368,7 @@ opcodes: nbAdded: 0 nbRemoved: 3 staticGas: S_MXP + flag1: true billing: byWord: type: TYPE_4 @@ -380,7 +383,7 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BASE - flag1: true + flag4: true - mnemonic: CODECOPY value: 0x39 instructionFamily: COPY @@ -418,8 +421,7 @@ opcodes: nbRemoved: 1 staticGas: S_HUB addressTrimmingInstruction: true - flag1: true - flag3: true + flag2: true - mnemonic: EXTCODECOPY value: 0x3c instructionFamily: COPY @@ -446,8 +448,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BASE - flag1: true - flag2: true - mnemonic: RETURNDATACOPY value: 0x3e instructionFamily: COPY @@ -475,7 +475,7 @@ opcodes: nbRemoved: 1 staticGas: S_HUB addressTrimmingInstruction: true - flag2: true + flag3: true - mnemonic: BLOCKHASH value: 0x40 instructionFamily: BATCH @@ -497,7 +497,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BLOCK_HASH - flag1: true - mnemonic: TIMESTAMP value: 0x42 instructionFamily: BATCH @@ -508,7 +507,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BLOCK_HASH - flag1: true - mnemonic: NUMBER value: 0x43 instructionFamily: BATCH @@ -519,7 +517,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BLOCK_HASH - flag1: true - mnemonic: DIFFICULTY value: 0x44 instructionFamily: BATCH @@ -530,7 +527,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BLOCK_HASH - flag1: true - mnemonic: GASLIMIT value: 0x45 instructionFamily: BATCH @@ -541,7 +537,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BLOCK_HASH - flag1: true - mnemonic: CHAINID value: 0x46 instructionFamily: BATCH @@ -552,7 +547,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BLOCK_HASH - flag1: true - mnemonic: SELFBALANCE value: 0x47 instructionFamily: ACCOUNT @@ -563,7 +557,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_LOW - flag1: true - mnemonic: BASEFEE value: 0x48 instructionFamily: BATCH @@ -574,7 +567,6 @@ opcodes: nbAdded: 1 nbRemoved: 0 staticGas: G_BLOCK_HASH - flag1: true - mnemonic: POP value: 0x50 instructionFamily: PUSH_POP @@ -1471,8 +1463,7 @@ opcodes: staticGas: G_LOG_2 twoLinesInstruction: true forbiddenInStatic: true - flag1: true - flag3: true + flag2: true billing: byByte: type: TYPE_4 @@ -1489,7 +1480,6 @@ opcodes: staticGas: G_LOG_3 twoLinesInstruction: true forbiddenInStatic: true - flag1: true flag3: true billing: byByte: @@ -1507,9 +1497,7 @@ opcodes: staticGas: G_LOG_4 twoLinesInstruction: true forbiddenInStatic: true - flag1: true - flag2: true - flag3: true + flag4: true billing: byByte: type: TYPE_4 @@ -1527,6 +1515,7 @@ opcodes: staticGas: G_CREATE twoLinesInstruction: true forbiddenInStatic: true + flag1: true billing: byMxp: type: TYPE_4 @@ -1542,6 +1531,7 @@ opcodes: oobFlag: true staticGas: S_CALL twoLinesInstruction: true + forbiddenInStatic: true addressTrimmingInstruction: true flag1: true billing: @@ -1609,7 +1599,7 @@ opcodes: staticGas: G_CREATE twoLinesInstruction: true forbiddenInStatic: true - flag1: true + flag2: true billing: byWord: type: TYPE_4 @@ -1654,6 +1644,7 @@ opcodes: nbAdded: 0 nbRemoved: 0 staticGas: G_ZERO + flag1: true - mnemonic: SELFDESTRUCT value: 0xff instructionFamily: HALT From 1615c7ea07e5fb1869c478d42ab0235fea7adf94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 1 Jun 2024 21:57:37 +0400 Subject: [PATCH 017/461] removed obsolete flags from instruction decoder removed: - oobFlag - addressTrimmingInstruction --- .../InstructionDecoder.java | 1 - .../src/main/resources/opcodes.yml | 19 ------------------- 2 files changed, 20 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java index 7e4da41263..90beaf04a8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java @@ -83,7 +83,6 @@ private static void traceStackSettings(OpCodeData op, Trace trace) { .staticGas(Bytes.ofUnsignedInt(op.stackSettings().staticGas().cost())) .twoLineInstruction(op.stackSettings().twoLinesInstruction()) .staticFlag(op.stackSettings().forbiddenInStatic()) - .addressTrimmingInstruction(op.stackSettings().addressTrimmingInstruction()) .flag1(op.stackSettings().flag1()) .flag2(op.stackSettings().flag2()) .flag3(op.stackSettings().flag3()) diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml index 48459ac5be..5a6796c75e 100644 --- a/arithmetization/src/main/resources/opcodes.yml +++ b/arithmetization/src/main/resources/opcodes.yml @@ -301,7 +301,6 @@ opcodes: nbAdded: 1 nbRemoved: 1 staticGas: S_HUB - addressTrimmingInstruction: true flag1: true - mnemonic: ORIGIN value: 0x32 @@ -345,7 +344,6 @@ opcodes: nbAdded: 1 nbRemoved: 1 staticGas: G_VERY_LOW - oobFlag: true flag1: true - mnemonic: CALLDATASIZE value: 0x36 @@ -420,7 +418,6 @@ opcodes: nbAdded: 1 nbRemoved: 1 staticGas: S_HUB - addressTrimmingInstruction: true flag2: true - mnemonic: EXTCODECOPY value: 0x3c @@ -432,7 +429,6 @@ opcodes: nbAdded: 0 nbRemoved: 4 staticGas: S_MXP - addressTrimmingInstruction: true flag4: true billing: byWord: @@ -457,7 +453,6 @@ opcodes: delta: 3 nbAdded: 0 nbRemoved: 3 - oobFlag: true staticGas: S_MXP flag2: true billing: @@ -474,7 +469,6 @@ opcodes: nbAdded: 1 nbRemoved: 1 staticGas: S_HUB - addressTrimmingInstruction: true flag3: true - mnemonic: BLOCKHASH value: 0x40 @@ -638,7 +632,6 @@ opcodes: delta: 2 nbAdded: 0 nbRemoved: 2 - oobFlag: true staticGas: S_HUB forbiddenInStatic: true flag1: true @@ -652,7 +645,6 @@ opcodes: nbAdded: 0 nbRemoved: 1 staticGas: G_MID - oobFlag: true flag1: true - mnemonic: JUMPI value: 0x57 @@ -664,7 +656,6 @@ opcodes: nbAdded: 0 nbRemoved: 2 staticGas: G_MID - oobFlag: true flag2: true - mnemonic: PC value: 0x58 @@ -1511,7 +1502,6 @@ opcodes: delta: 3 nbAdded: 1 nbRemoved: 3 - oobFlag: true staticGas: G_CREATE twoLinesInstruction: true forbiddenInStatic: true @@ -1528,11 +1518,9 @@ opcodes: delta: 7 nbAdded: 1 nbRemoved: 7 - oobFlag: true staticGas: S_CALL twoLinesInstruction: true forbiddenInStatic: true - addressTrimmingInstruction: true flag1: true billing: byMxp: @@ -1546,10 +1534,8 @@ opcodes: delta: 7 nbAdded: 1 nbRemoved: 7 - oobFlag: true staticGas: S_CALL twoLinesInstruction: true - addressTrimmingInstruction: true flag2: true billing: byMxp: @@ -1563,7 +1549,6 @@ opcodes: delta: 2 nbAdded: 0 nbRemoved: 2 - oobFlag: true staticGas: S_MXP flag1: true billing: @@ -1581,7 +1566,6 @@ opcodes: nbRemoved: 6 staticGas: S_CALL twoLinesInstruction: true - addressTrimmingInstruction: true flag3: true billing: byMxp: @@ -1595,7 +1579,6 @@ opcodes: delta: 4 nbAdded: 1 nbRemoved: 4 - oobFlag: true staticGas: G_CREATE twoLinesInstruction: true forbiddenInStatic: true @@ -1615,7 +1598,6 @@ opcodes: nbRemoved: 6 staticGas: S_CALL twoLinesInstruction: true - addressTrimmingInstruction: true flag4: true billing: byMxp: @@ -1656,5 +1638,4 @@ opcodes: nbRemoved: 1 staticGas: S_MXP forbiddenInStatic: true - addressTrimmingInstruction: true flag4: true From 218e3ba11659e5e2a8e508f7246b880b24cc7ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 1 Jun 2024 22:25:09 +0400 Subject: [PATCH 018/461] works again --- .../linea/zktracer/module/hub/Trace.java | 63 +- .../module/hub/fragment/AccountFragment.java | 2 +- .../fragment/scenario/ScenarioFragment.java | 4 +- .../InstructionDecoder.java | 82 +- .../tables/instructionDecoder/Trace.java | 1491 ++++------------- 5 files changed, 354 insertions(+), 1288 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 6af8e288f2..1fc62bee6e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -164,8 +164,8 @@ public class Trace { private final MappedByteBuffer prcModexpXorMxpFlag; private final MappedByteBuffer prcRipemd160XorOogx; private final MappedByteBuffer prcSha2256XorOpcx; - private final MappedByteBuffer prcSuccessWillRevertXorPushpopFlag; - private final MappedByteBuffer prcSuccessWontRevertXorRdcx; + private final MappedByteBuffer prcSuccessCallerWillRevertXorPushpopFlag; + private final MappedByteBuffer prcSuccessCallerWontRevertXorRdcx; private final MappedByteBuffer priorityFeePerGas; private final MappedByteBuffer programCounter; private final MappedByteBuffer programCounterNew; @@ -193,7 +193,7 @@ public class Trace { private final MappedByteBuffer rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4; private final MappedByteBuffer rlpaddrSaltHiXorMxpGasMxp; private final MappedByteBuffer rlpaddrSaltLoXorMxpOffset1Hi; - private final MappedByteBuffer romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag; + private final MappedByteBuffer romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag; private final MappedByteBuffer selfdestructExceptionXorStackItemPop4; private final MappedByteBuffer selfdestructWillRevertXorStaticx; private final MappedByteBuffer selfdestructWontRevertAlreadyMarkedXorStaticFlag; @@ -418,8 +418,8 @@ static List headers(int length) { new ColumnHeader("hub.PRC_MODEXP_xor_MXP_FLAG", 1, length), new ColumnHeader("hub.PRC_RIPEMD-160_xor_OOGX", 1, length), new ColumnHeader("hub.PRC_SHA2-256_xor_OPCX", 1, length), - new ColumnHeader("hub.PRC_SUCCESS_WILL_REVERT_xor_PUSHPOP_FLAG", 1, length), - new ColumnHeader("hub.PRC_SUCCESS_WONT_REVERT_xor_RDCX", 1, length), + new ColumnHeader("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG", 1, length), + new ColumnHeader("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX", 1, length), new ColumnHeader("hub.PRIORITY_FEE_PER_GAS", 32, length), new ColumnHeader("hub.PROGRAM_COUNTER", 8, length), new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 8, length), @@ -459,7 +459,7 @@ static List headers(int length) { new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), new ColumnHeader( - "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", + "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), @@ -646,8 +646,8 @@ public Trace(List buffers) { this.prcModexpXorMxpFlag = buffers.get(105); this.prcRipemd160XorOogx = buffers.get(106); this.prcSha2256XorOpcx = buffers.get(107); - this.prcSuccessWillRevertXorPushpopFlag = buffers.get(108); - this.prcSuccessWontRevertXorRdcx = buffers.get(109); + this.prcSuccessCallerWillRevertXorPushpopFlag = buffers.get(108); + this.prcSuccessCallerWontRevertXorRdcx = buffers.get(109); this.priorityFeePerGas = buffers.get(110); this.programCounter = buffers.get(111); this.programCounterNew = buffers.get(112); @@ -675,7 +675,7 @@ public Trace(List buffers) { this.rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4 = buffers.get(134); this.rlpaddrSaltHiXorMxpGasMxp = buffers.get(135); this.rlpaddrSaltLoXorMxpOffset1Hi = buffers.get(136); - this.romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag = buffers.get(137); + this.romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag = buffers.get(137); this.selfdestructExceptionXorStackItemPop4 = buffers.get(138); this.selfdestructWillRevertXorStaticx = buffers.get(139); this.selfdestructWontRevertAlreadyMarkedXorStaticFlag = buffers.get(140); @@ -1601,14 +1601,14 @@ public Trace pAccountRlpaddrSaltLo(final Bytes b) { return this; } - public Trace pAccountRomLexFlag(final Boolean b) { + public Trace pAccountRomlexFlag(final Boolean b) { if (filled.get(65)) { - throw new IllegalStateException("hub.account/ROM_LEX_FLAG already set"); + throw new IllegalStateException("hub.account/ROMLEX_FLAG already set"); } else { filled.set(65); } - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -2893,7 +2893,7 @@ public Trace pMiscStpWarmth(final Boolean b) { filled.set(65); } - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3068,7 +3068,7 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { filled.set(65); } - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -3396,26 +3396,26 @@ public Trace pScenarioPrcSha2256(final Boolean b) { return this; } - public Trace pScenarioPrcSuccessWillRevert(final Boolean b) { + public Trace pScenarioPrcSuccessCallerWillRevert(final Boolean b) { if (filled.get(85)) { - throw new IllegalStateException("hub.scenario/PRC_SUCCESS_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(85); } - prcSuccessWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); + prcSuccessCallerWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioPrcSuccessWontRevert(final Boolean b) { + public Trace pScenarioPrcSuccessCallerWontRevert(final Boolean b) { if (filled.get(86)) { - throw new IllegalStateException("hub.scenario/PRC_SUCCESS_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(86); } - prcSuccessWontRevertXorRdcx.put((byte) (b ? 1 : 0)); + prcSuccessCallerWontRevertXorRdcx.put((byte) (b ? 1 : 0)); return this; } @@ -3745,7 +3745,7 @@ public Trace pStackDupFlag(final Boolean b) { filled.set(65); } - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4097,7 +4097,7 @@ public Trace pStackPushpopFlag(final Boolean b) { filled.set(85); } - prcSuccessWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); + prcSuccessCallerWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4109,7 +4109,7 @@ public Trace pStackRdcx(final Boolean b) { filled.set(86); } - prcSuccessWontRevertXorRdcx.put((byte) (b ? 1 : 0)); + prcSuccessCallerWontRevertXorRdcx.put((byte) (b ? 1 : 0)); return this; } @@ -5961,11 +5961,12 @@ public Trace validateRow() { if (!filled.get(85)) { throw new IllegalStateException( - "hub.PRC_SUCCESS_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); + "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(86)) { - throw new IllegalStateException("hub.PRC_SUCCESS_WONT_REVERT_xor_RDCX has not been filled"); + throw new IllegalStateException( + "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); } if (!filled.get(129)) { @@ -6093,7 +6094,7 @@ public Trace validateRow() { if (!filled.get(65)) { throw new IllegalStateException( - "hub.ROM_LEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } if (!filled.get(94)) { @@ -6793,12 +6794,12 @@ public Trace fillAndValidateRow() { } if (!filled.get(85)) { - prcSuccessWillRevertXorPushpopFlag.position( - prcSuccessWillRevertXorPushpopFlag.position() + 1); + prcSuccessCallerWillRevertXorPushpopFlag.position( + prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); } if (!filled.get(86)) { - prcSuccessWontRevertXorRdcx.position(prcSuccessWontRevertXorRdcx.position() + 1); + prcSuccessCallerWontRevertXorRdcx.position(prcSuccessCallerWontRevertXorRdcx.position() + 1); } if (!filled.get(129)) { @@ -6922,8 +6923,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(65)) { - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( - romLexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } if (!filled.get(94)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java index 17ed7b7974..5cccf966b6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java @@ -111,7 +111,7 @@ public Trace trace(Trace trace) { .pAccountHasCode(oldState.code().getCodeHash() != Hash.EMPTY) .pAccountHasCodeNew(newState.code().getCodeHash() != Hash.EMPTY) .pAccountCodeFragmentIndex(this.codeFragmentIndex) - .pAccountRomLexFlag(false) // TODO + .pAccountRomlexFlag(false) // TODO .pAccountExists( oldState.nonce() > 0 || oldState.code().getCodeHash() != Hash.EMPTY diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 03631e044f..4c1b7ee6be 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -319,9 +319,9 @@ && targetIsPrecompile() precompileCall.map(x -> x.precompile().equals(Precompile.EC_PAIRING)).orElse(false)) .pScenarioPrcBlake2F( precompileCall.map(x -> x.precompile().equals(Precompile.BLAKE2F)).orElse(false)) - .pScenarioPrcSuccessWillRevert( + .pScenarioPrcSuccessCallerWillRevert( type.isPrecompile() && successfulPrecompileCall() && callerReverts) - .pScenarioPrcSuccessWontRevert( + .pScenarioPrcSuccessCallerWontRevert( type.isPrecompile() && successfulPrecompileCall() && !callerReverts) .pScenarioPrcFailureKnownToHub( precompileCall.map(PrecompileInvocation::hubFailure).orElse(false)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java index 90beaf04a8..13ff4401b2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java @@ -1,32 +1,28 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.tables.instructionDecoder; +package net.consensys.linea.zktracer.module.tables.instructionDecoder; /* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ import java.nio.MappedByteBuffer; import java.util.List; import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.opcode.DataLocation; import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; import net.consensys.linea.zktracer.opcode.gas.BillingRate; import net.consensys.linea.zktracer.opcode.gas.MxpType; -import net.consensys.linea.zktracer.opcode.stack.Pattern; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; @@ -62,25 +58,11 @@ private static void traceFamily(OpCodeData op, Trace trace) { private static void traceStackSettings(OpCodeData op, Trace trace) { trace - .patternZeroZero(op.stackSettings().pattern() == Pattern.ZERO_ZERO) - .patternOneZero(op.stackSettings().pattern() == Pattern.ONE_ZERO) - .patternTwoZero(op.stackSettings().pattern() == Pattern.TWO_ZERO) - .patternZeroOne(op.stackSettings().pattern() == Pattern.ZERO_ONE) - .patternOneOne(op.stackSettings().pattern() == Pattern.ONE_ONE) - .patternTwoOne(op.stackSettings().pattern() == Pattern.TWO_ONE) - .patternThreeOne(op.stackSettings().pattern() == Pattern.THREE_ONE) - .patternLoadStore(op.stackSettings().pattern() == Pattern.LOAD_STORE) - .patternDup(op.stackSettings().pattern() == Pattern.DUP) - .patternSwap(op.stackSettings().pattern() == Pattern.SWAP) - .patternLog(op.stackSettings().pattern() == Pattern.LOG) - .patternCopy(op.stackSettings().pattern() == Pattern.COPY) - .patternCall(op.stackSettings().pattern() == Pattern.CALL) - .patternCreate(op.stackSettings().pattern() == Pattern.CREATE) .alpha(UnsignedByte.of(op.stackSettings().alpha())) .delta(UnsignedByte.of(op.stackSettings().delta())) .nbAdded(UnsignedByte.of(op.stackSettings().nbAdded())) .nbRemoved(UnsignedByte.of(op.stackSettings().nbRemoved())) - .staticGas(Bytes.ofUnsignedInt(op.stackSettings().staticGas().cost())) + .staticGas(op.stackSettings().staticGas().cost()) .twoLineInstruction(op.stackSettings().twoLinesInstruction()) .staticFlag(op.stackSettings().forbiddenInStatic()) .flag1(op.stackSettings().flag1()) @@ -89,44 +71,15 @@ private static void traceStackSettings(OpCodeData op, Trace trace) { .flag4(op.stackSettings().flag4()); } - private static void traceRamSettings(OpCodeData op, Trace trace) { - trace - .ramEnabled(op.ramSettings().enabled()) - // Source - .ramSourceRom(op.ramSettings().source() == DataLocation.ROM) - .ramSourceRam(op.ramSettings().source() == DataLocation.RAM) - .ramSourceTxnData(op.ramSettings().source() == DataLocation.TXN_CALL_DATA) - .ramSourceStack(op.ramSettings().source() == DataLocation.STACK) - .ramSourceEcData(op.ramSettings().source() == DataLocation.EC_DATA) - .ramSourceEcInfo(op.ramSettings().source() == DataLocation.EC_INFO) - .ramSourceModexpData(op.ramSettings().source() == DataLocation.MOD_EXP_DATA) - .ramSourceHashData(op.ramSettings().source() == DataLocation.HASH_DATA) - .ramSourceHashInfo(op.ramSettings().source() == DataLocation.HASH_INFO) - .ramSourceBlakeData(op.ramSettings().source() == DataLocation.BLAKE_DATA) - .ramSourceLogData(op.ramSettings().source() == DataLocation.LOG_DATA) - // Target - .ramTargetRom(op.ramSettings().target() == DataLocation.ROM) - .ramTargetRam(op.ramSettings().target() == DataLocation.RAM) - .ramTargetTxnData(op.ramSettings().target() == DataLocation.TXN_CALL_DATA) - .ramTargetStack(op.ramSettings().target() == DataLocation.STACK) - .ramTargetEcData(op.ramSettings().target() == DataLocation.EC_DATA) - .ramTargetEcInfo(op.ramSettings().target() == DataLocation.EC_INFO) - .ramTargetModexpData(op.ramSettings().target() == DataLocation.MOD_EXP_DATA) - .ramTargetHashData(op.ramSettings().target() == DataLocation.HASH_DATA) - .ramTargetHashInfo(op.ramSettings().target() == DataLocation.HASH_INFO) - .ramTargetBlakeData(op.ramSettings().target() == DataLocation.BLAKE_DATA) - .ramTargetLogData(op.ramSettings().target() == DataLocation.LOG_DATA); - } - private static void traceBillingSettings(OpCodeData op, Trace trace) { trace .billingPerWord( - Bytes.ofUnsignedInt( + UnsignedByte.of( op.billing().billingRate() == BillingRate.BY_WORD ? op.billing().perUnit().cost() : 0)) .billingPerByte( - Bytes.ofUnsignedInt( + UnsignedByte.of( op.billing().billingRate() == BillingRate.BY_BYTE ? op.billing().perUnit().cost() : 0)) @@ -168,7 +121,6 @@ public void commit(List buffers) { traceFamily(op, trace); traceStackSettings(op, trace); - traceRamSettings(op, trace); traceBillingSettings(op, trace); trace .opcode(Bytes.ofUnsignedInt(i)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/Trace.java index 8278bd8d66..5e947f56c0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/Trace.java @@ -34,7 +34,6 @@ public class Trace { private final BitSet filled = new BitSet(); private int currentLine = 0; - private final MappedByteBuffer addressTrimmingInstruction; private final MappedByteBuffer alpha; private final MappedByteBuffer billingPerByte; private final MappedByteBuffer billingPerWord; @@ -79,53 +78,15 @@ public class Trace { private final MappedByteBuffer nbAdded; private final MappedByteBuffer nbRemoved; private final MappedByteBuffer opcode; - private final MappedByteBuffer patternCall; - private final MappedByteBuffer patternCopy; - private final MappedByteBuffer patternCreate; - private final MappedByteBuffer patternDup; - private final MappedByteBuffer patternLoadStore; - private final MappedByteBuffer patternLog; - private final MappedByteBuffer patternOneOne; - private final MappedByteBuffer patternOneZero; - private final MappedByteBuffer patternSwap; - private final MappedByteBuffer patternThreeOne; - private final MappedByteBuffer patternTwoOne; - private final MappedByteBuffer patternTwoZero; - private final MappedByteBuffer patternZeroOne; - private final MappedByteBuffer patternZeroZero; - private final MappedByteBuffer ramEnabled; - private final MappedByteBuffer ramSourceBlakeData; - private final MappedByteBuffer ramSourceEcData; - private final MappedByteBuffer ramSourceEcInfo; - private final MappedByteBuffer ramSourceHashData; - private final MappedByteBuffer ramSourceHashInfo; - private final MappedByteBuffer ramSourceLogData; - private final MappedByteBuffer ramSourceModexpData; - private final MappedByteBuffer ramSourceRam; - private final MappedByteBuffer ramSourceRom; - private final MappedByteBuffer ramSourceStack; - private final MappedByteBuffer ramSourceTxnData; - private final MappedByteBuffer ramTargetBlakeData; - private final MappedByteBuffer ramTargetEcData; - private final MappedByteBuffer ramTargetEcInfo; - private final MappedByteBuffer ramTargetHashData; - private final MappedByteBuffer ramTargetHashInfo; - private final MappedByteBuffer ramTargetLogData; - private final MappedByteBuffer ramTargetModexpData; - private final MappedByteBuffer ramTargetRam; - private final MappedByteBuffer ramTargetRom; - private final MappedByteBuffer ramTargetStack; - private final MappedByteBuffer ramTargetTxnData; private final MappedByteBuffer staticFlag; private final MappedByteBuffer staticGas; private final MappedByteBuffer twoLineInstruction; static List headers(int length) { return List.of( - new ColumnHeader("instdecoder.ADDRESS_TRIMMING_INSTRUCTION", 1, length), new ColumnHeader("instdecoder.ALPHA", 1, length), - new ColumnHeader("instdecoder.BILLING_PER_BYTE", 32, length), - new ColumnHeader("instdecoder.BILLING_PER_WORD", 32, length), + new ColumnHeader("instdecoder.BILLING_PER_BYTE", 1, length), + new ColumnHeader("instdecoder.BILLING_PER_WORD", 1, length), new ColumnHeader("instdecoder.DELTA", 1, length), new ColumnHeader("instdecoder.FAMILY_ACCOUNT", 1, length), new ColumnHeader("instdecoder.FAMILY_ADD", 1, length), @@ -167,134 +128,59 @@ static List headers(int length) { new ColumnHeader("instdecoder.NB_ADDED", 1, length), new ColumnHeader("instdecoder.NB_REMOVED", 1, length), new ColumnHeader("instdecoder.OPCODE", 32, length), - new ColumnHeader("instdecoder.PATTERN_CALL", 1, length), - new ColumnHeader("instdecoder.PATTERN_COPY", 1, length), - new ColumnHeader("instdecoder.PATTERN_CREATE", 1, length), - new ColumnHeader("instdecoder.PATTERN_DUP", 1, length), - new ColumnHeader("instdecoder.PATTERN_LOAD_STORE", 1, length), - new ColumnHeader("instdecoder.PATTERN_LOG", 1, length), - new ColumnHeader("instdecoder.PATTERN_ONE_ONE", 1, length), - new ColumnHeader("instdecoder.PATTERN_ONE_ZERO", 1, length), - new ColumnHeader("instdecoder.PATTERN_SWAP", 1, length), - new ColumnHeader("instdecoder.PATTERN_THREE_ONE", 1, length), - new ColumnHeader("instdecoder.PATTERN_TWO_ONE", 1, length), - new ColumnHeader("instdecoder.PATTERN_TWO_ZERO", 1, length), - new ColumnHeader("instdecoder.PATTERN_ZERO_ONE", 1, length), - new ColumnHeader("instdecoder.PATTERN_ZERO_ZERO", 1, length), - new ColumnHeader("instdecoder.RAM_ENABLED", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_BLAKE_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_EC_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_EC_INFO", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_HASH_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_HASH_INFO", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_LOG_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_MODEXP_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_RAM", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_ROM", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_STACK", 1, length), - new ColumnHeader("instdecoder.RAM_SOURCE_TXN_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_BLAKE_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_EC_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_EC_INFO", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_HASH_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_HASH_INFO", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_LOG_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_MODEXP_DATA", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_RAM", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_ROM", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_STACK", 1, length), - new ColumnHeader("instdecoder.RAM_TARGET_TXN_DATA", 1, length), new ColumnHeader("instdecoder.STATIC_FLAG", 1, length), - new ColumnHeader("instdecoder.STATIC_GAS", 32, length), + new ColumnHeader("instdecoder.STATIC_GAS", 8, length), new ColumnHeader("instdecoder.TWO_LINE_INSTRUCTION", 1, length)); } public Trace(List buffers) { - this.addressTrimmingInstruction = buffers.get(0); - this.alpha = buffers.get(1); - this.billingPerByte = buffers.get(2); - this.billingPerWord = buffers.get(3); - this.delta = buffers.get(4); - this.familyAccount = buffers.get(5); - this.familyAdd = buffers.get(6); - this.familyBatch = buffers.get(7); - this.familyBin = buffers.get(8); - this.familyCall = buffers.get(9); - this.familyContext = buffers.get(10); - this.familyCopy = buffers.get(11); - this.familyCreate = buffers.get(12); - this.familyDup = buffers.get(13); - this.familyExt = buffers.get(14); - this.familyHalt = buffers.get(15); - this.familyInvalid = buffers.get(16); - this.familyJump = buffers.get(17); - this.familyKec = buffers.get(18); - this.familyLog = buffers.get(19); - this.familyMachineState = buffers.get(20); - this.familyMod = buffers.get(21); - this.familyMul = buffers.get(22); - this.familyPushPop = buffers.get(23); - this.familyShf = buffers.get(24); - this.familyStackRam = buffers.get(25); - this.familyStorage = buffers.get(26); - this.familySwap = buffers.get(27); - this.familyTransaction = buffers.get(28); - this.familyWcp = buffers.get(29); - this.flag1 = buffers.get(30); - this.flag2 = buffers.get(31); - this.flag3 = buffers.get(32); - this.flag4 = buffers.get(33); - this.isJumpdest = buffers.get(34); - this.isPush = buffers.get(35); - this.mxpFlag = buffers.get(36); - this.mxpType1 = buffers.get(37); - this.mxpType2 = buffers.get(38); - this.mxpType3 = buffers.get(39); - this.mxpType4 = buffers.get(40); - this.mxpType5 = buffers.get(41); - this.nbAdded = buffers.get(42); - this.nbRemoved = buffers.get(43); - this.opcode = buffers.get(44); - this.patternCall = buffers.get(45); - this.patternCopy = buffers.get(46); - this.patternCreate = buffers.get(47); - this.patternDup = buffers.get(48); - this.patternLoadStore = buffers.get(49); - this.patternLog = buffers.get(50); - this.patternOneOne = buffers.get(51); - this.patternOneZero = buffers.get(52); - this.patternSwap = buffers.get(53); - this.patternThreeOne = buffers.get(54); - this.patternTwoOne = buffers.get(55); - this.patternTwoZero = buffers.get(56); - this.patternZeroOne = buffers.get(57); - this.patternZeroZero = buffers.get(58); - this.ramEnabled = buffers.get(59); - this.ramSourceBlakeData = buffers.get(60); - this.ramSourceEcData = buffers.get(61); - this.ramSourceEcInfo = buffers.get(62); - this.ramSourceHashData = buffers.get(63); - this.ramSourceHashInfo = buffers.get(64); - this.ramSourceLogData = buffers.get(65); - this.ramSourceModexpData = buffers.get(66); - this.ramSourceRam = buffers.get(67); - this.ramSourceRom = buffers.get(68); - this.ramSourceStack = buffers.get(69); - this.ramSourceTxnData = buffers.get(70); - this.ramTargetBlakeData = buffers.get(71); - this.ramTargetEcData = buffers.get(72); - this.ramTargetEcInfo = buffers.get(73); - this.ramTargetHashData = buffers.get(74); - this.ramTargetHashInfo = buffers.get(75); - this.ramTargetLogData = buffers.get(76); - this.ramTargetModexpData = buffers.get(77); - this.ramTargetRam = buffers.get(78); - this.ramTargetRom = buffers.get(79); - this.ramTargetStack = buffers.get(80); - this.ramTargetTxnData = buffers.get(81); - this.staticFlag = buffers.get(82); - this.staticGas = buffers.get(83); - this.twoLineInstruction = buffers.get(84); + this.alpha = buffers.get(0); + this.billingPerByte = buffers.get(1); + this.billingPerWord = buffers.get(2); + this.delta = buffers.get(3); + this.familyAccount = buffers.get(4); + this.familyAdd = buffers.get(5); + this.familyBatch = buffers.get(6); + this.familyBin = buffers.get(7); + this.familyCall = buffers.get(8); + this.familyContext = buffers.get(9); + this.familyCopy = buffers.get(10); + this.familyCreate = buffers.get(11); + this.familyDup = buffers.get(12); + this.familyExt = buffers.get(13); + this.familyHalt = buffers.get(14); + this.familyInvalid = buffers.get(15); + this.familyJump = buffers.get(16); + this.familyKec = buffers.get(17); + this.familyLog = buffers.get(18); + this.familyMachineState = buffers.get(19); + this.familyMod = buffers.get(20); + this.familyMul = buffers.get(21); + this.familyPushPop = buffers.get(22); + this.familyShf = buffers.get(23); + this.familyStackRam = buffers.get(24); + this.familyStorage = buffers.get(25); + this.familySwap = buffers.get(26); + this.familyTransaction = buffers.get(27); + this.familyWcp = buffers.get(28); + this.flag1 = buffers.get(29); + this.flag2 = buffers.get(30); + this.flag3 = buffers.get(31); + this.flag4 = buffers.get(32); + this.isJumpdest = buffers.get(33); + this.isPush = buffers.get(34); + this.mxpFlag = buffers.get(35); + this.mxpType1 = buffers.get(36); + this.mxpType2 = buffers.get(37); + this.mxpType3 = buffers.get(38); + this.mxpType4 = buffers.get(39); + this.mxpType5 = buffers.get(40); + this.nbAdded = buffers.get(41); + this.nbRemoved = buffers.get(42); + this.opcode = buffers.get(43); + this.staticFlag = buffers.get(44); + this.staticGas = buffers.get(45); + this.twoLineInstruction = buffers.get(46); } public int size() { @@ -305,67 +191,47 @@ public int size() { return this.currentLine; } - public Trace addressTrimmingInstruction(final Boolean b) { + public Trace alpha(final UnsignedByte b) { if (filled.get(0)) { - throw new IllegalStateException("instdecoder.ADDRESS_TRIMMING_INSTRUCTION already set"); + throw new IllegalStateException("instdecoder.ALPHA already set"); } else { filled.set(0); } - addressTrimmingInstruction.put((byte) (b ? 1 : 0)); + alpha.put(b.toByte()); return this; } - public Trace alpha(final UnsignedByte b) { + public Trace billingPerByte(final UnsignedByte b) { if (filled.get(1)) { - throw new IllegalStateException("instdecoder.ALPHA already set"); + throw new IllegalStateException("instdecoder.BILLING_PER_BYTE already set"); } else { filled.set(1); } - alpha.put(b.toByte()); + billingPerByte.put(b.toByte()); return this; } - public Trace billingPerByte(final Bytes b) { + public Trace billingPerWord(final UnsignedByte b) { if (filled.get(2)) { - throw new IllegalStateException("instdecoder.BILLING_PER_BYTE already set"); - } else { - filled.set(2); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - billingPerByte.put((byte) 0); - } - billingPerByte.put(b.toArrayUnsafe()); - - return this; - } - - public Trace billingPerWord(final Bytes b) { - if (filled.get(3)) { throw new IllegalStateException("instdecoder.BILLING_PER_WORD already set"); } else { - filled.set(3); + filled.set(2); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - billingPerWord.put((byte) 0); - } - billingPerWord.put(b.toArrayUnsafe()); + billingPerWord.put(b.toByte()); return this; } public Trace delta(final UnsignedByte b) { - if (filled.get(4)) { + if (filled.get(3)) { throw new IllegalStateException("instdecoder.DELTA already set"); } else { - filled.set(4); + filled.set(3); } delta.put(b.toByte()); @@ -374,10 +240,10 @@ public Trace delta(final UnsignedByte b) { } public Trace familyAccount(final Boolean b) { - if (filled.get(5)) { + if (filled.get(4)) { throw new IllegalStateException("instdecoder.FAMILY_ACCOUNT already set"); } else { - filled.set(5); + filled.set(4); } familyAccount.put((byte) (b ? 1 : 0)); @@ -386,10 +252,10 @@ public Trace familyAccount(final Boolean b) { } public Trace familyAdd(final Boolean b) { - if (filled.get(6)) { + if (filled.get(5)) { throw new IllegalStateException("instdecoder.FAMILY_ADD already set"); } else { - filled.set(6); + filled.set(5); } familyAdd.put((byte) (b ? 1 : 0)); @@ -398,10 +264,10 @@ public Trace familyAdd(final Boolean b) { } public Trace familyBatch(final Boolean b) { - if (filled.get(7)) { + if (filled.get(6)) { throw new IllegalStateException("instdecoder.FAMILY_BATCH already set"); } else { - filled.set(7); + filled.set(6); } familyBatch.put((byte) (b ? 1 : 0)); @@ -410,10 +276,10 @@ public Trace familyBatch(final Boolean b) { } public Trace familyBin(final Boolean b) { - if (filled.get(8)) { + if (filled.get(7)) { throw new IllegalStateException("instdecoder.FAMILY_BIN already set"); } else { - filled.set(8); + filled.set(7); } familyBin.put((byte) (b ? 1 : 0)); @@ -422,10 +288,10 @@ public Trace familyBin(final Boolean b) { } public Trace familyCall(final Boolean b) { - if (filled.get(9)) { + if (filled.get(8)) { throw new IllegalStateException("instdecoder.FAMILY_CALL already set"); } else { - filled.set(9); + filled.set(8); } familyCall.put((byte) (b ? 1 : 0)); @@ -434,10 +300,10 @@ public Trace familyCall(final Boolean b) { } public Trace familyContext(final Boolean b) { - if (filled.get(10)) { + if (filled.get(9)) { throw new IllegalStateException("instdecoder.FAMILY_CONTEXT already set"); } else { - filled.set(10); + filled.set(9); } familyContext.put((byte) (b ? 1 : 0)); @@ -446,10 +312,10 @@ public Trace familyContext(final Boolean b) { } public Trace familyCopy(final Boolean b) { - if (filled.get(11)) { + if (filled.get(10)) { throw new IllegalStateException("instdecoder.FAMILY_COPY already set"); } else { - filled.set(11); + filled.set(10); } familyCopy.put((byte) (b ? 1 : 0)); @@ -458,10 +324,10 @@ public Trace familyCopy(final Boolean b) { } public Trace familyCreate(final Boolean b) { - if (filled.get(12)) { + if (filled.get(11)) { throw new IllegalStateException("instdecoder.FAMILY_CREATE already set"); } else { - filled.set(12); + filled.set(11); } familyCreate.put((byte) (b ? 1 : 0)); @@ -470,10 +336,10 @@ public Trace familyCreate(final Boolean b) { } public Trace familyDup(final Boolean b) { - if (filled.get(13)) { + if (filled.get(12)) { throw new IllegalStateException("instdecoder.FAMILY_DUP already set"); } else { - filled.set(13); + filled.set(12); } familyDup.put((byte) (b ? 1 : 0)); @@ -482,10 +348,10 @@ public Trace familyDup(final Boolean b) { } public Trace familyExt(final Boolean b) { - if (filled.get(14)) { + if (filled.get(13)) { throw new IllegalStateException("instdecoder.FAMILY_EXT already set"); } else { - filled.set(14); + filled.set(13); } familyExt.put((byte) (b ? 1 : 0)); @@ -494,10 +360,10 @@ public Trace familyExt(final Boolean b) { } public Trace familyHalt(final Boolean b) { - if (filled.get(15)) { + if (filled.get(14)) { throw new IllegalStateException("instdecoder.FAMILY_HALT already set"); } else { - filled.set(15); + filled.set(14); } familyHalt.put((byte) (b ? 1 : 0)); @@ -506,10 +372,10 @@ public Trace familyHalt(final Boolean b) { } public Trace familyInvalid(final Boolean b) { - if (filled.get(16)) { + if (filled.get(15)) { throw new IllegalStateException("instdecoder.FAMILY_INVALID already set"); } else { - filled.set(16); + filled.set(15); } familyInvalid.put((byte) (b ? 1 : 0)); @@ -518,10 +384,10 @@ public Trace familyInvalid(final Boolean b) { } public Trace familyJump(final Boolean b) { - if (filled.get(17)) { + if (filled.get(16)) { throw new IllegalStateException("instdecoder.FAMILY_JUMP already set"); } else { - filled.set(17); + filled.set(16); } familyJump.put((byte) (b ? 1 : 0)); @@ -530,10 +396,10 @@ public Trace familyJump(final Boolean b) { } public Trace familyKec(final Boolean b) { - if (filled.get(18)) { + if (filled.get(17)) { throw new IllegalStateException("instdecoder.FAMILY_KEC already set"); } else { - filled.set(18); + filled.set(17); } familyKec.put((byte) (b ? 1 : 0)); @@ -542,10 +408,10 @@ public Trace familyKec(final Boolean b) { } public Trace familyLog(final Boolean b) { - if (filled.get(19)) { + if (filled.get(18)) { throw new IllegalStateException("instdecoder.FAMILY_LOG already set"); } else { - filled.set(19); + filled.set(18); } familyLog.put((byte) (b ? 1 : 0)); @@ -554,10 +420,10 @@ public Trace familyLog(final Boolean b) { } public Trace familyMachineState(final Boolean b) { - if (filled.get(20)) { + if (filled.get(19)) { throw new IllegalStateException("instdecoder.FAMILY_MACHINE_STATE already set"); } else { - filled.set(20); + filled.set(19); } familyMachineState.put((byte) (b ? 1 : 0)); @@ -566,10 +432,10 @@ public Trace familyMachineState(final Boolean b) { } public Trace familyMod(final Boolean b) { - if (filled.get(21)) { + if (filled.get(20)) { throw new IllegalStateException("instdecoder.FAMILY_MOD already set"); } else { - filled.set(21); + filled.set(20); } familyMod.put((byte) (b ? 1 : 0)); @@ -578,10 +444,10 @@ public Trace familyMod(final Boolean b) { } public Trace familyMul(final Boolean b) { - if (filled.get(22)) { + if (filled.get(21)) { throw new IllegalStateException("instdecoder.FAMILY_MUL already set"); } else { - filled.set(22); + filled.set(21); } familyMul.put((byte) (b ? 1 : 0)); @@ -590,10 +456,10 @@ public Trace familyMul(final Boolean b) { } public Trace familyPushPop(final Boolean b) { - if (filled.get(23)) { + if (filled.get(22)) { throw new IllegalStateException("instdecoder.FAMILY_PUSH_POP already set"); } else { - filled.set(23); + filled.set(22); } familyPushPop.put((byte) (b ? 1 : 0)); @@ -602,10 +468,10 @@ public Trace familyPushPop(final Boolean b) { } public Trace familyShf(final Boolean b) { - if (filled.get(24)) { + if (filled.get(23)) { throw new IllegalStateException("instdecoder.FAMILY_SHF already set"); } else { - filled.set(24); + filled.set(23); } familyShf.put((byte) (b ? 1 : 0)); @@ -614,10 +480,10 @@ public Trace familyShf(final Boolean b) { } public Trace familyStackRam(final Boolean b) { - if (filled.get(25)) { + if (filled.get(24)) { throw new IllegalStateException("instdecoder.FAMILY_STACK_RAM already set"); } else { - filled.set(25); + filled.set(24); } familyStackRam.put((byte) (b ? 1 : 0)); @@ -626,10 +492,10 @@ public Trace familyStackRam(final Boolean b) { } public Trace familyStorage(final Boolean b) { - if (filled.get(26)) { + if (filled.get(25)) { throw new IllegalStateException("instdecoder.FAMILY_STORAGE already set"); } else { - filled.set(26); + filled.set(25); } familyStorage.put((byte) (b ? 1 : 0)); @@ -638,10 +504,10 @@ public Trace familyStorage(final Boolean b) { } public Trace familySwap(final Boolean b) { - if (filled.get(27)) { + if (filled.get(26)) { throw new IllegalStateException("instdecoder.FAMILY_SWAP already set"); } else { - filled.set(27); + filled.set(26); } familySwap.put((byte) (b ? 1 : 0)); @@ -650,10 +516,10 @@ public Trace familySwap(final Boolean b) { } public Trace familyTransaction(final Boolean b) { - if (filled.get(28)) { + if (filled.get(27)) { throw new IllegalStateException("instdecoder.FAMILY_TRANSACTION already set"); } else { - filled.set(28); + filled.set(27); } familyTransaction.put((byte) (b ? 1 : 0)); @@ -662,10 +528,10 @@ public Trace familyTransaction(final Boolean b) { } public Trace familyWcp(final Boolean b) { - if (filled.get(29)) { + if (filled.get(28)) { throw new IllegalStateException("instdecoder.FAMILY_WCP already set"); } else { - filled.set(29); + filled.set(28); } familyWcp.put((byte) (b ? 1 : 0)); @@ -674,10 +540,10 @@ public Trace familyWcp(final Boolean b) { } public Trace flag1(final Boolean b) { - if (filled.get(30)) { + if (filled.get(29)) { throw new IllegalStateException("instdecoder.FLAG_1 already set"); } else { - filled.set(30); + filled.set(29); } flag1.put((byte) (b ? 1 : 0)); @@ -686,10 +552,10 @@ public Trace flag1(final Boolean b) { } public Trace flag2(final Boolean b) { - if (filled.get(31)) { + if (filled.get(30)) { throw new IllegalStateException("instdecoder.FLAG_2 already set"); } else { - filled.set(31); + filled.set(30); } flag2.put((byte) (b ? 1 : 0)); @@ -698,10 +564,10 @@ public Trace flag2(final Boolean b) { } public Trace flag3(final Boolean b) { - if (filled.get(32)) { + if (filled.get(31)) { throw new IllegalStateException("instdecoder.FLAG_3 already set"); } else { - filled.set(32); + filled.set(31); } flag3.put((byte) (b ? 1 : 0)); @@ -710,10 +576,10 @@ public Trace flag3(final Boolean b) { } public Trace flag4(final Boolean b) { - if (filled.get(33)) { + if (filled.get(32)) { throw new IllegalStateException("instdecoder.FLAG_4 already set"); } else { - filled.set(33); + filled.set(32); } flag4.put((byte) (b ? 1 : 0)); @@ -722,10 +588,10 @@ public Trace flag4(final Boolean b) { } public Trace isJumpdest(final Boolean b) { - if (filled.get(34)) { + if (filled.get(33)) { throw new IllegalStateException("instdecoder.IS_JUMPDEST already set"); } else { - filled.set(34); + filled.set(33); } isJumpdest.put((byte) (b ? 1 : 0)); @@ -734,10 +600,10 @@ public Trace isJumpdest(final Boolean b) { } public Trace isPush(final Boolean b) { - if (filled.get(35)) { + if (filled.get(34)) { throw new IllegalStateException("instdecoder.IS_PUSH already set"); } else { - filled.set(35); + filled.set(34); } isPush.put((byte) (b ? 1 : 0)); @@ -746,10 +612,10 @@ public Trace isPush(final Boolean b) { } public Trace mxpFlag(final Boolean b) { - if (filled.get(36)) { + if (filled.get(35)) { throw new IllegalStateException("instdecoder.MXP_FLAG already set"); } else { - filled.set(36); + filled.set(35); } mxpFlag.put((byte) (b ? 1 : 0)); @@ -758,10 +624,10 @@ public Trace mxpFlag(final Boolean b) { } public Trace mxpType1(final Boolean b) { - if (filled.get(37)) { + if (filled.get(36)) { throw new IllegalStateException("instdecoder.MXP_TYPE_1 already set"); } else { - filled.set(37); + filled.set(36); } mxpType1.put((byte) (b ? 1 : 0)); @@ -770,10 +636,10 @@ public Trace mxpType1(final Boolean b) { } public Trace mxpType2(final Boolean b) { - if (filled.get(38)) { + if (filled.get(37)) { throw new IllegalStateException("instdecoder.MXP_TYPE_2 already set"); } else { - filled.set(38); + filled.set(37); } mxpType2.put((byte) (b ? 1 : 0)); @@ -782,10 +648,10 @@ public Trace mxpType2(final Boolean b) { } public Trace mxpType3(final Boolean b) { - if (filled.get(39)) { + if (filled.get(38)) { throw new IllegalStateException("instdecoder.MXP_TYPE_3 already set"); } else { - filled.set(39); + filled.set(38); } mxpType3.put((byte) (b ? 1 : 0)); @@ -794,10 +660,10 @@ public Trace mxpType3(final Boolean b) { } public Trace mxpType4(final Boolean b) { - if (filled.get(40)) { + if (filled.get(39)) { throw new IllegalStateException("instdecoder.MXP_TYPE_4 already set"); } else { - filled.set(40); + filled.set(39); } mxpType4.put((byte) (b ? 1 : 0)); @@ -806,10 +672,10 @@ public Trace mxpType4(final Boolean b) { } public Trace mxpType5(final Boolean b) { - if (filled.get(41)) { + if (filled.get(40)) { throw new IllegalStateException("instdecoder.MXP_TYPE_5 already set"); } else { - filled.set(41); + filled.set(40); } mxpType5.put((byte) (b ? 1 : 0)); @@ -818,10 +684,10 @@ public Trace mxpType5(final Boolean b) { } public Trace nbAdded(final UnsignedByte b) { - if (filled.get(42)) { + if (filled.get(41)) { throw new IllegalStateException("instdecoder.NB_ADDED already set"); } else { - filled.set(42); + filled.set(41); } nbAdded.put(b.toByte()); @@ -830,10 +696,10 @@ public Trace nbAdded(final UnsignedByte b) { } public Trace nbRemoved(final UnsignedByte b) { - if (filled.get(43)) { + if (filled.get(42)) { throw new IllegalStateException("instdecoder.NB_REMOVED already set"); } else { - filled.set(43); + filled.set(42); } nbRemoved.put(b.toByte()); @@ -842,10 +708,10 @@ public Trace nbRemoved(final UnsignedByte b) { } public Trace opcode(final Bytes b) { - if (filled.get(44)) { + if (filled.get(43)) { throw new IllegalStateException("instdecoder.OPCODE already set"); } else { - filled.set(44); + filled.set(43); } final byte[] bs = b.toArrayUnsafe(); @@ -857,829 +723,228 @@ public Trace opcode(final Bytes b) { return this; } - public Trace patternCall(final Boolean b) { - if (filled.get(45)) { - throw new IllegalStateException("instdecoder.PATTERN_CALL already set"); + public Trace staticFlag(final Boolean b) { + if (filled.get(44)) { + throw new IllegalStateException("instdecoder.STATIC_FLAG already set"); } else { - filled.set(45); + filled.set(44); } - patternCall.put((byte) (b ? 1 : 0)); + staticFlag.put((byte) (b ? 1 : 0)); return this; } - public Trace patternCopy(final Boolean b) { - if (filled.get(46)) { - throw new IllegalStateException("instdecoder.PATTERN_COPY already set"); + public Trace staticGas(final long b) { + if (filled.get(45)) { + throw new IllegalStateException("instdecoder.STATIC_GAS already set"); } else { - filled.set(46); + filled.set(45); } - patternCopy.put((byte) (b ? 1 : 0)); + staticGas.putLong(b); return this; } - public Trace patternCreate(final Boolean b) { - if (filled.get(47)) { - throw new IllegalStateException("instdecoder.PATTERN_CREATE already set"); + public Trace twoLineInstruction(final Boolean b) { + if (filled.get(46)) { + throw new IllegalStateException("instdecoder.TWO_LINE_INSTRUCTION already set"); } else { - filled.set(47); + filled.set(46); } - patternCreate.put((byte) (b ? 1 : 0)); + twoLineInstruction.put((byte) (b ? 1 : 0)); return this; } - public Trace patternDup(final Boolean b) { - if (filled.get(48)) { - throw new IllegalStateException("instdecoder.PATTERN_DUP already set"); - } else { - filled.set(48); + public Trace validateRow() { + if (!filled.get(0)) { + throw new IllegalStateException("instdecoder.ALPHA has not been filled"); } - patternDup.put((byte) (b ? 1 : 0)); - - return this; - } + if (!filled.get(1)) { + throw new IllegalStateException("instdecoder.BILLING_PER_BYTE has not been filled"); + } - public Trace patternLoadStore(final Boolean b) { - if (filled.get(49)) { - throw new IllegalStateException("instdecoder.PATTERN_LOAD_STORE already set"); - } else { - filled.set(49); + if (!filled.get(2)) { + throw new IllegalStateException("instdecoder.BILLING_PER_WORD has not been filled"); } - patternLoadStore.put((byte) (b ? 1 : 0)); + if (!filled.get(3)) { + throw new IllegalStateException("instdecoder.DELTA has not been filled"); + } - return this; - } + if (!filled.get(4)) { + throw new IllegalStateException("instdecoder.FAMILY_ACCOUNT has not been filled"); + } - public Trace patternLog(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("instdecoder.PATTERN_LOG already set"); - } else { - filled.set(50); + if (!filled.get(5)) { + throw new IllegalStateException("instdecoder.FAMILY_ADD has not been filled"); } - patternLog.put((byte) (b ? 1 : 0)); + if (!filled.get(6)) { + throw new IllegalStateException("instdecoder.FAMILY_BATCH has not been filled"); + } - return this; - } + if (!filled.get(7)) { + throw new IllegalStateException("instdecoder.FAMILY_BIN has not been filled"); + } - public Trace patternOneOne(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("instdecoder.PATTERN_ONE_ONE already set"); - } else { - filled.set(51); + if (!filled.get(8)) { + throw new IllegalStateException("instdecoder.FAMILY_CALL has not been filled"); } - patternOneOne.put((byte) (b ? 1 : 0)); + if (!filled.get(9)) { + throw new IllegalStateException("instdecoder.FAMILY_CONTEXT has not been filled"); + } - return this; - } + if (!filled.get(10)) { + throw new IllegalStateException("instdecoder.FAMILY_COPY has not been filled"); + } - public Trace patternOneZero(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException("instdecoder.PATTERN_ONE_ZERO already set"); - } else { - filled.set(52); + if (!filled.get(11)) { + throw new IllegalStateException("instdecoder.FAMILY_CREATE has not been filled"); } - patternOneZero.put((byte) (b ? 1 : 0)); + if (!filled.get(12)) { + throw new IllegalStateException("instdecoder.FAMILY_DUP has not been filled"); + } - return this; - } - - public Trace patternSwap(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("instdecoder.PATTERN_SWAP already set"); - } else { - filled.set(53); - } - - patternSwap.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternThreeOne(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException("instdecoder.PATTERN_THREE_ONE already set"); - } else { - filled.set(54); - } - - patternThreeOne.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternTwoOne(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException("instdecoder.PATTERN_TWO_ONE already set"); - } else { - filled.set(55); - } - - patternTwoOne.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternTwoZero(final Boolean b) { - if (filled.get(56)) { - throw new IllegalStateException("instdecoder.PATTERN_TWO_ZERO already set"); - } else { - filled.set(56); - } - - patternTwoZero.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternZeroOne(final Boolean b) { - if (filled.get(57)) { - throw new IllegalStateException("instdecoder.PATTERN_ZERO_ONE already set"); - } else { - filled.set(57); - } - - patternZeroOne.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace patternZeroZero(final Boolean b) { - if (filled.get(58)) { - throw new IllegalStateException("instdecoder.PATTERN_ZERO_ZERO already set"); - } else { - filled.set(58); - } - - patternZeroZero.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramEnabled(final Boolean b) { - if (filled.get(59)) { - throw new IllegalStateException("instdecoder.RAM_ENABLED already set"); - } else { - filled.set(59); - } - - ramEnabled.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceBlakeData(final Boolean b) { - if (filled.get(60)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_BLAKE_DATA already set"); - } else { - filled.set(60); - } - - ramSourceBlakeData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceEcData(final Boolean b) { - if (filled.get(61)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_EC_DATA already set"); - } else { - filled.set(61); - } - - ramSourceEcData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceEcInfo(final Boolean b) { - if (filled.get(62)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_EC_INFO already set"); - } else { - filled.set(62); - } - - ramSourceEcInfo.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceHashData(final Boolean b) { - if (filled.get(63)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_HASH_DATA already set"); - } else { - filled.set(63); - } - - ramSourceHashData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceHashInfo(final Boolean b) { - if (filled.get(64)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_HASH_INFO already set"); - } else { - filled.set(64); - } - - ramSourceHashInfo.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceLogData(final Boolean b) { - if (filled.get(65)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_LOG_DATA already set"); - } else { - filled.set(65); - } - - ramSourceLogData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceModexpData(final Boolean b) { - if (filled.get(66)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_MODEXP_DATA already set"); - } else { - filled.set(66); - } - - ramSourceModexpData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceRam(final Boolean b) { - if (filled.get(67)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_RAM already set"); - } else { - filled.set(67); - } - - ramSourceRam.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceRom(final Boolean b) { - if (filled.get(68)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_ROM already set"); - } else { - filled.set(68); - } - - ramSourceRom.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceStack(final Boolean b) { - if (filled.get(69)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_STACK already set"); - } else { - filled.set(69); - } - - ramSourceStack.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramSourceTxnData(final Boolean b) { - if (filled.get(70)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_TXN_DATA already set"); - } else { - filled.set(70); - } - - ramSourceTxnData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetBlakeData(final Boolean b) { - if (filled.get(71)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_BLAKE_DATA already set"); - } else { - filled.set(71); - } - - ramTargetBlakeData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetEcData(final Boolean b) { - if (filled.get(72)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_EC_DATA already set"); - } else { - filled.set(72); - } - - ramTargetEcData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetEcInfo(final Boolean b) { - if (filled.get(73)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_EC_INFO already set"); - } else { - filled.set(73); - } - - ramTargetEcInfo.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetHashData(final Boolean b) { - if (filled.get(74)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_HASH_DATA already set"); - } else { - filled.set(74); - } - - ramTargetHashData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetHashInfo(final Boolean b) { - if (filled.get(75)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_HASH_INFO already set"); - } else { - filled.set(75); - } - - ramTargetHashInfo.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetLogData(final Boolean b) { - if (filled.get(76)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_LOG_DATA already set"); - } else { - filled.set(76); - } - - ramTargetLogData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetModexpData(final Boolean b) { - if (filled.get(77)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_MODEXP_DATA already set"); - } else { - filled.set(77); - } - - ramTargetModexpData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetRam(final Boolean b) { - if (filled.get(78)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_RAM already set"); - } else { - filled.set(78); - } - - ramTargetRam.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetRom(final Boolean b) { - if (filled.get(79)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_ROM already set"); - } else { - filled.set(79); - } - - ramTargetRom.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetStack(final Boolean b) { - if (filled.get(80)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_STACK already set"); - } else { - filled.set(80); - } - - ramTargetStack.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace ramTargetTxnData(final Boolean b) { - if (filled.get(81)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_TXN_DATA already set"); - } else { - filled.set(81); - } - - ramTargetTxnData.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace staticFlag(final Boolean b) { - if (filled.get(82)) { - throw new IllegalStateException("instdecoder.STATIC_FLAG already set"); - } else { - filled.set(82); - } - - staticFlag.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace staticGas(final Bytes b) { - if (filled.get(83)) { - throw new IllegalStateException("instdecoder.STATIC_GAS already set"); - } else { - filled.set(83); - } - - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - staticGas.put((byte) 0); - } - staticGas.put(b.toArrayUnsafe()); - - return this; - } - - public Trace twoLineInstruction(final Boolean b) { - if (filled.get(84)) { - throw new IllegalStateException("instdecoder.TWO_LINE_INSTRUCTION already set"); - } else { - filled.set(84); - } - - twoLineInstruction.put((byte) (b ? 1 : 0)); - - return this; - } - - public Trace validateRow() { - if (!filled.get(0)) { - throw new IllegalStateException( - "instdecoder.ADDRESS_TRIMMING_INSTRUCTION has not been filled"); - } - - if (!filled.get(1)) { - throw new IllegalStateException("instdecoder.ALPHA has not been filled"); - } - - if (!filled.get(2)) { - throw new IllegalStateException("instdecoder.BILLING_PER_BYTE has not been filled"); - } - - if (!filled.get(3)) { - throw new IllegalStateException("instdecoder.BILLING_PER_WORD has not been filled"); - } - - if (!filled.get(4)) { - throw new IllegalStateException("instdecoder.DELTA has not been filled"); - } - - if (!filled.get(5)) { - throw new IllegalStateException("instdecoder.FAMILY_ACCOUNT has not been filled"); - } - - if (!filled.get(6)) { - throw new IllegalStateException("instdecoder.FAMILY_ADD has not been filled"); - } - - if (!filled.get(7)) { - throw new IllegalStateException("instdecoder.FAMILY_BATCH has not been filled"); - } - - if (!filled.get(8)) { - throw new IllegalStateException("instdecoder.FAMILY_BIN has not been filled"); - } - - if (!filled.get(9)) { - throw new IllegalStateException("instdecoder.FAMILY_CALL has not been filled"); - } - - if (!filled.get(10)) { - throw new IllegalStateException("instdecoder.FAMILY_CONTEXT has not been filled"); - } - - if (!filled.get(11)) { - throw new IllegalStateException("instdecoder.FAMILY_COPY has not been filled"); - } - - if (!filled.get(12)) { - throw new IllegalStateException("instdecoder.FAMILY_CREATE has not been filled"); - } - - if (!filled.get(13)) { - throw new IllegalStateException("instdecoder.FAMILY_DUP has not been filled"); - } - - if (!filled.get(14)) { - throw new IllegalStateException("instdecoder.FAMILY_EXT has not been filled"); - } - - if (!filled.get(15)) { - throw new IllegalStateException("instdecoder.FAMILY_HALT has not been filled"); - } - - if (!filled.get(16)) { - throw new IllegalStateException("instdecoder.FAMILY_INVALID has not been filled"); - } - - if (!filled.get(17)) { - throw new IllegalStateException("instdecoder.FAMILY_JUMP has not been filled"); - } - - if (!filled.get(18)) { - throw new IllegalStateException("instdecoder.FAMILY_KEC has not been filled"); - } - - if (!filled.get(19)) { - throw new IllegalStateException("instdecoder.FAMILY_LOG has not been filled"); - } - - if (!filled.get(20)) { - throw new IllegalStateException("instdecoder.FAMILY_MACHINE_STATE has not been filled"); - } - - if (!filled.get(21)) { - throw new IllegalStateException("instdecoder.FAMILY_MOD has not been filled"); - } - - if (!filled.get(22)) { - throw new IllegalStateException("instdecoder.FAMILY_MUL has not been filled"); - } - - if (!filled.get(23)) { - throw new IllegalStateException("instdecoder.FAMILY_PUSH_POP has not been filled"); - } - - if (!filled.get(24)) { - throw new IllegalStateException("instdecoder.FAMILY_SHF has not been filled"); - } - - if (!filled.get(25)) { - throw new IllegalStateException("instdecoder.FAMILY_STACK_RAM has not been filled"); - } - - if (!filled.get(26)) { - throw new IllegalStateException("instdecoder.FAMILY_STORAGE has not been filled"); - } - - if (!filled.get(27)) { - throw new IllegalStateException("instdecoder.FAMILY_SWAP has not been filled"); - } - - if (!filled.get(28)) { - throw new IllegalStateException("instdecoder.FAMILY_TRANSACTION has not been filled"); - } - - if (!filled.get(29)) { - throw new IllegalStateException("instdecoder.FAMILY_WCP has not been filled"); - } - - if (!filled.get(30)) { - throw new IllegalStateException("instdecoder.FLAG_1 has not been filled"); - } - - if (!filled.get(31)) { - throw new IllegalStateException("instdecoder.FLAG_2 has not been filled"); - } - - if (!filled.get(32)) { - throw new IllegalStateException("instdecoder.FLAG_3 has not been filled"); - } - - if (!filled.get(33)) { - throw new IllegalStateException("instdecoder.FLAG_4 has not been filled"); - } - - if (!filled.get(34)) { - throw new IllegalStateException("instdecoder.IS_JUMPDEST has not been filled"); - } - - if (!filled.get(35)) { - throw new IllegalStateException("instdecoder.IS_PUSH has not been filled"); - } - - if (!filled.get(36)) { - throw new IllegalStateException("instdecoder.MXP_FLAG has not been filled"); - } - - if (!filled.get(37)) { - throw new IllegalStateException("instdecoder.MXP_TYPE_1 has not been filled"); - } - - if (!filled.get(38)) { - throw new IllegalStateException("instdecoder.MXP_TYPE_2 has not been filled"); - } - - if (!filled.get(39)) { - throw new IllegalStateException("instdecoder.MXP_TYPE_3 has not been filled"); - } - - if (!filled.get(40)) { - throw new IllegalStateException("instdecoder.MXP_TYPE_4 has not been filled"); - } - - if (!filled.get(41)) { - throw new IllegalStateException("instdecoder.MXP_TYPE_5 has not been filled"); - } - - if (!filled.get(42)) { - throw new IllegalStateException("instdecoder.NB_ADDED has not been filled"); - } - - if (!filled.get(43)) { - throw new IllegalStateException("instdecoder.NB_REMOVED has not been filled"); - } - - if (!filled.get(44)) { - throw new IllegalStateException("instdecoder.OPCODE has not been filled"); - } - - if (!filled.get(45)) { - throw new IllegalStateException("instdecoder.PATTERN_CALL has not been filled"); - } - - if (!filled.get(46)) { - throw new IllegalStateException("instdecoder.PATTERN_COPY has not been filled"); - } - - if (!filled.get(47)) { - throw new IllegalStateException("instdecoder.PATTERN_CREATE has not been filled"); - } - - if (!filled.get(48)) { - throw new IllegalStateException("instdecoder.PATTERN_DUP has not been filled"); - } - - if (!filled.get(49)) { - throw new IllegalStateException("instdecoder.PATTERN_LOAD_STORE has not been filled"); - } - - if (!filled.get(50)) { - throw new IllegalStateException("instdecoder.PATTERN_LOG has not been filled"); - } - - if (!filled.get(51)) { - throw new IllegalStateException("instdecoder.PATTERN_ONE_ONE has not been filled"); + if (!filled.get(13)) { + throw new IllegalStateException("instdecoder.FAMILY_EXT has not been filled"); } - if (!filled.get(52)) { - throw new IllegalStateException("instdecoder.PATTERN_ONE_ZERO has not been filled"); + if (!filled.get(14)) { + throw new IllegalStateException("instdecoder.FAMILY_HALT has not been filled"); } - if (!filled.get(53)) { - throw new IllegalStateException("instdecoder.PATTERN_SWAP has not been filled"); + if (!filled.get(15)) { + throw new IllegalStateException("instdecoder.FAMILY_INVALID has not been filled"); } - if (!filled.get(54)) { - throw new IllegalStateException("instdecoder.PATTERN_THREE_ONE has not been filled"); + if (!filled.get(16)) { + throw new IllegalStateException("instdecoder.FAMILY_JUMP has not been filled"); } - if (!filled.get(55)) { - throw new IllegalStateException("instdecoder.PATTERN_TWO_ONE has not been filled"); + if (!filled.get(17)) { + throw new IllegalStateException("instdecoder.FAMILY_KEC has not been filled"); } - if (!filled.get(56)) { - throw new IllegalStateException("instdecoder.PATTERN_TWO_ZERO has not been filled"); + if (!filled.get(18)) { + throw new IllegalStateException("instdecoder.FAMILY_LOG has not been filled"); } - if (!filled.get(57)) { - throw new IllegalStateException("instdecoder.PATTERN_ZERO_ONE has not been filled"); + if (!filled.get(19)) { + throw new IllegalStateException("instdecoder.FAMILY_MACHINE_STATE has not been filled"); } - if (!filled.get(58)) { - throw new IllegalStateException("instdecoder.PATTERN_ZERO_ZERO has not been filled"); + if (!filled.get(20)) { + throw new IllegalStateException("instdecoder.FAMILY_MOD has not been filled"); } - if (!filled.get(59)) { - throw new IllegalStateException("instdecoder.RAM_ENABLED has not been filled"); + if (!filled.get(21)) { + throw new IllegalStateException("instdecoder.FAMILY_MUL has not been filled"); } - if (!filled.get(60)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_BLAKE_DATA has not been filled"); + if (!filled.get(22)) { + throw new IllegalStateException("instdecoder.FAMILY_PUSH_POP has not been filled"); } - if (!filled.get(61)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_EC_DATA has not been filled"); + if (!filled.get(23)) { + throw new IllegalStateException("instdecoder.FAMILY_SHF has not been filled"); } - if (!filled.get(62)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_EC_INFO has not been filled"); + if (!filled.get(24)) { + throw new IllegalStateException("instdecoder.FAMILY_STACK_RAM has not been filled"); } - if (!filled.get(63)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_HASH_DATA has not been filled"); + if (!filled.get(25)) { + throw new IllegalStateException("instdecoder.FAMILY_STORAGE has not been filled"); } - if (!filled.get(64)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_HASH_INFO has not been filled"); + if (!filled.get(26)) { + throw new IllegalStateException("instdecoder.FAMILY_SWAP has not been filled"); } - if (!filled.get(65)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_LOG_DATA has not been filled"); + if (!filled.get(27)) { + throw new IllegalStateException("instdecoder.FAMILY_TRANSACTION has not been filled"); } - if (!filled.get(66)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_MODEXP_DATA has not been filled"); + if (!filled.get(28)) { + throw new IllegalStateException("instdecoder.FAMILY_WCP has not been filled"); } - if (!filled.get(67)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_RAM has not been filled"); + if (!filled.get(29)) { + throw new IllegalStateException("instdecoder.FLAG_1 has not been filled"); } - if (!filled.get(68)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_ROM has not been filled"); + if (!filled.get(30)) { + throw new IllegalStateException("instdecoder.FLAG_2 has not been filled"); } - if (!filled.get(69)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_STACK has not been filled"); + if (!filled.get(31)) { + throw new IllegalStateException("instdecoder.FLAG_3 has not been filled"); } - if (!filled.get(70)) { - throw new IllegalStateException("instdecoder.RAM_SOURCE_TXN_DATA has not been filled"); + if (!filled.get(32)) { + throw new IllegalStateException("instdecoder.FLAG_4 has not been filled"); } - if (!filled.get(71)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_BLAKE_DATA has not been filled"); + if (!filled.get(33)) { + throw new IllegalStateException("instdecoder.IS_JUMPDEST has not been filled"); } - if (!filled.get(72)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_EC_DATA has not been filled"); + if (!filled.get(34)) { + throw new IllegalStateException("instdecoder.IS_PUSH has not been filled"); } - if (!filled.get(73)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_EC_INFO has not been filled"); + if (!filled.get(35)) { + throw new IllegalStateException("instdecoder.MXP_FLAG has not been filled"); } - if (!filled.get(74)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_HASH_DATA has not been filled"); + if (!filled.get(36)) { + throw new IllegalStateException("instdecoder.MXP_TYPE_1 has not been filled"); } - if (!filled.get(75)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_HASH_INFO has not been filled"); + if (!filled.get(37)) { + throw new IllegalStateException("instdecoder.MXP_TYPE_2 has not been filled"); } - if (!filled.get(76)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_LOG_DATA has not been filled"); + if (!filled.get(38)) { + throw new IllegalStateException("instdecoder.MXP_TYPE_3 has not been filled"); } - if (!filled.get(77)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_MODEXP_DATA has not been filled"); + if (!filled.get(39)) { + throw new IllegalStateException("instdecoder.MXP_TYPE_4 has not been filled"); } - if (!filled.get(78)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_RAM has not been filled"); + if (!filled.get(40)) { + throw new IllegalStateException("instdecoder.MXP_TYPE_5 has not been filled"); } - if (!filled.get(79)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_ROM has not been filled"); + if (!filled.get(41)) { + throw new IllegalStateException("instdecoder.NB_ADDED has not been filled"); } - if (!filled.get(80)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_STACK has not been filled"); + if (!filled.get(42)) { + throw new IllegalStateException("instdecoder.NB_REMOVED has not been filled"); } - if (!filled.get(81)) { - throw new IllegalStateException("instdecoder.RAM_TARGET_TXN_DATA has not been filled"); + if (!filled.get(43)) { + throw new IllegalStateException("instdecoder.OPCODE has not been filled"); } - if (!filled.get(82)) { + if (!filled.get(44)) { throw new IllegalStateException("instdecoder.STATIC_FLAG has not been filled"); } - if (!filled.get(83)) { + if (!filled.get(45)) { throw new IllegalStateException("instdecoder.STATIC_GAS has not been filled"); } - if (!filled.get(84)) { + if (!filled.get(46)) { throw new IllegalStateException("instdecoder.TWO_LINE_INSTRUCTION has not been filled"); } @@ -1691,342 +956,190 @@ public Trace validateRow() { public Trace fillAndValidateRow() { if (!filled.get(0)) { - addressTrimmingInstruction.position(addressTrimmingInstruction.position() + 1); + alpha.position(alpha.position() + 1); } if (!filled.get(1)) { - alpha.position(alpha.position() + 1); + billingPerByte.position(billingPerByte.position() + 1); } if (!filled.get(2)) { - billingPerByte.position(billingPerByte.position() + 32); + billingPerWord.position(billingPerWord.position() + 1); } if (!filled.get(3)) { - billingPerWord.position(billingPerWord.position() + 32); + delta.position(delta.position() + 1); } if (!filled.get(4)) { - delta.position(delta.position() + 1); + familyAccount.position(familyAccount.position() + 1); } if (!filled.get(5)) { - familyAccount.position(familyAccount.position() + 1); + familyAdd.position(familyAdd.position() + 1); } if (!filled.get(6)) { - familyAdd.position(familyAdd.position() + 1); + familyBatch.position(familyBatch.position() + 1); } if (!filled.get(7)) { - familyBatch.position(familyBatch.position() + 1); + familyBin.position(familyBin.position() + 1); } if (!filled.get(8)) { - familyBin.position(familyBin.position() + 1); + familyCall.position(familyCall.position() + 1); } if (!filled.get(9)) { - familyCall.position(familyCall.position() + 1); + familyContext.position(familyContext.position() + 1); } if (!filled.get(10)) { - familyContext.position(familyContext.position() + 1); + familyCopy.position(familyCopy.position() + 1); } if (!filled.get(11)) { - familyCopy.position(familyCopy.position() + 1); + familyCreate.position(familyCreate.position() + 1); } if (!filled.get(12)) { - familyCreate.position(familyCreate.position() + 1); + familyDup.position(familyDup.position() + 1); } if (!filled.get(13)) { - familyDup.position(familyDup.position() + 1); + familyExt.position(familyExt.position() + 1); } if (!filled.get(14)) { - familyExt.position(familyExt.position() + 1); + familyHalt.position(familyHalt.position() + 1); } if (!filled.get(15)) { - familyHalt.position(familyHalt.position() + 1); + familyInvalid.position(familyInvalid.position() + 1); } if (!filled.get(16)) { - familyInvalid.position(familyInvalid.position() + 1); + familyJump.position(familyJump.position() + 1); } if (!filled.get(17)) { - familyJump.position(familyJump.position() + 1); + familyKec.position(familyKec.position() + 1); } if (!filled.get(18)) { - familyKec.position(familyKec.position() + 1); + familyLog.position(familyLog.position() + 1); } if (!filled.get(19)) { - familyLog.position(familyLog.position() + 1); + familyMachineState.position(familyMachineState.position() + 1); } if (!filled.get(20)) { - familyMachineState.position(familyMachineState.position() + 1); + familyMod.position(familyMod.position() + 1); } if (!filled.get(21)) { - familyMod.position(familyMod.position() + 1); + familyMul.position(familyMul.position() + 1); } if (!filled.get(22)) { - familyMul.position(familyMul.position() + 1); + familyPushPop.position(familyPushPop.position() + 1); } if (!filled.get(23)) { - familyPushPop.position(familyPushPop.position() + 1); + familyShf.position(familyShf.position() + 1); } if (!filled.get(24)) { - familyShf.position(familyShf.position() + 1); + familyStackRam.position(familyStackRam.position() + 1); } if (!filled.get(25)) { - familyStackRam.position(familyStackRam.position() + 1); + familyStorage.position(familyStorage.position() + 1); } if (!filled.get(26)) { - familyStorage.position(familyStorage.position() + 1); + familySwap.position(familySwap.position() + 1); } if (!filled.get(27)) { - familySwap.position(familySwap.position() + 1); + familyTransaction.position(familyTransaction.position() + 1); } if (!filled.get(28)) { - familyTransaction.position(familyTransaction.position() + 1); + familyWcp.position(familyWcp.position() + 1); } if (!filled.get(29)) { - familyWcp.position(familyWcp.position() + 1); + flag1.position(flag1.position() + 1); } if (!filled.get(30)) { - flag1.position(flag1.position() + 1); + flag2.position(flag2.position() + 1); } if (!filled.get(31)) { - flag2.position(flag2.position() + 1); + flag3.position(flag3.position() + 1); } if (!filled.get(32)) { - flag3.position(flag3.position() + 1); + flag4.position(flag4.position() + 1); } if (!filled.get(33)) { - flag4.position(flag4.position() + 1); + isJumpdest.position(isJumpdest.position() + 1); } if (!filled.get(34)) { - isJumpdest.position(isJumpdest.position() + 1); + isPush.position(isPush.position() + 1); } if (!filled.get(35)) { - isPush.position(isPush.position() + 1); + mxpFlag.position(mxpFlag.position() + 1); } if (!filled.get(36)) { - mxpFlag.position(mxpFlag.position() + 1); + mxpType1.position(mxpType1.position() + 1); } if (!filled.get(37)) { - mxpType1.position(mxpType1.position() + 1); + mxpType2.position(mxpType2.position() + 1); } if (!filled.get(38)) { - mxpType2.position(mxpType2.position() + 1); + mxpType3.position(mxpType3.position() + 1); } if (!filled.get(39)) { - mxpType3.position(mxpType3.position() + 1); + mxpType4.position(mxpType4.position() + 1); } if (!filled.get(40)) { - mxpType4.position(mxpType4.position() + 1); + mxpType5.position(mxpType5.position() + 1); } if (!filled.get(41)) { - mxpType5.position(mxpType5.position() + 1); + nbAdded.position(nbAdded.position() + 1); } if (!filled.get(42)) { - nbAdded.position(nbAdded.position() + 1); + nbRemoved.position(nbRemoved.position() + 1); } if (!filled.get(43)) { - nbRemoved.position(nbRemoved.position() + 1); + opcode.position(opcode.position() + 32); } if (!filled.get(44)) { - opcode.position(opcode.position() + 32); + staticFlag.position(staticFlag.position() + 1); } if (!filled.get(45)) { - patternCall.position(patternCall.position() + 1); + staticGas.position(staticGas.position() + 8); } if (!filled.get(46)) { - patternCopy.position(patternCopy.position() + 1); - } - - if (!filled.get(47)) { - patternCreate.position(patternCreate.position() + 1); - } - - if (!filled.get(48)) { - patternDup.position(patternDup.position() + 1); - } - - if (!filled.get(49)) { - patternLoadStore.position(patternLoadStore.position() + 1); - } - - if (!filled.get(50)) { - patternLog.position(patternLog.position() + 1); - } - - if (!filled.get(51)) { - patternOneOne.position(patternOneOne.position() + 1); - } - - if (!filled.get(52)) { - patternOneZero.position(patternOneZero.position() + 1); - } - - if (!filled.get(53)) { - patternSwap.position(patternSwap.position() + 1); - } - - if (!filled.get(54)) { - patternThreeOne.position(patternThreeOne.position() + 1); - } - - if (!filled.get(55)) { - patternTwoOne.position(patternTwoOne.position() + 1); - } - - if (!filled.get(56)) { - patternTwoZero.position(patternTwoZero.position() + 1); - } - - if (!filled.get(57)) { - patternZeroOne.position(patternZeroOne.position() + 1); - } - - if (!filled.get(58)) { - patternZeroZero.position(patternZeroZero.position() + 1); - } - - if (!filled.get(59)) { - ramEnabled.position(ramEnabled.position() + 1); - } - - if (!filled.get(60)) { - ramSourceBlakeData.position(ramSourceBlakeData.position() + 1); - } - - if (!filled.get(61)) { - ramSourceEcData.position(ramSourceEcData.position() + 1); - } - - if (!filled.get(62)) { - ramSourceEcInfo.position(ramSourceEcInfo.position() + 1); - } - - if (!filled.get(63)) { - ramSourceHashData.position(ramSourceHashData.position() + 1); - } - - if (!filled.get(64)) { - ramSourceHashInfo.position(ramSourceHashInfo.position() + 1); - } - - if (!filled.get(65)) { - ramSourceLogData.position(ramSourceLogData.position() + 1); - } - - if (!filled.get(66)) { - ramSourceModexpData.position(ramSourceModexpData.position() + 1); - } - - if (!filled.get(67)) { - ramSourceRam.position(ramSourceRam.position() + 1); - } - - if (!filled.get(68)) { - ramSourceRom.position(ramSourceRom.position() + 1); - } - - if (!filled.get(69)) { - ramSourceStack.position(ramSourceStack.position() + 1); - } - - if (!filled.get(70)) { - ramSourceTxnData.position(ramSourceTxnData.position() + 1); - } - - if (!filled.get(71)) { - ramTargetBlakeData.position(ramTargetBlakeData.position() + 1); - } - - if (!filled.get(72)) { - ramTargetEcData.position(ramTargetEcData.position() + 1); - } - - if (!filled.get(73)) { - ramTargetEcInfo.position(ramTargetEcInfo.position() + 1); - } - - if (!filled.get(74)) { - ramTargetHashData.position(ramTargetHashData.position() + 1); - } - - if (!filled.get(75)) { - ramTargetHashInfo.position(ramTargetHashInfo.position() + 1); - } - - if (!filled.get(76)) { - ramTargetLogData.position(ramTargetLogData.position() + 1); - } - - if (!filled.get(77)) { - ramTargetModexpData.position(ramTargetModexpData.position() + 1); - } - - if (!filled.get(78)) { - ramTargetRam.position(ramTargetRam.position() + 1); - } - - if (!filled.get(79)) { - ramTargetRom.position(ramTargetRom.position() + 1); - } - - if (!filled.get(80)) { - ramTargetStack.position(ramTargetStack.position() + 1); - } - - if (!filled.get(81)) { - ramTargetTxnData.position(ramTargetTxnData.position() + 1); - } - - if (!filled.get(82)) { - staticFlag.position(staticFlag.position() + 1); - } - - if (!filled.get(83)) { - staticGas.position(staticGas.position() + 32); - } - - if (!filled.get(84)) { twoLineInstruction.position(twoLineInstruction.position() + 1); } From 3e5b58aaf485288c6754d6d48dd13dd30a88c777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 1 Jun 2024 23:41:22 +0400 Subject: [PATCH 019/461] imperfect fixes temporary implementations of - remainingGas() - expectedGas() Allow to fix the following constraints for the Java test "testSmallZeroAdd" - [x] hub.setting-GAS_NEXT - [x] hub.stateless-instruction---gas-cost - [x] hub.tx-finalization-success-justifying-txn-data-prediction --- .../consensys/linea/zktracer/module/hub/Hub.java | 14 +++++++++++++- .../module/hub/fragment/CommonFragment.java | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 63850d1a76..9931a16309 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1247,8 +1247,20 @@ public long accruedRefunds() { return this.state.currentTxTrace().refundCounter(); } + // TODO: how do these implementations of remainingGas() + // and expectedGas() behave with respect to resuming + // execution after a CALL / CREATE ? One of them is + // necessarily false ... public long remainingGas() { - return 0; // TODO: + return this.state().getProcessingPhase() == HubProcessingPhase.TX_EXEC + ? this.currentFrame().frame().getRemainingGas() + : 0; + } + + public long expectedGas() { + return this.state().getProcessingPhase() == HubProcessingPhase.TX_EXEC + ? this.currentFrame().frame().getRemainingGas() + : 0; } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index c7f8c808d9..3bb02c8ff1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -80,6 +80,12 @@ public static CommonFragment fromHub( final long refundDelta = noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).refund() : 0; + // TODO: partial solution, will not work in general + final long gasExpected = hub.expectedGas(); + final long gasActual = hub.remainingGas(); + final long gasCost = noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).staticGas() : 0; + final long gasNext = hub.pch().exceptions().any() ? 0 : gasActual - gasCost; + final int height = hub.currentFrame().stack().getHeight(); final int heightNew = (noStackException @@ -110,6 +116,10 @@ public static CommonFragment fromHub( .heightNew((short) heightNew) .codeDeploymentNumber(frame.codeDeploymentNumber()) .codeDeploymentStatus(frame.underDeployment()) + .gasExpected(gasExpected) + .gasActual(gasActual) + .gasCost(gasCost) + .gasNext(gasNext) .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) .refundDelta(refundDelta) .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) From 1f69d4b05b1ab41c3ce883e6b8f77e1c23ee909f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 01:29:52 +0400 Subject: [PATCH 020/461] uncommented CFI code in Common Fragment hub-into-rom-instruction-fetching now works --- .../linea/zktracer/module/hub/Hub.java | 8 +++--- .../module/hub/fragment/CommonFragment.java | 25 +++++++++++-------- .../hub/section/TxFinalizationSection.java | 17 +++++++++++++ .../zktracer/module/wcp/WcpOperation.java | 4 +-- 4 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 9931a16309..bb33890f06 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1253,14 +1253,14 @@ public long accruedRefunds() { // necessarily false ... public long remainingGas() { return this.state().getProcessingPhase() == HubProcessingPhase.TX_EXEC - ? this.currentFrame().frame().getRemainingGas() - : 0; + ? this.currentFrame().frame().getRemainingGas() + : 0; } public long expectedGas() { return this.state().getProcessingPhase() == HubProcessingPhase.TX_EXEC - ? this.currentFrame().frame().getRemainingGas() - : 0; + ? this.currentFrame().frame().getRemainingGas() + : 0; } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 3bb02c8ff1..9e90debfb1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -27,9 +27,11 @@ import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; +import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.types.HubProcessingPhase; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -83,7 +85,8 @@ public static CommonFragment fromHub( // TODO: partial solution, will not work in general final long gasExpected = hub.expectedGas(); final long gasActual = hub.remainingGas(); - final long gasCost = noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).staticGas() : 0; + final long gasCost = + noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).staticGas() : 0; final long gasNext = hub.pch().exceptions().any() ? 0 : gasActual - gasCost; final int height = hub.currentFrame().stack().getHeight(); @@ -173,16 +176,16 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final TransactionProcessingMetadata tx = hub.txStack().getByAbsoluteTransactionNumber(this.absoluteTransactionNumber); // TODO: after ROMLex merge - final int codeFragmentIndex = 0; - // frame.type() == CallFrameType.MANTLE - // ? 0 - // : this.hub - // .romLex() - // .getCfiByMetadata( - // ContractMetadata.make( - // frame.codeAddress(), - // frame.codeDeploymentNumber(), - // frame.underDeployment())); + final int codeFragmentIndex = + frame.type() == CallFrameType.MANTLE + ? 0 + : this.hub + .romLex() + .getCodeFragmentIndexByMetadata( + ContractMetadata.make( + frame.codeAddress(), + frame.codeDeploymentNumber(), + frame.underDeployment())); final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); final boolean willRevert = frame.willRevert(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java new file mode 100644 index 0000000000..e2700ea28c --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -0,0 +1,17 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section; +public class TxFinalizationSection { +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/WcpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/WcpOperation.java index 66339e7095..ceaba2fa16 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/WcpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/WcpOperation.java @@ -95,7 +95,7 @@ private void compute() { this.arg2Lo = arg2.slice(LLARGE + offset, length); // Calculate Result Low - resLo = calculateResLow(wcpInst, arg1, arg2); + resLo = calculateResult(wcpInst, arg1, arg2); // Set bit 3 and AdjHi final BigInteger firstHi = this.arg1.slice(0, LLARGE).toUnsignedBigInteger(); @@ -133,7 +133,7 @@ private void compute() { this.bit2 = this.arg1Lo.compareTo(this.arg2Lo) == 0; } - private boolean calculateResLow(byte opCode, Bytes32 arg1, Bytes32 arg2) { + private boolean calculateResult(byte opCode, Bytes32 arg1, Bytes32 arg2) { return switch (opCode) { case EQbv -> arg1.compareTo(arg2) == 0; case ISZERObv -> arg1.isZero(); From d4e7ac9b9382b80b4ff3fbce9e798028b59de9cc Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 11:10:33 +0530 Subject: [PATCH 021/461] fix: spotless + fix cfi in shared and account rows --- .../linea/zktracer/module/hub/Hub.java | 10 +++++-- .../module/hub/fragment/AccountFragment.java | 13 ++++---- .../module/hub/fragment/CommonFragment.java | 12 +++----- .../hub/section/TxFinalizationSection.java | 4 +-- .../InstructionDecoder.java | 30 ++++++++++--------- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index bb33890f06..99ca82541b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1235,11 +1235,15 @@ public void traceStartConflation(long blockCount) { } @Override - public void traceEndConflation(final WorldView state) { - this.defers.runPostConflation(this, state); + public void traceEndConflation(final WorldView world) { + this.romLex.traceEndConflation(world); + + this.defers.runPostConflation(this, world); for (Module m : this.modules) { - m.traceEndConflation(state); + if (!m.equals(this.romLex)) { + m.traceEndConflation(world); + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java index 5cccf966b6..f3a9019f65 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.defer.PostConflationDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; @@ -151,11 +152,11 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces public void runPostConflation(Hub hub, WorldView world) { this.deploymentNumberInfinity = hub.transients().conflation().deploymentInfo().number(this.who); this.existsInfinity = world.get(this.who) != null; - // this.codeFragmentIndex = - // this.requiresCodeFragmentIndex - // ? hub.romLex() - // .getCodeFragmentIndexByMetadata( - // ContractMetadata.make(this.who, this.deploymentNumber, this.isDeployment)) - // : 0; + this.codeFragmentIndex = + this.requiresCodeFragmentIndex + ? hub.romLex() + .getCodeFragmentIndexByMetadata( + ContractMetadata.make(this.who, this.deploymentNumber, this.isDeployment)) + : 0; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 9e90debfb1..42f7e43d66 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -31,7 +31,6 @@ import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.types.HubProcessingPhase; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -175,17 +174,14 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final CallFrame frame = this.hub.callStack().getById(this.callFrameId); final TransactionProcessingMetadata tx = hub.txStack().getByAbsoluteTransactionNumber(this.absoluteTransactionNumber); - // TODO: after ROMLex merge final int codeFragmentIndex = - frame.type() == CallFrameType.MANTLE - ? 0 - : this.hub + this.hubProcessingPhase == HubProcessingPhase.TX_EXEC + ? this.hub .romLex() .getCodeFragmentIndexByMetadata( ContractMetadata.make( - frame.codeAddress(), - frame.codeDeploymentNumber(), - frame.underDeployment())); + frame.codeAddress(), frame.codeDeploymentNumber(), frame.underDeployment())) + : 0; final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); final boolean willRevert = frame.willRevert(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index e2700ea28c..277c959975 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -13,5 +13,5 @@ * SPDX-License-Identifier: Apache-2.0 */ package net.consensys.linea.zktracer.module.hub.section; -public class TxFinalizationSection { -} + +public class TxFinalizationSection {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java index 13ff4401b2..ddefa6caf2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java @@ -1,17 +1,19 @@ -package net.consensys.linea.zktracer.module.tables.instructionDecoder; /* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.tables.instructionDecoder; import java.nio.MappedByteBuffer; import java.util.List; From c8a1470638b82ea519a5d0a6f87b5ed38716d075 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 11:36:24 +0530 Subject: [PATCH 022/461] fix: trimming to address in init phase --- .../linea/zktracer/module/hub/Hub.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 99ca82541b..f9568dee6b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -18,6 +18,11 @@ import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; +import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_EXEC; +import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_FINAL; +import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_INIT; +import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_SKIP; +import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_WARM; import java.nio.MappedByteBuffer; import java.util.ArrayList; @@ -421,7 +426,7 @@ public List getModulesToCount() { * @param world a view onto the state */ void processStateSkip(WorldView world) { - this.state.setProcessingPhase(HubProcessingPhase.TX_SKIP); + this.state.setProcessingPhase(TX_SKIP); this.state.stamps().incrementHubStamp(); final boolean isDeployment = this.txStack.current().getBesuTransaction().getTo().isEmpty(); @@ -478,7 +483,7 @@ void processStateSkip(WorldView world) { * @param world a view onto the state */ void processPrewarmingPhase(WorldView world) { - this.state.setProcessingPhase(HubProcessingPhase.TX_WARM); + this.state.setProcessingPhase(TX_WARM); this.txStack .current() .getBesuTransaction() @@ -565,7 +570,7 @@ void processPrewarmingPhase(WorldView world) { * @param world a view onto the state */ void processStateInit(WorldView world) { - this.state.setProcessingPhase(HubProcessingPhase.TX_INIT); + this.state.setProcessingPhase(TX_INIT); this.state.stamps().incrementHubStamp(); final TransactionProcessingMetadata tx = this.transients.tx(); final boolean isDeployment = tx.getBesuTransaction().getTo().isEmpty(); @@ -627,13 +632,13 @@ void processStateInit(WorldView world) { this, accountFragmentFactory.make(preInitFromSnapshot, postInitFromSnapshot), accountFragmentFactory - .make(preInitToSnapshot, postInitToSnapshot) + .makeWithTrm(preInitToSnapshot, postInitToSnapshot, toAddress) .requiresCodeFragmentIndex(true), ImcFragment.forTxInit(this), ContextFragment.initializeExecutionContext(this), txFragment)); - this.state.setProcessingPhase(HubProcessingPhase.TX_EXEC); + this.state.setProcessingPhase(TX_EXEC); } public CallFrame currentFrame() { @@ -785,7 +790,7 @@ void processStateExec(MessageFrame frame) { } void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { - this.state.setProcessingPhase(HubProcessingPhase.TX_FINAL); + this.state.setProcessingPhase(TX_FINAL); this.state.stamps().incrementHubStamp(); final Address fromAddress = this.transients.tx().getBesuTransaction().getSender(); @@ -920,7 +925,7 @@ public void traceEndTx( .completeLineaTransaction( isSuccessful, leftoverGas, this.accruedRefunds(), this.state.stamps().hub()); this.txStack.exitTransaction(this, isSuccessful); - if (this.state.processingPhase != HubProcessingPhase.TX_SKIP) { + if (this.state.processingPhase != TX_SKIP) { this.processStateFinal(world, tx, isSuccessful); } @@ -1122,14 +1127,14 @@ public void traceContextExit(MessageFrame frame) { @Override public void tracePreOpcode(final MessageFrame frame) { - if (this.state().processingPhase == HubProcessingPhase.TX_SKIP) { + if (this.state().processingPhase == TX_SKIP) { return; } this.processStateExec(frame); } public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { - if (this.state.processingPhase == HubProcessingPhase.TX_SKIP) { + if (this.state.processingPhase == TX_SKIP) { return; } @@ -1256,13 +1261,13 @@ public long accruedRefunds() { // execution after a CALL / CREATE ? One of them is // necessarily false ... public long remainingGas() { - return this.state().getProcessingPhase() == HubProcessingPhase.TX_EXEC + return this.state().getProcessingPhase() == TX_EXEC ? this.currentFrame().frame().getRemainingGas() : 0; } public long expectedGas() { - return this.state().getProcessingPhase() == HubProcessingPhase.TX_EXEC + return this.state().getProcessingPhase() == TX_EXEC ? this.currentFrame().frame().getRemainingGas() : 0; } From ea21d0003f5c192cbf2230be112f288785a5f7fb Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 12:14:11 +0530 Subject: [PATCH 023/461] fix(trm): must trimm effectiveTo Address --- .../linea/zktracer/module/Module.java | 3 ++ .../linea/zktracer/module/ext/Ext.java | 7 ---- .../linea/zktracer/module/hub/Hub.java | 3 +- .../linea/zktracer/module/mod/Mod.java | 7 ---- .../linea/zktracer/module/mul/Mul.java | 7 ---- .../zktracer/module/rlpaddr/RlpAddr.java | 5 ++- .../linea/zktracer/module/trm/Trm.java | 16 ++++---- .../zktracer/module/trm/TrmDataTest.java | 40 ------------------- 8 files changed, 15 insertions(+), 73 deletions(-) delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmDataTest.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java index 003002ed7b..126c3cb43b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java @@ -19,6 +19,7 @@ import java.util.List; import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -41,6 +42,8 @@ default void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockB default void traceStartTx(WorldView worldView, Transaction tx) {} + default void traceStartTx(TransactionProcessingMetadata transactionProcessingMetadata) {} + default void traceEndTx( WorldView worldView, Transaction tx, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Ext.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Ext.java index 6f8f3779c5..d5992b8b94 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Ext.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/Ext.java @@ -27,9 +27,7 @@ import net.consensys.linea.zktracer.opcode.OpCodeData; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor public class Ext implements Module { @@ -43,11 +41,6 @@ public String moduleKey() { return "EXT"; } - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - this.operations.enter(); - } - @Override public void enterTransaction() { this.operations.enter(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f9568dee6b..22e0199a5e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -897,8 +897,9 @@ public void traceStartTx(final WorldView world, final Transaction tx) { } for (Module m : this.modules) { - // TODO: should use a LineaTransaction as its argument + // TODO: should use only a LineaTransaction as its argument m.traceStartTx(world, tx); + m.traceStartTx(this.txStack().current()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Mod.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Mod.java index 7833df3ac8..bc8e8a2901 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Mod.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mod/Mod.java @@ -26,9 +26,7 @@ import net.consensys.linea.zktracer.opcode.OpCodeData; import net.consensys.linea.zktracer.opcode.OpCodes; import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; public class Mod implements Module { @Override @@ -57,11 +55,6 @@ public void popTransaction() { this.chunks.pop(); } - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - this.chunks.enter(); - } - @Override public void commit(List buffers) { final Trace trace = new Trace(buffers); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Mul.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Mul.java index 1efcb203cd..726f769340 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Mul.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mul/Mul.java @@ -25,9 +25,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor public class Mul implements Module { @@ -59,11 +57,6 @@ public void popTransaction() { this.operations.pop(); } - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - this.operations.enter(); - } - @Override public int lineCount() { return 1 + this.operations.lineCount(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java index b822269bab..cf189b3707 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java @@ -47,13 +47,13 @@ import net.consensys.linea.zktracer.module.trm.Trm; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.BitDecOutput; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor public class RlpAddr implements Module { @@ -81,7 +81,8 @@ public void popTransaction() { } @Override - public void traceStartTx(WorldView world, Transaction tx) { + public void traceStartTx(TransactionProcessingMetadata txMetaData) { + final Transaction tx = txMetaData.getBesuTransaction(); if (tx.getTo().isEmpty()) { final Address senderAddress = tx.getSender(); final long nonce = tx.getNonce(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java index 8b70b765a7..57af31effe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java @@ -17,7 +17,6 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.List; @@ -26,13 +25,13 @@ import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.AccessListEntry; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; public class Trm implements Module { static final int MAX_CT = LLARGE; @@ -74,7 +73,12 @@ public Address callTrimming(Bytes32 rawHash) { } @Override - public void traceStartTx(WorldView worldView, Transaction tx) { + public void traceStartTx(TransactionProcessingMetadata txMetaData) { + // Add effective receiver Address + this.trimmings.add(new TrmOperation(EWord.of(txMetaData.getEffectiveTo()))); + + // Add Address in AccessList to warm + final Transaction tx = txMetaData.getBesuTransaction(); final TransactionType txType = tx.getType(); switch (txType) { case ACCESS_LIST, EIP1559 -> { @@ -93,12 +97,6 @@ public void traceStartTx(WorldView worldView, Transaction tx) { } } - public static boolean isPrec(EWord data) { - BigInteger trmAddrParamAsBigInt = data.slice(12, 20).toUnsignedBigInteger(); - return (!trmAddrParamAsBigInt.equals(BigInteger.ZERO) - && (trmAddrParamAsBigInt.compareTo(BigInteger.TEN) < 0)); - } - @Override public List columnsHeaders() { return Trace.headers(this.lineCount()); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmDataTest.java deleted file mode 100644 index af922c08a5..0000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmDataTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package net.consensys.linea.zktracer.module.trm; - -import static net.consensys.linea.zktracer.module.trm.Trm.isPrec; -import static org.assertj.core.api.Assertions.assertThat; - -import net.consensys.linea.zktracer.types.EWord; -import org.hyperledger.besu.datatypes.Address; -import org.junit.jupiter.api.Test; - -public class TrmDataTest { - - @Test - public void isPrecompile() { - assertThat(isPrec(EWord.ZERO)).isFalse(); - assertThat(isPrec(EWord.ofHexString("0x1234"))).isFalse(); - // 0x06 - assertThat(isPrec(EWord.of(Address.ALTBN128_ADD))).isTrue(); - assertThat(isPrec(EWord.of(Address.MODEXP))).isTrue(); - // 0x09 - assertThat(isPrec(EWord.of(Address.BLAKE2B_F_COMPRESSION))).isTrue(); - // 0x01 - assertThat(isPrec(EWord.of(Address.ECREC))).isTrue(); - // 0x0A - assertThat(isPrec(EWord.of(Address.BLS12_G1ADD))).isFalse(); // only true for 1-9 - } -} From 116e155a6d46a34c4a4b491d5d33535fd890e80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 10:43:45 +0400 Subject: [PATCH 024/461] resolved hub.tx-initialization---first-row-of-next-context-initializing-some-variables Note: Besu's dataCost computation includes the transaction cost of 21000 --- .../linea/zktracer/types/TransactionProcessingMetadata.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 376d3d8ee8..42aac2f4b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -131,9 +131,9 @@ private BigInteger getInitialBalance(WorldView world) { } public long getUpfrontGasCost() { + // Note: Besu's dataCost computation contains the 21_000 transaction cost return dataCost + (isDeployment ? GAS_CONST_G_CREATE : 0) - + GAS_CONST_G_TRANSACTION + accessListCost; } From cf5a71d6dc9709b30d7b432edc38aed8470ee8ea Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 12:17:00 +0530 Subject: [PATCH 025/461] style: spotless --- .../linea/zktracer/types/TransactionProcessingMetadata.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 42aac2f4b9..a39fbd0508 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -132,9 +132,7 @@ private BigInteger getInitialBalance(WorldView world) { public long getUpfrontGasCost() { // Note: Besu's dataCost computation contains the 21_000 transaction cost - return dataCost - + (isDeployment ? GAS_CONST_G_CREATE : 0) - + accessListCost; + return dataCost + (isDeployment ? GAS_CONST_G_CREATE : 0) + accessListCost; } public long getInitiallyAvailableGas() { From 23c1b7fd0dc7f32f6d8c1368e891e518a70d8bd7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 13:01:22 +0530 Subject: [PATCH 026/461] fix(hub:finalization): use TrabsactionProcessingMetadata --- .../linea/zktracer/module/hub/Hub.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 22e0199a5e..c2e5541cb4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -789,11 +789,11 @@ void processStateExec(MessageFrame frame) { } } - void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { + void processStateFinal(WorldView worldView) { this.state.setProcessingPhase(TX_FINAL); this.state.stamps().incrementHubStamp(); - final Address fromAddress = this.transients.tx().getBesuTransaction().getSender(); + final Address fromAddress = this.txStack.current().getBesuTransaction().getSender(); final Account fromAccount = worldView.get(fromAddress); final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); final AccountSnapshot preFinalFromSnapshot = @@ -811,26 +811,28 @@ void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { deploymentInfo.number(fromAddress), deploymentInfo.isDeploying(fromAddress)); - Account minerAccount = worldView.get(this.transients.block().minerAddress()); - AccountSnapshot preFinalCoinbaseSnapshot = + final Address minerAddress = this.txStack.current().getCoinbase(); + final Account minerAccount = worldView.get(minerAddress); + + final AccountSnapshot preFinalCoinbaseSnapshot = AccountSnapshot.fromAccount( minerAccount, true, - deploymentInfo.number(this.transients.block().minerAddress()), - deploymentInfo.isDeploying(this.transients.block().minerAddress())); + deploymentInfo.number(minerAddress), + deploymentInfo.isDeploying(minerAddress)); // TODO: still not finished - AccountSnapshot postFinalCoinbaseSnapshot = + final AccountSnapshot postFinalCoinbaseSnapshot = AccountSnapshot.fromAccount( minerAccount, true, - deploymentInfo.number(this.transients.block().minerAddress()), - deploymentInfo.isDeploying(this.transients.block().minerAddress())); + deploymentInfo.number(minerAddress), + deploymentInfo.isDeploying(minerAddress)); final AccountFragment.AccountFragmentFactory accountFragmentFactory = this.factories.accountFragment(); - if (isSuccess) { + if (this.txStack.current().statusCode()) { // if no revert: 2 account rows (sender, coinbase) + 1 tx row this.addTraceSection( new EndTransactionSection( @@ -845,9 +847,9 @@ void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { // this.exceptions = Exceptions.fromOutOfGas(); // } // otherwise 4 account rows (sender, coinbase, sender, recipient) + 1 tx row - Address toAddress = this.transients.tx().getBesuTransaction().getSender(); - Account toAccount = worldView.get(toAddress); - AccountSnapshot preFinalToSnapshot = + final Address toAddress = this.transients.tx().getBesuTransaction().getSender(); + final Account toAccount = worldView.get(toAddress); + final AccountSnapshot preFinalToSnapshot = AccountSnapshot.fromAccount( toAccount, true, @@ -855,7 +857,7 @@ void processStateFinal(WorldView worldView, Transaction tx, boolean isSuccess) { deploymentInfo.isDeploying(toAddress)); // TODO: still not finished - AccountSnapshot postFinalToSnapshot = + final AccountSnapshot postFinalToSnapshot = AccountSnapshot.fromAccount( toAccount, true, @@ -926,8 +928,9 @@ public void traceEndTx( .completeLineaTransaction( isSuccessful, leftoverGas, this.accruedRefunds(), this.state.stamps().hub()); this.txStack.exitTransaction(this, isSuccessful); + if (this.state.processingPhase != TX_SKIP) { - this.processStateFinal(world, tx, isSuccessful); + this.processStateFinal(world); } this.defers.runPostTx(this, world, tx, isSuccessful); From db103590427800a80a21f003da4c5657de90375e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 13:17:47 +0530 Subject: [PATCH 027/461] test(bin): correct bin test --- .../linea/zktracer/module/bin/BinTest.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java index ab361a7195..fd457edb20 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java @@ -35,24 +35,16 @@ public void edgeCase() { void testSignedSignextend() { BytecodeRunner.of( BytecodeCompiler.newProgram() - .immediate(UInt256.MAX_VALUE) - .immediate(UInt256.MAX_VALUE) + .push(UInt256.MAX_VALUE) + .push(UInt256.MAX_VALUE) .op(OpCode.SIGNEXTEND) - .compile()) - .run(); - - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.valueOf(31)) - .immediate(UInt256.MAX_VALUE) + .op(OpCode.POP) + .push(UInt256.valueOf(31)) + .push(UInt256.MAX_VALUE) .op(OpCode.SIGNEXTEND) - .compile()) - .run(); - - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .immediate(UInt256.valueOf(32)) - .immediate(UInt256.MAX_VALUE) + .op(OpCode.POP) + .push(UInt256.valueOf(32)) + .push(UInt256.MAX_VALUE) .op(OpCode.SIGNEXTEND) .compile()) .run(); From 88b3d083e860ea08257323d75767e6c5d1282971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 11:42:15 +0400 Subject: [PATCH 028/461] CallFrame changes CallFrame now has - callerAddress and should get it from the transaction both in Bedrock and MantleAndBedrock methods. --- .../linea/zktracer/module/Pin55.java | 6 ++-- .../linea/zktracer/module/hub/Hub.java | 21 ++++++------ .../module/hub/fragment/CommonFragment.java | 4 ++- .../module/hub/fragment/ContextFragment.java | 6 ++-- .../fragment/imc/call/oob/opcodes/Jump.java | 3 +- .../hub/signals/AbortingConditions.java | 4 +-- .../zktracer/runtime/callstack/CallFrame.java | 33 +++++++++++-------- .../zktracer/runtime/callstack/CallStack.java | 19 +++++++---- 8 files changed, 55 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Pin55.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Pin55.java index 09ee30f2b4..ab57fb19eb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Pin55.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Pin55.java @@ -227,7 +227,7 @@ public void traceContextEnter(final MessageFrame frame) { hub.currentFrame().id(), hub.currentFrame().contextNumber(), hub.currentFrame().type(), - hub.currentFrame().codeAddress().toUnprefixedHexString()); + hub.currentFrame().byteCodeAddress().toUnprefixedHexString()); } public void traceContextReEnter(final MessageFrame frame) { @@ -239,7 +239,7 @@ public void traceContextReEnter(final MessageFrame frame) { hub.currentFrame().id(), hub.currentFrame().contextNumber(), hub.currentFrame().type(), - hub.currentFrame().codeAddress().toUnprefixedHexString()); + hub.currentFrame().byteCodeAddress().toUnprefixedHexString()); } public void traceContextExit(final MessageFrame frame) { @@ -251,7 +251,7 @@ public void traceContextExit(final MessageFrame frame) { hub.currentFrame().id(), hub.currentFrame().contextNumber(), hub.currentFrame().type(), - hub.currentFrame().codeAddress().toUnprefixedHexString()); + hub.currentFrame().byteCodeAddress().toUnprefixedHexString()); } public void tracePreOpcode(final MessageFrame frame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c2e5541cb4..6129619ed1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1015,7 +1015,7 @@ public void traceContextEnter(MessageFrame frame) { } else { this.callStack.newBedrock( this.state.stamps().hub(), - // this.transients.tx().transaction().getSender(), + this.txStack.current().getBesuTransaction().getSender(), toAddress, CallFrameType.BEDROCK, new Bytecode( @@ -1066,6 +1066,7 @@ public void traceContextEnter(MessageFrame frame) { this.state.stamps().hub(), frame.getRecipientAddress(), frame.getContractAddress(), + frame.getRecipientAddress(), // TODO: this is likely false new Bytecode(frame.getCode().getBytes()), frameType, frame.getValue(), @@ -1112,7 +1113,7 @@ public void traceContextExit(MessageFrame frame) { this.transients .conflation() .deploymentInfo() - .unmarkDeploying(this.currentFrame().codeAddress()); + .unmarkDeploying(this.currentFrame().byteCodeAddress()); DeploymentExceptions contextExceptions = DeploymentExceptions.fromFrame(this.currentFrame(), frame); @@ -1352,7 +1353,7 @@ void traceOperation(MessageFrame frame) { final Bytes rawTargetAddress = switch (this.currentFrame().opCode()) { case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); - default -> this.currentFrame().address(); + default -> this.currentFrame().accountAddress(); }; final Address targetAddress = Words.toAddress(rawTargetAddress); final Account targetAccount = frame.getWorldUpdater().get(targetAddress); @@ -1377,7 +1378,7 @@ void traceOperation(MessageFrame frame) { final Bytes rawTargetAddress = switch (this.currentFrame().opCode()) { - case CODECOPY -> this.currentFrame().codeAddress(); + case CODECOPY -> this.currentFrame().byteCodeAddress(); case EXTCODECOPY -> frame.getStackItem(0); default -> throw new IllegalStateException("unexpected opcode"); }; @@ -1420,7 +1421,7 @@ void traceOperation(MessageFrame frame) { } } case STORAGE -> { - Address address = this.currentFrame().address(); + Address address = this.currentFrame().accountAddress(); EWord key = EWord.of(frame.getStackItem(0)); switch (this.currentFrame().opCode()) { case SSTORE -> { @@ -1459,7 +1460,7 @@ void traceOperation(MessageFrame frame) { } } case CREATE -> { - Address myAddress = this.currentFrame().address(); + Address myAddress = this.currentFrame().accountAddress(); Account myAccount = frame.getWorldUpdater().get(myAddress); AccountSnapshot myAccountSnapshot = AccountSnapshot.fromAccount( @@ -1468,7 +1469,7 @@ void traceOperation(MessageFrame frame) { this.transients.conflation().deploymentInfo().number(myAddress), this.transients.conflation().deploymentInfo().isDeploying(myAddress)); - Address createdAddress = this.currentFrame().address(); + Address createdAddress = this.currentFrame().accountAddress(); Account createdAccount = frame.getWorldUpdater().get(createdAddress); AccountSnapshot createdAccountSnapshot = AccountSnapshot.fromAccount( @@ -1484,7 +1485,7 @@ void traceOperation(MessageFrame frame) { } case CALL -> { - final Address myAddress = this.currentFrame().address(); + final Address myAddress = this.currentFrame().accountAddress(); final Account myAccount = frame.getWorldUpdater().get(myAddress); final AccountSnapshot myAccountSnapshot = AccountSnapshot.fromAccount( @@ -1597,12 +1598,12 @@ void traceOperation(MessageFrame frame) { case JUMP -> { AccountSnapshot codeAccountSnapshot = AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(this.currentFrame().codeAddress()), + frame.getWorldUpdater().get(this.currentFrame().byteCodeAddress()), true, this.transients .conflation() .deploymentInfo() - .number(this.currentFrame().codeAddress()), + .number(this.currentFrame().byteCodeAddress()), this.currentFrame().underDeployment()); JumpSection jumpSection = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 42f7e43d66..ae1fba0ad1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -180,7 +180,9 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .romLex() .getCodeFragmentIndexByMetadata( ContractMetadata.make( - frame.codeAddress(), frame.codeDeploymentNumber(), frame.underDeployment())) + frame.byteCodeAddress(), + frame.codeDeploymentNumber(), + frame.underDeployment())) : 0; final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index a815ace47f..ecaa37cfb2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -92,7 +92,7 @@ public Trace trace(Trace trace) { final EWord eAddress = callFrame.addressAsEWord(); final EWord eCodeAddress = callFrame.codeAddressAsEWord(); - final EWord parentAddress = parent.addressAsEWord(); + final EWord callerAddress = EWord.of(callFrame.callerAddress()); return trace .peekAtContext(true) .pContextContextNumber(callFrame.contextNumber()) @@ -107,8 +107,8 @@ public Trace trace(Trace trace) { .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) .pContextByteCodeCodeFragmentIndex(0) // TODO - .pContextCallerAddressHi(bytesToLong(parentAddress.hi())) - .pContextCallerAddressLo(parentAddress.lo()) + .pContextCallerAddressHi(bytesToLong(callerAddress.hi())) + .pContextCallerAddressLo(callerAddress.lo()) .pContextCallValue(callFrame.value()) .pContextCallDataContextNumber(parent.contextNumber()) .pContextCallDataOffset(callFrame.callDataInfo().memorySpan().offset()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java index 4a88e47a4e..1a9860c26d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java @@ -54,7 +54,8 @@ public Jump(Hub hub, MessageFrame frame) { this.targetPc = EWord.of(targetPc); this.jumpCondition = EWord.of(jumpCondition); - this.codeSize = frame.getWorldUpdater().get(hub.currentFrame().codeAddress()).getCode().size(); + this.codeSize = + frame.getWorldUpdater().get(hub.currentFrame().byteCodeAddress()).getCode().size(); this.event2 = jumpCondition > 0; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java index fb5e33ac7b..336a6dd434 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java @@ -61,7 +61,7 @@ public void prepare(Hub hub) { switch (hub.currentFrame().opCode()) { case CALL, CALLCODE -> { if (hub.pch().exceptions().none()) { - final Address myAddress = hub.currentFrame().address(); + final Address myAddress = hub.currentFrame().accountAddress(); final Wei myBalance = hub.messageFrame().getWorldUpdater().get(myAddress).getBalance(); final Wei value = Wei.of(UInt256.fromBytes(hub.messageFrame().getStackItem(2))); @@ -73,7 +73,7 @@ public void prepare(Hub hub) { } case CREATE, CREATE2 -> { if (hub.pch().exceptions().none()) { - final Address myAddress = hub.currentFrame().address(); + final Address myAddress = hub.currentFrame().accountAddress(); final Wei myBalance = hub.messageFrame().getWorldUpdater().get(myAddress).getBalance(); final Wei value = Wei.of(UInt256.fromBytes(hub.messageFrame().getStackItem(0))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index cf97905a67..ec664535bc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -64,11 +64,13 @@ public class CallFrame { @Getter private final List childFrames = new ArrayList<>(); /** the {@link Address} of the account executing this {@link CallFrame}. */ - @Getter private final Address address; + @Getter private final Address accountAddress; /** A memoized {@link EWord} conversion of `address` */ private EWord eAddress = null; /** the {@link Address} of the code executed in this {@link CallFrame}. */ - @Getter private Address codeAddress = Address.ZERO; + @Getter private Address byteCodeAddress = Address.ZERO; + + @Getter private Address callerAddress = Address.ZERO; /** A memoized {@link EWord} conversion of `codeAddress` */ private EWord eCodeAddress = null; @@ -117,10 +119,10 @@ public class CallFrame { @Getter @Setter private StackContext pending; /** Create a MANTLE call frame. */ - CallFrame(final Bytes callData, final int contextNumber) { + CallFrame(final Address origin, final Bytes callData, final int contextNumber) { this.type = CallFrameType.MANTLE; this.contextNumber = contextNumber; - this.address = Address.ZERO; + this.accountAddress = origin; this.callDataInfo = new CallDataInfo(callData, 0, callData.size(), contextNumber); } @@ -137,14 +139,14 @@ public class CallFrame { this.contextNumber = contextNumber; this.returnData = precompileResult; this.returnDataSource = new MemorySpan(returnDataOffset, precompileResult.size()); - this.address = precompileAddress; + this.accountAddress = precompileAddress; } /** Create an empty call frame. */ CallFrame() { this.type = CallFrameType.EMPTY; this.contextNumber = 0; - this.address = Address.ZERO; + this.accountAddress = Address.ZERO; this.parentFrame = -1; } @@ -156,7 +158,7 @@ public class CallFrame { * @param isDeployment whether the executing code is initcode * @param id the ID of this frame in the {@link CallStack} * @param hubStamp the hub stamp at the frame creation - * @param address the {@link Address} of this frame executor + * @param accountAddress the {@link Address} of this frame executor * @param type the {@link CallFrameType} of this frame * @param caller the ID of this frame caller in the {@link CallStack} * @param value how much ether was given to this frame @@ -169,8 +171,9 @@ public class CallFrame { boolean isDeployment, int id, int hubStamp, - Address address, - Address codeAddress, + Address accountAddress, + Address callerAddress, + Address byteCodeAddress, Bytecode code, CallFrameType type, int caller, @@ -186,8 +189,9 @@ public class CallFrame { this.underDeployment = isDeployment; this.id = id; this.contextNumber = hubStamp + 1; - this.address = address; - this.codeAddress = codeAddress; + this.accountAddress = accountAddress; + this.byteCodeAddress = byteCodeAddress; + this.callerAddress = callerAddress; this.code = code; this.type = type; this.parentFrame = caller; @@ -212,7 +216,7 @@ public boolean isRoot() { */ public EWord addressAsEWord() { if (this.eAddress == null) { - this.eAddress = EWord.of(this.address); + this.eAddress = EWord.of(this.accountAddress); } return this.eAddress; } @@ -224,7 +228,7 @@ public EWord addressAsEWord() { */ public EWord codeAddressAsEWord() { if (this.eCodeAddress == null) { - this.eCodeAddress = EWord.of(this.codeAddress); + this.eCodeAddress = EWord.of(this.byteCodeAddress); } return this.eCodeAddress; } @@ -248,7 +252,8 @@ public Optional lastCallee() { * @return the executed contract metadata */ public ContractMetadata metadata() { - return ContractMetadata.make(this.codeAddress, this.codeDeploymentNumber, this.underDeployment); + return ContractMetadata.make( + this.byteCodeAddress, this.codeDeploymentNumber, this.underDeployment); } private void revertChildren(CallStack callStack, int stamp) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 9c30e2a3be..c20b050664 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -61,6 +61,7 @@ public void newPrecompileResult( hubStamp, precompileAddress, precompileAddress, + precompileAddress, Bytecode.EMPTY, CallFrameType.PRECOMPILE_RETURN_DATA, this.current, @@ -77,7 +78,7 @@ public void newPrecompileResult( public void newBedrock( int hubStamp, - // Address from, + Address from, Address to, CallFrameType type, Bytecode toCode, @@ -92,6 +93,7 @@ public void newBedrock( hubStamp, to, to, + from, toCode == null ? Bytecode.EMPTY : toCode, type, value, @@ -134,11 +136,12 @@ public void newMantleAndBedrock( int codeDeploymentNumber, boolean codeDeploymentStatus) { this.depth = -1; - this.frames.add(new CallFrame(callData, hubStamp)); + this.frames.add(new CallFrame(from, callData, hubStamp)); this.enter( hubStamp, to, to, + from, toCode == null ? Bytecode.EMPTY : toCode, CallFrameType.BEDROCK, value, @@ -187,7 +190,7 @@ public Optional maybeCurrent() { * Creates a new call frame. * * @param hubStamp the hub stamp at the time of entry in the new frame - * @param address the {@link Address} of the bytecode being executed + * @param accountAddress the {@link Address} of the bytecode being executed * @param code the {@link Code} being executed * @param type the execution type of call frame * @param value the value given to this call frame @@ -199,8 +202,9 @@ public Optional maybeCurrent() { */ public void enter( int hubStamp, - Address address, - Address codeAddress, + Address accountAddress, + Address byteCodeAddress, + Address callerAddress, Bytecode code, CallFrameType type, Wei value, @@ -228,8 +232,9 @@ public void enter( isDeployment, newTop, hubStamp, - address, - codeAddress, + accountAddress, + callerAddress, + byteCodeAddress, code, type, caller, From 0d672f9c1a6cae0157c4d0deee13f6b1136f24b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 12:25:02 +0400 Subject: [PATCH 029/461] CFI inside of contextFragment --- resolves hub.tx-initialization---initializing-context --- .../linea/zktracer/module/hub/Hub.java | 37 +++++++++++-------- .../module/hub/fragment/CommonFragment.java | 10 +---- .../module/hub/fragment/ContextFragment.java | 34 +++++++++++------ .../precompiles/PrecompileLinesGenerator.java | 26 ++++++------- .../module/hub/section/CreateSection.java | 20 +++++----- .../module/hub/section/NoCodeCallSection.java | 4 +- .../hub/section/SmartContractCallSection.java | 4 +- 7 files changed, 72 insertions(+), 63 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6129619ed1..c81087d7a3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -83,6 +83,7 @@ import net.consensys.linea.zktracer.module.rlptxn.RlpTxn; import net.consensys.linea.zktracer.module.rlptxrcpt.RlpTxrcpt; import net.consensys.linea.zktracer.module.rom.Rom; +import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.module.romlex.RomLex; import net.consensys.linea.zktracer.module.shakiradata.ShakiraData; import net.consensys.linea.zktracer.module.shf.Shf; @@ -420,6 +421,13 @@ public List getModulesToCount() { .toList(); } + public int getCfiByMetaData( + final Address address, final int deploymentNumber, final boolean deploymentStatus) { + return this.romLex() + .getCodeFragmentIndexByMetadata( + ContractMetadata.make(address, deploymentNumber, deploymentStatus)); + } + /** * Traces a skipped transaction, i.e. a “pure” transaction without EVM execution. * @@ -785,7 +793,7 @@ void processStateExec(MessageFrame frame) { } else { this.addTraceSection(new StackOnlySection(this)); this.currentTraceSection() - .addFragmentsWithoutStack(this, ContextFragment.executionEmptyReturnData(this.callStack)); + .addFragmentsWithoutStack(this, ContextFragment.executionEmptyReturnData(this)); } } @@ -1337,17 +1345,16 @@ void traceOperation(MessageFrame frame) { new KeccakSection( this, this.currentFrame(), ImcFragment.forOpcode(this, this.messageFrame()))); case CONTEXT -> this.addTraceSection( - new ContextLogSection(this, ContextFragment.readContextData(callStack))); + new ContextLogSection(this, ContextFragment.readContextData(this))); case LOG -> { - this.addTraceSection( - new ContextLogSection(this, ContextFragment.readContextData(callStack))); + this.addTraceSection(new ContextLogSection(this, ContextFragment.readContextData(this))); LogInvocation.forOpcode(this); } case ACCOUNT -> { TraceSection accountSection = new AccountSection(this); if (this.opCodeData().stackSettings().flag1()) { accountSection.addFragment( - this, this.currentFrame(), ContextFragment.readContextData(callStack)); + this, this.currentFrame(), ContextFragment.readContextData(this)); } final Bytes rawTargetAddress = @@ -1400,8 +1407,7 @@ void traceOperation(MessageFrame frame) { .makeWithTrm(accountSnapshot, accountSnapshot, rawTargetAddress) : this.factories.accountFragment().make(accountSnapshot, accountSnapshot)); } else { - copySection.addFragment( - this, this.currentFrame(), ContextFragment.readContextData(callStack)); + copySection.addFragment(this, this.currentFrame(), ContextFragment.readContextData(this)); } this.addTraceSection(copySection); } @@ -1413,7 +1419,7 @@ void traceOperation(MessageFrame frame) { final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); this.addTraceSection( - new StackRam(this, imcFragment, ContextFragment.readContextData(callStack))); + new StackRam(this, imcFragment, ContextFragment.readContextData(this))); } case MLOAD, MSTORE, MSTORE8 -> this.addTraceSection( new StackRam(this, ImcFragment.forOpcode(this, frame))); @@ -1429,7 +1435,7 @@ void traceOperation(MessageFrame frame) { this.addTraceSection( new StorageSection( this, - ContextFragment.readContextData(callStack), + ContextFragment.readContextData(this), new StorageFragment( address, this.currentFrame().accountDeploymentNumber(), @@ -1445,7 +1451,7 @@ void traceOperation(MessageFrame frame) { this.addTraceSection( new StorageSection( this, - ContextFragment.readContextData(callStack), + ContextFragment.readContextData(this), new StorageFragment( address, this.currentFrame().accountDeploymentNumber(), @@ -1519,7 +1525,7 @@ void traceOperation(MessageFrame frame) { this, ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount), - ContextFragment.readContextData(callStack))); + ContextFragment.readContextData(this))); } else if (this.pch().exceptions().outOfMemoryExpansion()) { this.addTraceSection( new FailedCallSection( @@ -1546,12 +1552,12 @@ void traceOperation(MessageFrame frame) { this, ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount), - ContextFragment.readContextData(callStack), + ContextFragment.readContextData(this), this.factories.accountFragment().make(myAccountSnapshot, myAccountSnapshot), this.factories .accountFragment() .makeWithTrm(calledAccountSnapshot, calledAccountSnapshot, rawCalledAddress), - ContextFragment.nonExecutionEmptyReturnData(callStack)); + ContextFragment.nonExecutionEmptyReturnData(this)); this.addTraceSection(abortedSection); } else { final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); @@ -1609,7 +1615,7 @@ void traceOperation(MessageFrame frame) { JumpSection jumpSection = new JumpSection( this, - ContextFragment.readContextData(callStack), + ContextFragment.readContextData(this), this.factories.accountFragment().make(codeAccountSnapshot, codeAccountSnapshot), ImcFragment.forOpcode(this, frame)); @@ -1620,8 +1626,7 @@ void traceOperation(MessageFrame frame) { // In all cases, add a context fragment if an exception occurred if (this.pch().exceptions().any()) { this.currentTraceSection() - .addFragment( - this, this.currentFrame(), ContextFragment.executionEmptyReturnData(callStack)); + .addFragment(this, this.currentFrame(), ContextFragment.executionEmptyReturnData(this)); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index ae1fba0ad1..fbf608053a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -27,7 +27,6 @@ import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; -import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -176,13 +175,8 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { hub.txStack().getByAbsoluteTransactionNumber(this.absoluteTransactionNumber); final int codeFragmentIndex = this.hubProcessingPhase == HubProcessingPhase.TX_EXEC - ? this.hub - .romLex() - .getCodeFragmentIndexByMetadata( - ContractMetadata.make( - frame.byteCodeAddress(), - frame.codeDeploymentNumber(), - frame.underDeployment())) + ? this.hub.getCfiByMetaData( + frame.byteCodeAddress(), frame.codeDeploymentNumber(), frame.underDeployment()) : 0; final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index ecaa37cfb2..7bf2aebc07 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -27,6 +27,7 @@ import org.apache.tuweni.bytes.Bytes; public record ContextFragment( + Hub hub, CallStack callStack, // Left: callFrameId, Right: contextNumber Either callFrameReference, @@ -34,9 +35,10 @@ public record ContextFragment( boolean updateCallerReturndata) implements TraceFragment { - public static ContextFragment readContextData(final CallStack callStack) { - + public static ContextFragment readContextData(final Hub hub) { + CallStack callStack = hub.callStack(); return new ContextFragment( + hub, callStack, Either.left(callStack.current().id()), callStack.current().latestReturnDataSource().snapshot(), @@ -45,6 +47,7 @@ public static ContextFragment readContextData(final CallStack callStack) { public static ContextFragment initializeExecutionContext(final Hub hub) { return new ContextFragment( + hub, hub.callStack(), Either.right(hub.stamp() + 1), MemorySpan.fromStartEnd( @@ -52,32 +55,38 @@ public static ContextFragment initializeExecutionContext(final Hub hub) { false); } - public static ContextFragment executionEmptyReturnData(final CallStack callStack) { + public static ContextFragment executionEmptyReturnData(final Hub hub) { + CallStack callStack = hub.callStack(); return new ContextFragment( - callStack, Either.left(callStack.parent().id()), MemorySpan.empty(), true); + hub, callStack, Either.left(callStack.parent().id()), MemorySpan.empty(), true); } - public static ContextFragment nonExecutionEmptyReturnData(final CallStack callStack) { + public static ContextFragment nonExecutionEmptyReturnData(final Hub hub) { + CallStack callStack = hub.callStack(); return new ContextFragment( - callStack, Either.left(callStack.parent().id()), MemorySpan.empty(), true); + hub, callStack, Either.left(callStack.parent().id()), MemorySpan.empty(), true); } - public static ContextFragment executionReturnData(final CallStack callStack) { + public static ContextFragment executionReturnData(final Hub hub) { + CallStack callStack = hub.callStack(); return new ContextFragment( + hub, callStack, Either.left(callStack.parent().id()), callStack.current().returnDataSource(), true); } - public static ContextFragment enterContext( - final CallStack callStack, final CallFrame calledCallFrame) { + public static ContextFragment enterContext(final Hub hub, final CallFrame calledCallFrame) { + CallStack callStack = hub.callStack(); return new ContextFragment( - callStack, Either.left(calledCallFrame.id()), MemorySpan.empty(), false); + hub, callStack, Either.left(calledCallFrame.id()), MemorySpan.empty(), false); } - public static ContextFragment providesReturnData(final CallStack callStack) { + public static ContextFragment providesReturnData(final Hub hub) { + CallStack callStack = hub.callStack(); return new ContextFragment( + hub, callStack, Either.left(callStack.current().id()), callStack.current().latestReturnDataSource().snapshot(), @@ -93,6 +102,7 @@ public Trace trace(Trace trace) { final EWord eAddress = callFrame.addressAsEWord(); final EWord eCodeAddress = callFrame.codeAddressAsEWord(); final EWord callerAddress = EWord.of(callFrame.callerAddress()); + return trace .peekAtContext(true) .pContextContextNumber(callFrame.contextNumber()) @@ -106,7 +116,7 @@ public Trace trace(Trace trace) { .pContextByteCodeAddressLo(eCodeAddress.lo()) .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) - .pContextByteCodeCodeFragmentIndex(0) // TODO + .pContextByteCodeCodeFragmentIndex(hub.getCfiByMetaData(callFrame.byteCodeAddress(), callFrame.codeDeploymentNumber(), callFrame.underDeployment())) .pContextCallerAddressHi(bytesToLong(callerAddress.hi())) .pContextCallerAddressLo(callerAddress.lo()) .pContextCallValue(callFrame.value()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index 1f893ed8cb..c62383c82c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -177,7 +177,7 @@ public static List generateFor(final Hub hub, final PrecompileInv Math.max(mbsInt, bbsInt)))); if (p.ramFailure()) { - r.add(ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) @@ -198,16 +198,16 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 11))); } - r.add(ContextFragment.providesReturnData(hub.callStack())); + r.add(ContextFragment.providesReturnData(hub)); } } case EC_ADD -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new EcAdd(p))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (p.ramFailure()) { r.add(ImcFragment.empty(hub).callOob(new EcAdd(p)).callMmu(MmuCall.forEcAdd(hub, p, 0))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { r.add(ImcFragment.empty(hub).callOob(new EcAdd(p)).callMmu(MmuCall.forEcAdd(hub, p, 0))); r.add( @@ -220,16 +220,16 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcAdd(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub.callStack())); + r.add(ContextFragment.providesReturnData(hub)); } } case EC_MUL -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new EcMul(p))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (p.ramFailure()) { r.add(ImcFragment.empty(hub).callOob(new EcMul(p)).callMmu(MmuCall.forEcMul(hub, p, 0))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { r.add(ImcFragment.empty(hub).callOob(new EcMul(p)).callMmu(MmuCall.forEcMul(hub, p, 0))); r.add( @@ -242,19 +242,19 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcMul(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub.callStack())); + r.add(ContextFragment.providesReturnData(hub)); } } case EC_PAIRING -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new EcPairing(p))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) .callOob(new EcPairing(p)) .callMmu(MmuCall.forEcPairing(hub, p, 0))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) @@ -267,7 +267,7 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcPairing(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub.callStack())); + r.add(ContextFragment.providesReturnData(hub)); } } case BLAKE2F -> { @@ -296,8 +296,8 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add( p.success() - ? ContextFragment.providesReturnData(hub.callStack()) - : ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + ? ContextFragment.providesReturnData(hub) + : ContextFragment.nonExecutionEmptyReturnData(hub)); return r; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 1693e89878..49d0278453 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -183,23 +183,23 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces this.addFragmentsWithoutStack( hub, ImcFragment.empty(hub), - ContextFragment.readContextData(hub.callStack()), - ContextFragment.executionEmptyReturnData(hub.callStack())); + ContextFragment.readContextData(hub), + ContextFragment.executionEmptyReturnData(hub)); } else if (this.exceptions.outOfMemoryExpansion()) { this.addFragmentsWithoutStack( hub, ImcFragment.empty(hub).callMxp(MxpCall.build(hub)), - ContextFragment.executionEmptyReturnData(hub.callStack())); + ContextFragment.executionEmptyReturnData(hub)); } else if (this.exceptions.outOfGas()) { this.addFragmentsWithoutStack( - hub, commonImcFragment, ContextFragment.executionEmptyReturnData(hub.callStack())); + hub, commonImcFragment, ContextFragment.executionEmptyReturnData(hub)); } else if (this.aborts.any()) { this.addFragmentsWithoutStack( hub, commonImcFragment, - ContextFragment.readContextData(hub.callStack()), + ContextFragment.readContextData(hub), accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), - ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (this.failures.any()) { if (creatorReverted) { this.addFragmentsWithoutStack( @@ -209,14 +209,14 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), accountFragmentFactory.make(newCreatorSnapshot, oldCreatorSnapshot), accountFragmentFactory.make(newCreatedSnapshot, oldCreatedSnapshot), - ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + ContextFragment.nonExecutionEmptyReturnData(hub)); } else { this.addFragmentsWithoutStack( hub, commonImcFragment, accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), - ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + ContextFragment.nonExecutionEmptyReturnData(hub)); } } else { if (this.emptyInitCode) { @@ -228,14 +228,14 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), accountFragmentFactory.make(newCreatorSnapshot, oldCreatorSnapshot), accountFragmentFactory.make(newCreatedSnapshot, oldCreatedSnapshot), - ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + ContextFragment.nonExecutionEmptyReturnData(hub)); } else { this.addFragmentsWithoutStack( hub, commonImcFragment, accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), - ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + ContextFragment.nonExecutionEmptyReturnData(hub)); } } else { if (this.createSuccessful) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java index 213883cdda..d76b801ea0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java @@ -120,7 +120,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces callerCallFrame, this.scenarioFragment, this.imcFragment, - ContextFragment.readContextData(hub.callStack()), + ContextFragment.readContextData(hub), accountFragmentFactory.make( this.preCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot), accountFragmentFactory.makeWithTrm( @@ -158,7 +158,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces this.postCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); } this.addFragmentsWithoutStack( - hub, callerCallFrame, ContextFragment.nonExecutionEmptyReturnData(hub.callStack())); + hub, callerCallFrame, ContextFragment.nonExecutionEmptyReturnData(hub)); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java index 6d035befad..eaf5600a65 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java @@ -126,7 +126,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, callerCallFrame, this.scenarioFragment, - ContextFragment.readContextData(hub.callStack()), + ContextFragment.readContextData(hub), this.imcFragment, accountFragmentFactory.make( this.preCallCallerAccountSnapshot, this.inCallCallerAccountSnapshot), @@ -168,6 +168,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces } this.addFragmentsWithoutStack( - hub, callerCallFrame, ContextFragment.enterContext(hub.callStack(), calledCallFrame)); + hub, callerCallFrame, ContextFragment.enterContext(hub, calledCallFrame)); } } From bb935aedb72471f6bf00df6cd8c1ce62a3d9e0b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 13:30:51 +0400 Subject: [PATCH 030/461] account/ROMLEX_FLAG fix - partial fix of hub.tx-initialization---setting-recipient-account-row * fixed account/ROMLEX_FLAG constraint --- .../linea/zktracer/module/hub/fragment/AccountFragment.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java index f3a9019f65..45c807cf87 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java @@ -69,7 +69,7 @@ public AccountFragment makeWithTrm( private final boolean isDeployment; @Setter private boolean existsInfinity = false; // retconned on conflation end private int codeFragmentIndex; - @Setter private boolean requiresCodeFragmentIndex; + @Setter private boolean requiresRomlex; private final Optional addressToTrim; public AccountFragment( @@ -112,7 +112,7 @@ public Trace trace(Trace trace) { .pAccountHasCode(oldState.code().getCodeHash() != Hash.EMPTY) .pAccountHasCodeNew(newState.code().getCodeHash() != Hash.EMPTY) .pAccountCodeFragmentIndex(this.codeFragmentIndex) - .pAccountRomlexFlag(false) // TODO + .pAccountRomlexFlag(requiresRomlex) .pAccountExists( oldState.nonce() > 0 || oldState.code().getCodeHash() != Hash.EMPTY @@ -153,7 +153,7 @@ public void runPostConflation(Hub hub, WorldView world) { this.deploymentNumberInfinity = hub.transients().conflation().deploymentInfo().number(this.who); this.existsInfinity = world.get(this.who) != null; this.codeFragmentIndex = - this.requiresCodeFragmentIndex + this.requiresRomlex ? hub.romLex() .getCodeFragmentIndexByMetadata( ContractMetadata.make(this.who, this.deploymentNumber, this.isDeployment)) From 3a0b7f2377a394be8f442c29a0d86bed70db5a4b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 15:02:23 +0530 Subject: [PATCH 031/461] feat: add cfi in txMetaData, will be used by rlpTxn and TxnData --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 1 + .../linea/zktracer/module/hub/TransactionStack.java | 8 ++++++++ .../zktracer/module/hub/fragment/ContextFragment.java | 6 +++++- .../zktracer/types/TransactionProcessingMetadata.java | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c81087d7a3..a98e7d7be9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1257,6 +1257,7 @@ public void traceEndConflation(final WorldView world) { this.romLex.traceEndConflation(world); this.defers.runPostConflation(this, world); + this.txStack.setCodeFragmentIndex(this); for (Module m : this.modules) { if (!m.equals(this.romLex)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 8ca36d6b9f..4c407fe133 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -88,6 +88,14 @@ public void exitTransaction(final Hub hub, boolean isSuccessful) { this.current().setHubStampTransactionEnd(hub.stamp() + 1); } + public void setCodeFragmentIndex(Hub hub) { + for (TransactionProcessingMetadata tx : this.txs) { + final int cfi = + tx.requiresCfiUpdate() ? hub.getCfiByMetaData(tx.getEffectiveTo(), 1, true) : 0; + tx.setCodeFragmentIndex(cfi); + } + } + public static long computeInitGas(Transaction tx) { boolean isDeployment = tx.getTo().isEmpty(); return tx.getGasLimit() diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 7bf2aebc07..321009c124 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -116,7 +116,11 @@ public Trace trace(Trace trace) { .pContextByteCodeAddressLo(eCodeAddress.lo()) .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) - .pContextByteCodeCodeFragmentIndex(hub.getCfiByMetaData(callFrame.byteCodeAddress(), callFrame.codeDeploymentNumber(), callFrame.underDeployment())) + .pContextByteCodeCodeFragmentIndex( + hub.getCfiByMetaData( + callFrame.byteCodeAddress(), + callFrame.codeDeploymentNumber(), + callFrame.underDeployment())) .pContextCallerAddressHi(bytesToLong(callerAddress.hi())) .pContextCallerAddressLo(callerAddress.lo()) .pContextCallValue(callFrame.value()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index a39fbd0508..2408c7ccba 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -33,6 +33,7 @@ @Getter public class TransactionProcessingMetadata { + final int absoluteTransactionNumber; final int relativeTransactionNumber; final int relativeBlockNumber; @@ -79,6 +80,8 @@ public class TransactionProcessingMetadata { final StorageInitialValues storage = new StorageInitialValues(); + @Setter int codeFragmentIndex = -1; + public TransactionProcessingMetadata( WorldView world, Transaction transaction, @@ -179,4 +182,8 @@ public Address getSender() { public boolean requiresPrewarming() { return requiresEvmExecution && (accessListCost != 0); } + + public boolean requiresCfiUpdate() { + return requiresEvmExecution && isDeployment; + } } From a5274d0a95128851a628f12218bf34f113bd5b41 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 15:04:29 +0530 Subject: [PATCH 032/461] fix: renaming --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a98e7d7be9..54ab644b94 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -641,7 +641,7 @@ void processStateInit(WorldView world) { accountFragmentFactory.make(preInitFromSnapshot, postInitFromSnapshot), accountFragmentFactory .makeWithTrm(preInitToSnapshot, postInitToSnapshot, toAddress) - .requiresCodeFragmentIndex(true), + .requiresRomlex(true), ImcFragment.forTxInit(this), ContextFragment.initializeExecutionContext(this), txFragment)); From 1bfa9bfde59433caf5123fab49904c42b53a955f Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 16:50:52 +0530 Subject: [PATCH 033/461] fix: convert bytes in address --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 4 ++-- .../net/consensys/linea/zktracer/types/AddressUtils.java | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 54ab644b94..a27de60f33 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub; +import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; @@ -679,8 +680,7 @@ public int contextNumberNew(WorldView world) { if (pch().abortingConditions().any()) { return currentContextNumber; } - Address calleeAddress = - Address.extract((Bytes32) this.currentFrame().frame().getStackItem(1)); + Address calleeAddress = addressFromBytes(this.currentFrame().frame().getStackItem(1)); if (world.get(calleeAddress).hasCode()) { return 1 + stamp(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java index 71123aef60..8beeec58f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.types; +import static net.consensys.linea.zktracer.types.Utils.leftPadTo; + import java.util.List; import net.consensys.linea.zktracer.module.hub.transients.OperationAncillaries; @@ -101,4 +103,8 @@ public static Address getDeploymentAddress(final MessageFrame frame) { } return opcode.equals(OpCode.CREATE) ? getCreateAddress(frame) : getCreate2Address(frame); } + + public static Address addressFromBytes(final Bytes input) { + return Address.wrap(leftPadTo(input, Address.SIZE)); + } } From 12229c64366dfdcd34d5a91bb6d813c3ba8bef63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 15:34:37 +0400 Subject: [PATCH 034/461] TX_FINL implemented --- .../linea/zktracer/module/hub/Hub.java | 181 ++++++++++-------- .../hub/section/EndTransactionSection.java | 28 --- .../hub/section/TxFinalizationSection.java | 13 +- ...tion.java => TxInitializationSection.java} | 4 +- ...pSection.java => TxPrewarmingSection.java} | 4 +- 5 files changed, 121 insertions(+), 109 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/EndTransactionSection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{TxInitSection.java => TxInitializationSection.java} (87%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{WarmupSection.java => TxPrewarmingSection.java} (91%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a27de60f33..020c8ec2a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.module.hub; import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_REFUND_QUOTIENT; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; @@ -25,6 +26,7 @@ import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_WARM; +import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.ArrayList; import java.util.HashMap; @@ -568,7 +570,7 @@ void processPrewarmingPhase(WorldView world) { transactionProcessingMetadata.isReceiverPreWarmed( seenAddresses.contains(receiverAddress)); - this.addTraceSection(new WarmupSection(this, fragments)); + this.addTraceSection(new TxPrewarmingSection(this, fragments)); } }); } @@ -581,12 +583,12 @@ void processPrewarmingPhase(WorldView world) { void processStateInit(WorldView world) { this.state.setProcessingPhase(TX_INIT); this.state.stamps().incrementHubStamp(); - final TransactionProcessingMetadata tx = this.transients.tx(); - final boolean isDeployment = tx.getBesuTransaction().getTo().isEmpty(); - final Address toAddress = effectiveToAddress(tx.getBesuTransaction()); + TransactionProcessingMetadata tx = this.txStack.current(); + final boolean isDeployment = tx.isDeployment(); + final Address toAddress = tx.getEffectiveTo(); final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); - final Address fromAddress = tx.getBesuTransaction().getSender(); + final Address fromAddress = tx.getSender(); final Account fromAccount = world.get(fromAddress); final AccountSnapshot preInitFromSnapshot = AccountSnapshot.fromAccount( @@ -595,12 +597,7 @@ void processStateInit(WorldView world) { deploymentInfo.number(fromAddress), deploymentInfo.isDeploying(fromAddress)); - final Wei transactionGasPrice = - ZkTracer.feeMarket - .getTransactionPriceCalculator() - .price( - (org.hyperledger.besu.ethereum.core.Transaction) tx.getBesuTransaction(), - Optional.of(this.transients.block().baseFee())); + final Wei transactionGasPrice = Wei.of(tx.getEffectiveGasPrice()); final Wei value = (Wei) tx.getBesuTransaction().getValue(); final AccountSnapshot postInitFromSnapshot = preInitFromSnapshot.debit( @@ -630,14 +627,14 @@ void processStateInit(WorldView world) { ? preInitToSnapshot.deploy(value, initBytecode) : preInitToSnapshot.credit(value, true); - final TransactionFragment txFragment = TransactionFragment.prepare(this.txStack.current()); + final TransactionFragment txFragment = TransactionFragment.prepare(tx); this.defers.postTx(txFragment); final AccountFragment.AccountFragmentFactory accountFragmentFactory = this.factories.accountFragment(); this.addTraceSection( - new TxInitSection( + new TxInitializationSection( this, accountFragmentFactory.make(preInitFromSnapshot, postInitFromSnapshot), accountFragmentFactory @@ -797,86 +794,119 @@ void processStateExec(MessageFrame frame) { } } - void processStateFinal(WorldView worldView) { + void processStateFinal(WorldView worldView){ this.state.setProcessingPhase(TX_FINAL); this.state.stamps().incrementHubStamp(); - final Address fromAddress = this.txStack.current().getBesuTransaction().getSender(); - final Account fromAccount = worldView.get(fromAddress); + final TransactionProcessingMetadata tx = this.txStack.current(); + + final Address senderAddress = tx.getSender(); + final Address effectiveToAddress = tx.getEffectiveTo(); + final Address coinbaseAddress = tx.getCoinbase(); + final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); - final AccountSnapshot preFinalFromSnapshot = - AccountSnapshot.fromAccount( - fromAccount, - true, - deploymentInfo.number(fromAddress), - deploymentInfo.isDeploying(fromAddress)); + final boolean coinbaseWarmth = false; // TODO: get access to coinbase address warmth (still London!) - // TODO: still no finished - final AccountSnapshot postFinalFromSnapshot = + final Account senderAccount = worldView.get(senderAddress); + final AccountSnapshot senderAccountSnapshotBeforeRefunds = AccountSnapshot.fromAccount( - fromAccount, + senderAccount, true, - deploymentInfo.number(fromAddress), - deploymentInfo.isDeploying(fromAddress)); + deploymentInfo.number(senderAddress), + deploymentInfo.isDeploying(senderAddress)); - final Address minerAddress = this.txStack.current().getCoinbase(); - final Account minerAccount = worldView.get(minerAddress); - final AccountSnapshot preFinalCoinbaseSnapshot = - AccountSnapshot.fromAccount( - minerAccount, - true, - deploymentInfo.number(minerAddress), - deploymentInfo.isDeploying(minerAddress)); + final long gasUsed = tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas(); + final long effectiveRefunds = Math.min(this.accruedRefunds(), gasUsed / MAX_REFUND_QUOTIENT); + final long senderGasRefund = tx.getLeftoverGas() + effectiveRefunds; - // TODO: still not finished - final AccountSnapshot postFinalCoinbaseSnapshot = - AccountSnapshot.fromAccount( - minerAccount, - true, - deploymentInfo.number(minerAddress), - deploymentInfo.isDeploying(minerAddress)); + final long coinbaseGasReward = tx.getBesuTransaction().getGasLimit() - senderGasRefund; + final Wei coinbaseFee = Wei.of( + BigInteger.valueOf(tx.getEffectiveGasPrice()) + .multiply(BigInteger.valueOf(coinbaseGasReward))); final AccountFragment.AccountFragmentFactory accountFragmentFactory = - this.factories.accountFragment(); + this.factories.accountFragment(); if (this.txStack.current().statusCode()) { - // if no revert: 2 account rows (sender, coinbase) + 1 tx row + + final Wei senderWeiRefund = Wei.of( + BigInteger.valueOf(senderGasRefund) + .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) ); + + final AccountSnapshot senderAccountSnapshotAfterGasRefund = + senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); + + final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); + + final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = + coinbaseIsSender + ? senderAccountSnapshotAfterGasRefund + : AccountSnapshot.fromAccount( + worldView.get(coinbaseAddress), + coinbaseWarmth, + deploymentInfo.number(coinbaseAddress), + deploymentInfo.isDeploying(coinbaseAddress)); + + + final AccountSnapshot coinbaseSnapshotAfterFeeCollection = + coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee); this.addTraceSection( - new EndTransactionSection( - this, - accountFragmentFactory.make(preFinalFromSnapshot, postFinalFromSnapshot), - accountFragmentFactory.make(preFinalCoinbaseSnapshot, postFinalCoinbaseSnapshot), - TransactionFragment.prepare(this.txStack.current()))); + new TxFinalizationSection( + this, + accountFragmentFactory.make(senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasRefund), + accountFragmentFactory.make(coinbaseSnapshotBeforeFeeCollection, coinbaseSnapshotAfterFeeCollection), + TransactionFragment.prepare(this.txStack.current()))); } else { - // Trace the exceptions of a transaction that could not even start - // TODO: integrate with PCH - // if (this.exceptions == null) { - // this.exceptions = Exceptions.fromOutOfGas(); - // } - // otherwise 4 account rows (sender, coinbase, sender, recipient) + 1 tx row - final Address toAddress = this.transients.tx().getBesuTransaction().getSender(); - final Account toAccount = worldView.get(toAddress); - final AccountSnapshot preFinalToSnapshot = - AccountSnapshot.fromAccount( - toAccount, - true, - deploymentInfo.number(toAddress), - deploymentInfo.isDeploying(toAddress)); - - // TODO: still not finished - final AccountSnapshot postFinalToSnapshot = - AccountSnapshot.fromAccount( - toAccount, - true, - deploymentInfo.number(toAddress), - deploymentInfo.isDeploying(toAddress)); + // SENDER account snapshots + final Wei senderWeiRefund = + Wei.of( + BigInteger + .valueOf(senderGasRefund) + .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) + .add(tx.getBesuTransaction().getValue().getAsBigInteger())); + final AccountSnapshot senderAccountSnapshotAfterGasAndBalanceRefund = + senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); + + // RECIPIENT account snapshots + final boolean recipientIsSender = effectiveToAddress.equals(senderAddress); + final AccountSnapshot effectiveToAccountSnapshotBeforeReimbursingValue = + recipientIsSender + ? senderAccountSnapshotAfterGasAndBalanceRefund + : AccountSnapshot.fromAccount( + worldView.get(effectiveToAddress), + true, + deploymentInfo.number(effectiveToAddress), + deploymentInfo.isDeploying(effectiveToAddress)); + + final AccountSnapshot effectiveToAccountSnapshotAfterReimbursingValue = + effectiveToAccountSnapshotBeforeReimbursingValue.debit((Wei) tx.getBesuTransaction().getValue()); + + // COINBASE account snapshots + final boolean coinbaseIsRecipient = coinbaseAddress.equals(effectiveToAddress); + final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); + + AccountSnapshot coinbaseBeforeFeeCollection = + coinbaseIsRecipient + ? effectiveToAccountSnapshotAfterReimbursingValue + : coinbaseIsSender + ? senderAccountSnapshotAfterGasAndBalanceRefund + : AccountSnapshot.fromAccount( + worldView.get(coinbaseAddress), + coinbaseWarmth, + deploymentInfo.number(coinbaseAddress), + deploymentInfo.isDeploying(coinbaseAddress)); + + AccountSnapshot coinbaseAfterFeeCollection = + coinbaseBeforeFeeCollection.credit(coinbaseFee); + this.addTraceSection( - new EndTransactionSection( + new TxFinalizationSection( this, - accountFragmentFactory.make(preFinalFromSnapshot, postFinalFromSnapshot), - accountFragmentFactory.make(preFinalToSnapshot, postFinalToSnapshot), - accountFragmentFactory.make(preFinalCoinbaseSnapshot, postFinalCoinbaseSnapshot))); + accountFragmentFactory.make(senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasAndBalanceRefund), + accountFragmentFactory.make(effectiveToAccountSnapshotBeforeReimbursingValue, effectiveToAccountSnapshotAfterReimbursingValue), + accountFragmentFactory.make(coinbaseBeforeFeeCollection, coinbaseAfterFeeCollection), + TransactionFragment.prepare(this.txStack.current()))); } } @@ -1257,7 +1287,6 @@ public void traceEndConflation(final WorldView world) { this.romLex.traceEndConflation(world); this.defers.runPostConflation(this, world); - this.txStack.setCodeFragmentIndex(this); for (Module m : this.modules) { if (!m.equals(this.romLex)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/EndTransactionSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/EndTransactionSection.java deleted file mode 100644 index f95adc442e..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/EndTransactionSection.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; - -public class EndTransactionSection extends TraceSection { - public EndTransactionSection(Hub hub, TraceFragment... fragments) { - this.addFragmentsWithoutStack(hub, fragments); - } - - @Override - public void seal(Hub hub) {} -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 277c959975..7964357d06 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -12,6 +12,17 @@ * * SPDX-License-Identifier: Apache-2.0 */ + package net.consensys.linea.zktracer.module.hub.section; -public class TxFinalizationSection {} +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; + +public class TxFinalizationSection extends TraceSection { + public TxFinalizationSection(Hub hub, TraceFragment... fragments) { + this.addFragmentsWithoutStack(hub, fragments); + } + + @Override + public void seal(Hub hub) {} +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java similarity index 87% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index df9da52f79..9514ceb36d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -18,8 +18,8 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -public class TxInitSection extends TraceSection { - public TxInitSection(Hub hub, TraceFragment... chunks) { +public class TxInitializationSection extends TraceSection { + public TxInitializationSection(Hub hub, TraceFragment... chunks) { this.addFragmentsWithoutStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WarmupSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java similarity index 91% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WarmupSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java index 71d86a9fac..1c4af859a7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/WarmupSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java @@ -27,8 +27,8 @@ * contains a succession of {@link AccountFragment } and {@link StorageFragment} representing the * pre-warmed addresses and eventual keys. */ -public class WarmupSection extends TraceSection { - public WarmupSection(Hub hub, List fragments) { +public class TxPrewarmingSection extends TraceSection { + public TxPrewarmingSection(Hub hub, List fragments) { this.addFragmentsWithoutStack(hub, fragments.toArray(new TraceFragment[0])); } } From 09af6623b7148d78b01d5e27d6a3c6d6ed969079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 15:39:56 +0400 Subject: [PATCH 035/461] spotless ^^ --- .../linea/zktracer/module/hub/Hub.java | 101 +++++++++--------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 020c8ec2a1..8573ef1dbe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -15,8 +15,8 @@ package net.consensys.linea.zktracer.module.hub; -import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_REFUND_QUOTIENT; +import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; @@ -42,7 +42,6 @@ import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.bin.Bin; @@ -794,7 +793,7 @@ void processStateExec(MessageFrame frame) { } } - void processStateFinal(WorldView worldView){ + void processStateFinal(WorldView worldView) { this.state.setProcessingPhase(TX_FINAL); this.state.stamps().incrementHubStamp(); @@ -805,7 +804,8 @@ void processStateFinal(WorldView worldView){ final Address coinbaseAddress = tx.getCoinbase(); final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); - final boolean coinbaseWarmth = false; // TODO: get access to coinbase address warmth (still London!) + final boolean coinbaseWarmth = + false; // TODO: get access to coinbase address warmth (still London!) final Account senderAccount = worldView.get(senderAddress); final AccountSnapshot senderAccountSnapshotBeforeRefunds = @@ -815,96 +815,101 @@ void processStateFinal(WorldView worldView){ deploymentInfo.number(senderAddress), deploymentInfo.isDeploying(senderAddress)); - final long gasUsed = tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas(); final long effectiveRefunds = Math.min(this.accruedRefunds(), gasUsed / MAX_REFUND_QUOTIENT); final long senderGasRefund = tx.getLeftoverGas() + effectiveRefunds; final long coinbaseGasReward = tx.getBesuTransaction().getGasLimit() - senderGasRefund; - final Wei coinbaseFee = Wei.of( + final Wei coinbaseFee = + Wei.of( BigInteger.valueOf(tx.getEffectiveGasPrice()) - .multiply(BigInteger.valueOf(coinbaseGasReward))); + .multiply(BigInteger.valueOf(coinbaseGasReward))); final AccountFragment.AccountFragmentFactory accountFragmentFactory = - this.factories.accountFragment(); + this.factories.accountFragment(); if (this.txStack.current().statusCode()) { - final Wei senderWeiRefund = Wei.of( + final Wei senderWeiRefund = + Wei.of( BigInteger.valueOf(senderGasRefund) - .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) ); + .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice()))); final AccountSnapshot senderAccountSnapshotAfterGasRefund = - senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); + senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = - coinbaseIsSender - ? senderAccountSnapshotAfterGasRefund - : AccountSnapshot.fromAccount( - worldView.get(coinbaseAddress), - coinbaseWarmth, - deploymentInfo.number(coinbaseAddress), - deploymentInfo.isDeploying(coinbaseAddress)); - + coinbaseIsSender + ? senderAccountSnapshotAfterGasRefund + : AccountSnapshot.fromAccount( + worldView.get(coinbaseAddress), + coinbaseWarmth, + deploymentInfo.number(coinbaseAddress), + deploymentInfo.isDeploying(coinbaseAddress)); final AccountSnapshot coinbaseSnapshotAfterFeeCollection = - coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee); + coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee); this.addTraceSection( - new TxFinalizationSection( - this, - accountFragmentFactory.make(senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasRefund), - accountFragmentFactory.make(coinbaseSnapshotBeforeFeeCollection, coinbaseSnapshotAfterFeeCollection), - TransactionFragment.prepare(this.txStack.current()))); + new TxFinalizationSection( + this, + accountFragmentFactory.make( + senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasRefund), + accountFragmentFactory.make( + coinbaseSnapshotBeforeFeeCollection, coinbaseSnapshotAfterFeeCollection), + TransactionFragment.prepare(this.txStack.current()))); } else { // SENDER account snapshots final Wei senderWeiRefund = - Wei.of( - BigInteger - .valueOf(senderGasRefund) - .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) - .add(tx.getBesuTransaction().getValue().getAsBigInteger())); + Wei.of( + BigInteger.valueOf(senderGasRefund) + .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) + .add(tx.getBesuTransaction().getValue().getAsBigInteger())); final AccountSnapshot senderAccountSnapshotAfterGasAndBalanceRefund = - senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); + senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); // RECIPIENT account snapshots final boolean recipientIsSender = effectiveToAddress.equals(senderAddress); final AccountSnapshot effectiveToAccountSnapshotBeforeReimbursingValue = - recipientIsSender - ? senderAccountSnapshotAfterGasAndBalanceRefund - : AccountSnapshot.fromAccount( - worldView.get(effectiveToAddress), - true, - deploymentInfo.number(effectiveToAddress), - deploymentInfo.isDeploying(effectiveToAddress)); + recipientIsSender + ? senderAccountSnapshotAfterGasAndBalanceRefund + : AccountSnapshot.fromAccount( + worldView.get(effectiveToAddress), + true, + deploymentInfo.number(effectiveToAddress), + deploymentInfo.isDeploying(effectiveToAddress)); final AccountSnapshot effectiveToAccountSnapshotAfterReimbursingValue = - effectiveToAccountSnapshotBeforeReimbursingValue.debit((Wei) tx.getBesuTransaction().getValue()); + effectiveToAccountSnapshotBeforeReimbursingValue.debit( + (Wei) tx.getBesuTransaction().getValue()); // COINBASE account snapshots final boolean coinbaseIsRecipient = coinbaseAddress.equals(effectiveToAddress); final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); AccountSnapshot coinbaseBeforeFeeCollection = - coinbaseIsRecipient + coinbaseIsRecipient ? effectiveToAccountSnapshotAfterReimbursingValue - : coinbaseIsSender - ? senderAccountSnapshotAfterGasAndBalanceRefund - : AccountSnapshot.fromAccount( - worldView.get(coinbaseAddress), + : coinbaseIsSender + ? senderAccountSnapshotAfterGasAndBalanceRefund + : AccountSnapshot.fromAccount( + worldView.get(coinbaseAddress), coinbaseWarmth, deploymentInfo.number(coinbaseAddress), deploymentInfo.isDeploying(coinbaseAddress)); - AccountSnapshot coinbaseAfterFeeCollection = - coinbaseBeforeFeeCollection.credit(coinbaseFee); + AccountSnapshot coinbaseAfterFeeCollection = coinbaseBeforeFeeCollection.credit(coinbaseFee); this.addTraceSection( new TxFinalizationSection( this, - accountFragmentFactory.make(senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasAndBalanceRefund), - accountFragmentFactory.make(effectiveToAccountSnapshotBeforeReimbursingValue, effectiveToAccountSnapshotAfterReimbursingValue), + accountFragmentFactory.make( + senderAccountSnapshotBeforeRefunds, + senderAccountSnapshotAfterGasAndBalanceRefund), + accountFragmentFactory.make( + effectiveToAccountSnapshotBeforeReimbursingValue, + effectiveToAccountSnapshotAfterReimbursingValue), accountFragmentFactory.make(coinbaseBeforeFeeCollection, coinbaseAfterFeeCollection), TransactionFragment.prepare(this.txStack.current()))); } From ccab9dd35bd689b91604f8383a776f292124481f Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 18:36:04 +0530 Subject: [PATCH 036/461] feat(hub): storage and account type --- .../linea/zktracer/module/hub/Factories.java | 2 +- .../linea/zktracer/module/hub/Hub.java | 17 +++++---- .../hub}/HubProcessingPhase.java | 2 +- .../linea/zktracer/module/hub/State.java | 1 - .../zktracer/module/hub/TransactionStack.java | 1 - .../module/hub/fragment/CommonFragment.java | 2 +- .../{ => account}/AccountFragment.java | 3 +- .../fragment/account/AccountFragmentType.java | 23 ++++++++++++ .../{ => storage}/StorageFragment.java | 37 +++++++++---------- .../fragment/storage/StorageFragmentType.java | 21 +++++++++++ .../module/hub/section/CreateSection.java | 2 +- .../module/hub/section/NoCodeCallSection.java | 2 +- .../hub/section/SmartContractCallSection.java | 2 +- .../hub/section/TxPrewarmingSection.java | 4 +- .../zktracer/module/hub/transients/Tx.java | 2 +- 15 files changed, 83 insertions(+), 38 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/{types => module/hub}/HubProcessingPhase.java (93%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/{ => account}/AccountFragment.java (98%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/{ => storage}/StorageFragment.java (74%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragmentType.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java index 4f2ee33aaf..792c68dafe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java @@ -17,7 +17,7 @@ import lombok.Getter; import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.fragment.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; /** Contain factories for modules requiring access to longer-lived data. */ @Accessors(fluent = true) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 8573ef1dbe..5ab0a0bc63 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -16,15 +16,15 @@ package net.consensys.linea.zktracer.module.hub; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_REFUND_QUOTIENT; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; -import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_EXEC; -import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_FINAL; -import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_INIT; -import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_SKIP; -import static net.consensys.linea.zktracer.types.HubProcessingPhase.TX_WARM; import java.math.BigInteger; import java.nio.MappedByteBuffer; @@ -54,8 +54,10 @@ import net.consensys.linea.zktracer.module.ext.Ext; import net.consensys.linea.zktracer.module.hub.defer.*; import net.consensys.linea.zktracer.module.hub.fragment.*; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.section.*; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; @@ -1461,7 +1463,8 @@ void traceOperation(MessageFrame frame) { default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); } } - case STORAGE -> { + case STORAGE -> { // TODO: + /* Address address = this.currentFrame().accountAddress(); EWord key = EWord.of(frame.getStackItem(0)); switch (this.currentFrame().opCode()) { @@ -1498,7 +1501,7 @@ void traceOperation(MessageFrame frame) { true))); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); - } + } */ } case CREATE -> { Address myAddress = this.currentFrame().accountAddress(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/HubProcessingPhase.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/types/HubProcessingPhase.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java index f851ab2df2..0a2ac67536 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/HubProcessingPhase.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.types; +package net.consensys.linea.zktracer.module.hub; public enum HubProcessingPhase { TX_EXEC, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index e33ce93ca9..53f6cf9279 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -25,7 +25,6 @@ import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.State.TxState.Stamps; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; -import net.consensys.linea.zktracer.types.HubProcessingPhase; public class State implements StackedContainer { private final Deque state = new ArrayDeque<>(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 4c407fe133..74fc821c0a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -30,7 +30,6 @@ import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; -import net.consensys.linea.zktracer.types.HubProcessingPhase; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Transaction; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index fbf608053a..2a5e4c39b5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -22,6 +22,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; @@ -30,7 +31,6 @@ import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.HubProcessingPhase; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.worldstate.WorldView; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 45c807cf87..4f57b4c505 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment; +package net.consensys.linea.zktracer.module.hub.fragment.account; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.Conversions.bytesToLong; @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.defer.PostConflationDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java new file mode 100644 index 0000000000..7331a127f6 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java @@ -0,0 +1,23 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.account; + +public enum AccountFragmentType { + STANDARD, + REVERT_WITH_CURRENT, + REVERT_WITH_CHILD, + SELF_DESTRUCT +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java similarity index 74% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 6dba76deac..86cd59a726 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -13,30 +13,29 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment; +package net.consensys.linea.zktracer.module.hub.fragment.storage; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; -/** - * @param address target storage address - * @param deploymentNumber storage account deployment number - * @param key target storage slot - * @param valOrig value @key at the beginning of *transaction* - * @param valCurr value @key at the beginning of *opcode* - */ -public record StorageFragment( - Address address, - int deploymentNumber, - EWord key, - EWord valOrig, - EWord valCurr, - EWord valNext, - boolean oldWarmth, - boolean newWarmth) - implements TraceFragment { - @Override +@RequiredArgsConstructor +@Getter +public final class StorageFragment implements TraceFragment { + @Setter private StorageFragmentType type; + private final Address address; + private final int deploymentNumber; + private final EWord key; + private final EWord valOrig; + private final EWord valCurr; + private final EWord valNext; + private final boolean oldWarmth; + private final boolean newWarmth; + public Trace trace(Trace trace) { final EWord eAddress = EWord.of(address); return trace diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragmentType.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragmentType.java new file mode 100644 index 0000000000..d9ade4a4c1 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragmentType.java @@ -0,0 +1,21 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.storage; + +public enum StorageFragmentType { + STANDARD, + REVERT_WITH_CURRENT +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 49d0278453..85e894b155 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -23,8 +23,8 @@ import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; -import net.consensys.linea.zktracer.module.hub.fragment.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java index d76b801ea0..52cfd47f4d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java @@ -23,9 +23,9 @@ import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; -import net.consensys.linea.zktracer.module.hub.fragment.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java index eaf5600a65..ff2c608a9b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java @@ -20,8 +20,8 @@ import net.consensys.linea.zktracer.module.hub.defer.NextContextDefer; import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.fragment.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java index 1c4af859a7..25f539404c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java @@ -18,9 +18,9 @@ import java.util.List; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.StorageFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; /** * A warmup section is generated if a transaction features pre-warmed addresses and/or keys. It diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java index 1bbcf05d17..156415eab2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java @@ -25,7 +25,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.container.StackedContainer; -import net.consensys.linea.zktracer.types.HubProcessingPhase; +import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Transaction; From df8765a1b3cffe901e465323e4c155e29b51aee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 17:02:57 +0400 Subject: [PATCH 037/461] coinbase warmth remains the same in "post credit" snapshot --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 5ab0a0bc63..05f91b36a7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -852,7 +852,7 @@ void processStateFinal(WorldView worldView) { deploymentInfo.isDeploying(coinbaseAddress)); final AccountSnapshot coinbaseSnapshotAfterFeeCollection = - coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee); + coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); this.addTraceSection( new TxFinalizationSection( this, @@ -901,7 +901,7 @@ void processStateFinal(WorldView worldView) { deploymentInfo.number(coinbaseAddress), deploymentInfo.isDeploying(coinbaseAddress)); - AccountSnapshot coinbaseAfterFeeCollection = coinbaseBeforeFeeCollection.credit(coinbaseFee); + AccountSnapshot coinbaseAfterFeeCollection = coinbaseBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); this.addTraceSection( new TxFinalizationSection( From f2c964132492c5e7a0c464abae92993a4712a48e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 18:41:39 +0530 Subject: [PATCH 038/461] style: spotless --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 05f91b36a7..af5b6fd1f8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -901,7 +901,8 @@ void processStateFinal(WorldView worldView) { deploymentInfo.number(coinbaseAddress), deploymentInfo.isDeploying(coinbaseAddress)); - AccountSnapshot coinbaseAfterFeeCollection = coinbaseBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); + AccountSnapshot coinbaseAfterFeeCollection = + coinbaseBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); this.addTraceSection( new TxFinalizationSection( From 63fdc55fbb92c3b5deff324f938245765f3e8a79 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 18:57:42 +0530 Subject: [PATCH 039/461] feat: add hub constants --- .../linea/zktracer/module/hub/Trace.java | 2919 +++++++---------- gradle/trace-files.gradle | 6 +- 2 files changed, 1235 insertions(+), 1690 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 1fc62bee6e..1a0434ce1a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub; +import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -30,6 +31,10 @@ * Please DO NOT ATTEMPT TO MODIFY this code directly. */ public class Trace { + public static final int DOM_SUB_STAMP_OFFSET___REVERT = 0x8; + public static final int DOM_SUB_STAMP_OFFSET___SELFDESTRUCT = 0xc; + public static final int MULTIPLIER___DOM_SUB_STAMPS = 0x10; + public static final int MULTIPLIER___STACK_HEIGHT = 0x8; private final BitSet filled = new BitSet(); private int currentLine = 0; @@ -37,32 +42,24 @@ public class Trace { private final MappedByteBuffer absoluteTransactionNumber; private final MappedByteBuffer accFinal; private final MappedByteBuffer accFirst; - private final MappedByteBuffer - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; - private final MappedByteBuffer - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; + private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; private final MappedByteBuffer alpha; - private final MappedByteBuffer - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; - private final MappedByteBuffer - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; + private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; + private final MappedByteBuffer balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer batchNumber; private final MappedByteBuffer callDataOffsetXorMmuSize; private final MappedByteBuffer callDataSizeXorMmuSrcId; private final MappedByteBuffer callStackDepth; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; + private final MappedByteBuffer codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; private final MappedByteBuffer codeHashHiNewXorExpData5XorValueCurrLoXorValue; - private final MappedByteBuffer - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorValueNextLo; private final MappedByteBuffer codeHashLoXorMmuLimb1XorValueNextHi; - private final MappedByteBuffer - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; - private final MappedByteBuffer - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; + private final MappedByteBuffer codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; + private final MappedByteBuffer codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; private final MappedByteBuffer conAgain; private final MappedByteBuffer conFirst; private final MappedByteBuffer contextGetsReverted; @@ -78,51 +75,37 @@ public class Trace { private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; - private final MappedByteBuffer - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; private final MappedByteBuffer delta; - private final MappedByteBuffer - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; - private final MappedByteBuffer - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; - private final MappedByteBuffer - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; - private final MappedByteBuffer - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; - private final MappedByteBuffer - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; - private final MappedByteBuffer - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; + private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; + private final MappedByteBuffer deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; + private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; + private final MappedByteBuffer deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; + private final MappedByteBuffer deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; + private final MappedByteBuffer deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; - private final MappedByteBuffer - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; - private final MappedByteBuffer - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; + private final MappedByteBuffer existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; + private final MappedByteBuffer existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; - private final MappedByteBuffer - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; - private final MappedByteBuffer - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; + private final MappedByteBuffer hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; + private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; private final MappedByteBuffer hashInfoStamp; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; - private final MappedByteBuffer - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; + private final MappedByteBuffer isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; private final MappedByteBuffer logInfoStamp; - private final MappedByteBuffer - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; - private final MappedByteBuffer - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; + private final MappedByteBuffer markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; + private final MappedByteBuffer markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -224,7 +207,6 @@ public class Trace { private final MappedByteBuffer subStamp; private final MappedByteBuffer sux; private final MappedByteBuffer swapFlag; - private final MappedByteBuffer transactionReverts; private final MappedByteBuffer trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag; private final MappedByteBuffer trmRawAddressHiXorMxpOffset1Lo; private final MappedByteBuffer twoLineInstruction; @@ -243,49 +225,24 @@ static List headers(int length) { new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), - new ColumnHeader( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", - 8, - length), - new ColumnHeader( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", 8, length), + new ColumnHeader("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 32, length), new ColumnHeader("hub.ALPHA", 1, length), - new ColumnHeader( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", - 32, - length), - new ColumnHeader( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 32, length), + new ColumnHeader("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 32, length), new ColumnHeader("hub.BATCH_NUMBER", 4, length), new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), - new ColumnHeader( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", - 8, - length), - new ColumnHeader( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), - new ColumnHeader( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", 8, length), + new ColumnHeader("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), + new ColumnHeader("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), - new ColumnHeader( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", - 8, - length), - new ColumnHeader( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", - 8, - length), + new ColumnHeader("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", 8, length), + new ColumnHeader("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", 8, length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), @@ -299,83 +256,39 @@ static List headers(int length) { new ColumnHeader("hub.COUNTER_NSR", 2, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX", 1, length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", - 1, - length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), new ColumnHeader("hub.DELTA", 1, length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", - 1, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", - 1, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", - 1, - length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", 8, length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", 8, length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", 8, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", 1, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", 1, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", 1, length), new ColumnHeader("hub.DOM_STAMP", 8, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), - new ColumnHeader( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", - 1, - length), - new ColumnHeader( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", - 1, - length), + new ColumnHeader("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", 1, length), + new ColumnHeader("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", 1, length), new ColumnHeader("hub.GAS_ACTUAL", 8, length), new ColumnHeader("hub.GAS_COST", 32, length), new ColumnHeader("hub.GAS_EXPECTED", 8, length), new ColumnHeader("hub.GAS_LIMIT", 32, length), new ColumnHeader("hub.GAS_NEXT", 8, length), new ColumnHeader("hub.GAS_PRICE", 32, length), - new ColumnHeader( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", - 1, - length), - new ColumnHeader( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", - 1, - length), + new ColumnHeader("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", 1, length), + new ColumnHeader("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), new ColumnHeader("hub.HEIGHT", 2, length), new ColumnHeader("hub.HEIGHT_NEW", 2, length), new ColumnHeader("hub.HUB_STAMP", 8, length), new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), new ColumnHeader("hub.INSTRUCTION", 32, length), - new ColumnHeader( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", - 1, - length), + new ColumnHeader("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", 1, length), new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", - 1, - length), - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", - 1, - length), + new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", 1, length), + new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", 1, length), new ColumnHeader("hub.MMU_STAMP", 8, length), new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), @@ -389,8 +302,7 @@ static List headers(int length) { new ColumnHeader("hub.NB_REMOVED", 1, length), new ColumnHeader("hub.NON_STACK_ROWS", 2, length), new ColumnHeader("hub.NONCE", 32, length), - new ColumnHeader( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), + new ColumnHeader("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), new ColumnHeader("hub.OOB_DATA_1", 32, length), new ColumnHeader("hub.OOB_DATA_2", 32, length), @@ -434,34 +346,20 @@ static List headers(int length) { new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), - new ColumnHeader( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", - 1, - length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), + new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), + new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + new ColumnHeader("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), + new ColumnHeader("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), + new ColumnHeader("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", 1, length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), - new ColumnHeader( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), - new ColumnHeader( - "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", - 1, - length), + new ColumnHeader("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), @@ -492,9 +390,7 @@ static List headers(int length) { new ColumnHeader("hub.SUB_STAMP", 8, length), new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), - new ColumnHeader("hub.TRANSACTION_REVERTS", 1, length), - new ColumnHeader( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + new ColumnHeader("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -503,10 +399,7 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", - 1, - length), + new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -515,36 +408,24 @@ public Trace(List buffers) { this.absoluteTransactionNumber = buffers.get(0); this.accFinal = buffers.get(1); this.accFirst = buffers.get(2); - this - .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = - buffers.get(3); - this - .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = - buffers.get(4); + this.addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = buffers.get(3); + this.addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(4); this.alpha = buffers.get(5); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = - buffers.get(6); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = - buffers.get(7); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(6); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = buffers.get(7); this.batchNumber = buffers.get(8); this.callDataOffsetXorMmuSize = buffers.get(9); this.callDataSizeXorMmuSrcId = buffers.get(10); this.callStackDepth = buffers.get(11); this.callerContextNumber = buffers.get(12); this.codeFragmentIndex = buffers.get(13); - this - .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = - buffers.get(14); + this.codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = buffers.get(14); this.codeHashHiNewXorExpData5XorValueCurrLoXorValue = buffers.get(15); - this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = - buffers.get(16); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); this.codeHashLoNewXorMmuLimb2XorValueNextLo = buffers.get(17); this.codeHashLoXorMmuLimb1XorValueNextHi = buffers.get(18); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = - buffers.get(19); - this - .codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = - buffers.get(20); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = buffers.get(19); + this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = buffers.get(20); this.conAgain = buffers.get(21); this.conFirst = buffers.get(22); this.contextGetsReverted = buffers.get(23); @@ -563,48 +444,34 @@ public Trace(List buffers) { this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); this.delta = buffers.get(38); - this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = - buffers.get(39); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = buffers.get(39); this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); - this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = - buffers.get(41); - this - .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = - buffers.get(42); - this - .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = - buffers.get(43); - this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = - buffers.get(44); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = buffers.get(41); + this.deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = buffers.get(42); + this.deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = buffers.get(43); + this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = buffers.get(44); this.domStamp = buffers.get(45); this.exceptionAhoy = buffers.get(46); - this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = - buffers.get(47); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = - buffers.get(48); + this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = buffers.get(47); + this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = buffers.get(48); this.gasActual = buffers.get(49); this.gasCost = buffers.get(50); this.gasExpected = buffers.get(51); this.gasLimit = buffers.get(52); this.gasNext = buffers.get(53); this.gasPrice = buffers.get(54); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = - buffers.get(55); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = - buffers.get(56); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = buffers.get(55); + this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = buffers.get(56); this.hashInfoStamp = buffers.get(57); this.height = buffers.get(58); this.heightNew = buffers.get(59); this.hubStamp = buffers.get(60); this.hubStampTransactionEnd = buffers.get(61); this.instruction = buffers.get(62); - this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = - buffers.get(63); + this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = buffers.get(63); this.logInfoStamp = buffers.get(64); - this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = - buffers.get(65); - this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = - buffers.get(66); + this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = buffers.get(65); + this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = buffers.get(66); this.mmuStamp = buffers.get(67); this.mxpOffset2Hi = buffers.get(68); this.mxpOffset2Lo = buffers.get(69); @@ -706,19 +573,18 @@ public Trace(List buffers) { this.subStamp = buffers.get(165); this.sux = buffers.get(166); this.swapFlag = buffers.get(167); - this.transactionReverts = buffers.get(168); - this.trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag = buffers.get(169); - this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(170); - this.twoLineInstruction = buffers.get(171); - this.txExec = buffers.get(172); - this.txFinl = buffers.get(173); - this.txInit = buffers.get(174); - this.txSkip = buffers.get(175); - this.txWarm = buffers.get(176); - this.txnFlag = buffers.get(177); - this.warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag = buffers.get(178); - this.warmthXorCreateExceptionXorHaltFlag = buffers.get(179); - this.wcpFlag = buffers.get(180); + this.trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag = buffers.get(168); + this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(169); + this.twoLineInstruction = buffers.get(170); + this.txExec = buffers.get(171); + this.txFinl = buffers.get(172); + this.txInit = buffers.get(173); + this.txSkip = buffers.get(174); + this.txWarm = buffers.get(175); + this.txnFlag = buffers.get(176); + this.warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag = buffers.get(177); + this.warmthXorCreateExceptionXorHaltFlag = buffers.get(178); + this.wcpFlag = buffers.get(179); } public int size() { @@ -742,10 +608,10 @@ public Trace absoluteTransactionNumber(final int b) { } public Trace accFinal(final Boolean b) { - if (filled.get(47)) { + if (filled.get(46)) { throw new IllegalStateException("hub.acc_FINAL already set"); } else { - filled.set(47); + filled.set(46); } accFinal.put((byte) (b ? 1 : 0)); @@ -754,10 +620,10 @@ public Trace accFinal(final Boolean b) { } public Trace accFirst(final Boolean b) { - if (filled.get(48)) { + if (filled.get(47)) { throw new IllegalStateException("hub.acc_FIRST already set"); } else { - filled.set(48); + filled.set(47); } accFirst.put((byte) (b ? 1 : 0)); @@ -802,10 +668,10 @@ public Trace codeFragmentIndex(final long b) { } public Trace conAgain(final Boolean b) { - if (filled.get(49)) { + if (filled.get(48)) { throw new IllegalStateException("hub.con_AGAIN already set"); } else { - filled.set(49); + filled.set(48); } conAgain.put((byte) (b ? 1 : 0)); @@ -814,10 +680,10 @@ public Trace conAgain(final Boolean b) { } public Trace conFirst(final Boolean b) { - if (filled.get(50)) { + if (filled.get(49)) { throw new IllegalStateException("hub.con_FIRST already set"); } else { - filled.set(50); + filled.set(49); } conFirst.put((byte) (b ? 1 : 0)); @@ -1118,107 +984,98 @@ public Trace nonStackRows(final short b) { } public Trace pAccountAddressHi(final long b) { - if (filled.get(107)) { + if (filled.get(106)) { throw new IllegalStateException("hub.account/ADDRESS_HI already set"); } else { - filled.set(107); + filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } public Trace pAccountAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(131)) { throw new IllegalStateException("hub.account/ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(131); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pAccountBalance(final Bytes b) { - if (filled.get(133)) { + if (filled.get(132)) { throw new IllegalStateException("hub.account/BALANCE already set"); } else { - filled.set(133); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pAccountBalanceNew(final Bytes b) { - if (filled.get(134)) { + if (filled.get(133)) { throw new IllegalStateException("hub.account/BALANCE_NEW already set"); } else { - filled.set(134); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } public Trace pAccountCodeFragmentIndex(final long b) { - if (filled.get(108)) { + if (filled.get(107)) { throw new IllegalStateException("hub.account/CODE_FRAGMENT_INDEX already set"); } else { - filled.set(108); + filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } public Trace pAccountCodeHashHi(final Bytes b) { - if (filled.get(135)) { + if (filled.get(134)) { throw new IllegalStateException("hub.account/CODE_HASH_HI already set"); } else { - filled.set(135); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pAccountCodeHashHiNew(final Bytes b) { - if (filled.get(136)) { + if (filled.get(135)) { throw new IllegalStateException("hub.account/CODE_HASH_HI_NEW already set"); } else { - filled.set(136); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); @@ -1231,10 +1088,10 @@ public Trace pAccountCodeHashHiNew(final Bytes b) { } public Trace pAccountCodeHashLo(final Bytes b) { - if (filled.get(137)) { + if (filled.get(136)) { throw new IllegalStateException("hub.account/CODE_HASH_LO already set"); } else { - filled.set(137); + filled.set(136); } final byte[] bs = b.toArrayUnsafe(); @@ -1247,10 +1104,10 @@ public Trace pAccountCodeHashLo(final Bytes b) { } public Trace pAccountCodeHashLoNew(final Bytes b) { - if (filled.get(138)) { + if (filled.get(137)) { throw new IllegalStateException("hub.account/CODE_HASH_LO_NEW already set"); } else { - filled.set(138); + filled.set(137); } final byte[] bs = b.toArrayUnsafe(); @@ -1263,23 +1120,22 @@ public Trace pAccountCodeHashLoNew(final Bytes b) { } public Trace pAccountCodeSize(final long b) { - if (filled.get(109)) { + if (filled.get(108)) { throw new IllegalStateException("hub.account/CODE_SIZE already set"); } else { - filled.set(109); + filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } public Trace pAccountCodeSizeNew(final long b) { - if (filled.get(110)) { + if (filled.get(109)) { throw new IllegalStateException("hub.account/CODE_SIZE_NEW already set"); } else { - filled.set(110); + filled.set(109); } codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); @@ -1288,10 +1144,10 @@ public Trace pAccountCodeSizeNew(final long b) { } public Trace pAccountDeploymentNumber(final long b) { - if (filled.get(111)) { + if (filled.get(110)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER already set"); } else { - filled.set(111); + filled.set(110); } deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); @@ -1300,10 +1156,10 @@ public Trace pAccountDeploymentNumber(final long b) { } public Trace pAccountDeploymentNumberInfty(final long b) { - if (filled.get(112)) { + if (filled.get(111)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(112); + filled.set(111); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); @@ -1312,10 +1168,10 @@ public Trace pAccountDeploymentNumberInfty(final long b) { } public Trace pAccountDeploymentNumberNew(final long b) { - if (filled.get(113)) { + if (filled.get(112)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_NEW already set"); } else { - filled.set(113); + filled.set(112); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); @@ -1324,140 +1180,130 @@ public Trace pAccountDeploymentNumberNew(final long b) { } public Trace pAccountDeploymentStatus(final Boolean b) { - if (filled.get(53)) { + if (filled.get(52)) { throw new IllegalStateException("hub.account/DEPLOYMENT_STATUS already set"); } else { - filled.set(53); + filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountDeploymentStatusInfty(final Boolean b) { - if (filled.get(54)) { + if (filled.get(53)) { throw new IllegalStateException("hub.account/DEPLOYMENT_STATUS_INFTY already set"); } else { - filled.set(54); + filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountDeploymentStatusNew(final Boolean b) { - if (filled.get(55)) { + if (filled.get(54)) { throw new IllegalStateException("hub.account/DEPLOYMENT_STATUS_NEW already set"); } else { - filled.set(55); + filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountExists(final Boolean b) { - if (filled.get(56)) { + if (filled.get(55)) { throw new IllegalStateException("hub.account/EXISTS already set"); } else { - filled.set(56); + filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountExistsNew(final Boolean b) { - if (filled.get(57)) { + if (filled.get(56)) { throw new IllegalStateException("hub.account/EXISTS_NEW already set"); } else { - filled.set(57); + filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountHasCode(final Boolean b) { - if (filled.get(58)) { + if (filled.get(57)) { throw new IllegalStateException("hub.account/HAS_CODE already set"); } else { - filled.set(58); + filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountHasCodeNew(final Boolean b) { - if (filled.get(59)) { + if (filled.get(58)) { throw new IllegalStateException("hub.account/HAS_CODE_NEW already set"); } else { - filled.set(59); + filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountIsPrecompile(final Boolean b) { - if (filled.get(60)) { + if (filled.get(59)) { throw new IllegalStateException("hub.account/IS_PRECOMPILE already set"); } else { - filled.set(60); + filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountMarkedForSelfdestruct(final Boolean b) { - if (filled.get(61)) { + if (filled.get(60)) { throw new IllegalStateException("hub.account/MARKED_FOR_SELFDESTRUCT already set"); } else { - filled.set(61); + filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { - if (filled.get(62)) { + if (filled.get(61)) { throw new IllegalStateException("hub.account/MARKED_FOR_SELFDESTRUCT_NEW already set"); } else { - filled.set(62); + filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountNonce(final Bytes b) { - if (filled.get(123)) { + if (filled.get(122)) { throw new IllegalStateException("hub.account/NONCE already set"); } else { - filled.set(123); + filled.set(122); } final byte[] bs = b.toArrayUnsafe(); @@ -1470,10 +1316,10 @@ public Trace pAccountNonce(final Bytes b) { } public Trace pAccountNonceNew(final Bytes b) { - if (filled.get(124)) { + if (filled.get(123)) { throw new IllegalStateException("hub.account/NONCE_NEW already set"); } else { - filled.set(124); + filled.set(123); } final byte[] bs = b.toArrayUnsafe(); @@ -1486,10 +1332,10 @@ public Trace pAccountNonceNew(final Bytes b) { } public Trace pAccountRlpaddrDepAddrHi(final long b) { - if (filled.get(114)) { + if (filled.get(113)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_HI already set"); } else { - filled.set(114); + filled.set(113); } rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); @@ -1498,10 +1344,10 @@ public Trace pAccountRlpaddrDepAddrHi(final long b) { } public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { - if (filled.get(139)) { + if (filled.get(138)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_LO already set"); } else { - filled.set(139); + filled.set(138); } final byte[] bs = b.toArrayUnsafe(); @@ -1514,10 +1360,10 @@ public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { } public Trace pAccountRlpaddrFlag(final Boolean b) { - if (filled.get(63)) { + if (filled.get(62)) { throw new IllegalStateException("hub.account/RLPADDR_FLAG already set"); } else { - filled.set(63); + filled.set(62); } rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); @@ -1526,10 +1372,10 @@ public Trace pAccountRlpaddrFlag(final Boolean b) { } public Trace pAccountRlpaddrKecHi(final Bytes b) { - if (filled.get(140)) { + if (filled.get(139)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_HI already set"); } else { - filled.set(140); + filled.set(139); } final byte[] bs = b.toArrayUnsafe(); @@ -1542,10 +1388,10 @@ public Trace pAccountRlpaddrKecHi(final Bytes b) { } public Trace pAccountRlpaddrKecLo(final Bytes b) { - if (filled.get(141)) { + if (filled.get(140)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_LO already set"); } else { - filled.set(141); + filled.set(140); } final byte[] bs = b.toArrayUnsafe(); @@ -1558,10 +1404,10 @@ public Trace pAccountRlpaddrKecLo(final Bytes b) { } public Trace pAccountRlpaddrRecipe(final Boolean b) { - if (filled.get(64)) { + if (filled.get(63)) { throw new IllegalStateException("hub.account/RLPADDR_RECIPE already set"); } else { - filled.set(64); + filled.set(63); } rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); @@ -1570,10 +1416,10 @@ public Trace pAccountRlpaddrRecipe(final Boolean b) { } public Trace pAccountRlpaddrSaltHi(final Bytes b) { - if (filled.get(142)) { + if (filled.get(141)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_HI already set"); } else { - filled.set(142); + filled.set(141); } final byte[] bs = b.toArrayUnsafe(); @@ -1586,10 +1432,10 @@ public Trace pAccountRlpaddrSaltHi(final Bytes b) { } public Trace pAccountRlpaddrSaltLo(final Bytes b) { - if (filled.get(143)) { + if (filled.get(142)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_LO already set"); } else { - filled.set(143); + filled.set(142); } final byte[] bs = b.toArrayUnsafe(); @@ -1602,10 +1448,10 @@ public Trace pAccountRlpaddrSaltLo(final Bytes b) { } public Trace pAccountRomlexFlag(final Boolean b) { - if (filled.get(65)) { + if (filled.get(64)) { throw new IllegalStateException("hub.account/ROMLEX_FLAG already set"); } else { - filled.set(65); + filled.set(64); } romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); @@ -1614,10 +1460,10 @@ public Trace pAccountRomlexFlag(final Boolean b) { } public Trace pAccountTrmFlag(final Boolean b) { - if (filled.get(66)) { + if (filled.get(65)) { throw new IllegalStateException("hub.account/TRM_FLAG already set"); } else { - filled.set(66); + filled.set(65); } trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); @@ -1626,10 +1472,10 @@ public Trace pAccountTrmFlag(final Boolean b) { } public Trace pAccountTrmRawAddressHi(final Bytes b) { - if (filled.get(144)) { + if (filled.get(143)) { throw new IllegalStateException("hub.account/TRM_RAW_ADDRESS_HI already set"); } else { - filled.set(144); + filled.set(143); } final byte[] bs = b.toArrayUnsafe(); @@ -1642,10 +1488,10 @@ public Trace pAccountTrmRawAddressHi(final Bytes b) { } public Trace pAccountWarmth(final Boolean b) { - if (filled.get(67)) { + if (filled.get(66)) { throw new IllegalStateException("hub.account/WARMTH already set"); } else { - filled.set(67); + filled.set(66); } warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); @@ -1654,10 +1500,10 @@ public Trace pAccountWarmth(final Boolean b) { } public Trace pAccountWarmthNew(final Boolean b) { - if (filled.get(68)) { + if (filled.get(67)) { throw new IllegalStateException("hub.account/WARMTH_NEW already set"); } else { - filled.set(68); + filled.set(67); } warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); @@ -1666,85 +1512,78 @@ public Trace pAccountWarmthNew(final Boolean b) { } public Trace pContextAccountAddressHi(final long b) { - if (filled.get(107)) { + if (filled.get(106)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_HI already set"); } else { - filled.set(107); + filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } public Trace pContextAccountAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(131)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(131); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pContextAccountDeploymentNumber(final long b) { - if (filled.get(108)) { + if (filled.get(107)) { throw new IllegalStateException("hub.context/ACCOUNT_DEPLOYMENT_NUMBER already set"); } else { - filled.set(108); + filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } public Trace pContextByteCodeAddressHi(final long b) { - if (filled.get(109)) { + if (filled.get(108)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_HI already set"); } else { - filled.set(109); + filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } public Trace pContextByteCodeAddressLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(132)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_LO already set"); } else { - filled.set(133); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pContextByteCodeCodeFragmentIndex(final long b) { - if (filled.get(110)) { + if (filled.get(109)) { throw new IllegalStateException("hub.context/BYTE_CODE_CODE_FRAGMENT_INDEX already set"); } else { - filled.set(110); + filled.set(109); } codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); @@ -1753,10 +1592,10 @@ public Trace pContextByteCodeCodeFragmentIndex(final long b) { } public Trace pContextByteCodeDeploymentNumber(final long b) { - if (filled.get(111)) { + if (filled.get(110)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_NUMBER already set"); } else { - filled.set(111); + filled.set(110); } deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); @@ -1765,10 +1604,10 @@ public Trace pContextByteCodeDeploymentNumber(final long b) { } public Trace pContextByteCodeDeploymentStatus(final long b) { - if (filled.get(112)) { + if (filled.get(111)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_STATUS already set"); } else { - filled.set(112); + filled.set(111); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); @@ -1777,10 +1616,10 @@ public Trace pContextByteCodeDeploymentStatus(final long b) { } public Trace pContextCallDataContextNumber(final long b) { - if (filled.get(114)) { + if (filled.get(113)) { throw new IllegalStateException("hub.context/CALL_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(114); + filled.set(113); } rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); @@ -1789,10 +1628,10 @@ public Trace pContextCallDataContextNumber(final long b) { } public Trace pContextCallDataOffset(final long b) { - if (filled.get(115)) { + if (filled.get(114)) { throw new IllegalStateException("hub.context/CALL_DATA_OFFSET already set"); } else { - filled.set(115); + filled.set(114); } callDataOffsetXorMmuSize.putLong(b); @@ -1801,10 +1640,10 @@ public Trace pContextCallDataOffset(final long b) { } public Trace pContextCallDataSize(final long b) { - if (filled.get(116)) { + if (filled.get(115)) { throw new IllegalStateException("hub.context/CALL_DATA_SIZE already set"); } else { - filled.set(116); + filled.set(115); } callDataSizeXorMmuSrcId.putLong(b); @@ -1813,10 +1652,10 @@ public Trace pContextCallDataSize(final long b) { } public Trace pContextCallStackDepth(final short b) { - if (filled.get(106)) { + if (filled.get(105)) { throw new IllegalStateException("hub.context/CALL_STACK_DEPTH already set"); } else { - filled.set(106); + filled.set(105); } callStackDepth.putShort(b); @@ -1825,27 +1664,26 @@ public Trace pContextCallStackDepth(final short b) { } public Trace pContextCallValue(final Bytes b) { - if (filled.get(135)) { + if (filled.get(134)) { throw new IllegalStateException("hub.context/CALL_VALUE already set"); } else { - filled.set(135); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pContextCallerAddressHi(final long b) { - if (filled.get(113)) { + if (filled.get(112)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_HI already set"); } else { - filled.set(113); + filled.set(112); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); @@ -1854,28 +1692,26 @@ public Trace pContextCallerAddressHi(final long b) { } public Trace pContextCallerAddressLo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(133)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_LO already set"); } else { - filled.set(134); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } public Trace pContextContextNumber(final long b) { - if (filled.get(117)) { + if (filled.get(116)) { throw new IllegalStateException("hub.context/CONTEXT_NUMBER already set"); } else { - filled.set(117); + filled.set(116); } contextNumberXorMmuTgtId.putLong(b); @@ -1884,36 +1720,34 @@ public Trace pContextContextNumber(final long b) { } public Trace pContextIsRoot(final Boolean b) { - if (filled.get(53)) { + if (filled.get(52)) { throw new IllegalStateException("hub.context/IS_ROOT already set"); } else { - filled.set(53); + filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pContextIsStatic(final Boolean b) { - if (filled.get(54)) { + if (filled.get(53)) { throw new IllegalStateException("hub.context/IS_STATIC already set"); } else { - filled.set(54); + filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pContextReturnAtCapacity(final long b) { - if (filled.get(118)) { + if (filled.get(117)) { throw new IllegalStateException("hub.context/RETURN_AT_CAPACITY already set"); } else { - filled.set(118); + filled.set(117); } returnAtCapacityXorMxpInst.putLong(b); @@ -1922,10 +1756,10 @@ public Trace pContextReturnAtCapacity(final long b) { } public Trace pContextReturnAtOffset(final long b) { - if (filled.get(119)) { + if (filled.get(118)) { throw new IllegalStateException("hub.context/RETURN_AT_OFFSET already set"); } else { - filled.set(119); + filled.set(118); } returnAtOffsetXorOobInst.putLong(b); @@ -1934,10 +1768,10 @@ public Trace pContextReturnAtOffset(final long b) { } public Trace pContextReturnDataContextNumber(final long b) { - if (filled.get(120)) { + if (filled.get(119)) { throw new IllegalStateException("hub.context/RETURN_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(120); + filled.set(119); } returnDataContextNumberXorStpGasStipend.putLong(b); @@ -1946,10 +1780,10 @@ public Trace pContextReturnDataContextNumber(final long b) { } public Trace pContextReturnDataOffset(final long b) { - if (filled.get(121)) { + if (filled.get(120)) { throw new IllegalStateException("hub.context/RETURN_DATA_OFFSET already set"); } else { - filled.set(121); + filled.set(120); } returnDataOffsetXorStpInstruction.putLong(b); @@ -1958,10 +1792,10 @@ public Trace pContextReturnDataOffset(final long b) { } public Trace pContextReturnDataSize(final long b) { - if (filled.get(122)) { + if (filled.get(121)) { throw new IllegalStateException("hub.context/RETURN_DATA_SIZE already set"); } else { - filled.set(122); + filled.set(121); } returnDataSize.putLong(b); @@ -1970,120 +1804,110 @@ public Trace pContextReturnDataSize(final long b) { } public Trace pContextUpdate(final Boolean b) { - if (filled.get(55)) { + if (filled.get(54)) { throw new IllegalStateException("hub.context/UPDATE already set"); } else { - filled.set(55); + filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscCcrsStamp(final long b) { - if (filled.get(107)) { + if (filled.get(106)) { throw new IllegalStateException("hub.misc/CCRS_STAMP already set"); } else { - filled.set(107); + filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } public Trace pMiscCcsrFlag(final Boolean b) { - if (filled.get(53)) { + if (filled.get(52)) { throw new IllegalStateException("hub.misc/CCSR_FLAG already set"); } else { - filled.set(53); + filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscExpData1(final Bytes b) { - if (filled.get(132)) { + if (filled.get(131)) { throw new IllegalStateException("hub.misc/EXP_DATA_1 already set"); } else { - filled.set(132); + filled.set(131); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pMiscExpData2(final Bytes b) { - if (filled.get(133)) { + if (filled.get(132)) { throw new IllegalStateException("hub.misc/EXP_DATA_2 already set"); } else { - filled.set(133); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pMiscExpData3(final Bytes b) { - if (filled.get(134)) { + if (filled.get(133)) { throw new IllegalStateException("hub.misc/EXP_DATA_3 already set"); } else { - filled.set(134); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } public Trace pMiscExpData4(final Bytes b) { - if (filled.get(135)) { + if (filled.get(134)) { throw new IllegalStateException("hub.misc/EXP_DATA_4 already set"); } else { - filled.set(135); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pMiscExpData5(final Bytes b) { - if (filled.get(136)) { + if (filled.get(135)) { throw new IllegalStateException("hub.misc/EXP_DATA_5 already set"); } else { - filled.set(136); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); @@ -2096,49 +1920,46 @@ public Trace pMiscExpData5(final Bytes b) { } public Trace pMiscExpFlag(final Boolean b) { - if (filled.get(54)) { + if (filled.get(53)) { throw new IllegalStateException("hub.misc/EXP_FLAG already set"); } else { - filled.set(54); + filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscExpInst(final long b) { - if (filled.get(108)) { + if (filled.get(107)) { throw new IllegalStateException("hub.misc/EXP_INST already set"); } else { - filled.set(108); + filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } public Trace pMiscMmuAuxId(final long b) { - if (filled.get(109)) { + if (filled.get(108)) { throw new IllegalStateException("hub.misc/MMU_AUX_ID already set"); } else { - filled.set(109); + filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } public Trace pMiscMmuExoSum(final long b) { - if (filled.get(110)) { + if (filled.get(109)) { throw new IllegalStateException("hub.misc/MMU_EXO_SUM already set"); } else { - filled.set(110); + filled.set(109); } codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); @@ -2147,23 +1968,22 @@ public Trace pMiscMmuExoSum(final long b) { } public Trace pMiscMmuFlag(final Boolean b) { - if (filled.get(55)) { + if (filled.get(54)) { throw new IllegalStateException("hub.misc/MMU_FLAG already set"); } else { - filled.set(55); + filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMmuInst(final long b) { - if (filled.get(111)) { + if (filled.get(110)) { throw new IllegalStateException("hub.misc/MMU_INST already set"); } else { - filled.set(111); + filled.set(110); } deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); @@ -2172,10 +1992,10 @@ public Trace pMiscMmuInst(final long b) { } public Trace pMiscMmuLimb1(final Bytes b) { - if (filled.get(137)) { + if (filled.get(136)) { throw new IllegalStateException("hub.misc/MMU_LIMB_1 already set"); } else { - filled.set(137); + filled.set(136); } final byte[] bs = b.toArrayUnsafe(); @@ -2188,10 +2008,10 @@ public Trace pMiscMmuLimb1(final Bytes b) { } public Trace pMiscMmuLimb2(final Bytes b) { - if (filled.get(138)) { + if (filled.get(137)) { throw new IllegalStateException("hub.misc/MMU_LIMB_2 already set"); } else { - filled.set(138); + filled.set(137); } final byte[] bs = b.toArrayUnsafe(); @@ -2204,10 +2024,10 @@ public Trace pMiscMmuLimb2(final Bytes b) { } public Trace pMiscMmuPhase(final long b) { - if (filled.get(112)) { + if (filled.get(111)) { throw new IllegalStateException("hub.misc/MMU_PHASE already set"); } else { - filled.set(112); + filled.set(111); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); @@ -2216,10 +2036,10 @@ public Trace pMiscMmuPhase(final long b) { } public Trace pMiscMmuRefOffset(final long b) { - if (filled.get(113)) { + if (filled.get(112)) { throw new IllegalStateException("hub.misc/MMU_REF_OFFSET already set"); } else { - filled.set(113); + filled.set(112); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); @@ -2228,10 +2048,10 @@ public Trace pMiscMmuRefOffset(final long b) { } public Trace pMiscMmuRefSize(final long b) { - if (filled.get(114)) { + if (filled.get(113)) { throw new IllegalStateException("hub.misc/MMU_REF_SIZE already set"); } else { - filled.set(114); + filled.set(113); } rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); @@ -2240,10 +2060,10 @@ public Trace pMiscMmuRefSize(final long b) { } public Trace pMiscMmuSize(final long b) { - if (filled.get(115)) { + if (filled.get(114)) { throw new IllegalStateException("hub.misc/MMU_SIZE already set"); } else { - filled.set(115); + filled.set(114); } callDataOffsetXorMmuSize.putLong(b); @@ -2252,10 +2072,10 @@ public Trace pMiscMmuSize(final long b) { } public Trace pMiscMmuSrcId(final long b) { - if (filled.get(116)) { + if (filled.get(115)) { throw new IllegalStateException("hub.misc/MMU_SRC_ID already set"); } else { - filled.set(116); + filled.set(115); } callDataSizeXorMmuSrcId.putLong(b); @@ -2264,10 +2084,10 @@ public Trace pMiscMmuSrcId(final long b) { } public Trace pMiscMmuSrcOffsetHi(final Bytes b) { - if (filled.get(139)) { + if (filled.get(138)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_HI already set"); } else { - filled.set(139); + filled.set(138); } final byte[] bs = b.toArrayUnsafe(); @@ -2280,10 +2100,10 @@ public Trace pMiscMmuSrcOffsetHi(final Bytes b) { } public Trace pMiscMmuSrcOffsetLo(final Bytes b) { - if (filled.get(140)) { + if (filled.get(139)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_LO already set"); } else { - filled.set(140); + filled.set(139); } final byte[] bs = b.toArrayUnsafe(); @@ -2296,23 +2116,22 @@ public Trace pMiscMmuSrcOffsetLo(final Bytes b) { } public Trace pMiscMmuSuccessBit(final Boolean b) { - if (filled.get(56)) { + if (filled.get(55)) { throw new IllegalStateException("hub.misc/MMU_SUCCESS_BIT already set"); } else { - filled.set(56); + filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMmuTgtId(final long b) { - if (filled.get(117)) { + if (filled.get(116)) { throw new IllegalStateException("hub.misc/MMU_TGT_ID already set"); } else { - filled.set(117); + filled.set(116); } contextNumberXorMmuTgtId.putLong(b); @@ -2321,10 +2140,10 @@ public Trace pMiscMmuTgtId(final long b) { } public Trace pMiscMmuTgtOffsetLo(final Bytes b) { - if (filled.get(141)) { + if (filled.get(140)) { throw new IllegalStateException("hub.misc/MMU_TGT_OFFSET_LO already set"); } else { - filled.set(141); + filled.set(140); } final byte[] bs = b.toArrayUnsafe(); @@ -2337,36 +2156,34 @@ public Trace pMiscMmuTgtOffsetLo(final Bytes b) { } public Trace pMiscMxpDeploys(final Boolean b) { - if (filled.get(57)) { + if (filled.get(56)) { throw new IllegalStateException("hub.misc/MXP_DEPLOYS already set"); } else { - filled.set(57); + filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpFlag(final Boolean b) { - if (filled.get(58)) { + if (filled.get(57)) { throw new IllegalStateException("hub.misc/MXP_FLAG already set"); } else { - filled.set(58); + filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpGasMxp(final Bytes b) { - if (filled.get(142)) { + if (filled.get(141)) { throw new IllegalStateException("hub.misc/MXP_GAS_MXP already set"); } else { - filled.set(142); + filled.set(141); } final byte[] bs = b.toArrayUnsafe(); @@ -2379,10 +2196,10 @@ public Trace pMiscMxpGasMxp(final Bytes b) { } public Trace pMiscMxpInst(final long b) { - if (filled.get(118)) { + if (filled.get(117)) { throw new IllegalStateException("hub.misc/MXP_INST already set"); } else { - filled.set(118); + filled.set(117); } returnAtCapacityXorMxpInst.putLong(b); @@ -2391,36 +2208,34 @@ public Trace pMiscMxpInst(final long b) { } public Trace pMiscMxpMtntop(final Boolean b) { - if (filled.get(59)) { + if (filled.get(58)) { throw new IllegalStateException("hub.misc/MXP_MTNTOP already set"); } else { - filled.set(59); + filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpMxpx(final Boolean b) { - if (filled.get(60)) { + if (filled.get(59)) { throw new IllegalStateException("hub.misc/MXP_MXPX already set"); } else { - filled.set(60); + filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpOffset1Hi(final Bytes b) { - if (filled.get(143)) { + if (filled.get(142)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_HI already set"); } else { - filled.set(143); + filled.set(142); } final byte[] bs = b.toArrayUnsafe(); @@ -2433,10 +2248,10 @@ public Trace pMiscMxpOffset1Hi(final Bytes b) { } public Trace pMiscMxpOffset1Lo(final Bytes b) { - if (filled.get(144)) { + if (filled.get(143)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_LO already set"); } else { - filled.set(144); + filled.set(143); } final byte[] bs = b.toArrayUnsafe(); @@ -2449,10 +2264,10 @@ public Trace pMiscMxpOffset1Lo(final Bytes b) { } public Trace pMiscMxpOffset2Hi(final Bytes b) { - if (filled.get(145)) { + if (filled.get(144)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_HI already set"); } else { - filled.set(145); + filled.set(144); } final byte[] bs = b.toArrayUnsafe(); @@ -2465,10 +2280,10 @@ public Trace pMiscMxpOffset2Hi(final Bytes b) { } public Trace pMiscMxpOffset2Lo(final Bytes b) { - if (filled.get(146)) { + if (filled.get(145)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_LO already set"); } else { - filled.set(146); + filled.set(145); } final byte[] bs = b.toArrayUnsafe(); @@ -2481,10 +2296,10 @@ public Trace pMiscMxpOffset2Lo(final Bytes b) { } public Trace pMiscMxpSize1Hi(final Bytes b) { - if (filled.get(147)) { + if (filled.get(146)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_HI already set"); } else { - filled.set(147); + filled.set(146); } final byte[] bs = b.toArrayUnsafe(); @@ -2497,10 +2312,10 @@ public Trace pMiscMxpSize1Hi(final Bytes b) { } public Trace pMiscMxpSize1Lo(final Bytes b) { - if (filled.get(148)) { + if (filled.get(147)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_LO already set"); } else { - filled.set(148); + filled.set(147); } final byte[] bs = b.toArrayUnsafe(); @@ -2513,10 +2328,10 @@ public Trace pMiscMxpSize1Lo(final Bytes b) { } public Trace pMiscMxpSize2Hi(final Bytes b) { - if (filled.get(149)) { + if (filled.get(148)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_HI already set"); } else { - filled.set(149); + filled.set(148); } final byte[] bs = b.toArrayUnsafe(); @@ -2529,10 +2344,10 @@ public Trace pMiscMxpSize2Hi(final Bytes b) { } public Trace pMiscMxpSize2Lo(final Bytes b) { - if (filled.get(150)) { + if (filled.get(149)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_LO already set"); } else { - filled.set(150); + filled.set(149); } final byte[] bs = b.toArrayUnsafe(); @@ -2545,10 +2360,10 @@ public Trace pMiscMxpSize2Lo(final Bytes b) { } public Trace pMiscMxpWords(final Bytes b) { - if (filled.get(151)) { + if (filled.get(150)) { throw new IllegalStateException("hub.misc/MXP_WORDS already set"); } else { - filled.set(151); + filled.set(150); } final byte[] bs = b.toArrayUnsafe(); @@ -2561,10 +2376,10 @@ public Trace pMiscMxpWords(final Bytes b) { } public Trace pMiscOobData1(final Bytes b) { - if (filled.get(152)) { + if (filled.get(151)) { throw new IllegalStateException("hub.misc/OOB_DATA_1 already set"); } else { - filled.set(152); + filled.set(151); } final byte[] bs = b.toArrayUnsafe(); @@ -2577,10 +2392,10 @@ public Trace pMiscOobData1(final Bytes b) { } public Trace pMiscOobData2(final Bytes b) { - if (filled.get(153)) { + if (filled.get(152)) { throw new IllegalStateException("hub.misc/OOB_DATA_2 already set"); } else { - filled.set(153); + filled.set(152); } final byte[] bs = b.toArrayUnsafe(); @@ -2593,10 +2408,10 @@ public Trace pMiscOobData2(final Bytes b) { } public Trace pMiscOobData3(final Bytes b) { - if (filled.get(154)) { + if (filled.get(153)) { throw new IllegalStateException("hub.misc/OOB_DATA_3 already set"); } else { - filled.set(154); + filled.set(153); } final byte[] bs = b.toArrayUnsafe(); @@ -2609,10 +2424,10 @@ public Trace pMiscOobData3(final Bytes b) { } public Trace pMiscOobData4(final Bytes b) { - if (filled.get(155)) { + if (filled.get(154)) { throw new IllegalStateException("hub.misc/OOB_DATA_4 already set"); } else { - filled.set(155); + filled.set(154); } final byte[] bs = b.toArrayUnsafe(); @@ -2625,10 +2440,10 @@ public Trace pMiscOobData4(final Bytes b) { } public Trace pMiscOobData5(final Bytes b) { - if (filled.get(156)) { + if (filled.get(155)) { throw new IllegalStateException("hub.misc/OOB_DATA_5 already set"); } else { - filled.set(156); + filled.set(155); } final byte[] bs = b.toArrayUnsafe(); @@ -2641,10 +2456,10 @@ public Trace pMiscOobData5(final Bytes b) { } public Trace pMiscOobData6(final Bytes b) { - if (filled.get(157)) { + if (filled.get(156)) { throw new IllegalStateException("hub.misc/OOB_DATA_6 already set"); } else { - filled.set(157); + filled.set(156); } final byte[] bs = b.toArrayUnsafe(); @@ -2657,10 +2472,10 @@ public Trace pMiscOobData6(final Bytes b) { } public Trace pMiscOobData7(final Bytes b) { - if (filled.get(158)) { + if (filled.get(157)) { throw new IllegalStateException("hub.misc/OOB_DATA_7 already set"); } else { - filled.set(158); + filled.set(157); } final byte[] bs = b.toArrayUnsafe(); @@ -2673,10 +2488,10 @@ public Trace pMiscOobData7(final Bytes b) { } public Trace pMiscOobData8(final Bytes b) { - if (filled.get(159)) { + if (filled.get(158)) { throw new IllegalStateException("hub.misc/OOB_DATA_8 already set"); } else { - filled.set(159); + filled.set(158); } final byte[] bs = b.toArrayUnsafe(); @@ -2689,23 +2504,22 @@ public Trace pMiscOobData8(final Bytes b) { } public Trace pMiscOobFlag(final Boolean b) { - if (filled.get(61)) { + if (filled.get(60)) { throw new IllegalStateException("hub.misc/OOB_FLAG already set"); } else { - filled.set(61); + filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscOobInst(final long b) { - if (filled.get(119)) { + if (filled.get(118)) { throw new IllegalStateException("hub.misc/OOB_INST already set"); } else { - filled.set(119); + filled.set(118); } returnAtOffsetXorOobInst.putLong(b); @@ -2714,23 +2528,22 @@ public Trace pMiscOobInst(final long b) { } public Trace pMiscStpExists(final Boolean b) { - if (filled.get(62)) { + if (filled.get(61)) { throw new IllegalStateException("hub.misc/STP_EXISTS already set"); } else { - filled.set(62); + filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscStpFlag(final Boolean b) { - if (filled.get(63)) { + if (filled.get(62)) { throw new IllegalStateException("hub.misc/STP_FLAG already set"); } else { - filled.set(63); + filled.set(62); } rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); @@ -2739,10 +2552,10 @@ public Trace pMiscStpFlag(final Boolean b) { } public Trace pMiscStpGasHi(final Bytes b) { - if (filled.get(160)) { + if (filled.get(159)) { throw new IllegalStateException("hub.misc/STP_GAS_HI already set"); } else { - filled.set(160); + filled.set(159); } final byte[] bs = b.toArrayUnsafe(); @@ -2755,10 +2568,10 @@ public Trace pMiscStpGasHi(final Bytes b) { } public Trace pMiscStpGasLo(final Bytes b) { - if (filled.get(161)) { + if (filled.get(160)) { throw new IllegalStateException("hub.misc/STP_GAS_LO already set"); } else { - filled.set(161); + filled.set(160); } final byte[] bs = b.toArrayUnsafe(); @@ -2771,10 +2584,10 @@ public Trace pMiscStpGasLo(final Bytes b) { } public Trace pMiscStpGasMxp(final Bytes b) { - if (filled.get(123)) { + if (filled.get(122)) { throw new IllegalStateException("hub.misc/STP_GAS_MXP already set"); } else { - filled.set(123); + filled.set(122); } final byte[] bs = b.toArrayUnsafe(); @@ -2787,10 +2600,10 @@ public Trace pMiscStpGasMxp(final Bytes b) { } public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { - if (filled.get(124)) { + if (filled.get(123)) { throw new IllegalStateException("hub.misc/STP_GAS_PAID_OUT_OF_POCKET already set"); } else { - filled.set(124); + filled.set(123); } final byte[] bs = b.toArrayUnsafe(); @@ -2803,10 +2616,10 @@ public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { } public Trace pMiscStpGasStipend(final long b) { - if (filled.get(120)) { + if (filled.get(119)) { throw new IllegalStateException("hub.misc/STP_GAS_STIPEND already set"); } else { - filled.set(120); + filled.set(119); } returnDataContextNumberXorStpGasStipend.putLong(b); @@ -2815,10 +2628,10 @@ public Trace pMiscStpGasStipend(final long b) { } public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { - if (filled.get(125)) { + if (filled.get(124)) { throw new IllegalStateException("hub.misc/STP_GAS_UPFRONT_GAS_COST already set"); } else { - filled.set(125); + filled.set(124); } final byte[] bs = b.toArrayUnsafe(); @@ -2831,10 +2644,10 @@ public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { } public Trace pMiscStpInstruction(final long b) { - if (filled.get(121)) { + if (filled.get(120)) { throw new IllegalStateException("hub.misc/STP_INSTRUCTION already set"); } else { - filled.set(121); + filled.set(120); } returnDataOffsetXorStpInstruction.putLong(b); @@ -2843,10 +2656,10 @@ public Trace pMiscStpInstruction(final long b) { } public Trace pMiscStpOogx(final Boolean b) { - if (filled.get(64)) { + if (filled.get(63)) { throw new IllegalStateException("hub.misc/STP_OOGX already set"); } else { - filled.set(64); + filled.set(63); } rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); @@ -2855,10 +2668,10 @@ public Trace pMiscStpOogx(final Boolean b) { } public Trace pMiscStpValueHi(final Bytes b) { - if (filled.get(162)) { + if (filled.get(161)) { throw new IllegalStateException("hub.misc/STP_VALUE_HI already set"); } else { - filled.set(162); + filled.set(161); } final byte[] bs = b.toArrayUnsafe(); @@ -2871,10 +2684,10 @@ public Trace pMiscStpValueHi(final Bytes b) { } public Trace pMiscStpValueLo(final Bytes b) { - if (filled.get(163)) { + if (filled.get(162)) { throw new IllegalStateException("hub.misc/STP_VALUE_LO already set"); } else { - filled.set(163); + filled.set(162); } final byte[] bs = b.toArrayUnsafe(); @@ -2887,10 +2700,10 @@ public Trace pMiscStpValueLo(final Bytes b) { } public Trace pMiscStpWarmth(final Boolean b) { - if (filled.get(65)) { + if (filled.get(64)) { throw new IllegalStateException("hub.misc/STP_WARMTH already set"); } else { - filled.set(65); + filled.set(64); } romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); @@ -2899,148 +2712,130 @@ public Trace pMiscStpWarmth(final Boolean b) { } public Trace pScenarioCallAbort(final Boolean b) { - if (filled.get(53)) { + if (filled.get(52)) { throw new IllegalStateException("hub.scenario/CALL_ABORT already set"); } else { - filled.set(53); + filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); + if (filled.get(53)) { + throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); } else { - filled.set(54); + filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { - if (filled.get(55)) { - throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); + if (filled.get(54)) { + throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); } else { - filled.set(55); + filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallException(final Boolean b) { - if (filled.get(56)) { + if (filled.get(55)) { throw new IllegalStateException("hub.scenario/CALL_EXCEPTION already set"); } else { - filled.set(56); + filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcFailure(final Boolean b) { - if (filled.get(57)) { + if (filled.get(56)) { throw new IllegalStateException("hub.scenario/CALL_PRC_FAILURE already set"); } else { - filled.set(57); + filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { - if (filled.get(58)) { - throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); + if (filled.get(57)) { + throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { - filled.set(58); + filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { - if (filled.get(59)) { - throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); + if (filled.get(58)) { + throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { - filled.set(59); + filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { - if (filled.get(60)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); + if (filled.get(59)) { + throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); } else { - filled.set(60); + filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { - if (filled.get(61)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); + if (filled.get(60)) { + throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); } else { - filled.set(61); + filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { - if (filled.get(62)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); + if (filled.get(61)) { + throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); } else { - filled.set(62); + filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { - if (filled.get(63)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); + if (filled.get(62)) { + throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); } else { - filled.set(63); + filled.set(62); } rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); @@ -3049,10 +2844,10 @@ public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { } public Trace pScenarioCreateAbort(final Boolean b) { - if (filled.get(64)) { + if (filled.get(63)) { throw new IllegalStateException("hub.scenario/CREATE_ABORT already set"); } else { - filled.set(64); + filled.set(63); } rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); @@ -3061,11 +2856,10 @@ public Trace pScenarioCreateAbort(final Boolean b) { } public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { - if (filled.get(65)) { - throw new IllegalStateException( - "hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); + if (filled.get(64)) { + throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); } else { - filled.set(65); + filled.set(64); } romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); @@ -3074,11 +2868,10 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { } public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { - if (filled.get(66)) { - throw new IllegalStateException( - "hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); + if (filled.get(65)) { + throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); } else { - filled.set(66); + filled.set(65); } trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); @@ -3087,10 +2880,10 @@ public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { } public Trace pScenarioCreateException(final Boolean b) { - if (filled.get(67)) { + if (filled.get(66)) { throw new IllegalStateException("hub.scenario/CREATE_EXCEPTION already set"); } else { - filled.set(67); + filled.set(66); } warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); @@ -3099,11 +2892,10 @@ public Trace pScenarioCreateException(final Boolean b) { } public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { - if (filled.get(68)) { - throw new IllegalStateException( - "hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); + if (filled.get(67)) { + throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); } else { - filled.set(68); + filled.set(67); } warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); @@ -3112,11 +2904,10 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { } public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { - if (filled.get(69)) { - throw new IllegalStateException( - "hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); + if (filled.get(68)) { + throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); } else { - filled.set(69); + filled.set(68); } createFailureConditionWontRevertXorIcpx.put((byte) (b ? 1 : 0)); @@ -3125,11 +2916,10 @@ public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { } public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { - if (filled.get(70)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); + if (filled.get(69)) { + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); } else { - filled.set(70); + filled.set(69); } createNonemptyInitCodeFailureWillRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); @@ -3138,11 +2928,10 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { } public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { - if (filled.get(71)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); + if (filled.get(70)) { + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); } else { - filled.set(71); + filled.set(70); } createNonemptyInitCodeFailureWontRevertXorJumpx.put((byte) (b ? 1 : 0)); @@ -3151,25 +2940,22 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { } public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { - if (filled.get(72)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); + if (filled.get(71)) { + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); } else { - filled.set(72); + filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { - if (filled.get(73)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); + if (filled.get(72)) { + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); } else { - filled.set(73); + filled.set(72); } createNonemptyInitCodeSuccessWontRevertXorJumpFlag.put((byte) (b ? 1 : 0)); @@ -3178,10 +2964,10 @@ public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { } public Trace pScenarioPrcBlake2F(final Boolean b) { - if (filled.get(74)) { + if (filled.get(73)) { throw new IllegalStateException("hub.scenario/PRC_BLAKE2f already set"); } else { - filled.set(74); + filled.set(73); } prcBlake2FXorKecFlag.put((byte) (b ? 1 : 0)); @@ -3190,49 +2976,46 @@ public Trace pScenarioPrcBlake2F(final Boolean b) { } public Trace pScenarioPrcCalleeGas(final long b) { - if (filled.get(107)) { + if (filled.get(106)) { throw new IllegalStateException("hub.scenario/PRC_CALLEE_GAS already set"); } else { - filled.set(107); + filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } public Trace pScenarioPrcCallerGas(final long b) { - if (filled.get(108)) { + if (filled.get(107)) { throw new IllegalStateException("hub.scenario/PRC_CALLER_GAS already set"); } else { - filled.set(108); + filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } public Trace pScenarioPrcCdo(final long b) { - if (filled.get(109)) { + if (filled.get(108)) { throw new IllegalStateException("hub.scenario/PRC_CDO already set"); } else { - filled.set(109); + filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } public Trace pScenarioPrcCds(final long b) { - if (filled.get(110)) { + if (filled.get(109)) { throw new IllegalStateException("hub.scenario/PRC_CDS already set"); } else { - filled.set(110); + filled.set(109); } codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); @@ -3241,10 +3024,10 @@ public Trace pScenarioPrcCds(final long b) { } public Trace pScenarioPrcEcadd(final Boolean b) { - if (filled.get(75)) { + if (filled.get(74)) { throw new IllegalStateException("hub.scenario/PRC_ECADD already set"); } else { - filled.set(75); + filled.set(74); } prcEcaddXorLogFlag.put((byte) (b ? 1 : 0)); @@ -3253,10 +3036,10 @@ public Trace pScenarioPrcEcadd(final Boolean b) { } public Trace pScenarioPrcEcmul(final Boolean b) { - if (filled.get(76)) { + if (filled.get(75)) { throw new IllegalStateException("hub.scenario/PRC_ECMUL already set"); } else { - filled.set(76); + filled.set(75); } prcEcmulXorLogInfoFlag.put((byte) (b ? 1 : 0)); @@ -3265,10 +3048,10 @@ public Trace pScenarioPrcEcmul(final Boolean b) { } public Trace pScenarioPrcEcpairing(final Boolean b) { - if (filled.get(77)) { + if (filled.get(76)) { throw new IllegalStateException("hub.scenario/PRC_ECPAIRING already set"); } else { - filled.set(77); + filled.set(76); } prcEcpairingXorMachineStateFlag.put((byte) (b ? 1 : 0)); @@ -3277,10 +3060,10 @@ public Trace pScenarioPrcEcpairing(final Boolean b) { } public Trace pScenarioPrcEcrecover(final Boolean b) { - if (filled.get(78)) { + if (filled.get(77)) { throw new IllegalStateException("hub.scenario/PRC_ECRECOVER already set"); } else { - filled.set(78); + filled.set(77); } prcEcrecoverXorMaxcsx.put((byte) (b ? 1 : 0)); @@ -3289,10 +3072,10 @@ public Trace pScenarioPrcEcrecover(final Boolean b) { } public Trace pScenarioPrcFailureKnownToHub(final Boolean b) { - if (filled.get(79)) { + if (filled.get(78)) { throw new IllegalStateException("hub.scenario/PRC_FAILURE_KNOWN_TO_HUB already set"); } else { - filled.set(79); + filled.set(78); } prcFailureKnownToHubXorModFlag.put((byte) (b ? 1 : 0)); @@ -3301,10 +3084,10 @@ public Trace pScenarioPrcFailureKnownToHub(final Boolean b) { } public Trace pScenarioPrcFailureKnownToRam(final Boolean b) { - if (filled.get(80)) { + if (filled.get(79)) { throw new IllegalStateException("hub.scenario/PRC_FAILURE_KNOWN_TO_RAM already set"); } else { - filled.set(80); + filled.set(79); } prcFailureKnownToRamXorMulFlag.put((byte) (b ? 1 : 0)); @@ -3313,10 +3096,10 @@ public Trace pScenarioPrcFailureKnownToRam(final Boolean b) { } public Trace pScenarioPrcIdentity(final Boolean b) { - if (filled.get(81)) { + if (filled.get(80)) { throw new IllegalStateException("hub.scenario/PRC_IDENTITY already set"); } else { - filled.set(81); + filled.set(80); } prcIdentityXorMxpx.put((byte) (b ? 1 : 0)); @@ -3325,10 +3108,10 @@ public Trace pScenarioPrcIdentity(final Boolean b) { } public Trace pScenarioPrcModexp(final Boolean b) { - if (filled.get(82)) { + if (filled.get(81)) { throw new IllegalStateException("hub.scenario/PRC_MODEXP already set"); } else { - filled.set(82); + filled.set(81); } prcModexpXorMxpFlag.put((byte) (b ? 1 : 0)); @@ -3337,10 +3120,10 @@ public Trace pScenarioPrcModexp(final Boolean b) { } public Trace pScenarioPrcRac(final long b) { - if (filled.get(111)) { + if (filled.get(110)) { throw new IllegalStateException("hub.scenario/PRC_RAC already set"); } else { - filled.set(111); + filled.set(110); } deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); @@ -3349,10 +3132,10 @@ public Trace pScenarioPrcRac(final long b) { } public Trace pScenarioPrcRao(final long b) { - if (filled.get(112)) { + if (filled.get(111)) { throw new IllegalStateException("hub.scenario/PRC_RAO already set"); } else { - filled.set(112); + filled.set(111); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); @@ -3361,10 +3144,10 @@ public Trace pScenarioPrcRao(final long b) { } public Trace pScenarioPrcReturnGas(final long b) { - if (filled.get(113)) { + if (filled.get(112)) { throw new IllegalStateException("hub.scenario/PRC_RETURN_GAS already set"); } else { - filled.set(113); + filled.set(112); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); @@ -3373,10 +3156,10 @@ public Trace pScenarioPrcReturnGas(final long b) { } public Trace pScenarioPrcRipemd160(final Boolean b) { - if (filled.get(83)) { + if (filled.get(82)) { throw new IllegalStateException("hub.scenario/PRC_RIPEMD-160 already set"); } else { - filled.set(83); + filled.set(82); } prcRipemd160XorOogx.put((byte) (b ? 1 : 0)); @@ -3385,10 +3168,10 @@ public Trace pScenarioPrcRipemd160(final Boolean b) { } public Trace pScenarioPrcSha2256(final Boolean b) { - if (filled.get(84)) { + if (filled.get(83)) { throw new IllegalStateException("hub.scenario/PRC_SHA2-256 already set"); } else { - filled.set(84); + filled.set(83); } prcSha2256XorOpcx.put((byte) (b ? 1 : 0)); @@ -3397,10 +3180,10 @@ public Trace pScenarioPrcSha2256(final Boolean b) { } public Trace pScenarioPrcSuccessCallerWillRevert(final Boolean b) { - if (filled.get(85)) { + if (filled.get(84)) { throw new IllegalStateException("hub.scenario/PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { - filled.set(85); + filled.set(84); } prcSuccessCallerWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); @@ -3409,10 +3192,10 @@ public Trace pScenarioPrcSuccessCallerWillRevert(final Boolean b) { } public Trace pScenarioPrcSuccessCallerWontRevert(final Boolean b) { - if (filled.get(86)) { + if (filled.get(85)) { throw new IllegalStateException("hub.scenario/PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { - filled.set(86); + filled.set(85); } prcSuccessCallerWontRevertXorRdcx.put((byte) (b ? 1 : 0)); @@ -3421,10 +3204,10 @@ public Trace pScenarioPrcSuccessCallerWontRevert(final Boolean b) { } public Trace pScenarioReturnException(final Boolean b) { - if (filled.get(87)) { + if (filled.get(86)) { throw new IllegalStateException("hub.scenario/RETURN_EXCEPTION already set"); } else { - filled.set(87); + filled.set(86); } returnExceptionXorShfFlag.put((byte) (b ? 1 : 0)); @@ -3433,11 +3216,10 @@ public Trace pScenarioReturnException(final Boolean b) { } public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { - if (filled.get(88)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); + if (filled.get(87)) { + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { - filled.set(88); + filled.set(87); } returnFromDeploymentEmptyCodeWillRevertXorSox.put((byte) (b ? 1 : 0)); @@ -3446,11 +3228,10 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { } public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { - if (filled.get(89)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); + if (filled.get(88)) { + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { - filled.set(89); + filled.set(88); } returnFromDeploymentEmptyCodeWontRevertXorSstorex.put((byte) (b ? 1 : 0)); @@ -3459,11 +3240,10 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { } public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { - if (filled.get(90)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); + if (filled.get(89)) { + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { - filled.set(90); + filled.set(89); } returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.put((byte) (b ? 1 : 0)); @@ -3472,11 +3252,10 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b } public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { - if (filled.get(91)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); + if (filled.get(90)) { + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { - filled.set(91); + filled.set(90); } returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.put((byte) (b ? 1 : 0)); @@ -3485,11 +3264,10 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b } public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { - if (filled.get(92)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); + if (filled.get(91)) { + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { - filled.set(92); + filled.set(91); } returnFromMessageCallWillTouchRamXorStackItemPop2.put((byte) (b ? 1 : 0)); @@ -3498,11 +3276,10 @@ public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { } public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { - if (filled.get(93)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); + if (filled.get(92)) { + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { - filled.set(93); + filled.set(92); } returnFromMessageCallWontTouchRamXorStackItemPop3.put((byte) (b ? 1 : 0)); @@ -3511,10 +3288,10 @@ public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { } public Trace pScenarioSelfdestructException(final Boolean b) { - if (filled.get(94)) { + if (filled.get(93)) { throw new IllegalStateException("hub.scenario/SELFDESTRUCT_EXCEPTION already set"); } else { - filled.set(94); + filled.set(93); } selfdestructExceptionXorStackItemPop4.put((byte) (b ? 1 : 0)); @@ -3523,10 +3300,10 @@ public Trace pScenarioSelfdestructException(final Boolean b) { } public Trace pScenarioSelfdestructWillRevert(final Boolean b) { - if (filled.get(95)) { + if (filled.get(94)) { throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WILL_REVERT already set"); } else { - filled.set(95); + filled.set(94); } selfdestructWillRevertXorStaticx.put((byte) (b ? 1 : 0)); @@ -3535,11 +3312,10 @@ public Trace pScenarioSelfdestructWillRevert(final Boolean b) { } public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { - if (filled.get(96)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); + if (filled.get(95)) { + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { - filled.set(96); + filled.set(95); } selfdestructWontRevertAlreadyMarkedXorStaticFlag.put((byte) (b ? 1 : 0)); @@ -3548,11 +3324,10 @@ public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { } public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { - if (filled.get(97)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); + if (filled.get(96)) { + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { - filled.set(97); + filled.set(96); } selfdestructWontRevertNotYetMarkedXorStoFlag.put((byte) (b ? 1 : 0)); @@ -3561,36 +3336,34 @@ public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { } public Trace pStackAccFlag(final Boolean b) { - if (filled.get(53)) { + if (filled.get(52)) { throw new IllegalStateException("hub.stack/ACC_FLAG already set"); } else { - filled.set(53); + filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pStackAddFlag(final Boolean b) { - if (filled.get(54)) { + if (filled.get(53)) { throw new IllegalStateException("hub.stack/ADD_FLAG already set"); } else { - filled.set(54); + filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pStackAlpha(final UnsignedByte b) { - if (filled.get(102)) { + if (filled.get(101)) { throw new IllegalStateException("hub.stack/ALPHA already set"); } else { - filled.set(102); + filled.set(101); } alpha.put(b.toByte()); @@ -3599,114 +3372,106 @@ public Trace pStackAlpha(final UnsignedByte b) { } public Trace pStackBinFlag(final Boolean b) { - if (filled.get(55)) { + if (filled.get(54)) { throw new IllegalStateException("hub.stack/BIN_FLAG already set"); } else { - filled.set(55); + filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pStackBtcFlag(final Boolean b) { - if (filled.get(56)) { + if (filled.get(55)) { throw new IllegalStateException("hub.stack/BTC_FLAG already set"); } else { - filled.set(56); + filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } public Trace pStackCallFlag(final Boolean b) { - if (filled.get(57)) { + if (filled.get(56)) { throw new IllegalStateException("hub.stack/CALL_FLAG already set"); } else { - filled.set(57); + filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pStackConFlag(final Boolean b) { - if (filled.get(58)) { + if (filled.get(57)) { throw new IllegalStateException("hub.stack/CON_FLAG already set"); } else { - filled.set(58); + filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pStackCopyFlag(final Boolean b) { - if (filled.get(59)) { + if (filled.get(58)) { throw new IllegalStateException("hub.stack/COPY_FLAG already set"); } else { - filled.set(59); + filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pStackCreateFlag(final Boolean b) { - if (filled.get(60)) { + if (filled.get(59)) { throw new IllegalStateException("hub.stack/CREATE_FLAG already set"); } else { - filled.set(60); + filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pStackDecFlag1(final Boolean b) { - if (filled.get(61)) { + if (filled.get(60)) { throw new IllegalStateException("hub.stack/DEC_FLAG_1 already set"); } else { - filled.set(61); + filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } public Trace pStackDecFlag2(final Boolean b) { - if (filled.get(62)) { + if (filled.get(61)) { throw new IllegalStateException("hub.stack/DEC_FLAG_2 already set"); } else { - filled.set(62); + filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); return this; } public Trace pStackDecFlag3(final Boolean b) { - if (filled.get(63)) { + if (filled.get(62)) { throw new IllegalStateException("hub.stack/DEC_FLAG_3 already set"); } else { - filled.set(63); + filled.set(62); } rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); @@ -3715,10 +3480,10 @@ public Trace pStackDecFlag3(final Boolean b) { } public Trace pStackDecFlag4(final Boolean b) { - if (filled.get(64)) { + if (filled.get(63)) { throw new IllegalStateException("hub.stack/DEC_FLAG_4 already set"); } else { - filled.set(64); + filled.set(63); } rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); @@ -3727,10 +3492,10 @@ public Trace pStackDecFlag4(final Boolean b) { } public Trace pStackDelta(final UnsignedByte b) { - if (filled.get(103)) { + if (filled.get(102)) { throw new IllegalStateException("hub.stack/DELTA already set"); } else { - filled.set(103); + filled.set(102); } delta.put(b.toByte()); @@ -3739,10 +3504,10 @@ public Trace pStackDelta(final UnsignedByte b) { } public Trace pStackDupFlag(final Boolean b) { - if (filled.get(65)) { + if (filled.get(64)) { throw new IllegalStateException("hub.stack/DUP_FLAG already set"); } else { - filled.set(65); + filled.set(64); } romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); @@ -3751,10 +3516,10 @@ public Trace pStackDupFlag(final Boolean b) { } public Trace pStackExtFlag(final Boolean b) { - if (filled.get(66)) { + if (filled.get(65)) { throw new IllegalStateException("hub.stack/EXT_FLAG already set"); } else { - filled.set(66); + filled.set(65); } trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); @@ -3763,10 +3528,10 @@ public Trace pStackExtFlag(final Boolean b) { } public Trace pStackHaltFlag(final Boolean b) { - if (filled.get(67)) { + if (filled.get(66)) { throw new IllegalStateException("hub.stack/HALT_FLAG already set"); } else { - filled.set(67); + filled.set(66); } warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); @@ -3775,10 +3540,10 @@ public Trace pStackHaltFlag(final Boolean b) { } public Trace pStackHashInfoFlag(final Boolean b) { - if (filled.get(68)) { + if (filled.get(67)) { throw new IllegalStateException("hub.stack/HASH_INFO_FLAG already set"); } else { - filled.set(68); + filled.set(67); } warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); @@ -3787,46 +3552,42 @@ public Trace pStackHashInfoFlag(final Boolean b) { } public Trace pStackHashInfoKeccakHi(final Bytes b) { - if (filled.get(132)) { + if (filled.get(131)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_HI already set"); } else { - filled.set(132); + filled.set(131); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pStackHashInfoKeccakLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(132)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_LO already set"); } else { - filled.set(133); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pStackIcpx(final Boolean b) { - if (filled.get(69)) { + if (filled.get(68)) { throw new IllegalStateException("hub.stack/ICPX already set"); } else { - filled.set(69); + filled.set(68); } createFailureConditionWontRevertXorIcpx.put((byte) (b ? 1 : 0)); @@ -3835,10 +3596,10 @@ public Trace pStackIcpx(final Boolean b) { } public Trace pStackInstruction(final Bytes b) { - if (filled.get(164)) { + if (filled.get(163)) { throw new IllegalStateException("hub.stack/INSTRUCTION already set"); } else { - filled.set(164); + filled.set(163); } final byte[] bs = b.toArrayUnsafe(); @@ -3851,10 +3612,10 @@ public Trace pStackInstruction(final Bytes b) { } public Trace pStackInvalidFlag(final Boolean b) { - if (filled.get(70)) { + if (filled.get(69)) { throw new IllegalStateException("hub.stack/INVALID_FLAG already set"); } else { - filled.set(70); + filled.set(69); } createNonemptyInitCodeFailureWillRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); @@ -3863,23 +3624,22 @@ public Trace pStackInvalidFlag(final Boolean b) { } public Trace pStackJumpDestinationVettingRequired(final Boolean b) { - if (filled.get(72)) { + if (filled.get(71)) { throw new IllegalStateException("hub.stack/JUMP_DESTINATION_VETTING_REQUIRED already set"); } else { - filled.set(72); + filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); return this; } public Trace pStackJumpFlag(final Boolean b) { - if (filled.get(73)) { + if (filled.get(72)) { throw new IllegalStateException("hub.stack/JUMP_FLAG already set"); } else { - filled.set(73); + filled.set(72); } createNonemptyInitCodeSuccessWontRevertXorJumpFlag.put((byte) (b ? 1 : 0)); @@ -3888,10 +3648,10 @@ public Trace pStackJumpFlag(final Boolean b) { } public Trace pStackJumpx(final Boolean b) { - if (filled.get(71)) { + if (filled.get(70)) { throw new IllegalStateException("hub.stack/JUMPX already set"); } else { - filled.set(71); + filled.set(70); } createNonemptyInitCodeFailureWontRevertXorJumpx.put((byte) (b ? 1 : 0)); @@ -3900,10 +3660,10 @@ public Trace pStackJumpx(final Boolean b) { } public Trace pStackKecFlag(final Boolean b) { - if (filled.get(74)) { + if (filled.get(73)) { throw new IllegalStateException("hub.stack/KEC_FLAG already set"); } else { - filled.set(74); + filled.set(73); } prcBlake2FXorKecFlag.put((byte) (b ? 1 : 0)); @@ -3912,10 +3672,10 @@ public Trace pStackKecFlag(final Boolean b) { } public Trace pStackLogFlag(final Boolean b) { - if (filled.get(75)) { + if (filled.get(74)) { throw new IllegalStateException("hub.stack/LOG_FLAG already set"); } else { - filled.set(75); + filled.set(74); } prcEcaddXorLogFlag.put((byte) (b ? 1 : 0)); @@ -3924,10 +3684,10 @@ public Trace pStackLogFlag(final Boolean b) { } public Trace pStackLogInfoFlag(final Boolean b) { - if (filled.get(76)) { + if (filled.get(75)) { throw new IllegalStateException("hub.stack/LOG_INFO_FLAG already set"); } else { - filled.set(76); + filled.set(75); } prcEcmulXorLogInfoFlag.put((byte) (b ? 1 : 0)); @@ -3936,10 +3696,10 @@ public Trace pStackLogInfoFlag(final Boolean b) { } public Trace pStackMachineStateFlag(final Boolean b) { - if (filled.get(77)) { + if (filled.get(76)) { throw new IllegalStateException("hub.stack/MACHINE_STATE_FLAG already set"); } else { - filled.set(77); + filled.set(76); } prcEcpairingXorMachineStateFlag.put((byte) (b ? 1 : 0)); @@ -3948,10 +3708,10 @@ public Trace pStackMachineStateFlag(final Boolean b) { } public Trace pStackMaxcsx(final Boolean b) { - if (filled.get(78)) { + if (filled.get(77)) { throw new IllegalStateException("hub.stack/MAXCSX already set"); } else { - filled.set(78); + filled.set(77); } prcEcrecoverXorMaxcsx.put((byte) (b ? 1 : 0)); @@ -3960,10 +3720,10 @@ public Trace pStackMaxcsx(final Boolean b) { } public Trace pStackModFlag(final Boolean b) { - if (filled.get(79)) { + if (filled.get(78)) { throw new IllegalStateException("hub.stack/MOD_FLAG already set"); } else { - filled.set(79); + filled.set(78); } prcFailureKnownToHubXorModFlag.put((byte) (b ? 1 : 0)); @@ -3972,10 +3732,10 @@ public Trace pStackModFlag(final Boolean b) { } public Trace pStackMulFlag(final Boolean b) { - if (filled.get(80)) { + if (filled.get(79)) { throw new IllegalStateException("hub.stack/MUL_FLAG already set"); } else { - filled.set(80); + filled.set(79); } prcFailureKnownToRamXorMulFlag.put((byte) (b ? 1 : 0)); @@ -3984,10 +3744,10 @@ public Trace pStackMulFlag(final Boolean b) { } public Trace pStackMxpFlag(final Boolean b) { - if (filled.get(82)) { + if (filled.get(81)) { throw new IllegalStateException("hub.stack/MXP_FLAG already set"); } else { - filled.set(82); + filled.set(81); } prcModexpXorMxpFlag.put((byte) (b ? 1 : 0)); @@ -3996,10 +3756,10 @@ public Trace pStackMxpFlag(final Boolean b) { } public Trace pStackMxpx(final Boolean b) { - if (filled.get(81)) { + if (filled.get(80)) { throw new IllegalStateException("hub.stack/MXPX already set"); } else { - filled.set(81); + filled.set(80); } prcIdentityXorMxpx.put((byte) (b ? 1 : 0)); @@ -4008,10 +3768,10 @@ public Trace pStackMxpx(final Boolean b) { } public Trace pStackNbAdded(final UnsignedByte b) { - if (filled.get(104)) { + if (filled.get(103)) { throw new IllegalStateException("hub.stack/NB_ADDED already set"); } else { - filled.set(104); + filled.set(103); } nbAdded.put(b.toByte()); @@ -4020,10 +3780,10 @@ public Trace pStackNbAdded(final UnsignedByte b) { } public Trace pStackNbRemoved(final UnsignedByte b) { - if (filled.get(105)) { + if (filled.get(104)) { throw new IllegalStateException("hub.stack/NB_REMOVED already set"); } else { - filled.set(105); + filled.set(104); } nbRemoved.put(b.toByte()); @@ -4032,10 +3792,10 @@ public Trace pStackNbRemoved(final UnsignedByte b) { } public Trace pStackOogx(final Boolean b) { - if (filled.get(83)) { + if (filled.get(82)) { throw new IllegalStateException("hub.stack/OOGX already set"); } else { - filled.set(83); + filled.set(82); } prcRipemd160XorOogx.put((byte) (b ? 1 : 0)); @@ -4044,10 +3804,10 @@ public Trace pStackOogx(final Boolean b) { } public Trace pStackOpcx(final Boolean b) { - if (filled.get(84)) { + if (filled.get(83)) { throw new IllegalStateException("hub.stack/OPCX already set"); } else { - filled.set(84); + filled.set(83); } prcSha2256XorOpcx.put((byte) (b ? 1 : 0)); @@ -4056,45 +3816,42 @@ public Trace pStackOpcx(final Boolean b) { } public Trace pStackPushValueHi(final Bytes b) { - if (filled.get(134)) { + if (filled.get(133)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_HI already set"); } else { - filled.set(134); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } public Trace pStackPushValueLo(final Bytes b) { - if (filled.get(135)) { + if (filled.get(134)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_LO already set"); } else { - filled.set(135); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pStackPushpopFlag(final Boolean b) { - if (filled.get(85)) { + if (filled.get(84)) { throw new IllegalStateException("hub.stack/PUSHPOP_FLAG already set"); } else { - filled.set(85); + filled.set(84); } prcSuccessCallerWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); @@ -4103,10 +3860,10 @@ public Trace pStackPushpopFlag(final Boolean b) { } public Trace pStackRdcx(final Boolean b) { - if (filled.get(86)) { + if (filled.get(85)) { throw new IllegalStateException("hub.stack/RDCX already set"); } else { - filled.set(86); + filled.set(85); } prcSuccessCallerWontRevertXorRdcx.put((byte) (b ? 1 : 0)); @@ -4115,10 +3872,10 @@ public Trace pStackRdcx(final Boolean b) { } public Trace pStackShfFlag(final Boolean b) { - if (filled.get(87)) { + if (filled.get(86)) { throw new IllegalStateException("hub.stack/SHF_FLAG already set"); } else { - filled.set(87); + filled.set(86); } returnExceptionXorShfFlag.put((byte) (b ? 1 : 0)); @@ -4127,10 +3884,10 @@ public Trace pStackShfFlag(final Boolean b) { } public Trace pStackSox(final Boolean b) { - if (filled.get(88)) { + if (filled.get(87)) { throw new IllegalStateException("hub.stack/SOX already set"); } else { - filled.set(88); + filled.set(87); } returnFromDeploymentEmptyCodeWillRevertXorSox.put((byte) (b ? 1 : 0)); @@ -4139,10 +3896,10 @@ public Trace pStackSox(final Boolean b) { } public Trace pStackSstorex(final Boolean b) { - if (filled.get(89)) { + if (filled.get(88)) { throw new IllegalStateException("hub.stack/SSTOREX already set"); } else { - filled.set(89); + filled.set(88); } returnFromDeploymentEmptyCodeWontRevertXorSstorex.put((byte) (b ? 1 : 0)); @@ -4151,10 +3908,10 @@ public Trace pStackSstorex(final Boolean b) { } public Trace pStackStackItemHeight1(final Bytes b) { - if (filled.get(165)) { + if (filled.get(164)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_1 already set"); } else { - filled.set(165); + filled.set(164); } final byte[] bs = b.toArrayUnsafe(); @@ -4167,10 +3924,10 @@ public Trace pStackStackItemHeight1(final Bytes b) { } public Trace pStackStackItemHeight2(final Bytes b) { - if (filled.get(166)) { + if (filled.get(165)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_2 already set"); } else { - filled.set(166); + filled.set(165); } final byte[] bs = b.toArrayUnsafe(); @@ -4183,10 +3940,10 @@ public Trace pStackStackItemHeight2(final Bytes b) { } public Trace pStackStackItemHeight3(final Bytes b) { - if (filled.get(167)) { + if (filled.get(166)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_3 already set"); } else { - filled.set(167); + filled.set(166); } final byte[] bs = b.toArrayUnsafe(); @@ -4199,10 +3956,10 @@ public Trace pStackStackItemHeight3(final Bytes b) { } public Trace pStackStackItemHeight4(final Bytes b) { - if (filled.get(168)) { + if (filled.get(167)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_4 already set"); } else { - filled.set(168); + filled.set(167); } final byte[] bs = b.toArrayUnsafe(); @@ -4215,10 +3972,10 @@ public Trace pStackStackItemHeight4(final Bytes b) { } public Trace pStackStackItemPop1(final Boolean b) { - if (filled.get(91)) { + if (filled.get(90)) { throw new IllegalStateException("hub.stack/STACK_ITEM_POP_1 already set"); } else { - filled.set(91); + filled.set(90); } returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.put((byte) (b ? 1 : 0)); @@ -4227,10 +3984,10 @@ public Trace pStackStackItemPop1(final Boolean b) { } public Trace pStackStackItemPop2(final Boolean b) { - if (filled.get(92)) { + if (filled.get(91)) { throw new IllegalStateException("hub.stack/STACK_ITEM_POP_2 already set"); } else { - filled.set(92); + filled.set(91); } returnFromMessageCallWillTouchRamXorStackItemPop2.put((byte) (b ? 1 : 0)); @@ -4239,10 +3996,10 @@ public Trace pStackStackItemPop2(final Boolean b) { } public Trace pStackStackItemPop3(final Boolean b) { - if (filled.get(93)) { + if (filled.get(92)) { throw new IllegalStateException("hub.stack/STACK_ITEM_POP_3 already set"); } else { - filled.set(93); + filled.set(92); } returnFromMessageCallWontTouchRamXorStackItemPop3.put((byte) (b ? 1 : 0)); @@ -4251,10 +4008,10 @@ public Trace pStackStackItemPop3(final Boolean b) { } public Trace pStackStackItemPop4(final Boolean b) { - if (filled.get(94)) { + if (filled.get(93)) { throw new IllegalStateException("hub.stack/STACK_ITEM_POP_4 already set"); } else { - filled.set(94); + filled.set(93); } selfdestructExceptionXorStackItemPop4.put((byte) (b ? 1 : 0)); @@ -4263,10 +4020,10 @@ public Trace pStackStackItemPop4(final Boolean b) { } public Trace pStackStackItemStamp1(final Bytes b) { - if (filled.get(169)) { + if (filled.get(168)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_1 already set"); } else { - filled.set(169); + filled.set(168); } final byte[] bs = b.toArrayUnsafe(); @@ -4279,10 +4036,10 @@ public Trace pStackStackItemStamp1(final Bytes b) { } public Trace pStackStackItemStamp2(final Bytes b) { - if (filled.get(170)) { + if (filled.get(169)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_2 already set"); } else { - filled.set(170); + filled.set(169); } final byte[] bs = b.toArrayUnsafe(); @@ -4295,10 +4052,10 @@ public Trace pStackStackItemStamp2(final Bytes b) { } public Trace pStackStackItemStamp3(final Bytes b) { - if (filled.get(171)) { + if (filled.get(170)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_3 already set"); } else { - filled.set(171); + filled.set(170); } final byte[] bs = b.toArrayUnsafe(); @@ -4311,10 +4068,10 @@ public Trace pStackStackItemStamp3(final Bytes b) { } public Trace pStackStackItemStamp4(final Bytes b) { - if (filled.get(172)) { + if (filled.get(171)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_4 already set"); } else { - filled.set(172); + filled.set(171); } final byte[] bs = b.toArrayUnsafe(); @@ -4327,10 +4084,10 @@ public Trace pStackStackItemStamp4(final Bytes b) { } public Trace pStackStackItemValueHi1(final Bytes b) { - if (filled.get(173)) { + if (filled.get(172)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_1 already set"); } else { - filled.set(173); + filled.set(172); } final byte[] bs = b.toArrayUnsafe(); @@ -4343,10 +4100,10 @@ public Trace pStackStackItemValueHi1(final Bytes b) { } public Trace pStackStackItemValueHi2(final Bytes b) { - if (filled.get(174)) { + if (filled.get(173)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_2 already set"); } else { - filled.set(174); + filled.set(173); } final byte[] bs = b.toArrayUnsafe(); @@ -4359,10 +4116,10 @@ public Trace pStackStackItemValueHi2(final Bytes b) { } public Trace pStackStackItemValueHi3(final Bytes b) { - if (filled.get(175)) { + if (filled.get(174)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_3 already set"); } else { - filled.set(175); + filled.set(174); } final byte[] bs = b.toArrayUnsafe(); @@ -4375,10 +4132,10 @@ public Trace pStackStackItemValueHi3(final Bytes b) { } public Trace pStackStackItemValueHi4(final Bytes b) { - if (filled.get(176)) { + if (filled.get(175)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_4 already set"); } else { - filled.set(176); + filled.set(175); } final byte[] bs = b.toArrayUnsafe(); @@ -4391,10 +4148,10 @@ public Trace pStackStackItemValueHi4(final Bytes b) { } public Trace pStackStackItemValueLo1(final Bytes b) { - if (filled.get(177)) { + if (filled.get(176)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_1 already set"); } else { - filled.set(177); + filled.set(176); } final byte[] bs = b.toArrayUnsafe(); @@ -4407,10 +4164,10 @@ public Trace pStackStackItemValueLo1(final Bytes b) { } public Trace pStackStackItemValueLo2(final Bytes b) { - if (filled.get(178)) { + if (filled.get(177)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_2 already set"); } else { - filled.set(178); + filled.set(177); } final byte[] bs = b.toArrayUnsafe(); @@ -4423,10 +4180,10 @@ public Trace pStackStackItemValueLo2(final Bytes b) { } public Trace pStackStackItemValueLo3(final Bytes b) { - if (filled.get(179)) { + if (filled.get(178)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_3 already set"); } else { - filled.set(179); + filled.set(178); } final byte[] bs = b.toArrayUnsafe(); @@ -4439,10 +4196,10 @@ public Trace pStackStackItemValueLo3(final Bytes b) { } public Trace pStackStackItemValueLo4(final Bytes b) { - if (filled.get(180)) { + if (filled.get(179)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_4 already set"); } else { - filled.set(180); + filled.set(179); } final byte[] bs = b.toArrayUnsafe(); @@ -4455,10 +4212,10 @@ public Trace pStackStackItemValueLo4(final Bytes b) { } public Trace pStackStackramFlag(final Boolean b) { - if (filled.get(90)) { + if (filled.get(89)) { throw new IllegalStateException("hub.stack/STACKRAM_FLAG already set"); } else { - filled.set(90); + filled.set(89); } returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.put((byte) (b ? 1 : 0)); @@ -4467,10 +4224,10 @@ public Trace pStackStackramFlag(final Boolean b) { } public Trace pStackStaticFlag(final Boolean b) { - if (filled.get(96)) { + if (filled.get(95)) { throw new IllegalStateException("hub.stack/STATIC_FLAG already set"); } else { - filled.set(96); + filled.set(95); } selfdestructWontRevertAlreadyMarkedXorStaticFlag.put((byte) (b ? 1 : 0)); @@ -4479,23 +4236,22 @@ public Trace pStackStaticFlag(final Boolean b) { } public Trace pStackStaticGas(final long b) { - if (filled.get(107)) { + if (filled.get(106)) { throw new IllegalStateException("hub.stack/STATIC_GAS already set"); } else { - filled.set(107); + filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } public Trace pStackStaticx(final Boolean b) { - if (filled.get(95)) { + if (filled.get(94)) { throw new IllegalStateException("hub.stack/STATICX already set"); } else { - filled.set(95); + filled.set(94); } selfdestructWillRevertXorStaticx.put((byte) (b ? 1 : 0)); @@ -4504,10 +4260,10 @@ public Trace pStackStaticx(final Boolean b) { } public Trace pStackStoFlag(final Boolean b) { - if (filled.get(97)) { + if (filled.get(96)) { throw new IllegalStateException("hub.stack/STO_FLAG already set"); } else { - filled.set(97); + filled.set(96); } selfdestructWontRevertNotYetMarkedXorStoFlag.put((byte) (b ? 1 : 0)); @@ -4516,10 +4272,10 @@ public Trace pStackStoFlag(final Boolean b) { } public Trace pStackSux(final Boolean b) { - if (filled.get(98)) { + if (filled.get(97)) { throw new IllegalStateException("hub.stack/SUX already set"); } else { - filled.set(98); + filled.set(97); } sux.put((byte) (b ? 1 : 0)); @@ -4528,10 +4284,10 @@ public Trace pStackSux(final Boolean b) { } public Trace pStackSwapFlag(final Boolean b) { - if (filled.get(99)) { + if (filled.get(98)) { throw new IllegalStateException("hub.stack/SWAP_FLAG already set"); } else { - filled.set(99); + filled.set(98); } swapFlag.put((byte) (b ? 1 : 0)); @@ -4540,10 +4296,10 @@ public Trace pStackSwapFlag(final Boolean b) { } public Trace pStackTxnFlag(final Boolean b) { - if (filled.get(100)) { + if (filled.get(99)) { throw new IllegalStateException("hub.stack/TXN_FLAG already set"); } else { - filled.set(100); + filled.set(99); } txnFlag.put((byte) (b ? 1 : 0)); @@ -4552,10 +4308,10 @@ public Trace pStackTxnFlag(final Boolean b) { } public Trace pStackWcpFlag(final Boolean b) { - if (filled.get(101)) { + if (filled.get(100)) { throw new IllegalStateException("hub.stack/WCP_FLAG already set"); } else { - filled.set(101); + filled.set(100); } wcpFlag.put((byte) (b ? 1 : 0)); @@ -4564,159 +4320,146 @@ public Trace pStackWcpFlag(final Boolean b) { } public Trace pStorageAddressHi(final long b) { - if (filled.get(107)) { + if (filled.get(106)) { throw new IllegalStateException("hub.storage/ADDRESS_HI already set"); } else { - filled.set(107); + filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } public Trace pStorageAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(131)) { throw new IllegalStateException("hub.storage/ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(131); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pStorageDeploymentNumber(final long b) { - if (filled.get(108)) { + if (filled.get(107)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER already set"); } else { - filled.set(108); + filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } public Trace pStorageDeploymentNumberInfty(final long b) { - if (filled.get(109)) { + if (filled.get(108)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(109); + filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } public Trace pStorageStorageKeyHi(final Bytes b) { - if (filled.get(133)) { + if (filled.get(132)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_HI already set"); } else { - filled.set(133); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pStorageStorageKeyLo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(133)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_LO already set"); } else { - filled.set(134); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } public Trace pStorageValueCurrChanges(final Boolean b) { - if (filled.get(53)) { + if (filled.get(52)) { throw new IllegalStateException("hub.storage/VALUE_CURR_CHANGES already set"); } else { - filled.set(53); + filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrHi(final Bytes b) { - if (filled.get(135)) { + if (filled.get(134)) { throw new IllegalStateException("hub.storage/VALUE_CURR_HI already set"); } else { - filled.set(135); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pStorageValueCurrIsOrig(final Boolean b) { - if (filled.get(54)) { + if (filled.get(53)) { throw new IllegalStateException("hub.storage/VALUE_CURR_IS_ORIG already set"); } else { - filled.set(54); + filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrIsZero(final Boolean b) { - if (filled.get(55)) { + if (filled.get(54)) { throw new IllegalStateException("hub.storage/VALUE_CURR_IS_ZERO already set"); } else { - filled.set(55); + filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrLo(final Bytes b) { - if (filled.get(136)) { + if (filled.get(135)) { throw new IllegalStateException("hub.storage/VALUE_CURR_LO already set"); } else { - filled.set(136); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); @@ -4729,10 +4472,10 @@ public Trace pStorageValueCurrLo(final Bytes b) { } public Trace pStorageValueNextHi(final Bytes b) { - if (filled.get(137)) { + if (filled.get(136)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_HI already set"); } else { - filled.set(137); + filled.set(136); } final byte[] bs = b.toArrayUnsafe(); @@ -4745,49 +4488,46 @@ public Trace pStorageValueNextHi(final Bytes b) { } public Trace pStorageValueNextIsCurr(final Boolean b) { - if (filled.get(56)) { + if (filled.get(55)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_CURR already set"); } else { - filled.set(56); + filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextIsOrig(final Boolean b) { - if (filled.get(57)) { + if (filled.get(56)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_ORIG already set"); } else { - filled.set(57); + filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextIsZero(final Boolean b) { - if (filled.get(58)) { + if (filled.get(57)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_ZERO already set"); } else { - filled.set(58); + filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextLo(final Bytes b) { - if (filled.get(138)) { + if (filled.get(137)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_LO already set"); } else { - filled.set(138); + filled.set(137); } final byte[] bs = b.toArrayUnsafe(); @@ -4800,10 +4540,10 @@ public Trace pStorageValueNextLo(final Bytes b) { } public Trace pStorageValueOrigHi(final Bytes b) { - if (filled.get(139)) { + if (filled.get(138)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_HI already set"); } else { - filled.set(139); + filled.set(138); } final byte[] bs = b.toArrayUnsafe(); @@ -4816,23 +4556,22 @@ public Trace pStorageValueOrigHi(final Bytes b) { } public Trace pStorageValueOrigIsZero(final Boolean b) { - if (filled.get(59)) { + if (filled.get(58)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_IS_ZERO already set"); } else { - filled.set(59); + filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueOrigLo(final Bytes b) { - if (filled.get(140)) { + if (filled.get(139)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_LO already set"); } else { - filled.set(140); + filled.set(139); } final byte[] bs = b.toArrayUnsafe(); @@ -4845,36 +4584,34 @@ public Trace pStorageValueOrigLo(final Bytes b) { } public Trace pStorageWarmth(final Boolean b) { - if (filled.get(60)) { + if (filled.get(59)) { throw new IllegalStateException("hub.storage/WARMTH already set"); } else { - filled.set(60); + filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageWarmthNew(final Boolean b) { - if (filled.get(61)) { + if (filled.get(60)) { throw new IllegalStateException("hub.storage/WARMTH_NEW already set"); } else { - filled.set(61); + filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionBasefee(final Bytes b) { - if (filled.get(123)) { + if (filled.get(122)) { throw new IllegalStateException("hub.transaction/BASEFEE already set"); } else { - filled.set(123); + filled.set(122); } final byte[] bs = b.toArrayUnsafe(); @@ -4887,80 +4624,74 @@ public Trace pTransactionBasefee(final Bytes b) { } public Trace pTransactionBatchNum(final long b) { - if (filled.get(107)) { + if (filled.get(106)) { throw new IllegalStateException("hub.transaction/BATCH_NUM already set"); } else { - filled.set(107); + filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } public Trace pTransactionCallDataSize(final long b) { - if (filled.get(108)) { + if (filled.get(107)) { throw new IllegalStateException("hub.transaction/CALL_DATA_SIZE already set"); } else { - filled.set(108); + filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } public Trace pTransactionCoinbaseAddressHi(final long b) { - if (filled.get(109)) { + if (filled.get(108)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_HI already set"); } else { - filled.set(109); + filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } public Trace pTransactionCoinbaseAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(131)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(131); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pTransactionCopyTxcd(final Boolean b) { - if (filled.get(53)) { + if (filled.get(52)) { throw new IllegalStateException("hub.transaction/COPY_TXCD already set"); } else { - filled.set(53); + filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionFromAddressHi(final long b) { - if (filled.get(110)) { + if (filled.get(109)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_HI already set"); } else { - filled.set(110); + filled.set(109); } codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); @@ -4969,28 +4700,26 @@ public Trace pTransactionFromAddressHi(final long b) { } public Trace pTransactionFromAddressLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(132)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_LO already set"); } else { - filled.set(133); + filled.set(132); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pTransactionGasInitiallyAvailable(final Bytes b) { - if (filled.get(124)) { + if (filled.get(123)) { throw new IllegalStateException("hub.transaction/GAS_INITIALLY_AVAILABLE already set"); } else { - filled.set(124); + filled.set(123); } final byte[] bs = b.toArrayUnsafe(); @@ -5003,10 +4732,10 @@ public Trace pTransactionGasInitiallyAvailable(final Bytes b) { } public Trace pTransactionGasLeftover(final Bytes b) { - if (filled.get(125)) { + if (filled.get(124)) { throw new IllegalStateException("hub.transaction/GAS_LEFTOVER already set"); } else { - filled.set(125); + filled.set(124); } final byte[] bs = b.toArrayUnsafe(); @@ -5019,10 +4748,10 @@ public Trace pTransactionGasLeftover(final Bytes b) { } public Trace pTransactionGasLimit(final Bytes b) { - if (filled.get(126)) { + if (filled.get(125)) { throw new IllegalStateException("hub.transaction/GAS_LIMIT already set"); } else { - filled.set(126); + filled.set(125); } final byte[] bs = b.toArrayUnsafe(); @@ -5035,10 +4764,10 @@ public Trace pTransactionGasLimit(final Bytes b) { } public Trace pTransactionGasPrice(final Bytes b) { - if (filled.get(127)) { + if (filled.get(126)) { throw new IllegalStateException("hub.transaction/GAS_PRICE already set"); } else { - filled.set(127); + filled.set(126); } final byte[] bs = b.toArrayUnsafe(); @@ -5051,10 +4780,10 @@ public Trace pTransactionGasPrice(final Bytes b) { } public Trace pTransactionInitCodeSize(final long b) { - if (filled.get(111)) { + if (filled.get(110)) { throw new IllegalStateException("hub.transaction/INIT_CODE_SIZE already set"); } else { - filled.set(111); + filled.set(110); } deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); @@ -5063,54 +4792,50 @@ public Trace pTransactionInitCodeSize(final long b) { } public Trace pTransactionInitialBalance(final Bytes b) { - if (filled.get(134)) { + if (filled.get(133)) { throw new IllegalStateException("hub.transaction/INITIAL_BALANCE already set"); } else { - filled.set(134); + filled.set(133); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } public Trace pTransactionIsDeployment(final Boolean b) { - if (filled.get(54)) { + if (filled.get(53)) { throw new IllegalStateException("hub.transaction/IS_DEPLOYMENT already set"); } else { - filled.set(54); + filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionIsType2(final Boolean b) { - if (filled.get(55)) { + if (filled.get(54)) { throw new IllegalStateException("hub.transaction/IS_TYPE2 already set"); } else { - filled.set(55); + filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionNonce(final Bytes b) { - if (filled.get(128)) { + if (filled.get(127)) { throw new IllegalStateException("hub.transaction/NONCE already set"); } else { - filled.set(128); + filled.set(127); } final byte[] bs = b.toArrayUnsafe(); @@ -5123,10 +4848,10 @@ public Trace pTransactionNonce(final Bytes b) { } public Trace pTransactionPriorityFeePerGas(final Bytes b) { - if (filled.get(129)) { + if (filled.get(128)) { throw new IllegalStateException("hub.transaction/PRIORITY_FEE_PER_GAS already set"); } else { - filled.set(129); + filled.set(128); } final byte[] bs = b.toArrayUnsafe(); @@ -5139,10 +4864,10 @@ public Trace pTransactionPriorityFeePerGas(final Bytes b) { } public Trace pTransactionRefundCounterInfinity(final Bytes b) { - if (filled.get(130)) { + if (filled.get(129)) { throw new IllegalStateException("hub.transaction/REFUND_COUNTER_INFINITY already set"); } else { - filled.set(130); + filled.set(129); } final byte[] bs = b.toArrayUnsafe(); @@ -5155,10 +4880,10 @@ public Trace pTransactionRefundCounterInfinity(final Bytes b) { } public Trace pTransactionRefundEffective(final Bytes b) { - if (filled.get(131)) { + if (filled.get(130)) { throw new IllegalStateException("hub.transaction/REFUND_EFFECTIVE already set"); } else { - filled.set(131); + filled.set(130); } final byte[] bs = b.toArrayUnsafe(); @@ -5171,36 +4896,34 @@ public Trace pTransactionRefundEffective(final Bytes b) { } public Trace pTransactionRequiresEvmExecution(final Boolean b) { - if (filled.get(56)) { + if (filled.get(55)) { throw new IllegalStateException("hub.transaction/REQUIRES_EVM_EXECUTION already set"); } else { - filled.set(56); + filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionStatusCode(final Boolean b) { - if (filled.get(57)) { + if (filled.get(56)) { throw new IllegalStateException("hub.transaction/STATUS_CODE already set"); } else { - filled.set(57); + filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionToAddressHi(final long b) { - if (filled.get(112)) { + if (filled.get(111)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_HI already set"); } else { - filled.set(112); + filled.set(111); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); @@ -5209,27 +4932,26 @@ public Trace pTransactionToAddressHi(final long b) { } public Trace pTransactionToAddressLo(final Bytes b) { - if (filled.get(135)) { + if (filled.get(134)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_LO already set"); } else { - filled.set(135); + filled.set(134); } final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pTransactionValue(final Bytes b) { - if (filled.get(136)) { + if (filled.get(135)) { throw new IllegalStateException("hub.transaction/VALUE already set"); } else { - filled.set(136); + filled.set(135); } final byte[] bs = b.toArrayUnsafe(); @@ -5374,10 +5096,10 @@ public Trace refundCounterNew(final long b) { } public Trace stoFinal(final Boolean b) { - if (filled.get(51)) { + if (filled.get(50)) { throw new IllegalStateException("hub.sto_FINAL already set"); } else { - filled.set(51); + filled.set(50); } stoFinal.put((byte) (b ? 1 : 0)); @@ -5386,10 +5108,10 @@ public Trace stoFinal(final Boolean b) { } public Trace stoFirst(final Boolean b) { - if (filled.get(52)) { + if (filled.get(51)) { throw new IllegalStateException("hub.sto_FIRST already set"); } else { - filled.set(52); + filled.set(51); } stoFirst.put((byte) (b ? 1 : 0)); @@ -5409,23 +5131,11 @@ public Trace subStamp(final long b) { return this; } - public Trace transactionReverts(final Boolean b) { - if (filled.get(40)) { - throw new IllegalStateException("hub.TRANSACTION_REVERTS already set"); - } else { - filled.set(40); - } - - transactionReverts.put((byte) (b ? 1 : 0)); - - return this; - } - public Trace twoLineInstruction(final Boolean b) { - if (filled.get(41)) { + if (filled.get(40)) { throw new IllegalStateException("hub.TWO_LINE_INSTRUCTION already set"); } else { - filled.set(41); + filled.set(40); } twoLineInstruction.put((byte) (b ? 1 : 0)); @@ -5434,10 +5144,10 @@ public Trace twoLineInstruction(final Boolean b) { } public Trace txExec(final Boolean b) { - if (filled.get(42)) { + if (filled.get(41)) { throw new IllegalStateException("hub.TX_EXEC already set"); } else { - filled.set(42); + filled.set(41); } txExec.put((byte) (b ? 1 : 0)); @@ -5446,10 +5156,10 @@ public Trace txExec(final Boolean b) { } public Trace txFinl(final Boolean b) { - if (filled.get(43)) { + if (filled.get(42)) { throw new IllegalStateException("hub.TX_FINL already set"); } else { - filled.set(43); + filled.set(42); } txFinl.put((byte) (b ? 1 : 0)); @@ -5458,10 +5168,10 @@ public Trace txFinl(final Boolean b) { } public Trace txInit(final Boolean b) { - if (filled.get(44)) { + if (filled.get(43)) { throw new IllegalStateException("hub.TX_INIT already set"); } else { - filled.set(44); + filled.set(43); } txInit.put((byte) (b ? 1 : 0)); @@ -5470,10 +5180,10 @@ public Trace txInit(final Boolean b) { } public Trace txSkip(final Boolean b) { - if (filled.get(45)) { + if (filled.get(44)) { throw new IllegalStateException("hub.TX_SKIP already set"); } else { - filled.set(45); + filled.set(44); } txSkip.put((byte) (b ? 1 : 0)); @@ -5482,10 +5192,10 @@ public Trace txSkip(final Boolean b) { } public Trace txWarm(final Boolean b) { - if (filled.get(46)) { + if (filled.get(45)) { throw new IllegalStateException("hub.TX_WARM already set"); } else { - filled.set(46); + filled.set(45); } txWarm.put((byte) (b ? 1 : 0)); @@ -5498,51 +5208,47 @@ public Trace validateRow() { throw new IllegalStateException("hub.ABSOLUTE_TRANSACTION_NUMBER has not been filled"); } - if (!filled.get(47)) { + if (!filled.get(46)) { throw new IllegalStateException("hub.acc_FINAL has not been filled"); } - if (!filled.get(48)) { + if (!filled.get(47)) { throw new IllegalStateException("hub.acc_FIRST has not been filled"); } - if (!filled.get(107)) { - throw new IllegalStateException( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); + if (!filled.get(106)) { + throw new IllegalStateException("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } - if (!filled.get(132)) { - throw new IllegalStateException( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); + if (!filled.get(131)) { + throw new IllegalStateException("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } - if (!filled.get(102)) { + if (!filled.get(101)) { throw new IllegalStateException("hub.ALPHA has not been filled"); } - if (!filled.get(134)) { - throw new IllegalStateException( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); + if (!filled.get(133)) { + throw new IllegalStateException("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } - if (!filled.get(133)) { - throw new IllegalStateException( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); + if (!filled.get(132)) { + throw new IllegalStateException("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } if (!filled.get(1)) { throw new IllegalStateException("hub.BATCH_NUMBER has not been filled"); } - if (!filled.get(115)) { + if (!filled.get(114)) { throw new IllegalStateException("hub.CALL_DATA_OFFSET_xor_MMU_SIZE has not been filled"); } - if (!filled.get(116)) { + if (!filled.get(115)) { throw new IllegalStateException("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID has not been filled"); } - if (!filled.get(106)) { + if (!filled.get(105)) { throw new IllegalStateException("hub.CALL_STACK_DEPTH has not been filled"); } @@ -5554,46 +5260,39 @@ public Trace validateRow() { throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX has not been filled"); } - if (!filled.get(108)) { - throw new IllegalStateException( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); - } - - if (!filled.get(136)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); + if (!filled.get(107)) { + throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } if (!filled.get(135)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } - if (!filled.get(138)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); + if (!filled.get(134)) { + throw new IllegalStateException("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } if (!filled.get(137)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } - if (!filled.get(110)) { - throw new IllegalStateException( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); + if (!filled.get(136)) { + throw new IllegalStateException("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } if (!filled.get(109)) { - throw new IllegalStateException( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } - if (!filled.get(49)) { + if (!filled.get(108)) { + throw new IllegalStateException("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + } + + if (!filled.get(48)) { throw new IllegalStateException("hub.con_AGAIN has not been filled"); } - if (!filled.get(50)) { + if (!filled.get(49)) { throw new IllegalStateException("hub.con_FIRST has not been filled"); } @@ -5613,7 +5312,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.CONTEXT_NUMBER_NEW has not been filled"); } - if (!filled.get(117)) { + if (!filled.get(116)) { throw new IllegalStateException("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID has not been filled"); } @@ -5637,63 +5336,52 @@ public Trace validateRow() { throw new IllegalStateException("hub.COUNTER_TLI has not been filled"); } + if (!filled.get(68)) { + throw new IllegalStateException("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + } + if (!filled.get(69)) { - throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); } if (!filled.get(70)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); } if (!filled.get(71)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); } if (!filled.get(72)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); } - if (!filled.get(73)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); + if (!filled.get(102)) { + throw new IllegalStateException("hub.DELTA has not been filled"); } - if (!filled.get(103)) { - throw new IllegalStateException("hub.DELTA has not been filled"); + if (!filled.get(111)) { + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } if (!filled.get(112)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } - if (!filled.get(113)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + if (!filled.get(110)) { + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } - if (!filled.get(111)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); + if (!filled.get(53)) { + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(54)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); } - if (!filled.get(55)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); - } - - if (!filled.get(53)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); + if (!filled.get(52)) { + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); } if (!filled.get(13)) { @@ -5704,14 +5392,12 @@ public Trace validateRow() { throw new IllegalStateException("hub.EXCEPTION_AHOY has not been filled"); } - if (!filled.get(57)) { - throw new IllegalStateException( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); + if (!filled.get(56)) { + throw new IllegalStateException("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); } - if (!filled.get(56)) { - throw new IllegalStateException( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); + if (!filled.get(55)) { + throw new IllegalStateException("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(15)) { @@ -5726,7 +5412,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_EXPECTED has not been filled"); } - if (!filled.get(126)) { + if (!filled.get(125)) { throw new IllegalStateException("hub.GAS_LIMIT has not been filled"); } @@ -5734,18 +5420,16 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_NEXT has not been filled"); } - if (!filled.get(127)) { + if (!filled.get(126)) { throw new IllegalStateException("hub.GAS_PRICE has not been filled"); } - if (!filled.get(59)) { - throw new IllegalStateException( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); + if (!filled.get(58)) { + throw new IllegalStateException("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); } - if (!filled.get(58)) { - throw new IllegalStateException( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + if (!filled.get(57)) { + throw new IllegalStateException("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(19)) { @@ -5768,54 +5452,51 @@ public Trace validateRow() { throw new IllegalStateException("hub.HUB_STAMP_TRANSACTION_END has not been filled"); } - if (!filled.get(164)) { + if (!filled.get(163)) { throw new IllegalStateException("hub.INSTRUCTION has not been filled"); } - if (!filled.get(60)) { - throw new IllegalStateException( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); + if (!filled.get(59)) { + throw new IllegalStateException("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); } if (!filled.get(24)) { throw new IllegalStateException("hub.LOG_INFO_STAMP has not been filled"); } - if (!filled.get(62)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); + if (!filled.get(61)) { + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); } - if (!filled.get(61)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); + if (!filled.get(60)) { + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); } if (!filled.get(25)) { throw new IllegalStateException("hub.MMU_STAMP has not been filled"); } - if (!filled.get(145)) { + if (!filled.get(144)) { throw new IllegalStateException("hub.MXP_OFFSET_2_HI has not been filled"); } - if (!filled.get(146)) { + if (!filled.get(145)) { throw new IllegalStateException("hub.MXP_OFFSET_2_LO has not been filled"); } - if (!filled.get(147)) { + if (!filled.get(146)) { throw new IllegalStateException("hub.MXP_SIZE_1_HI has not been filled"); } - if (!filled.get(148)) { + if (!filled.get(147)) { throw new IllegalStateException("hub.MXP_SIZE_1_LO has not been filled"); } - if (!filled.get(149)) { + if (!filled.get(148)) { throw new IllegalStateException("hub.MXP_SIZE_2_HI has not been filled"); } - if (!filled.get(150)) { + if (!filled.get(149)) { throw new IllegalStateException("hub.MXP_SIZE_2_LO has not been filled"); } @@ -5823,15 +5504,15 @@ public Trace validateRow() { throw new IllegalStateException("hub.MXP_STAMP has not been filled"); } - if (!filled.get(151)) { + if (!filled.get(150)) { throw new IllegalStateException("hub.MXP_WORDS has not been filled"); } - if (!filled.get(104)) { + if (!filled.get(103)) { throw new IllegalStateException("hub.NB_ADDED has not been filled"); } - if (!filled.get(105)) { + if (!filled.get(104)) { throw new IllegalStateException("hub.NB_REMOVED has not been filled"); } @@ -5839,48 +5520,47 @@ public Trace validateRow() { throw new IllegalStateException("hub.NON_STACK_ROWS has not been filled"); } - if (!filled.get(128)) { + if (!filled.get(127)) { throw new IllegalStateException("hub.NONCE has not been filled"); } - if (!filled.get(124)) { - throw new IllegalStateException( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + if (!filled.get(123)) { + throw new IllegalStateException("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } - if (!filled.get(123)) { + if (!filled.get(122)) { throw new IllegalStateException("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE has not been filled"); } - if (!filled.get(152)) { + if (!filled.get(151)) { throw new IllegalStateException("hub.OOB_DATA_1 has not been filled"); } - if (!filled.get(153)) { + if (!filled.get(152)) { throw new IllegalStateException("hub.OOB_DATA_2 has not been filled"); } - if (!filled.get(154)) { + if (!filled.get(153)) { throw new IllegalStateException("hub.OOB_DATA_3 has not been filled"); } - if (!filled.get(155)) { + if (!filled.get(154)) { throw new IllegalStateException("hub.OOB_DATA_4 has not been filled"); } - if (!filled.get(156)) { + if (!filled.get(155)) { throw new IllegalStateException("hub.OOB_DATA_5 has not been filled"); } - if (!filled.get(157)) { + if (!filled.get(156)) { throw new IllegalStateException("hub.OOB_DATA_6 has not been filled"); } - if (!filled.get(158)) { + if (!filled.get(157)) { throw new IllegalStateException("hub.OOB_DATA_7 has not been filled"); } - if (!filled.get(159)) { + if (!filled.get(158)) { throw new IllegalStateException("hub.OOB_DATA_8 has not been filled"); } @@ -5912,64 +5592,59 @@ public Trace validateRow() { throw new IllegalStateException("hub.PEEK_AT_TRANSACTION has not been filled"); } - if (!filled.get(74)) { + if (!filled.get(73)) { throw new IllegalStateException("hub.PRC_BLAKE2f_xor_KEC_FLAG has not been filled"); } - if (!filled.get(75)) { + if (!filled.get(74)) { throw new IllegalStateException("hub.PRC_ECADD_xor_LOG_FLAG has not been filled"); } - if (!filled.get(76)) { + if (!filled.get(75)) { throw new IllegalStateException("hub.PRC_ECMUL_xor_LOG_INFO_FLAG has not been filled"); } + if (!filled.get(76)) { + throw new IllegalStateException("hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + } + if (!filled.get(77)) { - throw new IllegalStateException( - "hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_ECRECOVER_xor_MAXCSX has not been filled"); } if (!filled.get(78)) { - throw new IllegalStateException("hub.PRC_ECRECOVER_xor_MAXCSX has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); } if (!filled.get(79)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); } if (!filled.get(80)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_IDENTITY_xor_MXPX has not been filled"); } if (!filled.get(81)) { - throw new IllegalStateException("hub.PRC_IDENTITY_xor_MXPX has not been filled"); + throw new IllegalStateException("hub.PRC_MODEXP_xor_MXP_FLAG has not been filled"); } if (!filled.get(82)) { - throw new IllegalStateException("hub.PRC_MODEXP_xor_MXP_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_RIPEMD-160_xor_OOGX has not been filled"); } if (!filled.get(83)) { - throw new IllegalStateException("hub.PRC_RIPEMD-160_xor_OOGX has not been filled"); + throw new IllegalStateException("hub.PRC_SHA2-256_xor_OPCX has not been filled"); } if (!filled.get(84)) { - throw new IllegalStateException("hub.PRC_SHA2-256_xor_OPCX has not been filled"); + throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(85)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); - } - - if (!filled.get(86)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); + throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); } - if (!filled.get(129)) { + if (!filled.get(128)) { throw new IllegalStateException("hub.PRIORITY_FEE_PER_GAS has not been filled"); } @@ -5985,7 +5660,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER has not been filled"); } - if (!filled.get(130)) { + if (!filled.get(129)) { throw new IllegalStateException("hub.REFUND_COUNTER_INFINITY has not been filled"); } @@ -5993,220 +5668,199 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER_NEW has not been filled"); } - if (!filled.get(131)) { + if (!filled.get(130)) { throw new IllegalStateException("hub.REFUND_EFFECTIVE has not been filled"); } - if (!filled.get(118)) { + if (!filled.get(117)) { throw new IllegalStateException("hub.RETURN_AT_CAPACITY_xor_MXP_INST has not been filled"); } - if (!filled.get(119)) { + if (!filled.get(118)) { throw new IllegalStateException("hub.RETURN_AT_OFFSET_xor_OOB_INST has not been filled"); } + if (!filled.get(119)) { + throw new IllegalStateException("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + } + if (!filled.get(120)) { - throw new IllegalStateException( - "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + throw new IllegalStateException("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } if (!filled.get(121)) { - throw new IllegalStateException( - "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + throw new IllegalStateException("hub.RETURN_DATA_SIZE has not been filled"); } - if (!filled.get(122)) { - throw new IllegalStateException("hub.RETURN_DATA_SIZE has not been filled"); + if (!filled.get(86)) { + throw new IllegalStateException("hub.RETURN_EXCEPTION_xor_SHF_FLAG has not been filled"); } if (!filled.get(87)) { - throw new IllegalStateException("hub.RETURN_EXCEPTION_xor_SHF_FLAG has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); } if (!filled.get(88)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(89)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(90)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(91)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(92)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } - if (!filled.get(93)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + if (!filled.get(113)) { + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } - if (!filled.get(114)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); + if (!filled.get(138)) { + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } - if (!filled.get(139)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); + if (!filled.get(62)) { + throw new IllegalStateException("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); } - if (!filled.get(63)) { - throw new IllegalStateException( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); + if (!filled.get(139)) { + throw new IllegalStateException("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } if (!filled.get(140)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); + throw new IllegalStateException("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } - if (!filled.get(141)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); + if (!filled.get(63)) { + throw new IllegalStateException("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } - if (!filled.get(64)) { - throw new IllegalStateException( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + if (!filled.get(141)) { + throw new IllegalStateException("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP has not been filled"); } if (!filled.get(142)) { - throw new IllegalStateException("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP has not been filled"); + throw new IllegalStateException("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } - if (!filled.get(143)) { - throw new IllegalStateException( - "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); + if (!filled.get(64)) { + throw new IllegalStateException("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } - if (!filled.get(65)) { - throw new IllegalStateException( - "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + if (!filled.get(93)) { + throw new IllegalStateException("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); } if (!filled.get(94)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); } if (!filled.get(95)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); } if (!filled.get(96)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } - if (!filled.get(97)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); - } - - if (!filled.get(165)) { + if (!filled.get(164)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_1 has not been filled"); } - if (!filled.get(166)) { + if (!filled.get(165)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_2 has not been filled"); } - if (!filled.get(167)) { + if (!filled.get(166)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_3 has not been filled"); } - if (!filled.get(168)) { + if (!filled.get(167)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_4 has not been filled"); } - if (!filled.get(169)) { + if (!filled.get(168)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_1 has not been filled"); } - if (!filled.get(170)) { + if (!filled.get(169)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_2 has not been filled"); } - if (!filled.get(171)) { + if (!filled.get(170)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_3 has not been filled"); } - if (!filled.get(172)) { + if (!filled.get(171)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_4 has not been filled"); } - if (!filled.get(173)) { + if (!filled.get(172)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_1 has not been filled"); } - if (!filled.get(174)) { + if (!filled.get(173)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_2 has not been filled"); } - if (!filled.get(175)) { + if (!filled.get(174)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_3 has not been filled"); } - if (!filled.get(176)) { + if (!filled.get(175)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_4 has not been filled"); } - if (!filled.get(177)) { + if (!filled.get(176)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_1 has not been filled"); } - if (!filled.get(178)) { + if (!filled.get(177)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_2 has not been filled"); } - if (!filled.get(179)) { + if (!filled.get(178)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_3 has not been filled"); } - if (!filled.get(180)) { + if (!filled.get(179)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_4 has not been filled"); } - if (!filled.get(51)) { + if (!filled.get(50)) { throw new IllegalStateException("hub.sto_FINAL has not been filled"); } - if (!filled.get(52)) { + if (!filled.get(51)) { throw new IllegalStateException("hub.sto_FIRST has not been filled"); } - if (!filled.get(160)) { + if (!filled.get(159)) { throw new IllegalStateException("hub.STP_GAS_HI has not been filled"); } - if (!filled.get(161)) { + if (!filled.get(160)) { throw new IllegalStateException("hub.STP_GAS_LO has not been filled"); } - if (!filled.get(125)) { - throw new IllegalStateException( - "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); + if (!filled.get(124)) { + throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } - if (!filled.get(162)) { + if (!filled.get(161)) { throw new IllegalStateException("hub.STP_VALUE_HI has not been filled"); } - if (!filled.get(163)) { + if (!filled.get(162)) { throw new IllegalStateException("hub.STP_VALUE_LO has not been filled"); } @@ -6214,67 +5868,59 @@ public Trace validateRow() { throw new IllegalStateException("hub.SUB_STAMP has not been filled"); } - if (!filled.get(98)) { + if (!filled.get(97)) { throw new IllegalStateException("hub.SUX has not been filled"); } - if (!filled.get(99)) { + if (!filled.get(98)) { throw new IllegalStateException("hub.SWAP_FLAG has not been filled"); } - if (!filled.get(40)) { - throw new IllegalStateException("hub.TRANSACTION_REVERTS has not been filled"); - } - - if (!filled.get(66)) { - throw new IllegalStateException( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + if (!filled.get(65)) { + throw new IllegalStateException("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } - if (!filled.get(144)) { - throw new IllegalStateException( - "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); + if (!filled.get(143)) { + throw new IllegalStateException("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } - if (!filled.get(41)) { + if (!filled.get(40)) { throw new IllegalStateException("hub.TWO_LINE_INSTRUCTION has not been filled"); } - if (!filled.get(42)) { + if (!filled.get(41)) { throw new IllegalStateException("hub.TX_EXEC has not been filled"); } - if (!filled.get(43)) { + if (!filled.get(42)) { throw new IllegalStateException("hub.TX_FINL has not been filled"); } - if (!filled.get(44)) { + if (!filled.get(43)) { throw new IllegalStateException("hub.TX_INIT has not been filled"); } - if (!filled.get(45)) { + if (!filled.get(44)) { throw new IllegalStateException("hub.TX_SKIP has not been filled"); } - if (!filled.get(46)) { + if (!filled.get(45)) { throw new IllegalStateException("hub.TX_WARM has not been filled"); } - if (!filled.get(100)) { + if (!filled.get(99)) { throw new IllegalStateException("hub.TXN_FLAG has not been filled"); } - if (!filled.get(68)) { - throw new IllegalStateException( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + if (!filled.get(67)) { + throw new IllegalStateException("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); } - if (!filled.get(67)) { - throw new IllegalStateException( - "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + if (!filled.get(66)) { + throw new IllegalStateException("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } - if (!filled.get(101)) { + if (!filled.get(100)) { throw new IllegalStateException("hub.WCP_FLAG has not been filled"); } @@ -6289,63 +5935,47 @@ public Trace fillAndValidateRow() { absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 4); } - if (!filled.get(47)) { + if (!filled.get(46)) { accFinal.position(accFinal.position() + 1); } - if (!filled.get(48)) { + if (!filled.get(47)) { accFirst.position(accFirst.position() + 1); } - if (!filled.get(107)) { - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .position( - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .position() - + 8); + if (!filled.get(106)) { + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position(addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position() + 8); } - if (!filled.get(132)) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position( - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position() - + 32); + if (!filled.get(131)) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position(addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position() + 32); } - if (!filled.get(102)) { + if (!filled.get(101)) { alpha.position(alpha.position() + 1); } - if (!filled.get(134)) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position( - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position() - + 32); + if (!filled.get(133)) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position(balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position() + 32); } - if (!filled.get(133)) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position( - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position() - + 32); + if (!filled.get(132)) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position(balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position() + 32); } if (!filled.get(1)) { batchNumber.position(batchNumber.position() + 4); } - if (!filled.get(115)) { + if (!filled.get(114)) { callDataOffsetXorMmuSize.position(callDataOffsetXorMmuSize.position() + 8); } - if (!filled.get(116)) { + if (!filled.get(115)) { callDataSizeXorMmuSrcId.position(callDataSizeXorMmuSrcId.position() + 8); } - if (!filled.get(106)) { + if (!filled.get(105)) { callStackDepth.position(callStackDepth.position() + 2); } @@ -6357,54 +5987,39 @@ public Trace fillAndValidateRow() { codeFragmentIndex.position(codeFragmentIndex.position() + 8); } - if (!filled.get(108)) { - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .position( - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .position() - + 8); - } - - if (!filled.get(136)) { - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); + if (!filled.get(107)) { + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position(codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position() + 8); } if (!filled.get(135)) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() - + 32); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position(codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); } - if (!filled.get(138)) { - codeHashLoNewXorMmuLimb2XorValueNextLo.position( - codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); + if (!filled.get(134)) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position(codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 32); } if (!filled.get(137)) { - codeHashLoXorMmuLimb1XorValueNextHi.position( - codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); + codeHashLoNewXorMmuLimb2XorValueNextLo.position(codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); } - if (!filled.get(110)) { - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() - + 8); + if (!filled.get(136)) { + codeHashLoXorMmuLimb1XorValueNextHi.position(codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); } if (!filled.get(109)) { - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .position( - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .position() - + 8); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position(codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + 8); } - if (!filled.get(49)) { + if (!filled.get(108)) { + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position(codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position() + 8); + } + + if (!filled.get(48)) { conAgain.position(conAgain.position() + 1); } - if (!filled.get(50)) { + if (!filled.get(49)) { conFirst.position(conFirst.position() + 1); } @@ -6424,7 +6039,7 @@ public Trace fillAndValidateRow() { contextNumberNew.position(contextNumberNew.position() + 8); } - if (!filled.get(117)) { + if (!filled.get(116)) { contextNumberXorMmuTgtId.position(contextNumberXorMmuTgtId.position() + 8); } @@ -6448,75 +6063,52 @@ public Trace fillAndValidateRow() { counterTli.position(counterTli.position() + 1); } + if (!filled.get(68)) { + createFailureConditionWontRevertXorIcpx.position(createFailureConditionWontRevertXorIcpx.position() + 1); + } + if (!filled.get(69)) { - createFailureConditionWontRevertXorIcpx.position( - createFailureConditionWontRevertXorIcpx.position() + 1); + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position(createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); } if (!filled.get(70)) { - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position( - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); + createNonemptyInitCodeFailureWontRevertXorJumpx.position(createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); } if (!filled.get(71)) { - createNonemptyInitCodeFailureWontRevertXorJumpx.position( - createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position(createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); } if (!filled.get(72)) { - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position( - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position(createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); } - if (!filled.get(73)) { - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position( - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); + if (!filled.get(102)) { + delta.position(delta.position() + 1); } - if (!filled.get(103)) { - delta.position(delta.position() + 1); + if (!filled.get(111)) { + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position(deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position() + 8); } if (!filled.get(112)) { - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi - .position() - + 8); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position(deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); } - if (!filled.get(113)) { - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + if (!filled.get(110)) { + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position(deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + 8); } - if (!filled.get(111)) { - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() - + 8); + if (!filled.get(53)) { + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position(deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position() + 1); } if (!filled.get(54)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .position( - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .position() - + 1); - } - - if (!filled.get(55)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .position( - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .position() - + 1); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position(deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position() + 1); } - if (!filled.get(53)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd - .position( - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd - .position() - + 1); + if (!filled.get(52)) { + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position(deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position() + 1); } if (!filled.get(13)) { @@ -6527,19 +6119,12 @@ public Trace fillAndValidateRow() { exceptionAhoy.position(exceptionAhoy.position() + 1); } - if (!filled.get(57)) { - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position( - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode - .position() - + 1); + if (!filled.get(56)) { + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position(existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position() + 1); } - if (!filled.get(56)) { - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution - .position( - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution - .position() - + 1); + if (!filled.get(55)) { + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position(existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position() + 1); } if (!filled.get(15)) { @@ -6554,7 +6139,7 @@ public Trace fillAndValidateRow() { gasExpected.position(gasExpected.position() + 8); } - if (!filled.get(126)) { + if (!filled.get(125)) { gasLimit.position(gasLimit.position() + 32); } @@ -6562,21 +6147,16 @@ public Trace fillAndValidateRow() { gasNext.position(gasNext.position() + 8); } - if (!filled.get(127)) { + if (!filled.get(126)) { gasPrice.position(gasPrice.position() + 32); } - if (!filled.get(59)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position( - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero - .position() - + 1); + if (!filled.get(58)) { + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position(hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position() + 1); } - if (!filled.get(58)) { - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position( - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() - + 1); + if (!filled.get(57)) { + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position(hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() + 1); } if (!filled.get(19)) { @@ -6599,60 +6179,51 @@ public Trace fillAndValidateRow() { hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 8); } - if (!filled.get(164)) { + if (!filled.get(163)) { instruction.position(instruction.position() + 32); } - if (!filled.get(60)) { - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position( - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() - + 1); + if (!filled.get(59)) { + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position(isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + 1); } if (!filled.get(24)) { logInfoStamp.position(logInfoStamp.position() + 8); } - if (!filled.get(62)) { - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position( - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 - .position() - + 1); + if (!filled.get(61)) { + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position(markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position() + 1); } - if (!filled.get(61)) { - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew - .position( - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew - .position() - + 1); + if (!filled.get(60)) { + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position(markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position() + 1); } if (!filled.get(25)) { mmuStamp.position(mmuStamp.position() + 8); } - if (!filled.get(145)) { + if (!filled.get(144)) { mxpOffset2Hi.position(mxpOffset2Hi.position() + 32); } - if (!filled.get(146)) { + if (!filled.get(145)) { mxpOffset2Lo.position(mxpOffset2Lo.position() + 32); } - if (!filled.get(147)) { + if (!filled.get(146)) { mxpSize1Hi.position(mxpSize1Hi.position() + 32); } - if (!filled.get(148)) { + if (!filled.get(147)) { mxpSize1Lo.position(mxpSize1Lo.position() + 32); } - if (!filled.get(149)) { + if (!filled.get(148)) { mxpSize2Hi.position(mxpSize2Hi.position() + 32); } - if (!filled.get(150)) { + if (!filled.get(149)) { mxpSize2Lo.position(mxpSize2Lo.position() + 32); } @@ -6660,15 +6231,15 @@ public Trace fillAndValidateRow() { mxpStamp.position(mxpStamp.position() + 8); } - if (!filled.get(151)) { + if (!filled.get(150)) { mxpWords.position(mxpWords.position() + 32); } - if (!filled.get(104)) { + if (!filled.get(103)) { nbAdded.position(nbAdded.position() + 1); } - if (!filled.get(105)) { + if (!filled.get(104)) { nbRemoved.position(nbRemoved.position() + 1); } @@ -6676,48 +6247,47 @@ public Trace fillAndValidateRow() { nonStackRows.position(nonStackRows.position() + 2); } - if (!filled.get(128)) { + if (!filled.get(127)) { nonce.position(nonce.position() + 32); } - if (!filled.get(124)) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); + if (!filled.get(123)) { + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position(nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); } - if (!filled.get(123)) { + if (!filled.get(122)) { nonceXorStpGasMxpXorBasefee.position(nonceXorStpGasMxpXorBasefee.position() + 32); } - if (!filled.get(152)) { + if (!filled.get(151)) { oobData1.position(oobData1.position() + 32); } - if (!filled.get(153)) { + if (!filled.get(152)) { oobData2.position(oobData2.position() + 32); } - if (!filled.get(154)) { + if (!filled.get(153)) { oobData3.position(oobData3.position() + 32); } - if (!filled.get(155)) { + if (!filled.get(154)) { oobData4.position(oobData4.position() + 32); } - if (!filled.get(156)) { + if (!filled.get(155)) { oobData5.position(oobData5.position() + 32); } - if (!filled.get(157)) { + if (!filled.get(156)) { oobData6.position(oobData6.position() + 32); } - if (!filled.get(158)) { + if (!filled.get(157)) { oobData7.position(oobData7.position() + 32); } - if (!filled.get(159)) { + if (!filled.get(158)) { oobData8.position(oobData8.position() + 32); } @@ -6749,60 +6319,59 @@ public Trace fillAndValidateRow() { peekAtTransaction.position(peekAtTransaction.position() + 1); } - if (!filled.get(74)) { + if (!filled.get(73)) { prcBlake2FXorKecFlag.position(prcBlake2FXorKecFlag.position() + 1); } - if (!filled.get(75)) { + if (!filled.get(74)) { prcEcaddXorLogFlag.position(prcEcaddXorLogFlag.position() + 1); } - if (!filled.get(76)) { + if (!filled.get(75)) { prcEcmulXorLogInfoFlag.position(prcEcmulXorLogInfoFlag.position() + 1); } - if (!filled.get(77)) { + if (!filled.get(76)) { prcEcpairingXorMachineStateFlag.position(prcEcpairingXorMachineStateFlag.position() + 1); } - if (!filled.get(78)) { + if (!filled.get(77)) { prcEcrecoverXorMaxcsx.position(prcEcrecoverXorMaxcsx.position() + 1); } - if (!filled.get(79)) { + if (!filled.get(78)) { prcFailureKnownToHubXorModFlag.position(prcFailureKnownToHubXorModFlag.position() + 1); } - if (!filled.get(80)) { + if (!filled.get(79)) { prcFailureKnownToRamXorMulFlag.position(prcFailureKnownToRamXorMulFlag.position() + 1); } - if (!filled.get(81)) { + if (!filled.get(80)) { prcIdentityXorMxpx.position(prcIdentityXorMxpx.position() + 1); } - if (!filled.get(82)) { + if (!filled.get(81)) { prcModexpXorMxpFlag.position(prcModexpXorMxpFlag.position() + 1); } - if (!filled.get(83)) { + if (!filled.get(82)) { prcRipemd160XorOogx.position(prcRipemd160XorOogx.position() + 1); } - if (!filled.get(84)) { + if (!filled.get(83)) { prcSha2256XorOpcx.position(prcSha2256XorOpcx.position() + 1); } - if (!filled.get(85)) { - prcSuccessCallerWillRevertXorPushpopFlag.position( - prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); + if (!filled.get(84)) { + prcSuccessCallerWillRevertXorPushpopFlag.position(prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); } - if (!filled.get(86)) { + if (!filled.get(85)) { prcSuccessCallerWontRevertXorRdcx.position(prcSuccessCallerWontRevertXorRdcx.position() + 1); } - if (!filled.get(129)) { + if (!filled.get(128)) { priorityFeePerGas.position(priorityFeePerGas.position() + 32); } @@ -6818,7 +6387,7 @@ public Trace fillAndValidateRow() { refundCounter.position(refundCounter.position() + 8); } - if (!filled.get(130)) { + if (!filled.get(129)) { refundCounterInfinity.position(refundCounterInfinity.position() + 32); } @@ -6826,216 +6395,199 @@ public Trace fillAndValidateRow() { refundCounterNew.position(refundCounterNew.position() + 8); } - if (!filled.get(131)) { + if (!filled.get(130)) { refundEffective.position(refundEffective.position() + 32); } - if (!filled.get(118)) { + if (!filled.get(117)) { returnAtCapacityXorMxpInst.position(returnAtCapacityXorMxpInst.position() + 8); } - if (!filled.get(119)) { + if (!filled.get(118)) { returnAtOffsetXorOobInst.position(returnAtOffsetXorOobInst.position() + 8); } - if (!filled.get(120)) { - returnDataContextNumberXorStpGasStipend.position( - returnDataContextNumberXorStpGasStipend.position() + 8); + if (!filled.get(119)) { + returnDataContextNumberXorStpGasStipend.position(returnDataContextNumberXorStpGasStipend.position() + 8); } - if (!filled.get(121)) { + if (!filled.get(120)) { returnDataOffsetXorStpInstruction.position(returnDataOffsetXorStpInstruction.position() + 8); } - if (!filled.get(122)) { + if (!filled.get(121)) { returnDataSize.position(returnDataSize.position() + 8); } - if (!filled.get(87)) { + if (!filled.get(86)) { returnExceptionXorShfFlag.position(returnExceptionXorShfFlag.position() + 1); } + if (!filled.get(87)) { + returnFromDeploymentEmptyCodeWillRevertXorSox.position(returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + } + if (!filled.get(88)) { - returnFromDeploymentEmptyCodeWillRevertXorSox.position( - returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position(returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); } if (!filled.get(89)) { - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position( - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position(returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); } if (!filled.get(90)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position( - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position(returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); } if (!filled.get(91)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position( - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop2.position(returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); } if (!filled.get(92)) { - returnFromMessageCallWillTouchRamXorStackItemPop2.position( - returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); + returnFromMessageCallWontTouchRamXorStackItemPop3.position(returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } - if (!filled.get(93)) { - returnFromMessageCallWontTouchRamXorStackItemPop3.position( - returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); + if (!filled.get(113)) { + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position(rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); } - if (!filled.get(114)) { - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); + if (!filled.get(138)) { + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position(rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); } - if (!filled.get(139)) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); + if (!filled.get(62)) { + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position(rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); } - if (!filled.get(63)) { - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position( - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); + if (!filled.get(139)) { + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position(rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); } if (!filled.get(140)) { - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); - } - - if (!filled.get(141)) { rlpaddrKecLoXorMmuTgtOffsetLo.position(rlpaddrKecLoXorMmuTgtOffsetLo.position() + 32); } - if (!filled.get(64)) { - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); + if (!filled.get(63)) { + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position(rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } - if (!filled.get(142)) { + if (!filled.get(141)) { rlpaddrSaltHiXorMxpGasMxp.position(rlpaddrSaltHiXorMxpGasMxp.position() + 32); } - if (!filled.get(143)) { + if (!filled.get(142)) { rlpaddrSaltLoXorMxpOffset1Hi.position(rlpaddrSaltLoXorMxpOffset1Hi.position() + 32); } - if (!filled.get(65)) { - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + if (!filled.get(64)) { + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position(romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } - if (!filled.get(94)) { - selfdestructExceptionXorStackItemPop4.position( - selfdestructExceptionXorStackItemPop4.position() + 1); + if (!filled.get(93)) { + selfdestructExceptionXorStackItemPop4.position(selfdestructExceptionXorStackItemPop4.position() + 1); } - if (!filled.get(95)) { + if (!filled.get(94)) { selfdestructWillRevertXorStaticx.position(selfdestructWillRevertXorStaticx.position() + 1); } - if (!filled.get(96)) { - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position( - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); + if (!filled.get(95)) { + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position(selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); } - if (!filled.get(97)) { - selfdestructWontRevertNotYetMarkedXorStoFlag.position( - selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); + if (!filled.get(96)) { + selfdestructWontRevertNotYetMarkedXorStoFlag.position(selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } - if (!filled.get(165)) { + if (!filled.get(164)) { stackItemHeight1.position(stackItemHeight1.position() + 32); } - if (!filled.get(166)) { + if (!filled.get(165)) { stackItemHeight2.position(stackItemHeight2.position() + 32); } - if (!filled.get(167)) { + if (!filled.get(166)) { stackItemHeight3.position(stackItemHeight3.position() + 32); } - if (!filled.get(168)) { + if (!filled.get(167)) { stackItemHeight4.position(stackItemHeight4.position() + 32); } - if (!filled.get(169)) { + if (!filled.get(168)) { stackItemStamp1.position(stackItemStamp1.position() + 32); } - if (!filled.get(170)) { + if (!filled.get(169)) { stackItemStamp2.position(stackItemStamp2.position() + 32); } - if (!filled.get(171)) { + if (!filled.get(170)) { stackItemStamp3.position(stackItemStamp3.position() + 32); } - if (!filled.get(172)) { + if (!filled.get(171)) { stackItemStamp4.position(stackItemStamp4.position() + 32); } - if (!filled.get(173)) { + if (!filled.get(172)) { stackItemValueHi1.position(stackItemValueHi1.position() + 32); } - if (!filled.get(174)) { + if (!filled.get(173)) { stackItemValueHi2.position(stackItemValueHi2.position() + 32); } - if (!filled.get(175)) { + if (!filled.get(174)) { stackItemValueHi3.position(stackItemValueHi3.position() + 32); } - if (!filled.get(176)) { + if (!filled.get(175)) { stackItemValueHi4.position(stackItemValueHi4.position() + 32); } - if (!filled.get(177)) { + if (!filled.get(176)) { stackItemValueLo1.position(stackItemValueLo1.position() + 32); } - if (!filled.get(178)) { + if (!filled.get(177)) { stackItemValueLo2.position(stackItemValueLo2.position() + 32); } - if (!filled.get(179)) { + if (!filled.get(178)) { stackItemValueLo3.position(stackItemValueLo3.position() + 32); } - if (!filled.get(180)) { + if (!filled.get(179)) { stackItemValueLo4.position(stackItemValueLo4.position() + 32); } - if (!filled.get(51)) { + if (!filled.get(50)) { stoFinal.position(stoFinal.position() + 1); } - if (!filled.get(52)) { + if (!filled.get(51)) { stoFirst.position(stoFirst.position() + 1); } - if (!filled.get(160)) { + if (!filled.get(159)) { stpGasHi.position(stpGasHi.position() + 32); } - if (!filled.get(161)) { + if (!filled.get(160)) { stpGasLo.position(stpGasLo.position() + 32); } - if (!filled.get(125)) { - stpGasUpfrontGasCostXorGasLeftover.position( - stpGasUpfrontGasCostXorGasLeftover.position() + 32); + if (!filled.get(124)) { + stpGasUpfrontGasCostXorGasLeftover.position(stpGasUpfrontGasCostXorGasLeftover.position() + 32); } - if (!filled.get(162)) { + if (!filled.get(161)) { stpValueHi.position(stpValueHi.position() + 32); } - if (!filled.get(163)) { + if (!filled.get(162)) { stpValueLo.position(stpValueLo.position() + 32); } @@ -7043,66 +6595,59 @@ public Trace fillAndValidateRow() { subStamp.position(subStamp.position() + 8); } - if (!filled.get(98)) { + if (!filled.get(97)) { sux.position(sux.position() + 1); } - if (!filled.get(99)) { + if (!filled.get(98)) { swapFlag.position(swapFlag.position() + 1); } - if (!filled.get(40)) { - transactionReverts.position(transactionReverts.position() + 1); - } - - if (!filled.get(66)) { - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + if (!filled.get(65)) { + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position(trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } - if (!filled.get(144)) { + if (!filled.get(143)) { trmRawAddressHiXorMxpOffset1Lo.position(trmRawAddressHiXorMxpOffset1Lo.position() + 32); } - if (!filled.get(41)) { + if (!filled.get(40)) { twoLineInstruction.position(twoLineInstruction.position() + 1); } - if (!filled.get(42)) { + if (!filled.get(41)) { txExec.position(txExec.position() + 1); } - if (!filled.get(43)) { + if (!filled.get(42)) { txFinl.position(txFinl.position() + 1); } - if (!filled.get(44)) { + if (!filled.get(43)) { txInit.position(txInit.position() + 1); } - if (!filled.get(45)) { + if (!filled.get(44)) { txSkip.position(txSkip.position() + 1); } - if (!filled.get(46)) { + if (!filled.get(45)) { txWarm.position(txWarm.position() + 1); } - if (!filled.get(100)) { + if (!filled.get(99)) { txnFlag.position(txnFlag.position() + 1); } - if (!filled.get(68)) { - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); + if (!filled.get(67)) { + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position(warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); } - if (!filled.get(67)) { - warmthXorCreateExceptionXorHaltFlag.position( - warmthXorCreateExceptionXorHaltFlag.position() + 1); + if (!filled.get(66)) { + warmthXorCreateExceptionXorHaltFlag.position(warmthXorCreateExceptionXorHaltFlag.position() + 1); } - if (!filled.get(101)) { + if (!filled.get(100)) { wcpFlag.position(wcpFlag.position() + 1); } diff --git a/gradle/trace-files.gradle b/gradle/trace-files.gradle index b43f38bbec..497d4ac64a 100644 --- a/gradle/trace-files.gradle +++ b/gradle/trace-files.gradle @@ -32,8 +32,8 @@ tasks.register("hub", TraceFilesTask) { dependsOn corsetExists module = 'hub' - files = ['account', 'context', 'shared', 'stack', 'storage', 'transaction', 'scenario', 'miscellaneous'] - .collect {"hub/columns/${it}.lisp"} + files = ['hub/constants.lisp', 'hub/columns/account.lisp', 'hub/columns/context.lisp', 'hub/columns/shared.lisp', 'hub/columns/stack.lisp', + 'hub/columns/storage.lisp', 'hub/columns/transaction.lisp', 'hub/columns/scenario.lisp', 'hub/columns/miscellaneous.lisp'] } // @@ -106,7 +106,7 @@ tasks.register('binreftable', TraceFilesTask) { } // -// Put here modules following the conventional MODULE/columns.lisp, MODULE/constants.lisp naming scheme. +// Shared constants: // ['constants'].each {moduleName -> tasks.register(moduleName, TraceFilesTask) { From 76822aba6f6da5c6ae58617b1f7db38fc502686e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 2 Jun 2024 23:27:46 +0530 Subject: [PATCH 040/461] style: ras --- .../java/net/consensys/linea/zktracer/runtime/stack/Stack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 80ba268416..81f704ef15 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 @@ -345,7 +345,7 @@ public void processInstruction(final Hub hub, MessageFrame frame, int stackStamp hub.wcp().callLT(this.height, this.currentOpcodeData.stackSettings().delta()); if (!this.isUnderflow()) { - hub.wcp().callGT(this.height - delta + alpha, 1024); + hub.wcp().callGT(this.height - delta + alpha, MAX_STACK_SIZE); } if (this.status.isFailure()) { From bfdc15581385414fa87729cb414c7e5dd3c486d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 17:29:16 +0400 Subject: [PATCH 041/461] spotless 10x anginier ? --- .../linea/zktracer/module/hub/Trace.java | 1108 ++++++++++++----- 1 file changed, 772 insertions(+), 336 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 1a0434ce1a..5615a082c1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.hub; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -42,24 +41,32 @@ public class Trace { private final MappedByteBuffer absoluteTransactionNumber; private final MappedByteBuffer accFinal; private final MappedByteBuffer accFirst; - private final MappedByteBuffer addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; - private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; + private final MappedByteBuffer + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; private final MappedByteBuffer alpha; - private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; - private final MappedByteBuffer balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; + private final MappedByteBuffer + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; + private final MappedByteBuffer + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer batchNumber; private final MappedByteBuffer callDataOffsetXorMmuSize; private final MappedByteBuffer callDataSizeXorMmuSrcId; private final MappedByteBuffer callStackDepth; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; + private final MappedByteBuffer + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; private final MappedByteBuffer codeHashHiNewXorExpData5XorValueCurrLoXorValue; - private final MappedByteBuffer codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorValueNextLo; private final MappedByteBuffer codeHashLoXorMmuLimb1XorValueNextHi; - private final MappedByteBuffer codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; - private final MappedByteBuffer codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; + private final MappedByteBuffer + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; + private final MappedByteBuffer + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; private final MappedByteBuffer conAgain; private final MappedByteBuffer conFirst; private final MappedByteBuffer contextGetsReverted; @@ -75,37 +82,51 @@ public class Trace { private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; - private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; private final MappedByteBuffer delta; - private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; - private final MappedByteBuffer deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; - private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; - private final MappedByteBuffer deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; - private final MappedByteBuffer deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; - private final MappedByteBuffer deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; + private final MappedByteBuffer + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; + private final MappedByteBuffer + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; + private final MappedByteBuffer + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; + private final MappedByteBuffer + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; + private final MappedByteBuffer + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; + private final MappedByteBuffer + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; - private final MappedByteBuffer existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; - private final MappedByteBuffer existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; + private final MappedByteBuffer + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; + private final MappedByteBuffer + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; - private final MappedByteBuffer hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; - private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; + private final MappedByteBuffer + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; + private final MappedByteBuffer + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; private final MappedByteBuffer hashInfoStamp; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; - private final MappedByteBuffer isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; + private final MappedByteBuffer + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; private final MappedByteBuffer logInfoStamp; - private final MappedByteBuffer markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; - private final MappedByteBuffer markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; + private final MappedByteBuffer + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; + private final MappedByteBuffer + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -225,24 +246,49 @@ static List headers(int length) { new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), - new ColumnHeader("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", 8, length), - new ColumnHeader("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", + 8, + length), + new ColumnHeader( + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.ALPHA", 1, length), - new ColumnHeader("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 32, length), - new ColumnHeader("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", + 32, + length), + new ColumnHeader( + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.BATCH_NUMBER", 4, length), new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), - new ColumnHeader("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", 8, length), - new ColumnHeader("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), - new ColumnHeader("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", + 8, + length), + new ColumnHeader( + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), + new ColumnHeader( + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), - new ColumnHeader("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", 8, length), - new ColumnHeader("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", 8, length), + new ColumnHeader( + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", + 8, + length), + new ColumnHeader( + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", + 8, + length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), @@ -256,39 +302,83 @@ static List headers(int length) { new ColumnHeader("hub.COUNTER_NSR", 2, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", + 1, + length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), new ColumnHeader("hub.DELTA", 1, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", 8, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", 8, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", 8, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", 1, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", 1, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", 1, length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", + 1, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", + 1, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", + 1, + length), new ColumnHeader("hub.DOM_STAMP", 8, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), - new ColumnHeader("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", 1, length), - new ColumnHeader("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", 1, length), + new ColumnHeader( + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", + 1, + length), + new ColumnHeader( + "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", + 1, + length), new ColumnHeader("hub.GAS_ACTUAL", 8, length), new ColumnHeader("hub.GAS_COST", 32, length), new ColumnHeader("hub.GAS_EXPECTED", 8, length), new ColumnHeader("hub.GAS_LIMIT", 32, length), new ColumnHeader("hub.GAS_NEXT", 8, length), new ColumnHeader("hub.GAS_PRICE", 32, length), - new ColumnHeader("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", 1, length), - new ColumnHeader("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), + new ColumnHeader( + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", + 1, + length), + new ColumnHeader( + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", + 1, + length), new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), new ColumnHeader("hub.HEIGHT", 2, length), new ColumnHeader("hub.HEIGHT_NEW", 2, length), new ColumnHeader("hub.HUB_STAMP", 8, length), new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), new ColumnHeader("hub.INSTRUCTION", 32, length), - new ColumnHeader("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", 1, length), + new ColumnHeader( + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", + 1, + length), new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), - new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", 1, length), - new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", 1, length), + new ColumnHeader( + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", + 1, + length), + new ColumnHeader( + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", + 1, + length), new ColumnHeader("hub.MMU_STAMP", 8, length), new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), @@ -302,7 +392,8 @@ static List headers(int length) { new ColumnHeader("hub.NB_REMOVED", 1, length), new ColumnHeader("hub.NON_STACK_ROWS", 2, length), new ColumnHeader("hub.NONCE", 32, length), - new ColumnHeader("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), + new ColumnHeader( + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), new ColumnHeader("hub.OOB_DATA_1", 32, length), new ColumnHeader("hub.OOB_DATA_2", 32, length), @@ -346,20 +437,34 @@ static List headers(int length) { new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), - new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), - new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), - new ColumnHeader("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), - new ColumnHeader("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), - new ColumnHeader("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + new ColumnHeader( + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), + new ColumnHeader( + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), + new ColumnHeader( + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", + 1, + length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), - new ColumnHeader("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader( + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), - new ColumnHeader("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), + new ColumnHeader( + "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", + 1, + length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), @@ -390,7 +495,8 @@ static List headers(int length) { new ColumnHeader("hub.SUB_STAMP", 8, length), new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), - new ColumnHeader("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + new ColumnHeader( + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -399,7 +505,10 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), + new ColumnHeader( + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", + 1, + length), new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -408,24 +517,36 @@ public Trace(List buffers) { this.absoluteTransactionNumber = buffers.get(0); this.accFinal = buffers.get(1); this.accFirst = buffers.get(2); - this.addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = buffers.get(3); - this.addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(4); + this + .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = + buffers.get(3); + this + .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = + buffers.get(4); this.alpha = buffers.get(5); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(6); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = buffers.get(7); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = + buffers.get(6); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = + buffers.get(7); this.batchNumber = buffers.get(8); this.callDataOffsetXorMmuSize = buffers.get(9); this.callDataSizeXorMmuSrcId = buffers.get(10); this.callStackDepth = buffers.get(11); this.callerContextNumber = buffers.get(12); this.codeFragmentIndex = buffers.get(13); - this.codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = buffers.get(14); + this + .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = + buffers.get(14); this.codeHashHiNewXorExpData5XorValueCurrLoXorValue = buffers.get(15); - this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = + buffers.get(16); this.codeHashLoNewXorMmuLimb2XorValueNextLo = buffers.get(17); this.codeHashLoXorMmuLimb1XorValueNextHi = buffers.get(18); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = buffers.get(19); - this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = buffers.get(20); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = + buffers.get(19); + this + .codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = + buffers.get(20); this.conAgain = buffers.get(21); this.conFirst = buffers.get(22); this.contextGetsReverted = buffers.get(23); @@ -444,34 +565,48 @@ public Trace(List buffers) { this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); this.delta = buffers.get(38); - this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = buffers.get(39); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = + buffers.get(39); this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); - this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = buffers.get(41); - this.deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = buffers.get(42); - this.deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = buffers.get(43); - this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = buffers.get(44); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = + buffers.get(41); + this + .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = + buffers.get(42); + this + .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = + buffers.get(43); + this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = + buffers.get(44); this.domStamp = buffers.get(45); this.exceptionAhoy = buffers.get(46); - this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = buffers.get(47); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = buffers.get(48); + this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = + buffers.get(47); + this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = + buffers.get(48); this.gasActual = buffers.get(49); this.gasCost = buffers.get(50); this.gasExpected = buffers.get(51); this.gasLimit = buffers.get(52); this.gasNext = buffers.get(53); this.gasPrice = buffers.get(54); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = buffers.get(55); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = buffers.get(56); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = + buffers.get(55); + this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = + buffers.get(56); this.hashInfoStamp = buffers.get(57); this.height = buffers.get(58); this.heightNew = buffers.get(59); this.hubStamp = buffers.get(60); this.hubStampTransactionEnd = buffers.get(61); this.instruction = buffers.get(62); - this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = buffers.get(63); + this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = + buffers.get(63); this.logInfoStamp = buffers.get(64); - this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = buffers.get(65); - this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = buffers.get(66); + this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = + buffers.get(65); + this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = + buffers.get(66); this.mmuStamp = buffers.get(67); this.mxpOffset2Hi = buffers.get(68); this.mxpOffset2Lo = buffers.get(69); @@ -990,7 +1125,8 @@ public Trace pAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1004,9 +1140,11 @@ public Trace pAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1020,9 +1158,11 @@ public Trace pAccountBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1036,9 +1176,11 @@ public Trace pAccountBalanceNew(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1050,7 +1192,8 @@ public Trace pAccountCodeFragmentIndex(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1066,7 +1209,8 @@ public Trace pAccountCodeHashHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1126,7 +1270,8 @@ public Trace pAccountCodeSize(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1186,7 +1331,8 @@ public Trace pAccountDeploymentStatus(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1198,7 +1344,8 @@ public Trace pAccountDeploymentStatusInfty(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1210,7 +1357,8 @@ public Trace pAccountDeploymentStatusNew(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -1222,7 +1370,8 @@ public Trace pAccountExists(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -1234,7 +1383,8 @@ public Trace pAccountExistsNew(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -1246,7 +1396,8 @@ public Trace pAccountHasCode(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -1258,7 +1409,8 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -1270,7 +1422,8 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -1282,7 +1435,8 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -1294,7 +1448,8 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } @@ -1518,7 +1673,8 @@ public Trace pContextAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1532,9 +1688,11 @@ public Trace pContextAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1546,7 +1704,8 @@ public Trace pContextAccountDeploymentNumber(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1558,7 +1717,8 @@ public Trace pContextByteCodeAddressHi(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1572,9 +1732,11 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1674,7 +1836,8 @@ public Trace pContextCallValue(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1700,9 +1863,11 @@ public Trace pContextCallerAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1726,7 +1891,8 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1738,7 +1904,8 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1810,7 +1977,8 @@ public Trace pContextUpdate(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -1822,7 +1990,8 @@ public Trace pMiscCcrsStamp(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1834,7 +2003,8 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1848,9 +2018,11 @@ public Trace pMiscExpData1(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1864,9 +2036,11 @@ public Trace pMiscExpData2(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1880,9 +2054,11 @@ public Trace pMiscExpData3(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1898,7 +2074,8 @@ public Trace pMiscExpData4(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1926,7 +2103,8 @@ public Trace pMiscExpFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1938,7 +2116,8 @@ public Trace pMiscExpInst(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1950,7 +2129,8 @@ public Trace pMiscMmuAuxId(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1974,7 +2154,8 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -2122,7 +2303,8 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -2162,7 +2344,8 @@ public Trace pMiscMxpDeploys(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -2174,7 +2357,8 @@ public Trace pMiscMxpFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -2214,7 +2398,8 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -2226,7 +2411,8 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -2510,7 +2696,8 @@ public Trace pMiscOobFlag(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -2534,7 +2721,8 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } @@ -2718,31 +2906,36 @@ public Trace pScenarioCallAbort(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { if (filled.get(53)) { - throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { if (filled.get(54)) { - throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -2754,7 +2947,8 @@ public Trace pScenarioCallException(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -2766,74 +2960,86 @@ public Trace pScenarioCallPrcFailure(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { if (filled.get(57)) { - throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { if (filled.get(58)) { - throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { if (filled.get(59)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); } else { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { if (filled.get(60)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); } else { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { if (filled.get(61)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { if (filled.get(62)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(62); } @@ -2857,7 +3063,8 @@ public Trace pScenarioCreateAbort(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { if (filled.get(64)) { - throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); } else { filled.set(64); } @@ -2869,7 +3076,8 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { if (filled.get(65)) { - throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); } else { filled.set(65); } @@ -2893,7 +3101,8 @@ public Trace pScenarioCreateException(final Boolean b) { public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { if (filled.get(67)) { - throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); } else { filled.set(67); } @@ -2905,7 +3114,8 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { if (filled.get(68)) { - throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); } else { filled.set(68); } @@ -2917,7 +3127,8 @@ public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { if (filled.get(69)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); } else { filled.set(69); } @@ -2929,7 +3140,8 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { if (filled.get(70)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); } else { filled.set(70); } @@ -2941,19 +3153,22 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { if (filled.get(71)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); } else { filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { if (filled.get(72)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); } else { filled.set(72); } @@ -2982,7 +3197,8 @@ public Trace pScenarioPrcCalleeGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -2994,7 +3210,8 @@ public Trace pScenarioPrcCallerGas(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -3006,7 +3223,8 @@ public Trace pScenarioPrcCdo(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -3217,7 +3435,8 @@ public Trace pScenarioReturnException(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { if (filled.get(87)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { filled.set(87); } @@ -3229,7 +3448,8 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { if (filled.get(88)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { filled.set(88); } @@ -3241,7 +3461,8 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { if (filled.get(89)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { filled.set(89); } @@ -3253,7 +3474,8 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { if (filled.get(90)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { filled.set(90); } @@ -3265,7 +3487,8 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { if (filled.get(91)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { filled.set(91); } @@ -3277,7 +3500,8 @@ public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { if (filled.get(92)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { filled.set(92); } @@ -3313,7 +3537,8 @@ public Trace pScenarioSelfdestructWillRevert(final Boolean b) { public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { if (filled.get(95)) { - throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); + throw new IllegalStateException( + "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { filled.set(95); } @@ -3325,7 +3550,8 @@ public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { if (filled.get(96)) { - throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); + throw new IllegalStateException( + "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { filled.set(96); } @@ -3342,7 +3568,8 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -3354,7 +3581,8 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -3378,7 +3606,8 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -3390,7 +3619,8 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -3402,7 +3632,8 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -3414,7 +3645,8 @@ public Trace pStackConFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -3426,7 +3658,8 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -3438,7 +3671,8 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -3450,7 +3684,8 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -3462,7 +3697,8 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( + (byte) (b ? 1 : 0)); return this; } @@ -3560,9 +3796,11 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -3576,9 +3814,11 @@ public Trace pStackHashInfoKeccakLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -3630,7 +3870,8 @@ public Trace pStackJumpDestinationVettingRequired(final Boolean b) { filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( + (byte) (b ? 1 : 0)); return this; } @@ -3824,9 +4065,11 @@ public Trace pStackPushValueHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -3842,7 +4085,8 @@ public Trace pStackPushValueLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4242,7 +4486,8 @@ public Trace pStackStaticGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4326,7 +4571,8 @@ public Trace pStorageAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4340,9 +4586,11 @@ public Trace pStorageAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4354,7 +4602,8 @@ public Trace pStorageDeploymentNumber(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -4366,7 +4615,8 @@ public Trace pStorageDeploymentNumberInfty(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -4380,9 +4630,11 @@ public Trace pStorageStorageKeyHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4396,9 +4648,11 @@ public Trace pStorageStorageKeyLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -4410,7 +4664,8 @@ public Trace pStorageValueCurrChanges(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4426,7 +4681,8 @@ public Trace pStorageValueCurrHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4438,7 +4694,8 @@ public Trace pStorageValueCurrIsOrig(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -4450,7 +4707,8 @@ public Trace pStorageValueCurrIsZero(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -4494,7 +4752,8 @@ public Trace pStorageValueNextIsCurr(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -4506,7 +4765,8 @@ public Trace pStorageValueNextIsOrig(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -4518,7 +4778,8 @@ public Trace pStorageValueNextIsZero(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4562,7 +4823,8 @@ public Trace pStorageValueOrigIsZero(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4590,7 +4852,8 @@ public Trace pStorageWarmth(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -4602,7 +4865,8 @@ public Trace pStorageWarmthNew(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -4630,7 +4894,8 @@ public Trace pTransactionBatchNum(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4642,7 +4907,8 @@ public Trace pTransactionCallDataSize(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -4654,7 +4920,8 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -4668,9 +4935,11 @@ public Trace pTransactionCoinbaseAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4682,7 +4951,8 @@ public Trace pTransactionCopyTxcd(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4708,9 +4978,11 @@ public Trace pTransactionFromAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4800,9 +5072,11 @@ public Trace pTransactionInitialBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -4814,7 +5088,8 @@ public Trace pTransactionIsDeployment(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -4826,7 +5101,8 @@ public Trace pTransactionIsType2(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -4902,7 +5178,8 @@ public Trace pTransactionRequiresEvmExecution(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -4914,7 +5191,8 @@ public Trace pTransactionStatusCode(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -4942,7 +5220,8 @@ public Trace pTransactionToAddressLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -5217,11 +5496,13 @@ public Trace validateRow() { } if (!filled.get(106)) { - throw new IllegalStateException("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); + throw new IllegalStateException( + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } if (!filled.get(131)) { - throw new IllegalStateException("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } if (!filled.get(101)) { @@ -5229,11 +5510,13 @@ public Trace validateRow() { } if (!filled.get(133)) { - throw new IllegalStateException("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); + throw new IllegalStateException( + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } if (!filled.get(132)) { - throw new IllegalStateException("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } if (!filled.get(1)) { @@ -5261,31 +5544,38 @@ public Trace validateRow() { } if (!filled.get(107)) { - throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); + throw new IllegalStateException( + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } if (!filled.get(135)) { - throw new IllegalStateException("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } if (!filled.get(134)) { - throw new IllegalStateException("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } if (!filled.get(137)) { - throw new IllegalStateException("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } if (!filled.get(136)) { - throw new IllegalStateException("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } if (!filled.get(109)) { - throw new IllegalStateException("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } if (!filled.get(108)) { - throw new IllegalStateException("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); } if (!filled.get(48)) { @@ -5337,23 +5627,28 @@ public Trace validateRow() { } if (!filled.get(68)) { - throw new IllegalStateException("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + throw new IllegalStateException( + "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); } if (!filled.get(69)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); } if (!filled.get(70)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); } if (!filled.get(71)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); } if (!filled.get(72)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); } if (!filled.get(102)) { @@ -5361,27 +5656,33 @@ public Trace validateRow() { } if (!filled.get(111)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } if (!filled.get(112)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } if (!filled.get(110)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } if (!filled.get(53)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(54)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); } if (!filled.get(52)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); } if (!filled.get(13)) { @@ -5393,11 +5694,13 @@ public Trace validateRow() { } if (!filled.get(56)) { - throw new IllegalStateException("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); + throw new IllegalStateException( + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); } if (!filled.get(55)) { - throw new IllegalStateException("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); + throw new IllegalStateException( + "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(15)) { @@ -5425,11 +5728,13 @@ public Trace validateRow() { } if (!filled.get(58)) { - throw new IllegalStateException("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); + throw new IllegalStateException( + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(57)) { - throw new IllegalStateException("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + throw new IllegalStateException( + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(19)) { @@ -5457,7 +5762,8 @@ public Trace validateRow() { } if (!filled.get(59)) { - throw new IllegalStateException("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); + throw new IllegalStateException( + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); } if (!filled.get(24)) { @@ -5465,11 +5771,13 @@ public Trace validateRow() { } if (!filled.get(61)) { - throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); + throw new IllegalStateException( + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); } if (!filled.get(60)) { - throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); + throw new IllegalStateException( + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); } if (!filled.get(25)) { @@ -5525,7 +5833,8 @@ public Trace validateRow() { } if (!filled.get(123)) { - throw new IllegalStateException("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + throw new IllegalStateException( + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } if (!filled.get(122)) { @@ -5605,7 +5914,8 @@ public Trace validateRow() { } if (!filled.get(76)) { - throw new IllegalStateException("hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); } if (!filled.get(77)) { @@ -5613,11 +5923,13 @@ public Trace validateRow() { } if (!filled.get(78)) { - throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); } if (!filled.get(79)) { - throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); } if (!filled.get(80)) { @@ -5637,11 +5949,13 @@ public Trace validateRow() { } if (!filled.get(84)) { - throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(85)) { - throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); + throw new IllegalStateException( + "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); } if (!filled.get(128)) { @@ -5681,11 +5995,13 @@ public Trace validateRow() { } if (!filled.get(119)) { - throw new IllegalStateException("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + throw new IllegalStateException( + "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } if (!filled.get(120)) { - throw new IllegalStateException("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + throw new IllegalStateException( + "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } if (!filled.get(121)) { @@ -5697,51 +6013,63 @@ public Trace validateRow() { } if (!filled.get(87)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); } if (!filled.get(88)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(89)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(90)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(91)) { - throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(92)) { - throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } if (!filled.get(113)) { - throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } if (!filled.get(138)) { - throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } if (!filled.get(62)) { - throw new IllegalStateException("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); } if (!filled.get(139)) { - throw new IllegalStateException("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } if (!filled.get(140)) { - throw new IllegalStateException("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } if (!filled.get(63)) { - throw new IllegalStateException("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } if (!filled.get(141)) { @@ -5749,27 +6077,33 @@ public Trace validateRow() { } if (!filled.get(142)) { - throw new IllegalStateException("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } if (!filled.get(64)) { - throw new IllegalStateException("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } if (!filled.get(93)) { - throw new IllegalStateException("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); } if (!filled.get(94)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); } if (!filled.get(95)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); } if (!filled.get(96)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } if (!filled.get(164)) { @@ -5853,7 +6187,8 @@ public Trace validateRow() { } if (!filled.get(124)) { - throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); + throw new IllegalStateException( + "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } if (!filled.get(161)) { @@ -5877,11 +6212,13 @@ public Trace validateRow() { } if (!filled.get(65)) { - throw new IllegalStateException("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + throw new IllegalStateException( + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } if (!filled.get(143)) { - throw new IllegalStateException("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); + throw new IllegalStateException( + "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } if (!filled.get(40)) { @@ -5913,11 +6250,13 @@ public Trace validateRow() { } if (!filled.get(67)) { - throw new IllegalStateException("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + throw new IllegalStateException( + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); } if (!filled.get(66)) { - throw new IllegalStateException("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + throw new IllegalStateException( + "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } if (!filled.get(100)) { @@ -5944,11 +6283,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(106)) { - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position(addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position() + 8); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .position( + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .position() + + 8); } if (!filled.get(131)) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position(addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position() + 32); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position( + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position() + + 32); } if (!filled.get(101)) { @@ -5956,11 +6303,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(133)) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position(balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position() + 32); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance + .position( + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance + .position() + + 32); } if (!filled.get(132)) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position(balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position() + 32); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo + .position( + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo + .position() + + 32); } if (!filled.get(1)) { @@ -5988,31 +6343,46 @@ public Trace fillAndValidateRow() { } if (!filled.get(107)) { - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position(codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position() + 8); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .position( + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .position() + + 8); } if (!filled.get(135)) { - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position(codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); } if (!filled.get(134)) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position(codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 32); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + + 32); } if (!filled.get(137)) { - codeHashLoNewXorMmuLimb2XorValueNextLo.position(codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); + codeHashLoNewXorMmuLimb2XorValueNextLo.position( + codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); } if (!filled.get(136)) { - codeHashLoXorMmuLimb1XorValueNextHi.position(codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); + codeHashLoXorMmuLimb1XorValueNextHi.position( + codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); } if (!filled.get(109)) { - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position(codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + 8); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + + 8); } if (!filled.get(108)) { - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position(codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position() + 8); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position( + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position() + + 8); } if (!filled.get(48)) { @@ -6064,23 +6434,28 @@ public Trace fillAndValidateRow() { } if (!filled.get(68)) { - createFailureConditionWontRevertXorIcpx.position(createFailureConditionWontRevertXorIcpx.position() + 1); + createFailureConditionWontRevertXorIcpx.position( + createFailureConditionWontRevertXorIcpx.position() + 1); } if (!filled.get(69)) { - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position(createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position( + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); } if (!filled.get(70)) { - createNonemptyInitCodeFailureWontRevertXorJumpx.position(createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); + createNonemptyInitCodeFailureWontRevertXorJumpx.position( + createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); } if (!filled.get(71)) { - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position(createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position( + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); } if (!filled.get(72)) { - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position(createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position( + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); } if (!filled.get(102)) { @@ -6088,27 +6463,45 @@ public Trace fillAndValidateRow() { } if (!filled.get(111)) { - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position(deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position() + 8); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi + .position() + + 8); } if (!filled.get(112)) { - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position(deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); } if (!filled.get(110)) { - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position(deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + 8); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + + 8); } if (!filled.get(53)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position(deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment.position() + 1); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .position( + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment + .position() + + 1); } if (!filled.get(54)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position(deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2.position() + 1); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .position( + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 + .position() + + 1); } if (!filled.get(52)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position(deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.position() + 1); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd + .position( + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd + .position() + + 1); } if (!filled.get(13)) { @@ -6120,11 +6513,18 @@ public Trace fillAndValidateRow() { } if (!filled.get(56)) { - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position(existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position() + 1); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position( + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode + .position() + + 1); } if (!filled.get(55)) { - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position(existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.position() + 1); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution + .position( + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution + .position() + + 1); } if (!filled.get(15)) { @@ -6152,11 +6552,16 @@ public Trace fillAndValidateRow() { } if (!filled.get(58)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position(hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position() + 1); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero + .position() + + 1); } if (!filled.get(57)) { - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position(hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() + 1); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position( + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() + + 1); } if (!filled.get(19)) { @@ -6184,7 +6589,9 @@ public Trace fillAndValidateRow() { } if (!filled.get(59)) { - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position(isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + 1); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() + + 1); } if (!filled.get(24)) { @@ -6192,11 +6599,18 @@ public Trace fillAndValidateRow() { } if (!filled.get(61)) { - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position(markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position() + 1); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 + .position() + + 1); } if (!filled.get(60)) { - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position(markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.position() + 1); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew + .position( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew + .position() + + 1); } if (!filled.get(25)) { @@ -6252,7 +6666,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(123)) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position(nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); } if (!filled.get(122)) { @@ -6364,7 +6779,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(84)) { - prcSuccessCallerWillRevertXorPushpopFlag.position(prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); + prcSuccessCallerWillRevertXorPushpopFlag.position( + prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); } if (!filled.get(85)) { @@ -6408,7 +6824,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(119)) { - returnDataContextNumberXorStpGasStipend.position(returnDataContextNumberXorStpGasStipend.position() + 8); + returnDataContextNumberXorStpGasStipend.position( + returnDataContextNumberXorStpGasStipend.position() + 8); } if (!filled.get(120)) { @@ -6424,43 +6841,53 @@ public Trace fillAndValidateRow() { } if (!filled.get(87)) { - returnFromDeploymentEmptyCodeWillRevertXorSox.position(returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + returnFromDeploymentEmptyCodeWillRevertXorSox.position( + returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); } if (!filled.get(88)) { - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position(returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position( + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); } if (!filled.get(89)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position(returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position( + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); } if (!filled.get(90)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position(returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position( + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); } if (!filled.get(91)) { - returnFromMessageCallWillTouchRamXorStackItemPop2.position(returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop2.position( + returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); } if (!filled.get(92)) { - returnFromMessageCallWontTouchRamXorStackItemPop3.position(returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); + returnFromMessageCallWontTouchRamXorStackItemPop3.position( + returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } if (!filled.get(113)) { - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position(rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); } if (!filled.get(138)) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position(rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); } if (!filled.get(62)) { - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position(rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); } if (!filled.get(139)) { - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position(rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); } if (!filled.get(140)) { @@ -6468,7 +6895,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(63)) { - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position(rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } if (!filled.get(141)) { @@ -6480,11 +6908,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(64)) { - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position(romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } if (!filled.get(93)) { - selfdestructExceptionXorStackItemPop4.position(selfdestructExceptionXorStackItemPop4.position() + 1); + selfdestructExceptionXorStackItemPop4.position( + selfdestructExceptionXorStackItemPop4.position() + 1); } if (!filled.get(94)) { @@ -6492,11 +6922,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(95)) { - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position(selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position( + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); } if (!filled.get(96)) { - selfdestructWontRevertNotYetMarkedXorStoFlag.position(selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); + selfdestructWontRevertNotYetMarkedXorStoFlag.position( + selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } if (!filled.get(164)) { @@ -6580,7 +7012,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(124)) { - stpGasUpfrontGasCostXorGasLeftover.position(stpGasUpfrontGasCostXorGasLeftover.position() + 32); + stpGasUpfrontGasCostXorGasLeftover.position( + stpGasUpfrontGasCostXorGasLeftover.position() + 32); } if (!filled.get(161)) { @@ -6604,7 +7037,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(65)) { - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position(trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } if (!filled.get(143)) { @@ -6640,11 +7074,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(67)) { - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position(warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); } if (!filled.get(66)) { - warmthXorCreateExceptionXorHaltFlag.position(warmthXorCreateExceptionXorHaltFlag.position() + 1); + warmthXorCreateExceptionXorHaltFlag.position( + warmthXorCreateExceptionXorHaltFlag.position() + 1); } if (!filled.get(100)) { From 789e4f09e17d6e6fe1b82fa481b02240abf2c45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 2 Jun 2024 22:03:06 +0400 Subject: [PATCH 042/461] beginnings of a DomSubData type DomSubData should become a subfragment of the storage/ and account/ perspectives --- .../module/hub/fragment/DomSubData.java | 33 +++++++++++++++++++ .../fragment/account/AccountFragmentType.java | 23 ------------- newFragments | 10 ++++++ simplify_hub | 4 +++ 4 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java create mode 100644 newFragments create mode 100644 simplify_hub diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java new file mode 100644 index 0000000000..c451addd44 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java @@ -0,0 +1,33 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment; + +import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___DOM_SUB_STAMPS; + +import com.google.common.base.Preconditions; + +public record DomSubData(DomSubType type, int domOffset, int subOffset) { + public int domStamp(final int hubStamp) { + Preconditions.checkArgument(this.type == DomSubType.STANDARD); + return MULTIPLIER___DOM_SUB_STAMPS * hubStamp + this.domOffset; + } + + public enum DomSubType { + STANDARD, + REVERTS_WITH_CURRENT, + REVERTS_WITH_CHILD, + REVERTS_WITH_SELFDESTRUCT + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java deleted file mode 100644 index 7331a127f6..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragmentType.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.account; - -public enum AccountFragmentType { - STANDARD, - REVERT_WITH_CURRENT, - REVERT_WITH_CHILD, - SELF_DESTRUCT -} diff --git a/newFragments b/newFragments new file mode 100644 index 0000000000..3399adfe5a --- /dev/null +++ b/newFragments @@ -0,0 +1,10 @@ +Il nous faudrait des +- shared/domSubFragment +- stack/logInfoFragment +- stack/hashInfoFragment +- stack/jumpDestinationVettingFragment +- address/rlpAddrFragment +- address/romlexFragment +- address/trimFragment +- misc/childContextDataFragment +- gasFragment (?) diff --git a/simplify_hub b/simplify_hub new file mode 100644 index 0000000000..ae8d1d0253 --- /dev/null +++ b/simplify_hub @@ -0,0 +1,4 @@ +- make the CODE_HASH, NONCE and BALANCE comparisons required in the account perspective in the WCP and _NEW versions thereof +- make the ORIGINAL etc ... storage value comparions from the storage perspecive in the WCP + +This could be beneficial in terms of constraints, in particular these flags will be useful when detecting CREATE failure conditions. From b080a26208fd161021fa541e6383e3a9426fa788 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 3 Jun 2024 00:16:27 +0530 Subject: [PATCH 043/461] fix: some java issues --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 7 +++++-- .../zktracer/module/hub/fragment/StackFragment.java | 11 ++++++----- .../consensys/linea/zktracer/types/AddressUtils.java | 4 +++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index af5b6fd1f8..8aa14cb3d4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -678,7 +678,7 @@ public int contextNumberNew(WorldView world) { if (pch().abortingConditions().any()) { return currentContextNumber; } - Address calleeAddress = addressFromBytes(this.currentFrame().frame().getStackItem(1)); + Address calleeAddress = Words.toAddress(this.currentFrame().frame().getStackItem(1)); if (world.get(calleeAddress).hasCode()) { return 1 + stamp(); } @@ -1425,7 +1425,10 @@ void traceOperation(MessageFrame frame) { switch (this.currentFrame().opCode()) { case CODECOPY -> this.currentFrame().byteCodeAddress(); case EXTCODECOPY -> frame.getStackItem(0); - default -> throw new IllegalStateException("unexpected opcode"); + case CALLDATACOPY -> addressFromBytes( + Bytes.fromHexString("0xdeadbeef")); // TODO: implement me please + default -> throw new IllegalStateException( + String.format("unexpected opcode %s", this.opCode())); }; final Address targetAddress = Words.toAddress(rawTargetAddress); final Account targetAccount = frame.getWorldUpdater().get(targetAddress); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 03c0996a81..594c47bf76 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -42,6 +42,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; @Accessors(fluent = true) public final class StackFragment implements TraceFragment { @@ -85,19 +86,19 @@ private StackFragment( Bytes memorySegmentToHash; switch (this.opCode) { case SHA3, RETURN -> { - long offset = hub.currentFrame().frame().getStackItem(0).toLong(); - long size = hub.currentFrame().frame().getStackItem(1).toLong(); + final long offset = Words.clampedToLong(hub.currentFrame().frame().getStackItem(0)); + final long size = Words.clampedToLong(hub.currentFrame().frame().getStackItem(1)); memorySegmentToHash = hub.messageFrame().shadowReadMemory(offset, size); } case CREATE2 -> { - long offset = hub.currentFrame().frame().getStackItem(1).toLong(); - long size = hub.currentFrame().frame().getStackItem(2).toLong(); + final long offset = Words.clampedToLong(hub.currentFrame().frame().getStackItem(1)); + final long size = Words.clampedToLong(hub.currentFrame().frame().getStackItem(2)); memorySegmentToHash = hub.messageFrame().shadowReadMemory(offset, size); } default -> throw new UnsupportedOperationException( "Hash was attempted by the following opcode: " + this.opCode().toString()); } - this.hashInfoKeccak = EWord.of(memorySegmentToHash); + this.hashInfoKeccak = EWord.of(Hash.hash(memorySegmentToHash)); } this.staticGas = gp.staticGas(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java index 8beeec58f3..34c7b2e04a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java @@ -105,6 +105,8 @@ public static Address getDeploymentAddress(final MessageFrame frame) { } public static Address addressFromBytes(final Bytes input) { - return Address.wrap(leftPadTo(input, Address.SIZE)); + return input.size() == Address.SIZE + ? Address.wrap(input) + : Address.wrap(leftPadTo(input.trimLeadingZeros(), Address.SIZE)); } } From 319037ad43d51bb1a8738c12b89540f2538c4dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 01:57:44 +0400 Subject: [PATCH 044/461] moved transaction finalization out of the HUB worldView.get(coinbaseAddress) return null ... which kills the address constraint in the coinbase row of finalization (success case.) --- .../linea/zktracer/module/hub/Hub.java | 113 +----------- .../hub/section/TxFinalizationSection.java | 165 ++++++++++++++++++ 2 files changed, 167 insertions(+), 111 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 8aa14cb3d4..4b903c688c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.hub; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_REFUND_QUOTIENT; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; @@ -26,7 +25,6 @@ import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.ArrayList; import java.util.HashMap; @@ -799,122 +797,15 @@ void processStateFinal(WorldView worldView) { this.state.setProcessingPhase(TX_FINAL); this.state.stamps().incrementHubStamp(); - final TransactionProcessingMetadata tx = this.txStack.current(); - - final Address senderAddress = tx.getSender(); - final Address effectiveToAddress = tx.getEffectiveTo(); - final Address coinbaseAddress = tx.getCoinbase(); - - final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); final boolean coinbaseWarmth = false; // TODO: get access to coinbase address warmth (still London!) - final Account senderAccount = worldView.get(senderAddress); - final AccountSnapshot senderAccountSnapshotBeforeRefunds = - AccountSnapshot.fromAccount( - senderAccount, - true, - deploymentInfo.number(senderAddress), - deploymentInfo.isDeploying(senderAddress)); - - final long gasUsed = tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas(); - final long effectiveRefunds = Math.min(this.accruedRefunds(), gasUsed / MAX_REFUND_QUOTIENT); - final long senderGasRefund = tx.getLeftoverGas() + effectiveRefunds; - - final long coinbaseGasReward = tx.getBesuTransaction().getGasLimit() - senderGasRefund; - final Wei coinbaseFee = - Wei.of( - BigInteger.valueOf(tx.getEffectiveGasPrice()) - .multiply(BigInteger.valueOf(coinbaseGasReward))); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - this.factories.accountFragment(); - if (this.txStack.current().statusCode()) { - - final Wei senderWeiRefund = - Wei.of( - BigInteger.valueOf(senderGasRefund) - .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice()))); - - final AccountSnapshot senderAccountSnapshotAfterGasRefund = - senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); - - final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); - - final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = - coinbaseIsSender - ? senderAccountSnapshotAfterGasRefund - : AccountSnapshot.fromAccount( - worldView.get(coinbaseAddress), - coinbaseWarmth, - deploymentInfo.number(coinbaseAddress), - deploymentInfo.isDeploying(coinbaseAddress)); - - final AccountSnapshot coinbaseSnapshotAfterFeeCollection = - coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); this.addTraceSection( - new TxFinalizationSection( - this, - accountFragmentFactory.make( - senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasRefund), - accountFragmentFactory.make( - coinbaseSnapshotBeforeFeeCollection, coinbaseSnapshotAfterFeeCollection), - TransactionFragment.prepare(this.txStack.current()))); + TxFinalizationSection.finalizeSuccessfulTransaction(this, worldView, coinbaseWarmth)); } else { - // SENDER account snapshots - final Wei senderWeiRefund = - Wei.of( - BigInteger.valueOf(senderGasRefund) - .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) - .add(tx.getBesuTransaction().getValue().getAsBigInteger())); - final AccountSnapshot senderAccountSnapshotAfterGasAndBalanceRefund = - senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); - - // RECIPIENT account snapshots - final boolean recipientIsSender = effectiveToAddress.equals(senderAddress); - final AccountSnapshot effectiveToAccountSnapshotBeforeReimbursingValue = - recipientIsSender - ? senderAccountSnapshotAfterGasAndBalanceRefund - : AccountSnapshot.fromAccount( - worldView.get(effectiveToAddress), - true, - deploymentInfo.number(effectiveToAddress), - deploymentInfo.isDeploying(effectiveToAddress)); - - final AccountSnapshot effectiveToAccountSnapshotAfterReimbursingValue = - effectiveToAccountSnapshotBeforeReimbursingValue.debit( - (Wei) tx.getBesuTransaction().getValue()); - - // COINBASE account snapshots - final boolean coinbaseIsRecipient = coinbaseAddress.equals(effectiveToAddress); - final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); - - AccountSnapshot coinbaseBeforeFeeCollection = - coinbaseIsRecipient - ? effectiveToAccountSnapshotAfterReimbursingValue - : coinbaseIsSender - ? senderAccountSnapshotAfterGasAndBalanceRefund - : AccountSnapshot.fromAccount( - worldView.get(coinbaseAddress), - coinbaseWarmth, - deploymentInfo.number(coinbaseAddress), - deploymentInfo.isDeploying(coinbaseAddress)); - - AccountSnapshot coinbaseAfterFeeCollection = - coinbaseBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); - this.addTraceSection( - new TxFinalizationSection( - this, - accountFragmentFactory.make( - senderAccountSnapshotBeforeRefunds, - senderAccountSnapshotAfterGasAndBalanceRefund), - accountFragmentFactory.make( - effectiveToAccountSnapshotBeforeReimbursingValue, - effectiveToAccountSnapshotAfterReimbursingValue), - accountFragmentFactory.make(coinbaseBeforeFeeCollection, coinbaseAfterFeeCollection), - TransactionFragment.prepare(this.txStack.current()))); + TxFinalizationSection.finalizeUnsuccessfulTransaction(this, worldView, coinbaseWarmth)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 7964357d06..29c3a5e456 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -15,14 +15,179 @@ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_REFUND_QUOTIENT; + +import java.math.BigInteger; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.worldstate.WorldView; public class TxFinalizationSection extends TraceSection { public TxFinalizationSection(Hub hub, TraceFragment... fragments) { this.addFragmentsWithoutStack(hub, fragments); } + public static TxFinalizationSection finalizeSuccessfulTransaction( + final Hub hub, final WorldView worldView, final boolean coinbaseWarmth) { + + final TransactionProcessingMetadata tx = hub.txStack().current(); + + final Address senderAddress = tx.getSender(); + final Address coinbaseAddress = tx.getCoinbase(); + + final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); + + final long gasUsed = tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas(); + final long effectiveRefunds = Math.min(hub.accruedRefunds(), gasUsed / MAX_REFUND_QUOTIENT); + final long senderGasRefund = tx.getLeftoverGas() + effectiveRefunds; + final long coinbaseGasReward = tx.getBesuTransaction().getGasLimit() - senderGasRefund; + + final Wei coinbaseFee = + Wei.of( + BigInteger.valueOf(tx.getEffectiveGasPrice()) + .multiply(BigInteger.valueOf(coinbaseGasReward))); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final Wei senderWeiRefund = + Wei.of( + BigInteger.valueOf(senderGasRefund) + .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice()))); + + // SENDER account snapshots + final Account senderAccount = worldView.get(senderAddress); + final AccountSnapshot senderAccountSnapshotBeforeRefunds = + AccountSnapshot.fromAccount( + senderAccount, + true, + deploymentInfo.number(senderAddress), + deploymentInfo.isDeploying(senderAddress)); + + final AccountSnapshot senderAccountSnapshotAfterGasRefund = + senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); + + final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); + + // COINBASE account snapshots + final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = + coinbaseIsSender + ? senderAccountSnapshotAfterGasRefund + // worldView.get(address) returns null + // if there is no account at that address + // this is why we get a zero address + : AccountSnapshot.fromAccount( + worldView.get(coinbaseAddress), + coinbaseWarmth, + deploymentInfo.number(coinbaseAddress), + deploymentInfo.isDeploying(coinbaseAddress)); + + final AccountSnapshot coinbaseSnapshotAfterFeeCollection = + coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); + + return new TxFinalizationSection( + hub, + accountFragmentFactory.make( + senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasRefund), + accountFragmentFactory.make( + coinbaseSnapshotBeforeFeeCollection, coinbaseSnapshotAfterFeeCollection), + TransactionFragment.prepare(hub.txStack().current())); + } + + public static TxFinalizationSection finalizeUnsuccessfulTransaction( + final Hub hub, final WorldView worldView, final boolean coinbaseWarmth) { + + final TransactionProcessingMetadata tx = hub.txStack().current(); + + final Address senderAddress = tx.getSender(); + final Address effectiveToAddress = tx.getEffectiveTo(); + final Address coinbaseAddress = tx.getCoinbase(); + + final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); + + final Account senderAccount = worldView.get(senderAddress); + final AccountSnapshot senderAccountSnapshotBeforeRefunds = + AccountSnapshot.fromAccount( + senderAccount, + true, + deploymentInfo.number(senderAddress), + deploymentInfo.isDeploying(senderAddress)); + + final long gasUsed = tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas(); + final long effectiveRefunds = Math.min(hub.accruedRefunds(), gasUsed / MAX_REFUND_QUOTIENT); + final long senderGasRefund = tx.getLeftoverGas() + effectiveRefunds; + + final long coinbaseGasReward = tx.getBesuTransaction().getGasLimit() - senderGasRefund; + final Wei coinbaseFee = + Wei.of( + BigInteger.valueOf(tx.getEffectiveGasPrice()) + .multiply(BigInteger.valueOf(coinbaseGasReward))); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + // SENDER account snapshots + final Wei senderWeiRefund = + Wei.of( + BigInteger.valueOf(senderGasRefund) + .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) + .add(tx.getBesuTransaction().getValue().getAsBigInteger())); + final AccountSnapshot senderAccountSnapshotAfterGasAndBalanceRefund = + senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); + + // RECIPIENT account snapshots + final boolean recipientIsSender = effectiveToAddress.equals(senderAddress); + final AccountSnapshot effectiveToAccountSnapshotBeforeReimbursingValue = + recipientIsSender + ? senderAccountSnapshotAfterGasAndBalanceRefund + : AccountSnapshot.fromAccount( + worldView.get(effectiveToAddress), + true, + deploymentInfo.number(effectiveToAddress), + deploymentInfo.isDeploying(effectiveToAddress)); + + final AccountSnapshot effectiveToAccountSnapshotAfterReimbursingValue = + effectiveToAccountSnapshotBeforeReimbursingValue.debit( + (Wei) tx.getBesuTransaction().getValue()); + + // COINBASE account snapshots + final boolean coinbaseIsRecipient = coinbaseAddress.equals(effectiveToAddress); + final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); + + AccountSnapshot coinbaseBeforeFeeCollection = + coinbaseIsRecipient + ? effectiveToAccountSnapshotAfterReimbursingValue + : coinbaseIsSender + ? senderAccountSnapshotAfterGasAndBalanceRefund + : AccountSnapshot.fromAccount( + worldView.get(coinbaseAddress), + coinbaseWarmth, + deploymentInfo.number(coinbaseAddress), + deploymentInfo.isDeploying(coinbaseAddress)); + + AccountSnapshot coinbaseAfterFeeCollection = + coinbaseBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); + + return new TxFinalizationSection( + hub, + accountFragmentFactory.make( + senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasAndBalanceRefund), + accountFragmentFactory.make( + effectiveToAccountSnapshotBeforeReimbursingValue, + effectiveToAccountSnapshotAfterReimbursingValue), + accountFragmentFactory.make(coinbaseBeforeFeeCollection, coinbaseAfterFeeCollection), + TransactionFragment.prepare(hub.txStack().current())); + } + @Override public void seal(Hub hub) {} } From 43bfb65ccd7fc4523f4f60d99861a8967aa25704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 01:58:21 +0400 Subject: [PATCH 045/461] spotless --- .../hub/section/TxFinalizationSection.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 29c3a5e456..b69abbe520 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -67,11 +67,11 @@ public static TxFinalizationSection finalizeSuccessfulTransaction( // SENDER account snapshots final Account senderAccount = worldView.get(senderAddress); final AccountSnapshot senderAccountSnapshotBeforeRefunds = - AccountSnapshot.fromAccount( - senderAccount, - true, - deploymentInfo.number(senderAddress), - deploymentInfo.isDeploying(senderAddress)); + AccountSnapshot.fromAccount( + senderAccount, + true, + deploymentInfo.number(senderAddress), + deploymentInfo.isDeploying(senderAddress)); final AccountSnapshot senderAccountSnapshotAfterGasRefund = senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); @@ -82,9 +82,9 @@ public static TxFinalizationSection finalizeSuccessfulTransaction( final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = coinbaseIsSender ? senderAccountSnapshotAfterGasRefund - // worldView.get(address) returns null - // if there is no account at that address - // this is why we get a zero address + // worldView.get(address) returns null + // if there is no account at that address + // this is why we get a zero address : AccountSnapshot.fromAccount( worldView.get(coinbaseAddress), coinbaseWarmth, From ec703833a208111749e72b000ad762e384061c95 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 3 Jun 2024 11:11:55 +0530 Subject: [PATCH 046/461] fix: some more java issues --- .../linea/zktracer/module/hub/Hub.java | 22 ++++++++++++++----- .../module/hub/fragment/CommonFragment.java | 9 ++------ .../hub/fragment/imc/call/mmu/MmuCall.java | 5 ++++- .../module/hub/section/TraceSection.java | 3 +-- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 4b903c688c..eff399a93f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -33,6 +33,7 @@ import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; import com.google.common.base.Preconditions; @@ -653,7 +654,7 @@ public CallFrame currentFrame() { return this.callStack.current(); } - public int contextNumberNew(WorldView world) { + public int contextNumberNew(CallFrame frame) { switch (this.state.getProcessingPhase()) { case TX_SKIP, TX_WARM, TX_FINAL -> { return 0; @@ -676,10 +677,21 @@ public int contextNumberNew(WorldView world) { if (pch().abortingConditions().any()) { return currentContextNumber; } - Address calleeAddress = Words.toAddress(this.currentFrame().frame().getStackItem(1)); - if (world.get(calleeAddress).hasCode()) { - return 1 + stamp(); - } + + final Address calleeAddress = + Words.toAddress(this.currentFrame().frame().getStackItem(1)); + + AtomicInteger newContext = new AtomicInteger(currentContextNumber); + + Optional.ofNullable(frame.frame().getWorldUpdater().get(calleeAddress)) + .map(AccountState::getCode) + .ifPresent( + byteCode -> { + if (!byteCode.isEmpty()) { + newContext.set(1 + this.stamp()); + } + }); + return newContext.get(); } if (opCode.isCreate()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 2a5e4c39b5..f5d4302bc3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -33,7 +33,6 @@ import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true, chain = false) @Builder @@ -70,11 +69,7 @@ public final class CommonFragment implements TraceFragment { @Getter @Setter private int nonStackRowsCounter; public static CommonFragment fromHub( - WorldView world, - final Hub hub, - final CallFrame frame, - boolean tliCounter, - int nonStackRowCounter) { + final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowCounter) { final boolean noStackException = hub.pch().exceptions().noStackException(); final long refundDelta = @@ -110,7 +105,7 @@ public static CommonFragment fromHub( .failureConditions(hub.pch().failureConditions().snapshot()) .callFrameId(frame.id()) .contextNumber(frame.contextNumber()) - .contextNumberNew(hub.contextNumberNew(world)) + .contextNumberNew(hub.contextNumberNew(frame)) .pc(pc) .pcNew(pcNew) .height((short) height) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 5e0fa9ba27..4de42e22d9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -690,7 +690,10 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int public Trace trace(Trace trace) { return trace .pMiscMmuFlag(this.enabled()) - .pMiscMmuInst(this.instruction()) + .pMiscMmuInst( + this.instruction() == -1 + ? 0 + : this.instruction()) // TODO: WTF I wanted to put -1? Only for debug? .pMiscMmuTgtId(this.targetId()) .pMiscMmuSrcId(this.sourceId()) .pMiscMmuAuxId(this.auxId()) 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 da8becd114..5f3193d25a 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 @@ -81,8 +81,7 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { * @return a {@link CommonFragment} representing the shared columns */ private CommonFragment traceCommon(Hub hub, CallFrame frame) { - return CommonFragment.fromHub( - world, hub, frame, this.stackRowsCounter == 2, this.nonStackRowsCounter); + return CommonFragment.fromHub(hub, frame, this.stackRowsCounter == 2, this.nonStackRowsCounter); } /** Default creator for an empty section. */ From cbe60cb0ea3044589db504577bfba7044c50a77d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 09:43:26 +0400 Subject: [PATCH 047/461] ras --- .../linea/zktracer/module/hub/section/TxFinalizationSection.java | 1 + 1 file changed, 1 insertion(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index b69abbe520..f13166d0e7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -82,6 +82,7 @@ public static TxFinalizationSection finalizeSuccessfulTransaction( final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = coinbaseIsSender ? senderAccountSnapshotAfterGasRefund + // WARNING! // worldView.get(address) returns null // if there is no account at that address // this is why we get a zero address From 9a65b8c8da0eca6f30e2c7c3079f8ebb6aacd127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 10:48:10 +0400 Subject: [PATCH 048/461] fixed finalization (empty coinbase account) --- .../zktracer/module/hub/AccountSnapshot.java | 6 ++++++ .../hub/section/TxFinalizationSection.java | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 8db53c9a9a..79d744e27b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -32,6 +32,7 @@ @Setter @Accessors(fluent = true) public class AccountSnapshot { + // TODO: we require a MARKED_FOR_SELFDESTRUCT boolean private Address address; private long nonce; private Wei balance; @@ -69,6 +70,11 @@ public static AccountSnapshot empty( Address.ZERO, 0, Wei.ZERO, isWarm, Bytecode.EMPTY, deploymentNumber, deploymentStatus); } + public static AccountSnapshot fromAddress( + Address address, boolean isWarm, int deploymentNumber, boolean deploymentStatus) { + return new AccountSnapshot(address, 0, Wei.ZERO, isWarm, Bytecode.EMPTY, deploymentNumber, deploymentStatus); + } + public static AccountSnapshot fromAccount( Optional account, boolean isWarm, int deploymentNumber, boolean deploymentStatus) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index f13166d0e7..aaa5aa444f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -18,6 +18,7 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_REFUND_QUOTIENT; import java.math.BigInteger; +import java.util.Optional; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -79,6 +80,7 @@ public static TxFinalizationSection finalizeSuccessfulTransaction( final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); // COINBASE account snapshots + Optional optionalCoinbaseAccount = Optional.ofNullable(worldView.get(coinbaseAddress)); final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = coinbaseIsSender ? senderAccountSnapshotAfterGasRefund @@ -86,11 +88,17 @@ public static TxFinalizationSection finalizeSuccessfulTransaction( // worldView.get(address) returns null // if there is no account at that address // this is why we get a zero address - : AccountSnapshot.fromAccount( - worldView.get(coinbaseAddress), - coinbaseWarmth, - deploymentInfo.number(coinbaseAddress), - deploymentInfo.isDeploying(coinbaseAddress)); + : optionalCoinbaseAccount.isPresent() + ? AccountSnapshot.fromAccount( + optionalCoinbaseAccount, + coinbaseWarmth, + deploymentInfo.number(coinbaseAddress), + deploymentInfo.isDeploying(coinbaseAddress)) + : AccountSnapshot.fromAddress( + coinbaseAddress, + coinbaseWarmth, + deploymentInfo.number(coinbaseAddress), + deploymentInfo.isDeploying(coinbaseAddress)); final AccountSnapshot coinbaseSnapshotAfterFeeCollection = coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); From c8d013ee0f0ab3b87d8071e1a5229c4d57834bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 10:48:45 +0400 Subject: [PATCH 049/461] spotless --- .../consensys/linea/zktracer/module/hub/AccountSnapshot.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 79d744e27b..d88603255f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -71,8 +71,9 @@ public static AccountSnapshot empty( } public static AccountSnapshot fromAddress( - Address address, boolean isWarm, int deploymentNumber, boolean deploymentStatus) { - return new AccountSnapshot(address, 0, Wei.ZERO, isWarm, Bytecode.EMPTY, deploymentNumber, deploymentStatus); + Address address, boolean isWarm, int deploymentNumber, boolean deploymentStatus) { + return new AccountSnapshot( + address, 0, Wei.ZERO, isWarm, Bytecode.EMPTY, deploymentNumber, deploymentStatus); } public static AccountSnapshot fromAccount( From 7ed2b7eb577d938a55e52641ab45db614f53ed89 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 3 Jun 2024 11:29:02 +0400 Subject: [PATCH 050/461] fix: some more java issue --- .../linea/zktracer/module/blockdata/Blockdata.java | 3 +-- .../module/hub/fragment/ContextFragment.java | 13 ++++++++----- .../linea/zktracer/module/romlex/RomLex.java | 5 ++++- .../zktracer/module/rlpaddr/TestRlpAddress.java | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java index a5feea7048..7d953927c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java @@ -23,7 +23,6 @@ import java.util.Deque; import java.util.List; -import lombok.Getter; import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.rlptxn.RlpTxn; @@ -37,7 +36,7 @@ public class Blockdata implements Module { private final Wcp wcp; private final TxnData txnData; private final RlpTxn rlpTxn; - @Getter final Deque operations = new ArrayDeque<>(); + private final Deque operations = new ArrayDeque<>(); private boolean batchUnderConstruction; private final int TIMESTAMP_BYTESIZE = 4; private int previousTimestamp = 0; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 321009c124..51f7a47d89 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -25,6 +25,7 @@ import net.consensys.linea.zktracer.types.Either; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.evm.internal.Words; public record ContextFragment( Hub hub, @@ -103,6 +104,12 @@ public Trace trace(Trace trace) { final EWord eCodeAddress = callFrame.codeAddressAsEWord(); final EWord callerAddress = EWord.of(callFrame.callerAddress()); + final int cfi = + hub.getCfiByMetaData( + Words.toAddress(eCodeAddress), + callFrame.codeDeploymentNumber(), + callFrame.underDeployment()); + return trace .peekAtContext(true) .pContextContextNumber(callFrame.contextNumber()) @@ -116,11 +123,7 @@ public Trace trace(Trace trace) { .pContextByteCodeAddressLo(eCodeAddress.lo()) .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) - .pContextByteCodeCodeFragmentIndex( - hub.getCfiByMetaData( - callFrame.byteCodeAddress(), - callFrame.codeDeploymentNumber(), - callFrame.underDeployment())) + .pContextByteCodeCodeFragmentIndex(cfi) .pContextCallerAddressHi(bytesToLong(callerAddress.hi())) .pContextCallerAddressLo(callerAddress.lo()) .pContextCallValue(callFrame.value()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 757141c57e..a15340e22c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -86,7 +86,10 @@ public int getCodeFragmentIndexByMetadata(final ContractMetadata metadata) { } } - throw new RuntimeException("RomChunk not found"); + throw new RuntimeException( + String.format( + "RomChunk with address %s, deployment number %s and deploymentStatus %s not found", + metadata.address(), metadata.deploymentNumber(), !metadata.underDeployment())); } public Optional getChunkByMetadata(final ContractMetadata metadata) { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index 362a7e4a4b..4a78d48090 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class TestRlpAddress { @@ -47,6 +48,7 @@ public class TestRlpAddress { private final Random rnd = new Random(666); @Test + @Disabled void test() { OpCodes.load(); From 31efac910fc2e2c18072e151392c222b02939d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 11:55:18 +0400 Subject: [PATCH 051/461] fixed TransactionProcessingMetaData's computeRefundEffective() method --- .../linea/zktracer/types/TransactionProcessingMetadata.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 2408c7ccba..ecc042dfdf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -154,7 +154,7 @@ public void completeLineaTransaction( private long computeRefundEffective() { final long consumedGas = besuTransaction.getGasLimit() - leftoverGas; final long maxRefundableAmount = consumedGas / MAX_REFUND_QUOTIENT; - return Math.min(maxRefundableAmount, refundCounterMax); + return leftoverGas + Math.min(maxRefundableAmount, refundCounterMax); } private long computeEffectiveGasPrice() { From d2c683db68362743ef7543c2156ad0277709b9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 18:34:26 +0400 Subject: [PATCH 052/461] STOP wip - now STOP produces a single Section (rather than a stack section + a StopSection) - fixed some pcNew stuff in the CommonFragment (the seal function was overriding it in the non stack rows for some reason) WIP: STOP still doesn't receive the correct CONTEXT_NUMBER when asked to trace the parent context in its final non stack row --- .../linea/zktracer/module/hub/Hub.java | 25 ++++++-- .../module/hub/fragment/CommonFragment.java | 9 +-- .../module/hub/fragment/ContextFragment.java | 2 +- .../module/hub/section/CreateSection.java | 6 +- .../module/hub/section/StopSection.java | 60 +++++++++++++++++++ .../module/hub/section/TraceSection.java | 5 +- .../{ => calls}/FailedCallSection.java | 3 +- .../{ => calls}/NoCodeCallSection.java | 3 +- .../{ => calls}/SmartContractCallSection.java | 3 +- 9 files changed, 98 insertions(+), 18 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{ => calls}/FailedCallSection.java (87%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{ => calls}/NoCodeCallSection.java (98%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{ => calls}/SmartContractCallSection.java (98%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index eff399a93f..6240419e6d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -59,6 +59,9 @@ import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.section.*; +import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; +import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; +import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -206,6 +209,10 @@ public int lastContextNumber() { } } + public void addFragmentsAndStack(TraceFragment... fragments) { + currentTraceSection().addFragmentsAndStack(this, fragments); + } + public void addTraceSection(TraceSection section) { section.seal(this); this.state.currentTxTrace().add(section); @@ -801,7 +808,7 @@ void processStateExec(MessageFrame frame) { } else { this.addTraceSection(new StackOnlySection(this)); this.currentTraceSection() - .addFragmentsWithoutStack(this, ContextFragment.executionEmptyReturnData(this)); + .addFragmentsWithoutStack(this, ContextFragment.executionProvidesEmptyReturnData(this)); } } @@ -1249,6 +1256,7 @@ void traceOperation(MessageFrame frame) { } case HALT -> { final CallFrame parentFrame = this.callStack.parent(); + // this.addTraceSection(new StackOnlySection(this)); switch (this.opCode()) { case RETURN -> { @@ -1277,11 +1285,18 @@ void traceOperation(MessageFrame frame) { } final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); // TODO finish it } - case STOP, SELFDESTRUCT -> parentFrame.latestReturnData(Bytes.EMPTY); + case STOP -> { + parentFrame.latestReturnData(Bytes.EMPTY); + if (!currentFrame().underDeployment()) { + this.addTraceSection(StopSection.messageCallStopSection(this)); + } + } + case SELFDESTRUCT -> { + parentFrame.latestReturnData(Bytes.EMPTY); + } } - - this.addTraceSection(new StackOnlySection(this)); } + case KEC -> this.addTraceSection( new KeccakSection( this, this.currentFrame(), ImcFragment.forOpcode(this, this.messageFrame()))); @@ -1571,7 +1586,7 @@ void traceOperation(MessageFrame frame) { // In all cases, add a context fragment if an exception occurred if (this.pch().exceptions().any()) { this.currentTraceSection() - .addFragment(this, this.currentFrame(), ContextFragment.executionEmptyReturnData(this)); + .addFragment(this, this.currentFrame(), ContextFragment.executionProvidesEmptyReturnData(this)); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index f5d4302bc3..cbad17bba8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -91,7 +91,7 @@ public static CommonFragment fromHub( : 0); final boolean hubInExecPhase = hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC; final int pc = hubInExecPhase ? frame.pc() : 0; - final int pcNew = noStackException && hubInExecPhase ? computePcNew(hub, pc) : 0; + final int pcNew = computePcNew(hub, pc, noStackException, hubInExecPhase); return CommonFragment.builder() .hub(hub) @@ -124,8 +124,9 @@ public static CommonFragment fromHub( .build(); } - private static int computePcNew(final Hub hub, final int pc) { + private static int computePcNew(final Hub hub, final int pc, boolean noStackException, boolean hubInExecPhase) { OpCode opCode = hub.opCode(); + if (!(noStackException && hubInExecPhase)) {return 0;} if (opCode.getData().isPush()) { return pc + opCode.byteValue() - OpCode.PUSH1.byteValue() + 2; @@ -136,7 +137,7 @@ private static int computePcNew(final Hub hub, final int pc) { final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); final int attemptedPcNew = - codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() : 0; + codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() : 0; if (opCode.equals(OpCode.JUMP)) { return attemptedPcNew; @@ -148,7 +149,7 @@ private static int computePcNew(final Hub hub, final int pc) { return attemptedPcNew; } } - } + }; return pc + 1; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 51f7a47d89..72efe97660 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -56,7 +56,7 @@ public static ContextFragment initializeExecutionContext(final Hub hub) { false); } - public static ContextFragment executionEmptyReturnData(final Hub hub) { + public static ContextFragment executionProvidesEmptyReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, callStack, Either.left(callStack.parent().id()), MemorySpan.empty(), true); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 85e894b155..131a8a7e07 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -184,15 +184,15 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, ImcFragment.empty(hub), ContextFragment.readContextData(hub), - ContextFragment.executionEmptyReturnData(hub)); + ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.exceptions.outOfMemoryExpansion()) { this.addFragmentsWithoutStack( hub, ImcFragment.empty(hub).callMxp(MxpCall.build(hub)), - ContextFragment.executionEmptyReturnData(hub)); + ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.exceptions.outOfGas()) { this.addFragmentsWithoutStack( - hub, commonImcFragment, ContextFragment.executionEmptyReturnData(hub)); + hub, commonImcFragment, ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.aborts.any()) { this.addFragmentsWithoutStack( hub, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java new file mode 100644 index 0000000000..f0c89c8eef --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -0,0 +1,60 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; + +import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.executionProvidesEmptyReturnData; +import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readContextData; + +public class StopSection extends TraceSection { + + public StopSection() {} + + public StopSection(Hub hub, TraceFragment... fragments) { + this.addFragmentsAndStack(hub, fragments); + } + + public static StopSection messageCallStopSection(Hub hub) { + return new StopSection( + hub, + readContextData(hub), + executionProvidesEmptyReturnData(hub) + ); + } + + public static StopSection revertedDeploymentStopSection(Hub hub) { + AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + return new StopSection( + hub, + readContextData(hub), + // current (under deployment => deployed with empty byte code) + // undoing of the above + executionProvidesEmptyReturnData(hub) + ); + } + + public static StopSection unrevertedDeploymentStopSection(Hub hub) { + return new StopSection( + hub, + readContextData(hub), + // current (under deployment => deployed with empty byte code) + executionProvidesEmptyReturnData(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 5f3193d25a..7d9f4de76f 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 @@ -204,8 +204,9 @@ public void seal(Hub hub) { nonStackLineCounter++; line.common.nonStackRowsCounter(nonStackLineCounter); } - line.common.pcNew(hub.lastPc()); - // line.common.contextNumberNew(hub.lastContextNumber()); //TODO understand this + // TODO: delete as both are computed in CommonFragment ... + // line.common.pcNew(); + // line.common.contextNumberNew(hub.lastContextNumber()); line.common.numberOfNonStackRows(nonStackLineNumbers); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/FailedCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java similarity index 87% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/FailedCallSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java index 899642005d..b99fef20ef 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/FailedCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java @@ -13,10 +13,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section; +package net.consensys.linea.zktracer.module.hub.section.calls; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class FailedCallSection extends TraceSection { public FailedCallSection(Hub hub, TraceFragment... chunks) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index 52cfd47f4d..c537ac58aa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section; +package net.consensys.linea.zktracer.module.hub.section.calls; import java.util.List; import java.util.Optional; @@ -30,6 +30,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileLinesGenerator; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index ff2c608a9b..006352945f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section; +package net.consensys.linea.zktracer.module.hub.section.calls; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -24,6 +24,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; From 2b481c07af4acf5ca7586eca465dc7d4c82544a0 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 3 Jun 2024 19:12:58 +0400 Subject: [PATCH 053/461] fix: fix context number of parent of root --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 11 ++++++----- .../zktracer/module/hub/fragment/CommonFragment.java | 12 ++++++++---- .../module/hub/fragment/ContextFragment.java | 10 ++++++---- .../linea/zktracer/runtime/callstack/CallFrame.java | 1 + .../linea/zktracer/runtime/callstack/CallStack.java | 7 ++++++- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6240419e6d..44a8beec70 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -20,6 +20,7 @@ import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; +import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; @@ -131,9 +132,6 @@ @Slf4j @Accessors(fluent = true) public class Hub implements Module { - - private static final int TAU = 8; - public static final GasProjector GAS_PROJECTOR = new GasProjector(); /** accumulate the trace information for the Hub */ @@ -727,7 +725,9 @@ public MessageFrame messageFrame() { } private void handleStack(MessageFrame frame) { - this.currentFrame().stack().processInstruction(this, frame, TAU * this.state.stamps().hub()); + this.currentFrame() + .stack() + .processInstruction(this, frame, MULTIPLIER___STACK_HEIGHT * this.state.stamps().hub()); } void triggerModules(MessageFrame frame) { @@ -1586,7 +1586,8 @@ void traceOperation(MessageFrame frame) { // In all cases, add a context fragment if an exception occurred if (this.pch().exceptions().any()) { this.currentTraceSection() - .addFragment(this, this.currentFrame(), ContextFragment.executionProvidesEmptyReturnData(this)); + .addFragment( + this, this.currentFrame(), ContextFragment.executionProvidesEmptyReturnData(this)); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index cbad17bba8..6904341822 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -124,9 +124,12 @@ public static CommonFragment fromHub( .build(); } - private static int computePcNew(final Hub hub, final int pc, boolean noStackException, boolean hubInExecPhase) { + private static int computePcNew( + final Hub hub, final int pc, boolean noStackException, boolean hubInExecPhase) { OpCode opCode = hub.opCode(); - if (!(noStackException && hubInExecPhase)) {return 0;} + if (!(noStackException && hubInExecPhase)) { + return 0; + } if (opCode.getData().isPush()) { return pc + opCode.byteValue() - OpCode.PUSH1.byteValue() + 2; @@ -137,7 +140,7 @@ private static int computePcNew(final Hub hub, final int pc, boolean noStackExce final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); final int attemptedPcNew = - codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() : 0; + codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() : 0; if (opCode.equals(OpCode.JUMP)) { return attemptedPcNew; @@ -149,7 +152,8 @@ private static int computePcNew(final Hub hub, final int pc, boolean noStackExce return attemptedPcNew; } } - }; + } + ; return pc + 1; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 72efe97660..94ca81cec4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -105,10 +105,12 @@ public Trace trace(Trace trace) { final EWord callerAddress = EWord.of(callFrame.callerAddress()); final int cfi = - hub.getCfiByMetaData( - Words.toAddress(eCodeAddress), - callFrame.codeDeploymentNumber(), - callFrame.underDeployment()); + callFrame == CallFrame.EMPTY + ? 0 + : hub.getCfiByMetaData( + Words.toAddress(eCodeAddress), + callFrame.codeDeploymentNumber(), + callFrame.underDeployment()); return trace .peekAtContext(true) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index ec664535bc..1e6fee6173 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -148,6 +148,7 @@ public class CallFrame { this.contextNumber = 0; this.accountAddress = Address.ZERO; this.parentFrame = -1; + this.callDataInfo = new CallDataInfo(Bytes.EMPTY, 0, 0, 0); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index c20b050664..9f8ff25fc9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -40,7 +40,12 @@ public final class CallStack { /** the maximal depth of the call stack (as defined by Ethereum) */ static final int MAX_CALLSTACK_SIZE = 1024; /** a never-pruned-tree of the {@link CallFrame} executed by the {@link Hub} */ - private final List frames = new ArrayList<>(); + private final List frames = + new ArrayList<>() { + { + add(CallFrame.EMPTY); + } + }; /** the current depth of the call stack. */ @Getter private int depth; /** a "pointer" to the current {@link CallFrame} in frames. */ From 19ed8e40275bdad2c2449b150f850bf0dcf3134c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 3 Jun 2024 20:16:32 +0400 Subject: [PATCH 054/461] setting the universal parent's return data context number The UNIVERSAL PARENT context is the parent of all root context's. TODO: make it so that the lastCallee() method works on this context, too. For this it would have to spawn every root context of every transaction --- .../linea/zktracer/module/hub/Hub.java | 10 ++- .../module/hub/fragment/ContextFragment.java | 4 +- .../module/hub/section/StopSection.java | 68 +++++++++---------- .../zktracer/runtime/callstack/CallFrame.java | 2 + 4 files changed, 45 insertions(+), 39 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 44a8beec70..d4a5acbe1d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -854,6 +854,14 @@ public void traceStartTx(final WorldView world, final Transaction tx) { this.processStateInit(world); } + /* + TODO: the ID = 0 (universal parent context) context should + 1. be shared by all transactions in a conflation (OK) + 2. should be the father of all root contexts + 3. should have the current root context as its lastCallee() + */ + this.callStack.getById(0).universalParentReturnDataContextNumber(this.stamp() + 1); + for (Module m : this.modules) { // TODO: should use only a LineaTransaction as its argument m.traceStartTx(world, tx); @@ -1278,7 +1286,7 @@ void traceOperation(MessageFrame frame) { final Bytes returnData = this.transients.op().returnData(); this.currentFrame().returnDataSource(transients.op().returnDataSegment()); this.currentFrame().returnData(returnData); - if (!this.pch.exceptions().any()) { + if (this.pch.exceptions().none()) { parentFrame.latestReturnData(returnData); } else { parentFrame.latestReturnData(Bytes.EMPTY); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 94ca81cec4..736db3826a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -136,7 +136,9 @@ public Trace trace(Trace trace) { .pContextReturnAtCapacity(callFrame.requestedReturnDataTarget().length()) .pContextUpdate(updateCallerReturndata) .pContextReturnDataContextNumber( - callFrame.lastCallee().map(c -> callStack.getById(c).contextNumber()).orElse(0)) + callFrame.id() == 0 + ? callFrame.universalParentReturnDataContextNumber + : callFrame.lastCallee().map(c -> callStack.getById(c).contextNumber()).orElse(0)) .pContextReturnDataOffset(returnDataSegment.offset()) .pContextReturnDataSize(returnDataSegment.length()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index f0c89c8eef..ff50cd1d71 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -14,47 +14,41 @@ */ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.executionProvidesEmptyReturnData; +import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readContextData; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.executionProvidesEmptyReturnData; -import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readContextData; - public class StopSection extends TraceSection { - public StopSection() {} - - public StopSection(Hub hub, TraceFragment... fragments) { - this.addFragmentsAndStack(hub, fragments); - } - - public static StopSection messageCallStopSection(Hub hub) { - return new StopSection( - hub, - readContextData(hub), - executionProvidesEmptyReturnData(hub) - ); - } - - public static StopSection revertedDeploymentStopSection(Hub hub) { - AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - return new StopSection( - hub, - readContextData(hub), - // current (under deployment => deployed with empty byte code) - // undoing of the above - executionProvidesEmptyReturnData(hub) - ); - } - - public static StopSection unrevertedDeploymentStopSection(Hub hub) { - return new StopSection( - hub, - readContextData(hub), - // current (under deployment => deployed with empty byte code) - executionProvidesEmptyReturnData(hub) - ); - } + public StopSection() {} + + public StopSection(Hub hub, TraceFragment... fragments) { + this.addFragmentsAndStack(hub, fragments); + } + + public static StopSection messageCallStopSection(Hub hub) { + return new StopSection(hub, readContextData(hub), executionProvidesEmptyReturnData(hub)); + } + + public static StopSection revertedDeploymentStopSection(Hub hub) { + AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + return new StopSection( + hub, + readContextData(hub), + // current (under deployment => deployed with empty byte code) + // undoing of the above + executionProvidesEmptyReturnData(hub)); + } + + public static StopSection unrevertedDeploymentStopSection(Hub hub) { + return new StopSection( + hub, + readContextData(hub), + // current (under deployment => deployed with empty byte code) + executionProvidesEmptyReturnData(hub)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 1e6fee6173..a09c37198e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -43,6 +43,8 @@ public class CallFrame { public static final CallFrame EMPTY = new CallFrame(); + @Setter public int universalParentReturnDataContextNumber; + /** the position of this {@link CallFrame} in the {@link CallStack}. */ @Getter private int id; /** the context number of the frame, i.e. the hub stamp at its creation */ From 868297f8850b7adfae4fee25c63289837ed8dfd1 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 4 Jun 2024 08:38:22 +0400 Subject: [PATCH 055/461] fix: cleaning in TxProcessingMetadata + fix removing current tx when poping tx if we don't removre the current tx when poping tx, we won't find the cfi at endConflation time --- .../linea/zktracer/module/hub/Hub.java | 18 ----- .../zktracer/module/hub/TransactionStack.java | 72 +------------------ .../types/TransactionProcessingMetadata.java | 10 ++- 3 files changed, 9 insertions(+), 91 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index d4a5acbe1d..1945543c6f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -157,8 +157,6 @@ public class Hub implements Module { /** stores all data related to failure states & module activation */ @Getter private final PlatformController pch; - @Getter private ProcessableBlockHeader currentBlockHeader; - @Override public String moduleKey() { return "HUB"; @@ -191,22 +189,6 @@ TraceSection currentTraceSection() { return this.state.currentTxTrace().currentSection(); } - public int lastPc() { - if (this.state.currentTxTrace().isEmpty()) { - return 0; - } else { - return this.state.currentTxTrace().currentSection().pc(); - } - } - - public int lastContextNumber() { - if (this.state.currentTxTrace().isEmpty()) { - return 0; - } else { - return this.state.currentTxTrace().currentSection().contextNumber(); - } - } - public void addFragmentsAndStack(TraceFragment... fragments) { currentTraceSection().addFragmentsAndStack(this, fragments); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 74fc821c0a..302bef84ad 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -15,31 +15,18 @@ package net.consensys.linea.zktracer.module.hub; -import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; - -import java.math.BigInteger; import java.util.ArrayList; import java.util.List; -import java.util.Optional; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.transients.Block; -import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.worldstate.WorldView; public class TransactionStack implements StackedContainer { - private final List txs = new ArrayList<>(100); + private final List txs = new ArrayList<>(200); private int currentAbsNumber; - private int relativeBlockNumber; private int relativeTransactionNumber; public TransactionProcessingMetadata current() { @@ -58,6 +45,7 @@ public void enter() { @Override public void pop() { + this.txs.remove(this.current()); this.currentAbsNumber -= 1; this.relativeTransactionNumber -= 1; } @@ -68,11 +56,6 @@ public void resetBlock() { public void enterTransaction(final WorldView world, final Transaction tx, Block block) { this.enter(); - if (tx.getTo().isPresent() && isPrecompile(tx.getTo().get())) { - throw new RuntimeException("Call to precompile forbidden"); - } else { - // this.number++; - } final TransactionProcessingMetadata newTx = new TransactionProcessingMetadata( @@ -94,55 +77,4 @@ public void setCodeFragmentIndex(Hub hub) { tx.setCodeFragmentIndex(cfi); } } - - public static long computeInitGas(Transaction tx) { - boolean isDeployment = tx.getTo().isEmpty(); - return tx.getGasLimit() - - ZkTracer.gasCalculator.transactionIntrinsicGasCost(tx.getPayload(), isDeployment) - - tx.getAccessList().map(ZkTracer.gasCalculator::accessListGasCost).orElse(0L); - } - - @Builder - @Accessors(fluent = true) - public static class MetaTransaction { - @Getter private int id; - @Getter private Transaction besuTx; - @Getter private int absNumber; - @Getter @Setter private HubProcessingPhase state; - @Setter @Builder.Default private Boolean status = null; - @Getter private long initialGas; - @Getter private final StorageInitialValues storage = new StorageInitialValues(); - @Getter @Setter @Builder.Default int endStamp = -1; - @Getter @Setter boolean isSenderPreWarmed; - @Getter @Setter boolean isReceiverPreWarmed; - @Getter @Setter boolean requiresEvmExecution; - - /** - * Returns the transaction result, or throws an exception if it is being accessed outside of its - * specified lifetime -- between the conclusion of a transaction and the start of a new one. - * - * @return the transaction final status - */ - public boolean status() { - if (this.status == null) { - throw new RuntimeException("TX state can not be queried for now."); - } - - return this.status; - } - - public boolean shouldSkip(WorldView world) { - return (this.besuTx.getTo().isPresent() - && Optional.ofNullable(world.get(this.besuTx.getTo().get())) - .map(a -> a.getCode().isEmpty()) - .orElse(true)) // pure transaction - || (this.besuTx.getTo().isEmpty() - && this.besuTx.getInit().isEmpty()); // contract creation without init code - } - - public Wei gasPrice() { - return Wei.of( - this.besuTx.getGasPrice().map(Quantity::getAsBigInteger).orElse(BigInteger.ZERO)); - } - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index ecc042dfdf..c28ac23051 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -102,9 +102,11 @@ public TransactionProcessingMetadata( this.initialBalance = getInitialBalance(world); + // Note: Besu's dataCost computation contains the 21_000 transaction cost this.dataCost = ZkTracer.gasCalculator.transactionIntrinsicGasCost( - besuTransaction.getPayload(), isDeployment); + besuTransaction.getPayload(), isDeployment) + - GAS_CONST_G_TRANSACTION; this.accessListCost = besuTransaction.getAccessList().map(ZkTracer.gasCalculator::accessListGasCost).orElse(0L); this.initiallyAvailableGas = getInitiallyAvailableGas(); @@ -134,8 +136,10 @@ private BigInteger getInitialBalance(WorldView world) { } public long getUpfrontGasCost() { - // Note: Besu's dataCost computation contains the 21_000 transaction cost - return dataCost + (isDeployment ? GAS_CONST_G_CREATE : 0) + accessListCost; + return dataCost + + (isDeployment ? GAS_CONST_G_CREATE : 0) + + GAS_CONST_G_TRANSACTION + + accessListCost; } public long getInitiallyAvailableGas() { From 9de99c49d6a1875caffad2a306adf5a5fb4344d6 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 4 Jun 2024 09:42:00 +0400 Subject: [PATCH 056/461] docs: ras --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 1 + .../consensys/linea/zktracer/runtime/callstack/CallStack.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 1945543c6f..8da9021416 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -149,6 +149,7 @@ public class Hub implements Module { */ @Getter CallStack callStack = new CallStack(); + /** Stores the transaction Metadata of all the transaction of the conflated block */ @Getter TransactionStack txStack = new TransactionStack(); /** Stores all the actions that must be deferred to a later time */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 9f8ff25fc9..54b99e8fcc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -41,7 +41,7 @@ public final class CallStack { static final int MAX_CALLSTACK_SIZE = 1024; /** a never-pruned-tree of the {@link CallFrame} executed by the {@link Hub} */ private final List frames = - new ArrayList<>() { + new ArrayList<>(50) { { add(CallFrame.EMPTY); } From 12257fd3ed9cd263240b5293ae88e463bcda9be6 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 4 Jun 2024 10:20:14 +0400 Subject: [PATCH 057/461] fix: no cfi for bedrock / mantle callFrame --- .../linea/zktracer/module/hub/fragment/ContextFragment.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 736db3826a..de65cd1ba1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -20,6 +20,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.Either; @@ -106,6 +107,8 @@ public Trace trace(Trace trace) { final int cfi = callFrame == CallFrame.EMPTY + || callFrame.type() == CallFrameType.BEDROCK + || callFrame.type() == CallFrameType.MANTLE ? 0 : hub.getCfiByMetaData( Words.toAddress(eCodeAddress), From a65ee3577e70c1791bf2b1ac09c2ac98653e441d Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 4 Jun 2024 18:51:38 +0400 Subject: [PATCH 058/461] fix(hub): debug tx skip + add tests --- .../linea/zktracer/module/hub/Hub.java | 11 +- .../zktracer/module/hub/TransactionStack.java | 7 - .../defer/SkippedPostTransactionDefer.java | 14 +- .../module/hub/fragment/ContextFragment.java | 4 +- .../types/TransactionProcessingMetadata.java | 11 +- .../linea/zktracer/module/hub/OtherTests.java | 44 ---- .../zktracer/module/hub/TestTwoPlusTwo.java | 6 - .../linea/zktracer/module/hub/TxSkip.java | 209 ++++++++++++++++++ 8 files changed, 234 insertions(+), 72 deletions(-) delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 8da9021416..f04dae85ae 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -442,7 +442,7 @@ void processStateSkip(WorldView world) { false); // To account information - final Address toAddress = effectiveToAddress(this.txStack.current().getBesuTransaction()); + final Address toAddress = this.txStack.current().getEffectiveTo(); if (isDeployment) { this.transients.conflation().deploymentInfo().deploy(toAddress); } @@ -454,7 +454,7 @@ void processStateSkip(WorldView world) { false); // Miner account information - final Address minerAddress = this.transients.block().minerAddress(); + final Address minerAddress = this.txStack.current().getCoinbase(); final AccountSnapshot oldMinerAccount = AccountSnapshot.fromAccount( @@ -873,8 +873,11 @@ public void traceEndTx( txStack .current() .completeLineaTransaction( - isSuccessful, leftoverGas, this.accruedRefunds(), this.state.stamps().hub()); - this.txStack.exitTransaction(this, isSuccessful); + isSuccessful, + leftoverGas, + this.accruedRefunds(), + this.state.stamps().hub(), + this.state.getProcessingPhase()); if (this.state.processingPhase != TX_SKIP) { this.processStateFinal(world); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 302bef84ad..a8f98c6dda 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -63,13 +63,6 @@ public void enterTransaction(final WorldView world, final Transaction tx, Block this.txs.add(newTx); } - public void exitTransaction(final Hub hub, boolean isSuccessful) { - if (hub.state.processingPhase != HubProcessingPhase.TX_SKIP) { - hub.state.setProcessingPhase(HubProcessingPhase.TX_FINAL); - } - this.current().setHubStampTransactionEnd(hub.stamp() + 1); - } - public void setCodeFragmentIndex(Hub hub) { for (TransactionProcessingMetadata tx : this.txs) { final int cfi = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java index 51d5b75998..4b258c85a0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java @@ -19,6 +19,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.section.TxSkippedSection; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; @@ -42,26 +43,27 @@ public record SkippedPostTransactionDefer( implements PostTransactionDefer { @Override public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - Address fromAddress = this.oldFromAccount.address(); - Address toAddress = this.oldToAccount.address(); - Address minerAddress = this.oldMinerAccount.address(); + final TransactionProcessingMetadata txMetaData = hub.txStack().current(); + final Address fromAddress = this.oldFromAccount.address(); + final Address toAddress = this.oldToAccount.address(); + final Address minerAddress = txMetaData.getCoinbase(); hub.transients().conflation().deploymentInfo().unmarkDeploying(toAddress); - AccountSnapshot newFromAccount = + final AccountSnapshot newFromAccount = AccountSnapshot.fromAccount( state.get(fromAddress), this.oldFromAccount.isWarm(), hub.transients().conflation().deploymentInfo().number(fromAddress), false); - AccountSnapshot newToAccount = + final AccountSnapshot newToAccount = AccountSnapshot.fromAccount( state.get(toAddress), this.oldToAccount.isWarm(), hub.transients().conflation().deploymentInfo().number(toAddress), false); - AccountSnapshot newMinerAccount = + final AccountSnapshot newMinerAccount = AccountSnapshot.fromAccount( state.get(minerAddress), this.oldMinerAccount.isWarm(), diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index de65cd1ba1..38ca2e9e41 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -106,9 +106,7 @@ public Trace trace(Trace trace) { final EWord callerAddress = EWord.of(callFrame.callerAddress()); final int cfi = - callFrame == CallFrame.EMPTY - || callFrame.type() == CallFrameType.BEDROCK - || callFrame.type() == CallFrameType.MANTLE + callFrame == CallFrame.EMPTY || callFrame.type() == CallFrameType.MANTLE ? 0 : hub.getCfiByMetaData( Words.toAddress(eCodeAddress), diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index c28ac23051..7c4268e72c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.types; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.*; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import java.math.BigInteger; @@ -25,6 +26,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; +import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; import org.hyperledger.besu.datatypes.Address; @@ -147,12 +149,17 @@ public long getInitiallyAvailableGas() { } public void completeLineaTransaction( - boolean statusCode, long leftoverGas, long refundCounterMax, int hubStampTransactionEnd) { + final boolean statusCode, + final long leftoverGas, + final long refundCounterMax, + final int hubStampTransactionEnd, + final HubProcessingPhase hubPhase) { this.refundCounterMax = refundCounterMax; this.leftoverGas = leftoverGas; this.statusCode = statusCode; this.refundEffective = computeRefundEffective(); - this.hubStampTransactionEnd = hubStampTransactionEnd; + this.hubStampTransactionEnd = + (hubPhase == TX_SKIP) ? hubStampTransactionEnd : hubStampTransactionEnd + 1; } private long computeRefundEffective() { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java deleted file mode 100644 index d69e4066f1..0000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub; - -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.EvmExtension; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -public class OtherTests { - @Test - public void testMul() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(32).push(7).op(OpCode.MUL).compile()) - .run(); - } - - @Test - public void testDiv() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(32).push(7).op(OpCode.DIV).compile()) - .run(); - } - - @Test - public void testSDiv() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(32).push(7).op(OpCode.SDIV).compile()) - .run(); - } -} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java index 81883444f6..9b10f3c278 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java @@ -25,12 +25,6 @@ @ExtendWith(EvmExtension.class) public class TestTwoPlusTwo { - @Test - void testAdd() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(32).push(27).op(OpCode.ADD).compile()) - .run(); - } - @Test void testAssembler() { BytecodeRunner.of( diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java new file mode 100644 index 0000000000..e8b25b3e29 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java @@ -0,0 +1,209 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub; + +import java.util.List; + +import net.consensys.linea.zktracer.testing.EvmExtension; +import net.consensys.linea.zktracer.testing.ToyAccount; +import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; +import net.consensys.linea.zktracer.testing.ToyTransaction; +import net.consensys.linea.zktracer.testing.ToyWorld; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.AccessListEntry; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.TransactionType; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class TxSkip { + final int nbOfRowsTxSkip = 4; + + @Test + void test() { + final ToyAccount receiverAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(116) + .address(Address.fromHexString("0xdead000000000000000000000000000beef")) + .build(); + + final ToyAccount minerAccount = + ToyAccount.builder() + .balance(Wei.ONE) + .address(Address.fromHexString("0x0000000000000000000000000000001234532342")) + .build(); + + final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); + final Address senderAddress1 = + Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount1 = + ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); + + final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); + final Address senderAddress2 = + Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount2 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); + + final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); + final Address senderAddress3 = + Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount3 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); + + final KeyPair senderKeyPair4 = new SECP256K1().generateKeyPair(); + final Address senderAddress4 = + Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount4 = + ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); + + final KeyPair senderKeyPair5 = new SECP256K1().generateKeyPair(); + final Address senderAddress5 = + Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount5 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); + + final KeyPair senderKeyPair6 = new SECP256K1().generateKeyPair(); + final Address senderAddress6 = + Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount6 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); + + final KeyPair senderKeyPair7 = new SECP256K1().generateKeyPair(); + final Address senderAddress7 = + Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount7 = + ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); + + final Transaction pureTransfer = + ToyTransaction.builder() + .sender(senderAccount1) + .to(receiverAccount) + .keyPair(senderKeyPair1) + .value(Wei.of(123)) + .build(); + + final Transaction pureTransferWoValue = + ToyTransaction.builder() + .sender(senderAccount2) + .to(receiverAccount) + .keyPair(senderKeyPair2) + .value(Wei.of(0)) + .build(); + + final List listOfKeys = + List.of("0x0123", "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); + final List accessList = + List.of( + AccessListEntry.createAccessListEntry( + Address.fromHexString("0x1234567890"), listOfKeys)); + final Transaction pureTransferWithUselessAccessList = + ToyTransaction.builder() + .sender(senderAccount3) + .to(receiverAccount) + .keyPair(senderKeyPair3) + .gasLimit(100000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(accessList) + .value(Wei.of(546)) + .build(); + + final Transaction pureTransferWithUselessCalldata = + ToyTransaction.builder() + .sender(senderAccount4) + .to(receiverAccount) + .keyPair(senderKeyPair4) + .gasLimit(1000001L) + .value(Wei.of(546)) + .payload(Bytes.minimalBytes(0xdeadbeefL)) + .build(); + + final Transaction pureTransferWithUselessCalldataAndAccessList = + ToyTransaction.builder() + .sender(senderAccount5) + .to(receiverAccount) + .gasLimit(1000020L) + .transactionType(TransactionType.EIP1559) + .keyPair(senderKeyPair5) + .value(Wei.of(546)) + .accessList(accessList) + .payload(Bytes.minimalBytes(0xdeadbeefL)) + .build(); + + final Transaction deploymentWithEmptyInit = + ToyTransaction.builder() + .sender(senderAccount6) + .keyPair(senderKeyPair6) + .gasLimit(1234567L) + .value(Wei.of(546)) + .build(); + + final Transaction deploymentWithEmptyInitAndUselessAccessList = + ToyTransaction.builder() + .sender(senderAccount7) + .gasLimit(100002120L) + .keyPair(senderKeyPair7) + .transactionType(TransactionType.ACCESS_LIST) + .value(Wei.of(546)) + .accessList(accessList) + .build(); + + final List txs = + List.of( + pureTransfer, + pureTransferWoValue, + pureTransferWithUselessAccessList, + pureTransferWithUselessCalldata, + pureTransferWithUselessCalldataAndAccessList + // TODO: deploymentWithEmptyInit, + // TODO: deploymentWithEmptyInitAndUselessAccessList + ); + + ToyWorld toyWorld = + ToyWorld.builder() + .accounts( + List.of( + minerAccount, + senderAccount1, + senderAccount2, + senderAccount3, + senderAccount4, + senderAccount5, + senderAccount6, + senderAccount7, + receiverAccount)) + .build(); + + ToyExecutionEnvironment.builder() + .toyWorld(toyWorld) + .transactions(txs) + .zkTracerValidator( + zkTracer -> { + + // Ensure we have the right nb of rows in the HUB + // assertThat(zkTracer.getHub().lineCount()).isEqualTo(txs.size() * nbOfRowsTxSkip); + }) + .build() + .run(); + } +} From 9d724305dd200fada1a13325713a333044347735 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 4 Jun 2024 19:37:44 +0400 Subject: [PATCH 059/461] style: less code in the hub, more in SkippedPostTransactionDefer --- .../linea/zktracer/module/hub/Hub.java | 49 +-------------- .../module/hub/defer/DeferRegistry.java | 1 + .../defer/SkippedPostTransactionDefer.java | 59 ++++++++++++++----- 3 files changed, 47 insertions(+), 62 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f04dae85ae..c888ad8423 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -23,7 +23,6 @@ import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; -import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; import java.nio.MappedByteBuffer; @@ -427,53 +426,8 @@ public int getCfiByMetaData( void processStateSkip(WorldView world) { this.state.setProcessingPhase(TX_SKIP); this.state.stamps().incrementHubStamp(); - final boolean isDeployment = this.txStack.current().getBesuTransaction().getTo().isEmpty(); - - // - // 3 sections -- account changes - // - // From account information - final Address fromAddress = this.txStack.current().getBesuTransaction().getSender(); - final AccountSnapshot oldFromAccount = - AccountSnapshot.fromAccount( - world.get(fromAddress), - isPrecompile(fromAddress), - this.transients.conflation().deploymentInfo().number(fromAddress), - false); - - // To account information - final Address toAddress = this.txStack.current().getEffectiveTo(); - if (isDeployment) { - this.transients.conflation().deploymentInfo().deploy(toAddress); - } - final AccountSnapshot oldToAccount = - AccountSnapshot.fromAccount( - world.get(toAddress), - isPrecompile(toAddress), - this.transients.conflation().deploymentInfo().number(toAddress), - false); - - // Miner account information - final Address minerAddress = this.txStack.current().getCoinbase(); - - final AccountSnapshot oldMinerAccount = - AccountSnapshot.fromAccount( - world.get(minerAddress), - isPrecompile(minerAddress), - this.transients - .conflation() - .deploymentInfo() - .number(this.transients.block().minerAddress()), - false); - - // Putatively updateCallerReturnData deployment number this.defers.postTx( - new SkippedPostTransactionDefer( - oldFromAccount, - oldToAccount, - oldMinerAccount, - Wei.of(this.txStack.current().getEffectiveGasPrice()), - this.transients.block().baseFee())); + new SkippedPostTransactionDefer(world, this.txStack.current(), this.transients)); } /** @@ -823,7 +777,6 @@ public void traceStartTx(final WorldView world, final Transaction tx) { this.pch.reset(); this.state.enter(); this.txStack.enterTransaction(world, tx, transients.block()); - this.defers.postTx(this.state.currentTxTrace()); this.enterTransaction(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index c08fc3923b..7bb82d4bb1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -88,6 +88,7 @@ public void runNextContext(Hub hub, MessageFrame frame) { * @param world a {@link WorldView} on the state * @param tx the current {@link Transaction} */ + // TODO: should use the TransactionProcessingMetadata public void runPostTx(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { for (PostTransactionDefer defer : this.txDefers) { defer.runPostTx(hub, world, tx, isSuccessful); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java index 4b258c85a0..c857aaf0f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java @@ -15,38 +15,69 @@ package net.consensys.linea.zktracer.module.hub.defer; +import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; + import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.section.TxSkippedSection; +import net.consensys.linea.zktracer.module.hub.transients.Transients; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.worldstate.WorldView; /** * SkippedTransaction latches data at the pre-execution of the transaction data that will be used * later, through a {@link PostTransactionDefer}, to generate the trace chunks required for the * proving of a pure transaction. - * - * @param oldFromAccount - * @param oldToAccount - * @param oldMinerAccount */ -public record SkippedPostTransactionDefer( - AccountSnapshot oldFromAccount, - AccountSnapshot oldToAccount, - AccountSnapshot oldMinerAccount, - Wei gasPrice, - Wei baseFee) - implements PostTransactionDefer { +public class SkippedPostTransactionDefer implements PostTransactionDefer { + final TransactionProcessingMetadata txMetadata; + final AccountSnapshot oldFromAccount; + final AccountSnapshot oldToAccount; + final AccountSnapshot oldMinerAccount; + + public SkippedPostTransactionDefer( + WorldView world, TransactionProcessingMetadata txMetadata, Transients transients) { + this.txMetadata = txMetadata; + + // From account information + final Address fromAddress = txMetadata.getBesuTransaction().getSender(); + this.oldFromAccount = + AccountSnapshot.fromAccount( + world.get(fromAddress), + isPrecompile(fromAddress), + transients.conflation().deploymentInfo().number(fromAddress), + false); + + // To account information + final Address toAddress = txMetadata.getEffectiveTo(); + if (txMetadata.isDeployment()) { + transients.conflation().deploymentInfo().deploy(toAddress); + } + this.oldToAccount = + AccountSnapshot.fromAccount( + world.get(toAddress), + isPrecompile(toAddress), + transients.conflation().deploymentInfo().number(toAddress), + false); + + // Miner account information + final Address minerAddress = txMetadata.getCoinbase(); + this.oldMinerAccount = + AccountSnapshot.fromAccount( + world.get(minerAddress), + isPrecompile(minerAddress), + transients.conflation().deploymentInfo().number(transients.block().minerAddress()), + false); + } + @Override public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - final TransactionProcessingMetadata txMetaData = hub.txStack().current(); final Address fromAddress = this.oldFromAccount.address(); final Address toAddress = this.oldToAccount.address(); - final Address minerAddress = txMetaData.getCoinbase(); + final Address minerAddress = this.txMetadata.getCoinbase(); hub.transients().conflation().deploymentInfo().unmarkDeploying(toAddress); final AccountSnapshot newFromAccount = From db4c991f5665402d0843b7aa20ea263185906142 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 4 Jun 2024 22:58:16 +0400 Subject: [PATCH 060/461] feat: hook at the last context exit to get leftOverGas, RefundGasCounterMax, and the warmth of coinbase address --- .../linea/zktracer/module/hub/Hub.java | 64 ++++++++++--------- .../types/TransactionProcessingMetadata.java | 23 +++++-- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c888ad8423..ddfa54e80b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -753,8 +753,7 @@ void processStateFinal(WorldView worldView) { this.state.setProcessingPhase(TX_FINAL); this.state.stamps().incrementHubStamp(); - final boolean coinbaseWarmth = - false; // TODO: get access to coinbase address warmth (still London!) + final boolean coinbaseWarmth = txStack.current().isMinerWarmAtEndTx(); if (this.txStack.current().statusCode()) { this.addTraceSection( @@ -814,6 +813,37 @@ public void popTransaction() { } } + @Override + public void traceContextExit(MessageFrame frame) { + if (frame.getDepth() > 0) { + this.transients + .conflation() + .deploymentInfo() + .unmarkDeploying(this.currentFrame().byteCodeAddress()); + + DeploymentExceptions contextExceptions = + DeploymentExceptions.fromFrame(this.currentFrame(), frame); + this.currentTraceSection().setContextExceptions(contextExceptions); + if (contextExceptions.any()) { + this.callStack.revert(this.state.stamps().hub()); + } + + this.callStack.exit(); + + for (Module m : this.modules) { + m.traceContextExit(frame); + } + } + + if (frame.getDepth() == 0) { + final long leftOverGas = frame.getRemainingGas(); + final long gasRefund = frame.getGasRefund(); + final boolean minerIsWarm = frame.isAddressWarm(txStack.current().getCoinbase()); + + txStack.current().setPreFinalisationValues(leftOverGas, gasRefund, minerIsWarm); + } + } + @Override public void traceEndTx( WorldView world, @@ -822,15 +852,10 @@ public void traceEndTx( Bytes output, List logs, long gasUsed) { - final long leftoverGas = txStack.current().getBesuTransaction().getGasLimit() - gasUsed; txStack .current() .completeLineaTransaction( - isSuccessful, - leftoverGas, - this.accruedRefunds(), - this.state.stamps().hub(), - this.state.getProcessingPhase()); + isSuccessful, this.state.stamps().hub(), this.state.getProcessingPhase()); if (this.state.processingPhase != TX_SKIP) { this.processStateFinal(world); @@ -1010,29 +1035,6 @@ public void traceContextReEnter(MessageFrame frame) { } } - @Override - public void traceContextExit(MessageFrame frame) { - if (frame.getDepth() > 0) { - this.transients - .conflation() - .deploymentInfo() - .unmarkDeploying(this.currentFrame().byteCodeAddress()); - - DeploymentExceptions contextExceptions = - DeploymentExceptions.fromFrame(this.currentFrame(), frame); - this.currentTraceSection().setContextExceptions(contextExceptions); - if (contextExceptions.any()) { - this.callStack.revert(this.state.stamps().hub()); - } - - this.callStack.exit(); - - for (Module m : this.modules) { - m.traceContextExit(frame); - } - } - } - @Override public void tracePreOpcode(final MessageFrame frame) { if (this.state().processingPhase == TX_SKIP) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 7c4268e72c..5afabd7bcb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -80,6 +80,10 @@ public class TransactionProcessingMetadata { @Setter boolean isReceiverPreWarmed = false; + @Accessors(fluent = true) + @Setter + boolean isMinerWarmAtEndTx = false; + final StorageInitialValues storage = new StorageInitialValues(); @Setter int codeFragmentIndex = -1; @@ -148,16 +152,21 @@ public long getInitiallyAvailableGas() { return besuTransaction.getGasLimit() - getUpfrontGasCost(); } + public void setPreFinalisationValues( + final long leftOverGas, + final long refundCounterMax, + final boolean minerIsWarmAtFinalisation) { + this.isMinerWarmAtEndTx(minerIsWarmAtFinalisation); + this.refundCounterMax = refundCounterMax; + this.setLeftoverGas(leftOverGas); + this.refundEffective = computeRefundEffective(); + } + public void completeLineaTransaction( final boolean statusCode, - final long leftoverGas, - final long refundCounterMax, final int hubStampTransactionEnd, final HubProcessingPhase hubPhase) { - this.refundCounterMax = refundCounterMax; - this.leftoverGas = leftoverGas; this.statusCode = statusCode; - this.refundEffective = computeRefundEffective(); this.hubStampTransactionEnd = (hubPhase == TX_SKIP) ? hubStampTransactionEnd : hubStampTransactionEnd + 1; } @@ -197,4 +206,8 @@ public boolean requiresPrewarming() { public boolean requiresCfiUpdate() { return requiresEvmExecution && isDeployment; } + + public long getGasUsed() { + return besuTransaction.getGasLimit() - leftoverGas; + } } From 373858c7a8a3b2594fce9f0bf09152e62256c66b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 5 Jun 2024 17:54:07 +0400 Subject: [PATCH 061/461] fix: wip more and simpler stuff in TransactionProcessingMetadata --- .../linea/zktracer/module/hub/Hub.java | 13 +++--- .../hub/section/TxFinalizationSection.java | 6 +-- .../types/TransactionProcessingMetadata.java | 41 +++++++++++++++---- .../linea/zktracer/module/hub/TxSkip.java | 8 ++-- .../testing/ToyExecutionEnvironment.java | 5 ++- 5 files changed, 47 insertions(+), 26 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index ddfa54e80b..c25cceb03f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1037,16 +1037,17 @@ public void traceContextReEnter(MessageFrame frame) { @Override public void tracePreOpcode(final MessageFrame frame) { - if (this.state().processingPhase == TX_SKIP) { - return; - } + Preconditions.checkArgument( + this.state().processingPhase != TX_SKIP, + "There can't be any execution if the HUB is in the a skip phase"); + this.processStateExec(frame); } public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { - if (this.state.processingPhase == TX_SKIP) { - return; - } + Preconditions.checkArgument( + this.state().processingPhase != TX_SKIP, + "There can't be any execution if the HUB is in the a skip phase"); if (this.currentFrame().opCode().isCreate() && operationResult.getHaltReason() == null) { this.handleCreate(Words.toAddress(frame.getStackItem(0))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index aaa5aa444f..cd75b3604d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -47,10 +47,8 @@ public static TxFinalizationSection finalizeSuccessfulTransaction( final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); - final long gasUsed = tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas(); - final long effectiveRefunds = Math.min(hub.accruedRefunds(), gasUsed / MAX_REFUND_QUOTIENT); - final long senderGasRefund = tx.getLeftoverGas() + effectiveRefunds; - final long coinbaseGasReward = tx.getBesuTransaction().getGasLimit() - senderGasRefund; + final long senderGasRefund = tx.getGasRefunded(); + final long coinbaseGasReward = tx.getTotalGasUsed(); final Wei coinbaseFee = Wei.of( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 5afabd7bcb..e6b78c7c2e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -56,15 +56,26 @@ public class TransactionProcessingMetadata { final long dataCost; final long accessListCost; + + /* g in the EYP, defined by g = TG - g0 */ final long initiallyAvailableGas; final Address effectiveTo; final long effectiveGasPrice; - @Setter long refundCounterMax = 0; - @Setter long refundEffective = 0; - @Setter long leftoverGas = 0; + /* g' in the EYP*/ + @Setter long leftoverGas = -1; + /* Ar in the EYP*/ + @Setter long refundCounterMax = -1; + /* g* - g' in the EYP*/ + @Setter long refundEffective = -1; + /* Tg - g' in the EYP*/ + @Setter long gasUsed = -1; + /* g* in the EYP */ + @Setter long gasRefunded = -1; + /* Tg - g* in the EYP */ + @Setter long totalGasUsed = -1; @Accessors(fluent = true) @Setter @@ -160,6 +171,9 @@ public void setPreFinalisationValues( this.refundCounterMax = refundCounterMax; this.setLeftoverGas(leftOverGas); this.refundEffective = computeRefundEffective(); + this.gasUsed = computeGasUsed(); + this.gasRefunded = computeRefunded(); + this.totalGasUsed = computeTotalGasUsed(); } public void completeLineaTransaction( @@ -172,13 +186,11 @@ public void completeLineaTransaction( } private long computeRefundEffective() { - final long consumedGas = besuTransaction.getGasLimit() - leftoverGas; - final long maxRefundableAmount = consumedGas / MAX_REFUND_QUOTIENT; - return leftoverGas + Math.min(maxRefundableAmount, refundCounterMax); + final long maxRefundableAmount = this.getGasUsed() / MAX_REFUND_QUOTIENT; + return Math.min(maxRefundableAmount, refundCounterMax); } private long computeEffectiveGasPrice() { - final Transaction tx = besuTransaction; switch (tx.getType()) { case FRONTIER, ACCESS_LIST -> { @@ -187,7 +199,7 @@ private long computeEffectiveGasPrice() { case EIP1559 -> { final long baseFee = this.baseFee; final long maxPriorityFee = - tx.getMaxPriorityFeePerGas().get().getAsBigInteger().longValue(); + tx.getMaxPriorityFeePerGas().get().getAsBigInteger().longValueExact(); final long maxFeePerGas = tx.getMaxFeePerGas().get().getAsBigInteger().longValueExact(); return Math.min(baseFee + maxPriorityFee, maxFeePerGas); } @@ -207,7 +219,18 @@ public boolean requiresCfiUpdate() { return requiresEvmExecution && isDeployment; } - public long getGasUsed() { + /* Tg - g' in the EYP*/ + public long computeGasUsed() { return besuTransaction.getGasLimit() - leftoverGas; } + + /* g* in the EYP */ + public long computeRefunded() { + return leftoverGas + this.refundEffective; + } + + /* Tg - g* in the EYP */ + public long computeTotalGasUsed() { + return besuTransaction.getGasLimit() - getGasRefunded(); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java index e8b25b3e29..2e79363d9b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub; +import static net.consensys.linea.zktracer.testing.ToyExecutionEnvironment.minerAddress; + import java.util.List; import net.consensys.linea.zktracer.testing.EvmExtension; @@ -47,11 +49,7 @@ void test() { .address(Address.fromHexString("0xdead000000000000000000000000000beef")) .build(); - final ToyAccount minerAccount = - ToyAccount.builder() - .balance(Wei.ONE) - .address(Address.fromHexString("0x0000000000000000000000000000001234532342")) - .build(); + final ToyAccount minerAccount = ToyAccount.builder().address(minerAddress).build(); final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); final Address senderAddress1 = diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java index 83844f8ec8..f21def6314 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java @@ -77,9 +77,10 @@ public class ToyExecutionEnvironment { private static final Wei DEFAULT_BASE_FEE = Wei.of(LINEA_BASE_FEE); private static final GasCalculator gasCalculator = ZkTracer.gasCalculator; - private static final Address minerAddress = Address.fromHexString("0x1234532342"); + public static final Address minerAddress = + Address.fromHexString("0xc019ba5e00000000c019ba5e00000000c019ba5e"); private static final long DEFAULT_BLOCK_NUMBER = 6678980; - private static final long DEFAULT_TIME_STAMP = 1347310; + private static final long DEFAULT_TIME_STAMP = 14071789; private static final Hash DEFAULT_HASH = Hash.fromHexStringLenient("0xdeadbeef123123666dead666dead666"); From 317c3d81df79e042732ed2324f616ae8b9d8c14e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 5 Jun 2024 18:13:24 +0400 Subject: [PATCH 062/461] style: cosmetic renaming --- .../net/consensys/linea/zktracer/module/hub/TxSkip.java | 6 ++---- .../linea/zktracer/testing/ToyExecutionEnvironment.java | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java index 2e79363d9b..655b72d14a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.hub; -import static net.consensys.linea.zktracer.testing.ToyExecutionEnvironment.minerAddress; - import java.util.List; import net.consensys.linea.zktracer.testing.EvmExtension; @@ -49,7 +47,7 @@ void test() { .address(Address.fromHexString("0xdead000000000000000000000000000beef")) .build(); - final ToyAccount minerAccount = ToyAccount.builder().address(minerAddress).build(); + // final ToyAccount minerAccount = ToyAccount.builder().address(minerAddress).build(); final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); final Address senderAddress1 = @@ -181,7 +179,7 @@ void test() { ToyWorld.builder() .accounts( List.of( - minerAccount, + // minerAccount, senderAccount1, senderAccount2, senderAccount3, diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java index f21def6314..6afb13a696 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java @@ -77,7 +77,7 @@ public class ToyExecutionEnvironment { private static final Wei DEFAULT_BASE_FEE = Wei.of(LINEA_BASE_FEE); private static final GasCalculator gasCalculator = ZkTracer.gasCalculator; - public static final Address minerAddress = + private static final Address DEFAULT_MINER_ADDRESS = Address.fromHexString("0xc019ba5e00000000c019ba5e00000000c019ba5e"); private static final long DEFAULT_BLOCK_NUMBER = 6678980; private static final long DEFAULT_TIME_STAMP = 14071789; @@ -185,7 +185,7 @@ private void execute() { .gasLimit(LINEA_BLOCK_GAS_LIMIT) .difficulty(Difficulty.of(LINEA_DIFFICULTY)) .number(DEFAULT_BLOCK_NUMBER) - .coinbase(minerAddress) + .coinbase(DEFAULT_MINER_ADDRESS) .timestamp(DEFAULT_TIME_STAMP) .parentHash(DEFAULT_HASH) .buildBlockHeader(); From f36f8a57b433e8178f2a5023edbff03ed1931f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 5 Jun 2024 17:56:26 +0400 Subject: [PATCH 063/461] domSubStamps methods + inclusion into accountFragments (wip) --- .../linea/zktracer/module/hub/Hub.java | 138 ++++++++++++++---- .../module/hub/fragment/CommonFragment.java | 17 ++- .../module/hub/fragment/DomSubData.java | 33 ----- .../hub/fragment/DomSubStampsSubFragment.java | 110 ++++++++++++++ .../hub/fragment/account/AccountFragment.java | 25 +++- .../module/hub/fragment/imc/ImcFragment.java | 4 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 1 + .../hub/section/TxFinalizationSection.java | 1 + .../hub/section/calls/NoCodeCallSection.java | 24 ++- .../calls/SmartContractCallSection.java | 109 +++++++++----- code | 51 +++++++ 11 files changed, 392 insertions(+), 121 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java create mode 100644 code diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c25cceb03f..e18dc6f1e2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -469,11 +469,17 @@ void processPrewarmingPhase(WorldView world) { AccountSnapshot.fromAccount( world.get(address), true, deploymentNumber, false); + DomSubStampsSubFragment domSubStampsSubFragment = + new DomSubStampsSubFragment( + DomSubStampsSubFragment.DomSubType.STANDARD, this.stamp(), 0, 0, 0, 0, 0); fragments.add( this.factories .accountFragment() .makeWithTrm( - preWarmingAccountSnapshot, postWarmingAccountSnapshot, address)); + preWarmingAccountSnapshot, + postWarmingAccountSnapshot, + address, + domSubStampsSubFragment)); seenAddresses.add(address); @@ -530,30 +536,32 @@ void processStateInit(WorldView world) { final Address toAddress = tx.getEffectiveTo(); final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); - final Address fromAddress = tx.getSender(); - final Account fromAccount = world.get(fromAddress); - final AccountSnapshot preInitFromSnapshot = + final Address senderAddress = tx.getSender(); + final Account senderAccount = world.get(senderAddress); + final AccountSnapshot senderBeforePayingForTransaction = AccountSnapshot.fromAccount( - fromAccount, + senderAccount, tx.isSenderPreWarmed(), - deploymentInfo.number(fromAddress), - deploymentInfo.isDeploying(fromAddress)); + deploymentInfo.number(senderAddress), + deploymentInfo.isDeploying(senderAddress)); + final DomSubStampsSubFragment senderDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 0); final Wei transactionGasPrice = Wei.of(tx.getEffectiveGasPrice()); final Wei value = (Wei) tx.getBesuTransaction().getValue(); - final AccountSnapshot postInitFromSnapshot = - preInitFromSnapshot.debit( + final AccountSnapshot senderAfterPayingForTransaction = + senderBeforePayingForTransaction.debit( transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value), true); - final boolean isSelfCredit = toAddress.equals(fromAddress); + final boolean isSelfCredit = toAddress.equals(senderAddress); - final Account toAccount = world.get(toAddress); + final Account recipientAccount = world.get(toAddress); - final AccountSnapshot preInitToSnapshot = + final AccountSnapshot recipientBeforeValueTransfer = isSelfCredit - ? postInitFromSnapshot + ? senderAfterPayingForTransaction : AccountSnapshot.fromAccount( - toAccount, + recipientAccount, tx.isReceiverPreWarmed(), deploymentInfo.number(toAddress), deploymentInfo.isDeploying(toAddress)); @@ -564,10 +572,12 @@ void processStateInit(WorldView world) { final Bytecode initBytecode = new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); - final AccountSnapshot postInitToSnapshot = + final AccountSnapshot recipientAfterValueTransfer = isDeployment - ? preInitToSnapshot.deploy(value, initBytecode) - : preInitToSnapshot.credit(value, true); + ? recipientBeforeValueTransfer.deploy(value, initBytecode) + : recipientBeforeValueTransfer.credit(value, true); + final DomSubStampsSubFragment recipientDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 1); final TransactionFragment txFragment = TransactionFragment.prepare(tx); this.defers.postTx(txFragment); @@ -578,9 +588,16 @@ void processStateInit(WorldView world) { this.addTraceSection( new TxInitializationSection( this, - accountFragmentFactory.make(preInitFromSnapshot, postInitFromSnapshot), + accountFragmentFactory.make( + senderBeforePayingForTransaction, + senderAfterPayingForTransaction, + senderDomSubStamps), accountFragmentFactory - .makeWithTrm(preInitToSnapshot, postInitToSnapshot, toAddress) + .makeWithTrm( + recipientBeforeValueTransfer, + recipientAfterValueTransfer, + toAddress, + recipientDomSubStamps) .requiresRomlex(true), ImcFragment.forTxInit(this), ContextFragment.initializeExecutionContext(this), @@ -1258,7 +1275,7 @@ void traceOperation(MessageFrame frame) { } case ACCOUNT -> { TraceSection accountSection = new AccountSection(this); - if (this.opCodeData().stackSettings().flag1()) { + if (this.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { accountSection.addFragment( this, this.currentFrame(), ContextFragment.readContextData(this)); } @@ -1270,25 +1287,43 @@ void traceOperation(MessageFrame frame) { }; final Address targetAddress = Words.toAddress(rawTargetAddress); final Account targetAccount = frame.getWorldUpdater().get(targetAddress); - final AccountSnapshot accountSnapshot = + final AccountSnapshot accountBefore = AccountSnapshot.fromAccount( targetAccount, frame.isAddressWarm(targetAddress), this.transients.conflation().deploymentInfo().number(targetAddress), this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + final AccountSnapshot accountAfter = + AccountSnapshot.fromAccount( + targetAccount, + true, + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + final DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 0); accountSection.addFragment( this, this.currentFrame(), this.factories .accountFragment() - .makeWithTrm(accountSnapshot, accountSnapshot, rawTargetAddress)); + .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps)); + + if (this.currentFrame().willRevert()) { + final DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); + accountSection.addFragment( + this, + this.currentFrame(), + this.factories + .accountFragment() + .make(accountBefore, accountAfter, undoingDomSubStamps)); + } this.addTraceSection(accountSection); } case COPY -> { TraceSection copySection = new CopySection(this); - if (this.opCodeData().stackSettings().flag1()) { - + if (!this.opCode().equals(OpCode.RETURNDATACOPY)) { final Bytes rawTargetAddress = switch (this.currentFrame().opCode()) { case CODECOPY -> this.currentFrame().byteCodeAddress(); @@ -1300,21 +1335,45 @@ void traceOperation(MessageFrame frame) { }; final Address targetAddress = Words.toAddress(rawTargetAddress); final Account targetAccount = frame.getWorldUpdater().get(targetAddress); - AccountSnapshot accountSnapshot = + + AccountSnapshot accountBefore = AccountSnapshot.fromAccount( targetAccount, frame.isAddressWarm(targetAddress), this.transients.conflation().deploymentInfo().number(targetAddress), this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + AccountSnapshot accountAfter = + AccountSnapshot.fromAccount( + targetAccount, + true, + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + + DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 0); copySection.addFragment( this, this.currentFrame(), this.currentFrame().opCode() == OpCode.EXTCODECOPY ? this.factories .accountFragment() - .makeWithTrm(accountSnapshot, accountSnapshot, rawTargetAddress) - : this.factories.accountFragment().make(accountSnapshot, accountSnapshot)); + .makeWithTrm( + accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps) + : this.factories + .accountFragment() + .make(accountBefore, accountAfter, doingDomSubStamps)); + + if (this.callStack.current().willRevert()) { + DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); + copySection.addFragment( + this, + this.currentFrame(), + this.factories + .accountFragment() + .make(accountAfter, accountBefore, undoingDomSubStamps)); + } } else { copySection.addFragment(this, this.currentFrame(), ContextFragment.readContextData(this)); } @@ -1451,7 +1510,10 @@ void traceOperation(MessageFrame frame) { this.factories .accountFragment() .makeWithTrm( - calledAccountSnapshot, calledAccountSnapshot, rawCalledAddress))); + calledAccountSnapshot, + calledAccountSnapshot, + rawCalledAddress, + DomSubStampsSubFragment.standardDomSubStamps(this, 0)))); } } else if (this.pch.abortingConditions().any()) { // @@ -1463,10 +1525,19 @@ void traceOperation(MessageFrame frame) { ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount), ContextFragment.readContextData(this), - this.factories.accountFragment().make(myAccountSnapshot, myAccountSnapshot), this.factories .accountFragment() - .makeWithTrm(calledAccountSnapshot, calledAccountSnapshot, rawCalledAddress), + .make( + myAccountSnapshot, + myAccountSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this, 0)), + this.factories + .accountFragment() + .makeWithTrm( + calledAccountSnapshot, + calledAccountSnapshot, + rawCalledAddress, + DomSubStampsSubFragment.standardDomSubStamps(this, 1)), ContextFragment.nonExecutionEmptyReturnData(this)); this.addTraceSection(abortedSection); } else { @@ -1526,7 +1597,12 @@ void traceOperation(MessageFrame frame) { new JumpSection( this, ContextFragment.readContextData(this), - this.factories.accountFragment().make(codeAccountSnapshot, codeAccountSnapshot), + this.factories + .accountFragment() + .make( + codeAccountSnapshot, + codeAccountSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this, 0)), ImcFragment.forOpcode(this, frame)); this.addTraceSection(jumpSection); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 6904341822..54f0010afb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -181,6 +181,13 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); final boolean willRevert = frame.willRevert(); + final boolean contextMayChange = + this.hubProcessingPhase == HubProcessingPhase.TX_EXEC + && ((instructionFamily == InstructionFamily.CALL + || instructionFamily == InstructionFamily.CREATE + || instructionFamily == InstructionFamily.HALT + || instructionFamily == InstructionFamily.INVALID) + || exceptions.any()); return trace .absoluteTransactionNumber(tx.getAbsoluteTransactionNumber()) @@ -192,17 +199,12 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .txFinl(this.hubProcessingPhase == HubProcessingPhase.TX_FINAL) .hubStamp(this.stamps.hub()) .hubStampTransactionEnd(tx.getHubStampTransactionEnd()) - .contextMayChange( - this.hubProcessingPhase == HubProcessingPhase.TX_EXEC - && ((instructionFamily == InstructionFamily.CALL - || instructionFamily == InstructionFamily.CREATE - || instructionFamily == InstructionFamily.HALT - || instructionFamily == InstructionFamily.INVALID) - || exceptions.any())) + .contextMayChange(contextMayChange) .exceptionAhoy(exceptions.any()) .logInfoStamp(this.stamps.log()) .mmuStamp(this.stamps.mmu()) .mxpStamp(this.stamps.mxp()) + // nontrivial dom / sub are traced in storage or account fragments only .contextNumber(contextNumber) .contextNumberNew(contextNumberNew) .callerContextNumber(callerContextNumber) @@ -215,6 +217,7 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .programCounterNew(pcNew) .height((short) stackHeight) .heightNew((short) stackHeightNew) + // peeking flags are traced in the respective fragments .gasExpected(gasExpected) .gasActual(gasActual) .gasCost(Bytes.ofUnsignedLong(gasCost)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java deleted file mode 100644 index c451addd44..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubData.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package net.consensys.linea.zktracer.module.hub.fragment; - -import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___DOM_SUB_STAMPS; - -import com.google.common.base.Preconditions; - -public record DomSubData(DomSubType type, int domOffset, int subOffset) { - public int domStamp(final int hubStamp) { - Preconditions.checkArgument(this.type == DomSubType.STANDARD); - return MULTIPLIER___DOM_SUB_STAMPS * hubStamp + this.domOffset; - } - - public enum DomSubType { - STANDARD, - REVERTS_WITH_CURRENT, - REVERTS_WITH_CHILD, - REVERTS_WITH_SELFDESTRUCT - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java new file mode 100644 index 0000000000..7d98e9c65a --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java @@ -0,0 +1,110 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment; + +import static net.consensys.linea.zktracer.module.hub.Trace.*; + +import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; + +@RequiredArgsConstructor +public class DomSubStampsSubFragment implements TraceSubFragment { + + public enum DomSubType { + STANDARD, + REVERTS_WITH_CURRENT, + REVERTS_WITH_CHILD, + SELFDESTRUCT + } + + final DomSubType type; + final int hubStamp; + final int domOffset; + final int subOffset; + final int revertStamp; + final int childRevertStamp; + final int transactionEndStamp; + + public static DomSubStampsSubFragment standardDomSubStamps(final Hub hub, final int domOffset) { + return new DomSubStampsSubFragment(DomSubType.STANDARD, hub.stamp(), domOffset, 0, 0, 0, 0); + } + + public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( + final Hub hub, final int subOffset) { + return new DomSubStampsSubFragment( + DomSubType.REVERTS_WITH_CURRENT, + hub.stamp(), + 0, + subOffset, + hub.callStack().current().getsRevertedAt(), + 0, + 0); + } + + public static DomSubStampsSubFragment revertsWithChildDomSubStamps( + final Hub hub, final CallFrame child, final int subOffset) { + return new DomSubStampsSubFragment( + DomSubType.REVERTS_WITH_CHILD, hub.stamp(), 0, subOffset, 0, child.getsRevertedAt(), 0); + } + + public static DomSubStampsSubFragment selfdestructDomSubStamps(final Hub hub) { + return new DomSubStampsSubFragment( + DomSubType.SELFDESTRUCT, + hub.stamp(), + 0, + 0, + 0, + 0, + hub.txStack().current().getHubStampTransactionEnd()); + } + + public int domStamp() { + switch (type) { + case STANDARD -> { + return MULTIPLIER___DOM_SUB_STAMPS * hubStamp + this.domOffset; + } + case REVERTS_WITH_CURRENT -> { + return MULTIPLIER___DOM_SUB_STAMPS * revertStamp + DOM_SUB_STAMP_OFFSET___REVERT; + } + case REVERTS_WITH_CHILD -> { + return MULTIPLIER___DOM_SUB_STAMPS * childRevertStamp + DOM_SUB_STAMP_OFFSET___REVERT; + } + case SELFDESTRUCT -> { + return MULTIPLIER___DOM_SUB_STAMPS * transactionEndStamp + + DOM_SUB_STAMP_OFFSET___SELFDESTRUCT; + } + default -> throw new RuntimeException("DomSubType not supported"); + } + } + + public int subStamp() { + switch (type) { + case STANDARD -> { + return this.subOffset; + } + case REVERTS_WITH_CURRENT, REVERTS_WITH_CHILD, SELFDESTRUCT -> { + return MULTIPLIER___DOM_SUB_STAMPS * this.hubStamp + this.subOffset; + } + default -> throw new RuntimeException("DomSubType not supported"); + } + } + + @Override + public Trace trace(Trace trace) { + return trace.domStamp(this.domStamp()).subStamp(this.subStamp()); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 4f57b4c505..b74d6ac9fd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.defer.PostConflationDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; @@ -52,13 +53,21 @@ public final class AccountFragment public static class AccountFragmentFactory { private final DeferRegistry defers; - public AccountFragment make(AccountSnapshot oldState, AccountSnapshot newState) { - return new AccountFragment(this.defers, oldState, newState, Optional.empty()); + public AccountFragment make( + AccountSnapshot oldState, + AccountSnapshot newState, + DomSubStampsSubFragment domSubStampsSubFragment) { + return new AccountFragment( + this.defers, oldState, newState, Optional.empty(), domSubStampsSubFragment); } public AccountFragment makeWithTrm( - AccountSnapshot oldState, AccountSnapshot newState, Bytes toTrim) { - return new AccountFragment(this.defers, oldState, newState, Optional.of(toTrim)); + AccountSnapshot oldState, + AccountSnapshot newState, + Bytes toTrim, + DomSubStampsSubFragment domSubStampsSubFragment) { + return new AccountFragment( + this.defers, oldState, newState, Optional.of(toTrim), domSubStampsSubFragment); } } @@ -72,12 +81,14 @@ public AccountFragment makeWithTrm( private int codeFragmentIndex; @Setter private boolean requiresRomlex; private final Optional addressToTrim; + private final DomSubStampsSubFragment domSubStampsSubFragment; public AccountFragment( final DeferRegistry defers, AccountSnapshot oldState, AccountSnapshot newState, - Optional addressToTrim) { + Optional addressToTrim, + DomSubStampsSubFragment domSubStampsSubFragment) { Preconditions.checkArgument(oldState.address().equals(newState.address())); this.who = oldState.address(); @@ -86,6 +97,7 @@ public AccountFragment( this.deploymentNumber = newState.deploymentNumber(); this.isDeployment = newState.deploymentStatus(); this.addressToTrim = addressToTrim; + this.domSubStampsSubFragment = domSubStampsSubFragment; defers.postConflation(this); } @@ -96,6 +108,9 @@ public Trace trace(Trace trace) { final EWord eCodeHash = EWord.of(oldState.code().getCodeHash()); final EWord eCodeHashNew = EWord.of(newState.code().getCodeHash()); + // tracing + this.domSubStampsSubFragment.trace(trace); + return trace .peekAtAccount(true) .pAccountAddressHi(bytesToLong(eWho.hi())) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index be74764653..c4a8d0442f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -88,11 +88,11 @@ public static ImcFragment forTxInit(final Hub hub) { // isdeployment == false // non empty calldata final TransactionProcessingMetadata currentTx = hub.txStack().current(); - final boolean isDeployment = currentTx.getBesuTransaction().getTo().isEmpty(); + final boolean isMessageCallTransaction = currentTx.getBesuTransaction().getTo().isPresent(); final Optional txData = currentTx.getBesuTransaction().getData(); final boolean shouldCopyTxCallData = - !isDeployment + isMessageCallTransaction && txData.isPresent() && !txData.get().isEmpty() && currentTx.requiresEvmExecution(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 4de42e22d9..b846122368 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -152,6 +152,7 @@ final MmuCall setEcData() { return this.exoIsEcData(true).updateExoSum(EXO_SUM_WEIGHT_ECDATA); } + // TODO: make the instruction an enum public MmuCall(final int instruction) { this.instruction = instruction; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index cd75b3604d..b12f5893a5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -22,6 +22,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index c537ac58aa..8335f21237 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -24,6 +24,7 @@ import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; @@ -123,11 +124,14 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces this.imcFragment, ContextFragment.readContextData(hub), accountFragmentFactory.make( - this.preCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot), + this.preCallCallerAccountSnapshot, + this.postCallCallerAccountSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), accountFragmentFactory.makeWithTrm( this.preCallCalledAccountSnapshot, this.postCallCalledAccountSnapshot, - this.rawCalledAddress)); + this.rawCalledAddress, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1))); if (precompileInvocation.isPresent()) { if (this.callSuccessful && callerCallFrame.hasReverted()) { @@ -135,9 +139,13 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, callerCallFrame, accountFragmentFactory.make( - this.postCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot), + this.postCallCallerAccountSnapshot, + this.preCallCallerAccountSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), accountFragmentFactory.make( - this.postCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); + this.postCallCalledAccountSnapshot, + this.preCallCalledAccountSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); } this.addFragmentsWithoutStack( hub, @@ -154,9 +162,13 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, callerCallFrame, accountFragmentFactory.make( - this.postCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot), + this.postCallCallerAccountSnapshot, + this.preCallCallerAccountSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), accountFragmentFactory.make( - this.postCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); + this.postCallCalledAccountSnapshot, + this.preCallCalledAccountSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); } this.addFragmentsWithoutStack( hub, callerCallFrame, ContextFragment.nonExecutionEmptyReturnData(hub)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index 006352945f..1a99025e5f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -21,6 +21,7 @@ import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; @@ -40,13 +41,13 @@ public class SmartContractCallSection extends TraceSection private final CallFrame callerCallFrame; private final int calledCallFrameId; private final AccountSnapshot preCallCallerAccountSnapshot; - private final AccountSnapshot preCallCalledAccountSnapshot; + private final AccountSnapshot preCallCalleeAccountSnapshot; private AccountSnapshot inCallCallerAccountSnapshot; - private AccountSnapshot inCallCalledAccountSnapshot; + private AccountSnapshot inCallCalleeAccountSnapshot; private AccountSnapshot postCallCallerAccountSnapshot; - private AccountSnapshot postCallCalledAccountSnapshot; + private AccountSnapshot postCallCalleeAccountSnapshot; private final ScenarioFragment scenarioFragment; private final ImcFragment imcFragment; @@ -54,14 +55,14 @@ public class SmartContractCallSection extends TraceSection public SmartContractCallSection( Hub hub, AccountSnapshot preCallCallerAccountSnapshot, - AccountSnapshot preCallCalledAccountSnapshot, + AccountSnapshot preCallCalleeAccountSnapshot, Bytes rawCalledAddress, ImcFragment imcFragment) { this.rawCalledAddress = rawCalledAddress; this.callerCallFrame = hub.currentFrame(); this.calledCallFrameId = hub.callStack().futureId(); this.preCallCallerAccountSnapshot = preCallCallerAccountSnapshot; - this.preCallCalledAccountSnapshot = preCallCalledAccountSnapshot; + this.preCallCalleeAccountSnapshot = preCallCalleeAccountSnapshot; this.imcFragment = imcFragment; this.scenarioFragment = ScenarioFragment.forSmartContractCallSection( @@ -78,7 +79,7 @@ public SmartContractCallSection( public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); - final Address calledAddress = preCallCalledAccountSnapshot.address(); + final Address calledAddress = preCallCalleeAccountSnapshot.address(); final Account calledAccount = frame.getWorldUpdater().get(calledAddress); this.postCallCallerAccountSnapshot = @@ -87,7 +88,7 @@ public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult o frame.isAddressWarm(callerAddress), hub.transients().conflation().deploymentInfo().number(callerAddress), hub.transients().conflation().deploymentInfo().isDeploying(callerAddress)); - this.postCallCalledAccountSnapshot = + this.postCallCalleeAccountSnapshot = AccountSnapshot.fromAccount( calledAccount, frame.isAddressWarm(calledAddress), @@ -99,7 +100,7 @@ public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult o public void runNextContext(Hub hub, MessageFrame frame) { final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); - final Address calledAddress = preCallCalledAccountSnapshot.address(); + final Address calledAddress = preCallCalleeAccountSnapshot.address(); final Account calledAccount = frame.getWorldUpdater().get(calledAddress); this.inCallCallerAccountSnapshot = @@ -108,7 +109,7 @@ public void runNextContext(Hub hub, MessageFrame frame) { frame.isAddressWarm(callerAddress), hub.transients().conflation().deploymentInfo().number(callerAddress), hub.transients().conflation().deploymentInfo().isDeploying(callerAddress)); - this.inCallCalledAccountSnapshot = + this.inCallCalleeAccountSnapshot = AccountSnapshot.fromAccount( calledAccount, frame.isAddressWarm(calledAddress), @@ -123,6 +124,12 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces final CallFrame calledCallFrame = hub.callStack().getById(this.calledCallFrameId); this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); + DomSubStampsSubFragment firstCallerDoingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + + DomSubStampsSubFragment firstCalleeDoingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(hub, 1); + this.addFragmentsWithoutStack( hub, callerCallFrame, @@ -130,41 +137,69 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces ContextFragment.readContextData(hub), this.imcFragment, accountFragmentFactory.make( - this.preCallCallerAccountSnapshot, this.inCallCallerAccountSnapshot), + this.preCallCallerAccountSnapshot, + this.inCallCallerAccountSnapshot, + firstCallerDoingDomSubStamps), accountFragmentFactory.makeWithTrm( - this.preCallCalledAccountSnapshot, - this.inCallCalledAccountSnapshot, - this.rawCalledAddress)); + this.preCallCalleeAccountSnapshot, + this.inCallCalleeAccountSnapshot, + this.rawCalledAddress, + firstCalleeDoingDomSubStamps)); + + // caller: WILL_REVERT + // child: FAILURE + // TODO: get the right account snapshots + if (callerCallFrame.willRevert() && calledCallFrame.selfReverts()) { + this.addFragmentsWithoutStack( + hub, + callerCallFrame, + accountFragmentFactory.make( + this.inCallCallerAccountSnapshot, + this.preCallCallerAccountSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 2)), + accountFragmentFactory.make( + this.inCallCalleeAccountSnapshot, + this.postCallCalleeAccountSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 3)), + accountFragmentFactory.make( + this.postCallCalleeAccountSnapshot, + this.preCallCalleeAccountSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 4))); + } - if (callerCallFrame.hasReverted()) { - if (calledCallFrame.hasReverted()) { - this.addFragmentsWithoutStack( - hub, - callerCallFrame, - accountFragmentFactory.make( - this.inCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot), - accountFragmentFactory.make( - this.inCallCalledAccountSnapshot, this.postCallCalledAccountSnapshot), - accountFragmentFactory.make( - this.postCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); - } else { - this.addFragmentsWithoutStack( - hub, - callerCallFrame, - accountFragmentFactory.make( - this.inCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot), - accountFragmentFactory.make( - this.inCallCalledAccountSnapshot, this.preCallCalledAccountSnapshot)); - } - } else { - if (calledCallFrame.hasReverted()) { + // caller: WILL_REVERT + // child: SUCCESS + // TODO: get the right account snapshots + if (callerCallFrame.willRevert() && !calledCallFrame.selfReverts()) { + this.addFragmentsWithoutStack( + hub, + callerCallFrame, + accountFragmentFactory.make( + this.inCallCallerAccountSnapshot, + this.preCallCallerAccountSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), + accountFragmentFactory.make( + this.inCallCalleeAccountSnapshot, + this.preCallCalleeAccountSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); + } + + // caller: WONT_REVERT + // child: FAILURE + // TODO: get the right account snapshots + if (!callerCallFrame.willRevert() && calledCallFrame.selfReverts()) { + if (calledCallFrame.selfReverts()) { this.addFragmentsWithoutStack( hub, callerCallFrame, accountFragmentFactory.make( - this.inCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot), + this.inCallCallerAccountSnapshot, + this.postCallCallerAccountSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 2)), accountFragmentFactory.make( - this.inCallCalledAccountSnapshot, this.postCallCalledAccountSnapshot)); + this.inCallCalleeAccountSnapshot, + this.postCallCalleeAccountSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 3))); } } diff --git a/code b/code new file mode 100644 index 0000000000..ff247b008a --- /dev/null +++ b/code @@ -0,0 +1,51 @@ +PUSH6 0xaabbccddeeff +PUSH1 208 +SHL +PUSH1 0x00 +MSTORE +PUSH1 0x06 +PUSH1 0x00 +RETURN + + +65aabbccddeeff60d01b60005260066000f3 + + +PUSH32 0x65aabbccddeeff60d01b60005260066000f30000000000000000000000000000 +PUSH1 0x00 +MSTORE +PUSH1 0x10 +PUSH1 0x00 +RETURN + +CALLDATA: 0x7f65aabbccddeeff60d01b60005260066000f3000000000000000000000000000060005260106000f3 + +======================== +code to run on EVM.codes +======================== + +CALLDATA: 0x7f65aabbccddeeff60d01b60005260066000f3000000000000000000000000000060005260106000f3 + +------------------------ + +CALLDATASIZE +PUSH1 0x29 +PUSH1 0x00 +PUSH1 0x00 +CALLDATACOPY + + +PUSH1 0x29 +PUSH1 0x00 +PUSH1 0x00 +CREATE + +PUSH1 0x20 +PUSH1 0x00 +PUSH1 0x20 +PUSH1 0x00 +DUP5 +PUSH2 0xffff +STATICCALL + +RETURNDATASIZE From 997892ffc7317510614fa871986e668c9a8a0485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 5 Jun 2024 19:04:57 +0400 Subject: [PATCH 064/461] COINBASE address now gets paid :) --- .../defer/SkippedPostTransactionDefer.java | 22 ++- .../hub/fragment/TransactionFragment.java | 2 +- .../module/hub/section/CreateSection.java | 163 ++++++++++++++---- .../hub/section/TxFinalizationSection.java | 20 ++- .../types/TransactionProcessingMetadata.java | 2 +- 5 files changed, 165 insertions(+), 44 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java index c857aaf0f1..4b916fb2b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java @@ -19,6 +19,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.section.TxSkippedSection; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -107,11 +108,26 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, // 3 lines -- account changes // From - hub.factories().accountFragment().make(oldFromAccount, newFromAccount), + hub.factories() + .accountFragment() + .make( + oldFromAccount, + newFromAccount, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), // To - hub.factories().accountFragment().make(oldToAccount, newToAccount), + hub.factories() + .accountFragment() + .make( + oldToAccount, + newToAccount, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), // Miner - hub.factories().accountFragment().make(oldMinerAccount, newMinerAccount), + hub.factories() + .accountFragment() + .make( + oldMinerAccount, + newMinerAccount, + DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), // 1 line -- transaction data TransactionFragment.prepare(hub.txStack().current()))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index 177a7e3c20..e97c555c78 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -78,7 +78,7 @@ public Trace trace(Trace trace) { .pTransactionRefundCounterInfinity( Bytes.minimalBytes(transactionProcessingMetadata.getRefundCounterMax())) .pTransactionRefundEffective( - Bytes.minimalBytes(transactionProcessingMetadata.getRefundEffective())) + Bytes.minimalBytes(transactionProcessingMetadata.getGasRefunded())) .pTransactionCoinbaseAddressHi(bytesToLong(miner.hi())) .pTransactionCoinbaseAddressLo(miner.lo()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 131a8a7e07..64194185ac 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -24,6 +24,7 @@ import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -148,7 +149,7 @@ public void runAtReEnter(Hub hub, MessageFrame frame) { public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); - final boolean creatorReverted = hub.callStack().getById(this.creatorContextId).hasReverted(); + final boolean creatorWillRevert = hub.callStack().getById(this.creatorContextId).hasReverted(); final GasProjection projection = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()); final long upfrontCost = projection.memoryExpansion() + projection.linearPerWord() + GasConstants.G_TX_CREATE.cost(); @@ -198,85 +199,179 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, commonImcFragment, ContextFragment.readContextData(hub), - accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (this.failures.any()) { - if (creatorReverted) { + if (creatorWillRevert) { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), - accountFragmentFactory.make(newCreatorSnapshot, oldCreatorSnapshot), - accountFragmentFactory.make(newCreatedSnapshot, oldCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + accountFragmentFactory.make( + newCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), + accountFragmentFactory.make( + newCreatedSnapshot, + oldCreatedSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3)), ContextFragment.nonExecutionEmptyReturnData(hub)); } else { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), ContextFragment.nonExecutionEmptyReturnData(hub)); } } else { + // entry into the CREATE operation if (this.emptyInitCode) { - if (creatorReverted) { + if (creatorWillRevert) { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), - accountFragmentFactory.make(newCreatorSnapshot, oldCreatorSnapshot), - accountFragmentFactory.make(newCreatedSnapshot, oldCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + accountFragmentFactory.make( + newCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), + accountFragmentFactory.make( + newCreatedSnapshot, + oldCreatedSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3)), ContextFragment.nonExecutionEmptyReturnData(hub)); } else { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, newCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, newCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), ContextFragment.nonExecutionEmptyReturnData(hub)); } } else { + // non empty code + final int createeContextId = hub.callStack().futureId(); if (this.createSuccessful) { - if (creatorReverted) { + if (creatorWillRevert) { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, midCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, midCreatedSnapshot), - accountFragmentFactory.make(midCreatorSnapshot, oldCreatorSnapshot), - accountFragmentFactory.make(midCreatedSnapshot, oldCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + midCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + midCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + accountFragmentFactory.make( + midCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), + accountFragmentFactory.make( + midCreatedSnapshot, + oldCreatedSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3)), ContextFragment.initializeExecutionContext(hub)); } else { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, midCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, midCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + midCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + midCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), ContextFragment.initializeExecutionContext(hub)); } } else { - if (creatorReverted) { + if (creatorWillRevert) { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, midCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, midCreatedSnapshot), - accountFragmentFactory.make(midCreatorSnapshot, newCreatorSnapshot), - accountFragmentFactory.make(midCreatedSnapshot, newCreatedSnapshot), - accountFragmentFactory.make(newCreatorSnapshot, oldCreatorSnapshot), - accountFragmentFactory.make(newCreatedSnapshot, oldCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + midCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + midCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + accountFragmentFactory.make( + midCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + hub, hub.callStack().getById(createeContextId), 2)), + accountFragmentFactory.make( + midCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + hub, hub.callStack().getById(createeContextId), 3)), + accountFragmentFactory.make( + newCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 4)), + accountFragmentFactory.make( + newCreatedSnapshot, + oldCreatedSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 5)), ContextFragment.initializeExecutionContext(hub)); } else { this.addFragmentsWithoutStack( hub, commonImcFragment, - accountFragmentFactory.make(oldCreatorSnapshot, midCreatorSnapshot), - accountFragmentFactory.make(oldCreatedSnapshot, midCreatedSnapshot), - accountFragmentFactory.make(midCreatorSnapshot, newCreatorSnapshot), - accountFragmentFactory.make(midCreatedSnapshot, newCreatedSnapshot), + accountFragmentFactory.make( + oldCreatorSnapshot, + midCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + accountFragmentFactory.make( + oldCreatedSnapshot, + midCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + accountFragmentFactory.make( + midCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + hub, hub.callStack().getById(createeContextId), 2)), + accountFragmentFactory.make( + midCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + hub, hub.callStack().getById(createeContextId), 3)), ContextFragment.initializeExecutionContext(hub)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index b12f5893a5..0e400e69f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -105,9 +105,13 @@ public static TxFinalizationSection finalizeSuccessfulTransaction( return new TxFinalizationSection( hub, accountFragmentFactory.make( - senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasRefund), + senderAccountSnapshotBeforeRefunds, + senderAccountSnapshotAfterGasRefund, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), accountFragmentFactory.make( - coinbaseSnapshotBeforeFeeCollection, coinbaseSnapshotAfterFeeCollection), + coinbaseSnapshotBeforeFeeCollection, + coinbaseSnapshotAfterFeeCollection, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), TransactionFragment.prepare(hub.txStack().current())); } @@ -188,11 +192,17 @@ public static TxFinalizationSection finalizeUnsuccessfulTransaction( return new TxFinalizationSection( hub, accountFragmentFactory.make( - senderAccountSnapshotBeforeRefunds, senderAccountSnapshotAfterGasAndBalanceRefund), + senderAccountSnapshotBeforeRefunds, + senderAccountSnapshotAfterGasAndBalanceRefund, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), accountFragmentFactory.make( effectiveToAccountSnapshotBeforeReimbursingValue, - effectiveToAccountSnapshotAfterReimbursingValue), - accountFragmentFactory.make(coinbaseBeforeFeeCollection, coinbaseAfterFeeCollection), + effectiveToAccountSnapshotAfterReimbursingValue, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + accountFragmentFactory.make( + coinbaseBeforeFeeCollection, + coinbaseAfterFeeCollection, + DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), TransactionFragment.prepare(hub.txStack().current())); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index e6b78c7c2e..7b67567e08 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -170,8 +170,8 @@ public void setPreFinalisationValues( this.isMinerWarmAtEndTx(minerIsWarmAtFinalisation); this.refundCounterMax = refundCounterMax; this.setLeftoverGas(leftOverGas); - this.refundEffective = computeRefundEffective(); this.gasUsed = computeGasUsed(); + this.refundEffective = computeRefundEffective(); this.gasRefunded = computeRefunded(); this.totalGasUsed = computeTotalGasUsed(); } From b052c9cb65f76afec377c1b839f9353dd2cd8ee2 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 5 Jun 2024 21:55:13 +0400 Subject: [PATCH 065/461] feat: implements defers for txFinalization --- .../zktracer/module/hub/AccountSnapshot.java | 9 + .../linea/zktracer/module/hub/Hub.java | 24 +- .../hub/section/TxFinalizationSection.java | 211 ---------------- .../TxFinalizationPostTxDefer.java | 225 ++++++++++++++++++ .../txFinalization/TxFinalizationSection.java | 26 ++ .../SkippedPostTransactionDefer.java | 4 +- .../TxSkippedSection.java | 3 +- .../types/TransactionProcessingMetadata.java | 19 ++ .../consensys/linea/zktracer/ReplayTests.java | 3 + .../linea/zktracer/module/hub/TxSkip.java | 11 +- .../testing/ToyExecutionEnvironment.java | 2 +- 11 files changed, 304 insertions(+), 233 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationPostTxDefer.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/{defer => section/txSkipippedSection}/SkippedPostTransactionDefer.java (97%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{ => txSkipippedSection}/TxSkippedSection.java (86%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index d88603255f..36b1cbad0a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -59,6 +59,15 @@ public AccountSnapshot incrementNonce() { return this; } + // TODO: Warning, does it really creates a copy or a pointer ?? + public static AccountSnapshot deepCopy(final AccountSnapshot accountSnapshot) { + return AccountSnapshot.fromAccount( + (Account) accountSnapshot, + accountSnapshot.isWarm(), + accountSnapshot.deploymentNumber(), + accountSnapshot.deploymentStatus()); + } + public static AccountSnapshot fromAccount( Account account, boolean isWarm, int deploymentNumber, boolean deploymentStatus) { return fromAccount(Optional.ofNullable(account), isWarm, deploymentNumber, deploymentStatus); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index e18dc6f1e2..93db2f50fd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -62,6 +62,8 @@ import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; +import net.consensys.linea.zktracer.module.hub.section.txFinalization.TxFinalizationPostTxDefer; +import net.consensys.linea.zktracer.module.hub.section.txSkipippedSection.SkippedPostTransactionDefer; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -766,21 +768,6 @@ void processStateExec(MessageFrame frame) { } } - void processStateFinal(WorldView worldView) { - this.state.setProcessingPhase(TX_FINAL); - this.state.stamps().incrementHubStamp(); - - final boolean coinbaseWarmth = txStack.current().isMinerWarmAtEndTx(); - - if (this.txStack.current().statusCode()) { - this.addTraceSection( - TxFinalizationSection.finalizeSuccessfulTransaction(this, worldView, coinbaseWarmth)); - } else { - this.addTraceSection( - TxFinalizationSection.finalizeUnsuccessfulTransaction(this, worldView, coinbaseWarmth)); - } - } - @Override public void enterTransaction() { for (Module m : this.modules) { @@ -858,6 +845,10 @@ public void traceContextExit(MessageFrame frame) { final boolean minerIsWarm = frame.isAddressWarm(txStack.current().getCoinbase()); txStack.current().setPreFinalisationValues(leftOverGas, gasRefund, minerIsWarm); + + if (this.state.getProcessingPhase() != TX_SKIP) { + this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); + } } } @@ -875,7 +866,8 @@ public void traceEndTx( isSuccessful, this.state.stamps().hub(), this.state.getProcessingPhase()); if (this.state.processingPhase != TX_SKIP) { - this.processStateFinal(world); + this.state.setProcessingPhase(TX_FINAL); + this.state.stamps().incrementHubStamp(); } this.defers.runPostTx(this, world, tx, isSuccessful); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java deleted file mode 100644 index 0e400e69f3..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_REFUND_QUOTIENT; - -import java.math.BigInteger; -import java.util.Optional; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class TxFinalizationSection extends TraceSection { - public TxFinalizationSection(Hub hub, TraceFragment... fragments) { - this.addFragmentsWithoutStack(hub, fragments); - } - - public static TxFinalizationSection finalizeSuccessfulTransaction( - final Hub hub, final WorldView worldView, final boolean coinbaseWarmth) { - - final TransactionProcessingMetadata tx = hub.txStack().current(); - - final Address senderAddress = tx.getSender(); - final Address coinbaseAddress = tx.getCoinbase(); - - final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); - - final long senderGasRefund = tx.getGasRefunded(); - final long coinbaseGasReward = tx.getTotalGasUsed(); - - final Wei coinbaseFee = - Wei.of( - BigInteger.valueOf(tx.getEffectiveGasPrice()) - .multiply(BigInteger.valueOf(coinbaseGasReward))); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - final Wei senderWeiRefund = - Wei.of( - BigInteger.valueOf(senderGasRefund) - .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice()))); - - // SENDER account snapshots - final Account senderAccount = worldView.get(senderAddress); - final AccountSnapshot senderAccountSnapshotBeforeRefunds = - AccountSnapshot.fromAccount( - senderAccount, - true, - deploymentInfo.number(senderAddress), - deploymentInfo.isDeploying(senderAddress)); - - final AccountSnapshot senderAccountSnapshotAfterGasRefund = - senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); - - final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); - - // COINBASE account snapshots - Optional optionalCoinbaseAccount = Optional.ofNullable(worldView.get(coinbaseAddress)); - final AccountSnapshot coinbaseSnapshotBeforeFeeCollection = - coinbaseIsSender - ? senderAccountSnapshotAfterGasRefund - // WARNING! - // worldView.get(address) returns null - // if there is no account at that address - // this is why we get a zero address - : optionalCoinbaseAccount.isPresent() - ? AccountSnapshot.fromAccount( - optionalCoinbaseAccount, - coinbaseWarmth, - deploymentInfo.number(coinbaseAddress), - deploymentInfo.isDeploying(coinbaseAddress)) - : AccountSnapshot.fromAddress( - coinbaseAddress, - coinbaseWarmth, - deploymentInfo.number(coinbaseAddress), - deploymentInfo.isDeploying(coinbaseAddress)); - - final AccountSnapshot coinbaseSnapshotAfterFeeCollection = - coinbaseSnapshotBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); - - return new TxFinalizationSection( - hub, - accountFragmentFactory.make( - senderAccountSnapshotBeforeRefunds, - senderAccountSnapshotAfterGasRefund, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - coinbaseSnapshotBeforeFeeCollection, - coinbaseSnapshotAfterFeeCollection, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - TransactionFragment.prepare(hub.txStack().current())); - } - - public static TxFinalizationSection finalizeUnsuccessfulTransaction( - final Hub hub, final WorldView worldView, final boolean coinbaseWarmth) { - - final TransactionProcessingMetadata tx = hub.txStack().current(); - - final Address senderAddress = tx.getSender(); - final Address effectiveToAddress = tx.getEffectiveTo(); - final Address coinbaseAddress = tx.getCoinbase(); - - final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); - - final Account senderAccount = worldView.get(senderAddress); - final AccountSnapshot senderAccountSnapshotBeforeRefunds = - AccountSnapshot.fromAccount( - senderAccount, - true, - deploymentInfo.number(senderAddress), - deploymentInfo.isDeploying(senderAddress)); - - final long gasUsed = tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas(); - final long effectiveRefunds = Math.min(hub.accruedRefunds(), gasUsed / MAX_REFUND_QUOTIENT); - final long senderGasRefund = tx.getLeftoverGas() + effectiveRefunds; - - final long coinbaseGasReward = tx.getBesuTransaction().getGasLimit() - senderGasRefund; - final Wei coinbaseFee = - Wei.of( - BigInteger.valueOf(tx.getEffectiveGasPrice()) - .multiply(BigInteger.valueOf(coinbaseGasReward))); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - // SENDER account snapshots - final Wei senderWeiRefund = - Wei.of( - BigInteger.valueOf(senderGasRefund) - .multiply(BigInteger.valueOf(tx.getEffectiveGasPrice())) - .add(tx.getBesuTransaction().getValue().getAsBigInteger())); - final AccountSnapshot senderAccountSnapshotAfterGasAndBalanceRefund = - senderAccountSnapshotBeforeRefunds.credit(senderWeiRefund); - - // RECIPIENT account snapshots - final boolean recipientIsSender = effectiveToAddress.equals(senderAddress); - final AccountSnapshot effectiveToAccountSnapshotBeforeReimbursingValue = - recipientIsSender - ? senderAccountSnapshotAfterGasAndBalanceRefund - : AccountSnapshot.fromAccount( - worldView.get(effectiveToAddress), - true, - deploymentInfo.number(effectiveToAddress), - deploymentInfo.isDeploying(effectiveToAddress)); - - final AccountSnapshot effectiveToAccountSnapshotAfterReimbursingValue = - effectiveToAccountSnapshotBeforeReimbursingValue.debit( - (Wei) tx.getBesuTransaction().getValue()); - - // COINBASE account snapshots - final boolean coinbaseIsRecipient = coinbaseAddress.equals(effectiveToAddress); - final boolean coinbaseIsSender = coinbaseAddress.equals(senderAddress); - - AccountSnapshot coinbaseBeforeFeeCollection = - coinbaseIsRecipient - ? effectiveToAccountSnapshotAfterReimbursingValue - : coinbaseIsSender - ? senderAccountSnapshotAfterGasAndBalanceRefund - : AccountSnapshot.fromAccount( - worldView.get(coinbaseAddress), - coinbaseWarmth, - deploymentInfo.number(coinbaseAddress), - deploymentInfo.isDeploying(coinbaseAddress)); - - AccountSnapshot coinbaseAfterFeeCollection = - coinbaseBeforeFeeCollection.credit(coinbaseFee, coinbaseWarmth); - - return new TxFinalizationSection( - hub, - accountFragmentFactory.make( - senderAccountSnapshotBeforeRefunds, - senderAccountSnapshotAfterGasAndBalanceRefund, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - effectiveToAccountSnapshotBeforeReimbursingValue, - effectiveToAccountSnapshotAfterReimbursingValue, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - accountFragmentFactory.make( - coinbaseBeforeFeeCollection, - coinbaseAfterFeeCollection, - DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), - TransactionFragment.prepare(hub.txStack().current())); - } - - @Override - public void seal(Hub hub) {} -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationPostTxDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationPostTxDefer.java new file mode 100644 index 0000000000..9c31de98a1 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationPostTxDefer.java @@ -0,0 +1,225 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.txFinalization; + +import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; +import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class TxFinalizationPostTxDefer implements PostTransactionDefer { + private final TransactionProcessingMetadata txMetadata; + private final AccountSnapshot fromAccountBeforeTxFinalization; + private final AccountSnapshot toAccountBeforeTxFinalization; + private final AccountSnapshot minerAccountBeforeTxFinalization; + private @Setter AccountSnapshot fromAccountAfterTxFinalization; + private @Setter AccountSnapshot toAccountAfterTxFinalization; + private @Setter AccountSnapshot minerAccountAfterTxFinalization; + + public TxFinalizationPostTxDefer(Hub hub, WorldView world) { + this.txMetadata = hub.txStack().current(); + + final DeploymentInfo depInfo = hub.transients().conflation().deploymentInfo(); + + // old Sender account snapshot + final Address senderAddress = txMetadata.getSender(); + this.fromAccountBeforeTxFinalization = + AccountSnapshot.fromAccount( + world.get(senderAddress), + true, + depInfo.number(senderAddress), + depInfo.isDeploying(senderAddress)); + + // old Recipient account snapshot + final Address toAddress = txMetadata.getEffectiveTo(); + this.toAccountBeforeTxFinalization = + AccountSnapshot.fromAccount( + world.get(toAddress), true, depInfo.number(toAddress), depInfo.isDeploying(toAddress)); + + // old Miner Account snapshot + final Address minerAddress = txMetadata.getCoinbase(); + this.minerAccountBeforeTxFinalization = + AccountSnapshot.fromAccount( + world.get(minerAddress), + txMetadata.isMinerWarmAtEndTx(), + depInfo.number(minerAddress), + depInfo.isDeploying(minerAddress)); + } + + @Override + public void runPostTx(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { + final DeploymentInfo depInfo = hub.transients().conflation().deploymentInfo(); + + final Address fromAddress = fromAccountBeforeTxFinalization.address(); + this.fromAccountAfterTxFinalization = + AccountSnapshot.fromAccount( + world.get(fromAddress), + true, + depInfo.number(fromAddress), + depInfo.isDeploying(fromAddress)); + + final Address toAddress = toAccountBeforeTxFinalization.address(); + this.toAccountAfterTxFinalization = + AccountSnapshot.fromAccount( + world.get(toAddress), true, depInfo.number(toAddress), depInfo.isDeploying(toAddress)); + + final Address minerAddress = minerAccountBeforeTxFinalization.address(); + this.minerAccountAfterTxFinalization = + AccountSnapshot.fromAccount( + world.get(minerAddress), + txMetadata.isMinerWarmAtEndTx(), + depInfo.number(minerAddress), + depInfo.isDeploying(minerAddress)); + + if (txMetadata.statusCode()) { + successfulFinalization(hub); + } else { + unsuccessfulFinalization(hub); + } + } + + private void successfulFinalization(Hub hub) { + if (!senderIsMiner()) { + hub.addTraceSection( + new TxFinalizationSection( + hub, + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + hub.factories() + .accountFragment() + .make( + this.minerAccountBeforeTxFinalization, + this.minerAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + TransactionFragment.prepare(hub.txStack().current()))); + } else { + // TODO: verify it works + hub.addTraceSection( + new TxFinalizationSection( + hub, + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountBeforeTxFinalization.incrementBalance( + txMetadata.getGasRefundInWei()), + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.minerAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + TransactionFragment.prepare(hub.txStack().current()))); + } + } + + private void unsuccessfulFinalization(Hub hub) { + + if (noAccountCollision()) { + hub.addTraceSection( + new TxFinalizationSection( + hub, + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + hub.factories() + .accountFragment() + .make( + this.toAccountBeforeTxFinalization, + this.toAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + hub.factories() + .accountFragment() + .make( + this.minerAccountBeforeTxFinalization, + this.minerAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), + TransactionFragment.prepare(hub.txStack().current()))); + } else { + // TODO: test this + hub.addTraceSection( + new TxFinalizationSection( + hub, + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountBeforeTxFinalization + .incrementBalance((Wei) txMetadata.getBesuTransaction().getValue()) + .incrementBalance(txMetadata.getGasRefundInWei()), + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + hub.factories() + .accountFragment() + .make( + senderIsTo() + ? this.fromAccountBeforeTxFinalization + : this.toAccountBeforeTxFinalization, + senderIsTo() + ? this.fromAccountBeforeTxFinalization.decrementBalance( + (Wei) txMetadata.getBesuTransaction().getValue()) + : this.toAccountBeforeTxFinalization.decrementBalance( + (Wei) txMetadata.getBesuTransaction().getValue()), + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + hub.factories() + .accountFragment() + .make( + this.minerAccountAfterTxFinalization.decrementBalance( + txMetadata.getMinerReward()), + this.minerAccountAfterTxFinalization.incrementBalance( + txMetadata.getMinerReward()), + DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), + TransactionFragment.prepare(hub.txStack().current()))); + } + } + + private boolean senderIsMiner() { + return this.fromAccountBeforeTxFinalization + .address() + .equals(this.minerAccountBeforeTxFinalization.address()); + } + + private boolean senderIsTo() { + return this.fromAccountBeforeTxFinalization + .address() + .equals(this.toAccountBeforeTxFinalization.address()); + } + + private boolean toIsMiner() { + return this.toAccountBeforeTxFinalization + .address() + .equals(this.minerAccountBeforeTxFinalization.address()); + } + + private boolean noAccountCollision() { + return !senderIsMiner() && !senderIsTo() && !toIsMiner(); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java new file mode 100644 index 0000000000..a482a7edc7 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java @@ -0,0 +1,26 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.txFinalization; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class TxFinalizationSection extends TraceSection { + public TxFinalizationSection(Hub hub, TraceFragment... chunks) { + this.addFragmentsWithoutStack(hub, chunks); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/SkippedPostTransactionDefer.java similarity index 97% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/SkippedPostTransactionDefer.java index 4b916fb2b8..7696638498 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/SkippedPostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/SkippedPostTransactionDefer.java @@ -13,15 +13,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.defer; +package net.consensys.linea.zktracer.module.hub.section.txSkipippedSection; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; -import net.consensys.linea.zktracer.module.hub.section.TxSkippedSection; import net.consensys.linea.zktracer.module.hub.transients.Transients; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/TxSkippedSection.java similarity index 86% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/TxSkippedSection.java index f024ce55b6..96c500c41c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/TxSkippedSection.java @@ -13,10 +13,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section; +package net.consensys.linea.zktracer.module.hub.section.txSkipippedSection; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class TxSkippedSection extends TraceSection { public TxSkippedSection(Hub hub, TraceFragment... chunks) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 7b67567e08..41c2f1f764 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.worldstate.WorldView; @Getter @@ -233,4 +234,22 @@ public long computeRefunded() { public long computeTotalGasUsed() { return besuTransaction.getGasLimit() - getGasRefunded(); } + + public long weiPerGasForMiner() { + return switch (besuTransaction.getType()) { + case FRONTIER, ACCESS_LIST -> effectiveGasPrice; + case EIP1559 -> effectiveGasPrice - baseFee; + default -> throw new IllegalStateException( + "Transaction Type not supported: " + besuTransaction.getType()); + }; + } + + public Wei getMinerReward() { + return Wei.of( + BigInteger.valueOf(totalGasUsed).multiply(BigInteger.valueOf(weiPerGasForMiner()))); + } + + public Wei getGasRefundInWei() { + return Wei.of(BigInteger.valueOf(gasRefunded).multiply(BigInteger.valueOf(effectiveGasPrice))); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java index 3b265d6c0a..7f9e5dc03a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java @@ -24,8 +24,10 @@ import java.util.zip.GZIPInputStream; import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; /** * Replays are captured on a fully (not snapshot) synchronized Besu node running the plugin: @@ -42,6 +44,7 @@ * } */ @Slf4j +@ExtendWith(EvmExtension.class) public class ReplayTests { /** * Loads a .json or .json.gz replay file generated by the {@link diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java index 655b72d14a..9517c40c20 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub; +import static net.consensys.linea.zktracer.testing.ToyExecutionEnvironment.DEFAULT_MINER_ADDRESS; + import java.util.List; import net.consensys.linea.zktracer.testing.EvmExtension; @@ -47,7 +49,12 @@ void test() { .address(Address.fromHexString("0xdead000000000000000000000000000beef")) .build(); - // final ToyAccount minerAccount = ToyAccount.builder().address(minerAddress).build(); + final ToyAccount minerAccount = + ToyAccount.builder() + .address(DEFAULT_MINER_ADDRESS) + .balance(Wei.fromEth(2)) + .nonce(5) + .build(); final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); final Address senderAddress1 = @@ -179,7 +186,7 @@ void test() { ToyWorld.builder() .accounts( List.of( - // minerAccount, + minerAccount, senderAccount1, senderAccount2, senderAccount3, diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java index 6afb13a696..fd648434ab 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java @@ -77,7 +77,7 @@ public class ToyExecutionEnvironment { private static final Wei DEFAULT_BASE_FEE = Wei.of(LINEA_BASE_FEE); private static final GasCalculator gasCalculator = ZkTracer.gasCalculator; - private static final Address DEFAULT_MINER_ADDRESS = + public static final Address DEFAULT_MINER_ADDRESS = Address.fromHexString("0xc019ba5e00000000c019ba5e00000000c019ba5e"); private static final long DEFAULT_BLOCK_NUMBER = 6678980; private static final long DEFAULT_TIME_STAMP = 14071789; From 93b002b4186c31990082ec3c9204f31f40a895c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 6 Jun 2024 12:59:02 +0400 Subject: [PATCH 066/461] fix(toyExecutionEnvironment): coinbase is cold (London) + ras --- .../testing/ToyExecutionEnvironment.java | 2 +- code | 51 ------------------- newFragments | 21 ++++---- 3 files changed, 12 insertions(+), 62 deletions(-) delete mode 100644 code diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java index fd648434ab..8aa4ef1765 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java @@ -243,7 +243,7 @@ private MainnetTransactionProcessor getMainnetTransactionProcessor() { contractCreationProcessor, messageCallProcessor, true, - true, + false, MAX_STACK_SIZE, feeMarket, CoinbaseFeePriceCalculator.eip1559()); diff --git a/code b/code deleted file mode 100644 index ff247b008a..0000000000 --- a/code +++ /dev/null @@ -1,51 +0,0 @@ -PUSH6 0xaabbccddeeff -PUSH1 208 -SHL -PUSH1 0x00 -MSTORE -PUSH1 0x06 -PUSH1 0x00 -RETURN - - -65aabbccddeeff60d01b60005260066000f3 - - -PUSH32 0x65aabbccddeeff60d01b60005260066000f30000000000000000000000000000 -PUSH1 0x00 -MSTORE -PUSH1 0x10 -PUSH1 0x00 -RETURN - -CALLDATA: 0x7f65aabbccddeeff60d01b60005260066000f3000000000000000000000000000060005260106000f3 - -======================== -code to run on EVM.codes -======================== - -CALLDATA: 0x7f65aabbccddeeff60d01b60005260066000f3000000000000000000000000000060005260106000f3 - ------------------------- - -CALLDATASIZE -PUSH1 0x29 -PUSH1 0x00 -PUSH1 0x00 -CALLDATACOPY - - -PUSH1 0x29 -PUSH1 0x00 -PUSH1 0x00 -CREATE - -PUSH1 0x20 -PUSH1 0x00 -PUSH1 0x20 -PUSH1 0x00 -DUP5 -PUSH2 0xffff -STATICCALL - -RETURNDATASIZE diff --git a/newFragments b/newFragments index 3399adfe5a..6aa01ea884 100644 --- a/newFragments +++ b/newFragments @@ -1,10 +1,11 @@ -Il nous faudrait des -- shared/domSubFragment -- stack/logInfoFragment -- stack/hashInfoFragment -- stack/jumpDestinationVettingFragment -- address/rlpAddrFragment -- address/romlexFragment -- address/trimFragment -- misc/childContextDataFragment -- gasFragment (?) +We require the following subfragments: +- [ ] stack/logInfoFragment +- [ ] stack/hashInfoFragment +- [ ] stack/jumpDestinationVettingFragment +- [ ] address/rlpAddrFragment +- [ ] address/romlexFragment +- [ ] address/trimFragment (makeWithTrim) +- [x] address/domSubFragment +- [ ] storage/domSubFragment +- [ ] misc/childContextDataFragment +- [ ] gasFragment (?) From a06bf36470c00976c7469dd1c686d77db1a24934 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 6 Jun 2024 13:40:54 +0400 Subject: [PATCH 067/461] feat: more in txMetadata --- .../linea/zktracer/module/hub/Hub.java | 10 ++- .../zktracer/module/hub/TransactionStack.java | 9 +++ .../zktracer/module/txndata/TxnData.java | 2 +- .../types/TransactionProcessingMetadata.java | 64 +++++++++++-------- 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 93db2f50fd..a9bacd8a81 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -844,7 +844,13 @@ public void traceContextExit(MessageFrame frame) { final long gasRefund = frame.getGasRefund(); final boolean minerIsWarm = frame.isAddressWarm(txStack.current().getCoinbase()); - txStack.current().setPreFinalisationValues(leftOverGas, gasRefund, minerIsWarm); + txStack + .current() + .setPreFinalisationValues( + leftOverGas, + gasRefund, + minerIsWarm, + this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); if (this.state.getProcessingPhase() != TX_SKIP) { this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); @@ -863,7 +869,7 @@ public void traceEndTx( txStack .current() .completeLineaTransaction( - isSuccessful, this.state.stamps().hub(), this.state.getProcessingPhase()); + isSuccessful, this.state.stamps().hub(), this.state.getProcessingPhase(), logs); if (this.state.processingPhase != TX_SKIP) { this.state.setProcessingPhase(TX_FINAL); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index a8f98c6dda..2a33e4216c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -33,6 +33,11 @@ public TransactionProcessingMetadata current() { return this.txs.get(this.txs.size() - 1); } + /* WARN: can't be called if currentAbsNumber == 1*/ + public TransactionProcessingMetadata previous() { + return this.txs.get(this.txs.size() - 2); + } + public TransactionProcessingMetadata getByAbsoluteTransactionNumber(final int id) { return this.txs.get(id - 1); } @@ -70,4 +75,8 @@ public void setCodeFragmentIndex(Hub hub) { tx.setCodeFragmentIndex(cfi); } } + + public int getAccumulativeGasUsedInBlockBeforeTxStart() { + return this.relativeTransactionNumber == 1 ? 0 : this.previous().getAccumulatedGasUsedInBlock(); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java index 1da2524a67..80cee58798 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java @@ -173,7 +173,7 @@ private void traceTx( .get() .getAsBigInteger() .subtract(tx.baseFee().get().getAsBigInteger())) - : gasPrice; + : Bytes.EMPTY; final Bytes nonce = Bytes.ofUnsignedLong(tx.nonce()); final Bytes initialBalance = bigIntegerToBytes(tx.initialSenderBalance()); final Bytes value = bigIntegerToBytes(tx.value()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 41c2f1f764..9daa2e7d37 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -20,6 +20,7 @@ import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import java.math.BigInteger; +import java.util.List; import java.util.Optional; import lombok.Getter; @@ -32,6 +33,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.worldstate.WorldView; @Getter @@ -84,6 +86,8 @@ public class TransactionProcessingMetadata { @Setter int hubStampTransactionEnd; + @Setter int accumulatedGasUsedInBlock = -1; + @Accessors(fluent = true) @Setter boolean isSenderPreWarmed = false; @@ -96,16 +100,18 @@ public class TransactionProcessingMetadata { @Setter boolean isMinerWarmAtEndTx = false; + @Setter List logs; + final StorageInitialValues storage = new StorageInitialValues(); @Setter int codeFragmentIndex = -1; public TransactionProcessingMetadata( - WorldView world, - Transaction transaction, - Block block, - int relativeTransactionNumber, - int absoluteTransactionNumber) { + final WorldView world, + final Transaction transaction, + final Block block, + final int relativeTransactionNumber, + final int absoluteTransactionNumber) { this.absoluteTransactionNumber = absoluteTransactionNumber; this.relativeBlockNumber = block.blockNumber(); this.coinbase = block.minerAddress(); @@ -134,6 +140,32 @@ public TransactionProcessingMetadata( this.effectiveGasPrice = computeEffectiveGasPrice(); } + public void setPreFinalisationValues( + final long leftOverGas, + final long refundCounterMax, + final boolean minerIsWarmAtFinalisation, + final int accumulatedGasUsedInBlockAtStartTx) { + this.isMinerWarmAtEndTx(minerIsWarmAtFinalisation); + this.refundCounterMax = refundCounterMax; + this.setLeftoverGas(leftOverGas); + this.gasUsed = computeGasUsed(); + this.refundEffective = computeRefundEffective(); + this.gasRefunded = computeRefunded(); + this.totalGasUsed = computeTotalGasUsed(); + this.accumulatedGasUsedInBlock = (int) (accumulatedGasUsedInBlockAtStartTx + totalGasUsed); + } + + public void completeLineaTransaction( + final boolean statusCode, + final int hubStampTransactionEnd, + final HubProcessingPhase hubPhase, + List logs) { + this.statusCode = statusCode; + this.hubStampTransactionEnd = + (hubPhase == TX_SKIP) ? hubStampTransactionEnd : hubStampTransactionEnd + 1; + this.logs = logs; + } + private boolean computeCopyCallData() { return requiresEvmExecution && !isDeployment && !besuTransaction.getData().get().isEmpty(); } @@ -164,28 +196,6 @@ public long getInitiallyAvailableGas() { return besuTransaction.getGasLimit() - getUpfrontGasCost(); } - public void setPreFinalisationValues( - final long leftOverGas, - final long refundCounterMax, - final boolean minerIsWarmAtFinalisation) { - this.isMinerWarmAtEndTx(minerIsWarmAtFinalisation); - this.refundCounterMax = refundCounterMax; - this.setLeftoverGas(leftOverGas); - this.gasUsed = computeGasUsed(); - this.refundEffective = computeRefundEffective(); - this.gasRefunded = computeRefunded(); - this.totalGasUsed = computeTotalGasUsed(); - } - - public void completeLineaTransaction( - final boolean statusCode, - final int hubStampTransactionEnd, - final HubProcessingPhase hubPhase) { - this.statusCode = statusCode; - this.hubStampTransactionEnd = - (hubPhase == TX_SKIP) ? hubStampTransactionEnd : hubStampTransactionEnd + 1; - } - private long computeRefundEffective() { final long maxRefundableAmount = this.getGasUsed() / MAX_REFUND_QUOTIENT; return Math.min(maxRefundableAmount, refundCounterMax); From d692390fce3a898cb7e2e40bd1b468a1415f9ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 6 Jun 2024 13:58:36 +0400 Subject: [PATCH 068/461] storage now knows about Dom / Sub stamps --- .../linea/zktracer/module/hub/Hub.java | 106 +++++++++++++----- .../module/hub/fragment/ContextFragment.java | 3 + .../hub/fragment/storage/StorageFragment.java | 2 + .../module/hub/section/StorageSection.java | 4 + 4 files changed, 85 insertions(+), 30 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a9bacd8a81..a5757cada9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -504,7 +504,8 @@ void processPrewarmingPhase(WorldView world) { value, value, seenKeys.computeIfAbsent(address, x -> new HashSet<>()).contains(key), - true)); + true, + DomSubStampsSubFragment.standardDomSubStamps(this, 0))); seenKeys.get(address).add(key); } @@ -677,7 +678,8 @@ public int contextNumberNew(CallFrame frame) { } public MessageFrame messageFrame() { - return this.callStack.current().frame(); + MessageFrame frame = this.callStack.current().frame(); + return frame; } private void handleStack(MessageFrame frame) { @@ -1392,45 +1394,89 @@ void traceOperation(MessageFrame frame) { default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); } } - case STORAGE -> { // TODO: - /* + case STORAGE -> { Address address = this.currentFrame().accountAddress(); EWord key = EWord.of(frame.getStackItem(0)); switch (this.currentFrame().opCode()) { case SSTORE -> { EWord valNext = EWord.of(frame.getStackItem(0)); - this.addTraceSection( + + // doing the SSTORE operation + StorageFragment doingStorageFragment = + new StorageFragment( + address, + this.currentFrame().accountDeploymentNumber(), + key, + this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), + EWord.of(frame.getTransientStorageValue(address, key)), + valNext, + frame.isStorageWarm(address, key), + true, + DomSubStampsSubFragment.standardDomSubStamps(this, 0)); + + StorageSection storageSection = new StorageSection( - this, - ContextFragment.readContextData(this), - new StorageFragment( - address, - this.currentFrame().accountDeploymentNumber(), - key, - this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - EWord.of(frame.getTransientStorageValue(address, key)), - valNext, - frame.isStorageWarm(address, key), - true))); + this, ContextFragment.readContextData(this), doingStorageFragment); + + // undoing the previous changes (value + warmth) if current context will revert + if (this.callStack().current().willRevert()) { + StorageFragment undoingStorageFragment = + new StorageFragment( + address, + this.currentFrame().accountDeploymentNumber(), + key, + this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), + valNext, + EWord.of(frame.getTransientStorageValue(address, key)), + true, + frame.isStorageWarm(address, key), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1)); + storageSection.addFragment(this, undoingStorageFragment); + } + + this.addTraceSection(storageSection); } case SLOAD -> { - EWord valCurrent = EWord.of(frame.getTransientStorageValue(address, key)); - this.addTraceSection( + EWord valueCurrent = EWord.of(frame.getTransientStorageValue(address, key)); + + // doing the SLOAD operation + StorageFragment doingStorageFragment = + new StorageFragment( + address, + this.currentFrame().accountDeploymentNumber(), + key, + this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), + valueCurrent, + valueCurrent, + frame.isStorageWarm(address, key), + true, + DomSubStampsSubFragment.standardDomSubStamps(this, 0)); + + StorageSection storageSection = new StorageSection( - this, - ContextFragment.readContextData(this), - new StorageFragment( - address, - this.currentFrame().accountDeploymentNumber(), - key, - this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - valCurrent, - valCurrent, - frame.isStorageWarm(address, key), - true))); + this, ContextFragment.readContextData(this), doingStorageFragment); + + // undoing the previous changes (warmth) if current context will revert + if (this.callStack().current().willRevert()) { + StorageFragment undoingStorageFragment = + new StorageFragment( + address, + this.currentFrame().accountDeploymentNumber(), + key, + this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), + valueCurrent, + valueCurrent, + true, + frame.isStorageWarm(address, key), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1)); + + storageSection.addFragment(this, undoingStorageFragment); + } + + this.addTraceSection(storageSection); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); - } */ + } } case CREATE -> { Address myAddress = this.currentFrame().accountAddress(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 38ca2e9e41..9dfe88fd63 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -37,6 +37,9 @@ public record ContextFragment( boolean updateCallerReturndata) implements TraceFragment { + // TODO: in the spec readContextData accepts an argument + // which is _some_ context number, not necessarily that + // of the currently executing execution context. public static ContextFragment readContextData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 86cd59a726..60245dd40b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; @@ -35,6 +36,7 @@ public final class StorageFragment implements TraceFragment { private final EWord valNext; private final boolean oldWarmth; private final boolean newWarmth; + private final DomSubStampsSubFragment domSubStampsSubFragment; public Trace trace(Trace trace) { final EWord eAddress = EWord.of(address); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java index 5dab10ddbd..4d2ef0ad6a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java @@ -23,6 +23,10 @@ public StorageSection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } + public void addFragment(Hub hub, TraceFragment fragment) { + this.addFragmentsWithoutStack(hub, fragment); + } + @Override public void seal(Hub hub) {} } From 472d9c62e0b941f1e2a4d16be5974cc7b85aa467 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 6 Jun 2024 16:42:31 +0400 Subject: [PATCH 069/461] fix: go back to wrong value in txndata, lookup from hub is breaking. Will need a fix of txndata in a separate PR --- .../consensys/linea/zktracer/module/hub/TransactionStack.java | 3 ++- .../net/consensys/linea/zktracer/module/txndata/TxnData.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 2a33e4216c..21fb6940ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -25,7 +25,8 @@ import org.hyperledger.besu.evm.worldstate.WorldView; public class TransactionStack implements StackedContainer { - private final List txs = new ArrayList<>(200); + private final List txs = + new ArrayList<>(200); // TODO: write the allocated memory from .toml file private int currentAbsNumber; private int relativeTransactionNumber; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java index 80cee58798..1da2524a67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java @@ -173,7 +173,7 @@ private void traceTx( .get() .getAsBigInteger() .subtract(tx.baseFee().get().getAsBigInteger())) - : Bytes.EMPTY; + : gasPrice; final Bytes nonce = Bytes.ofUnsignedLong(tx.nonce()); final Bytes initialBalance = bigIntegerToBytes(tx.initialSenderBalance()); final Bytes value = bigIntegerToBytes(tx.value()); From 8dd6a081665d4b3395683f99ca6b91ad0fba2b6c Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 6 Jun 2024 17:25:32 +0400 Subject: [PATCH 070/461] fix: ras, overflowing hi part of addresses --- .../module/hub/fragment/ContextFragment.java | 25 ++++++++++--------- .../hub/fragment/TransactionFragment.java | 23 +++++++++-------- .../hub/fragment/account/AccountFragment.java | 8 +++--- .../hub/fragment/storage/StorageFragment.java | 8 +++--- .../linea/zktracer/types/AddressUtils.java | 9 +++++++ 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 9dfe88fd63..391ed4b939 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -15,17 +15,18 @@ package net.consensys.linea.zktracer.module.hub.fragment; -import static net.consensys.linea.zktracer.types.Conversions.bytesToLong; +import static net.consensys.linea.zktracer.types.AddressUtils.highPart; +import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.runtime.callstack.CallStack; -import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.Either; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.internal.Words; public record ContextFragment( @@ -104,15 +105,15 @@ public Trace trace(Trace trace) { this.callFrameReference.map(this.callStack::getById, this.callStack::getByContextNumber); final CallFrame parent = callStack.getParentOf(callFrame.id()); - final EWord eAddress = callFrame.addressAsEWord(); - final EWord eCodeAddress = callFrame.codeAddressAsEWord(); - final EWord callerAddress = EWord.of(callFrame.callerAddress()); + final Address address = callFrame.accountAddress(); + final Address codeAddress = callFrame.byteCodeAddress(); + final Address callerAddress = callFrame.callerAddress(); final int cfi = callFrame == CallFrame.EMPTY || callFrame.type() == CallFrameType.MANTLE ? 0 : hub.getCfiByMetaData( - Words.toAddress(eCodeAddress), + Words.toAddress(codeAddress), callFrame.codeDeploymentNumber(), callFrame.underDeployment()); @@ -122,16 +123,16 @@ public Trace trace(Trace trace) { .pContextCallStackDepth((short) callFrame.depth()) .pContextIsRoot(callFrame.isRoot()) .pContextIsStatic(callFrame.type().isStatic()) - .pContextAccountAddressHi(bytesToLong(eAddress.hi())) - .pContextAccountAddressLo(eAddress.lo()) + .pContextAccountAddressHi(highPart(address)) + .pContextAccountAddressLo(lowPart(address)) .pContextAccountDeploymentNumber(callFrame.accountDeploymentNumber()) - .pContextByteCodeAddressHi(bytesToLong(eCodeAddress.hi())) - .pContextByteCodeAddressLo(eCodeAddress.lo()) + .pContextByteCodeAddressHi(highPart(codeAddress)) + .pContextByteCodeAddressLo(lowPart(codeAddress)) .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) .pContextByteCodeCodeFragmentIndex(cfi) - .pContextCallerAddressHi(bytesToLong(callerAddress.hi())) - .pContextCallerAddressLo(callerAddress.lo()) + .pContextCallerAddressHi(highPart(callerAddress)) + .pContextCallerAddressLo(lowPart(callerAddress)) .pContextCallValue(callFrame.value()) .pContextCallDataContextNumber(parent.contextNumber()) .pContextCallDataOffset(callFrame.callDataInfo().memorySpan().offset()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index e97c555c78..a3e9969953 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -15,17 +15,18 @@ package net.consensys.linea.zktracer.module.hub.fragment; +import static net.consensys.linea.zktracer.types.AddressUtils.highPart; +import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.bytesToLong; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -46,21 +47,21 @@ public static TransactionFragment prepare( @Override public Trace trace(Trace trace) { final Transaction tx = transactionProcessingMetadata.getBesuTransaction(); - final EWord to = EWord.of(transactionProcessingMetadata.getEffectiveTo()); - final EWord from = EWord.of(transactionProcessingMetadata.getSender()); - final EWord miner = EWord.of(transactionProcessingMetadata.getCoinbase()); + final Address to = transactionProcessingMetadata.getEffectiveTo(); + final Address from = transactionProcessingMetadata.getSender(); + final Address miner = transactionProcessingMetadata.getCoinbase(); return trace .peekAtTransaction(true) .pTransactionBatchNum(transactionProcessingMetadata.getRelativeBlockNumber()) - .pTransactionFromAddressHi(bytesToLong(from.hi())) - .pTransactionFromAddressLo(from.lo()) + .pTransactionFromAddressHi(highPart(from)) + .pTransactionFromAddressLo(lowPart(from)) .pTransactionNonce(Bytes.ofUnsignedLong(tx.getNonce())) .pTransactionInitialBalance( bigIntegerToBytes(transactionProcessingMetadata.getInitialBalance())) .pTransactionValue(bigIntegerToBytes(tx.getValue().getAsBigInteger())) - .pTransactionToAddressHi(bytesToLong(to.hi())) - .pTransactionToAddressLo(to.lo()) + .pTransactionToAddressHi(highPart(to)) + .pTransactionToAddressLo(lowPart(to)) .pTransactionRequiresEvmExecution(transactionProcessingMetadata.requiresEvmExecution()) .pTransactionCopyTxcd(transactionProcessingMetadata.copyTransactionCallData()) .pTransactionIsDeployment(tx.getTo().isEmpty()) @@ -79,8 +80,8 @@ public Trace trace(Trace trace) { Bytes.minimalBytes(transactionProcessingMetadata.getRefundCounterMax())) .pTransactionRefundEffective( Bytes.minimalBytes(transactionProcessingMetadata.getGasRefunded())) - .pTransactionCoinbaseAddressHi(bytesToLong(miner.hi())) - .pTransactionCoinbaseAddressLo(miner.lo()); + .pTransactionCoinbaseAddressHi(highPart(miner)) + .pTransactionCoinbaseAddressLo(lowPart(miner)); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index b74d6ac9fd..9581483238 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -15,8 +15,9 @@ package net.consensys.linea.zktracer.module.hub.fragment.account; +import static net.consensys.linea.zktracer.types.AddressUtils.highPart; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; -import static net.consensys.linea.zktracer.types.Conversions.bytesToLong; +import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; import java.util.Optional; @@ -104,7 +105,6 @@ public AccountFragment( @Override public Trace trace(Trace trace) { - final EWord eWho = EWord.of(who); final EWord eCodeHash = EWord.of(oldState.code().getCodeHash()); final EWord eCodeHashNew = EWord.of(newState.code().getCodeHash()); @@ -113,8 +113,8 @@ public Trace trace(Trace trace) { return trace .peekAtAccount(true) - .pAccountAddressHi(bytesToLong(eWho.hi())) - .pAccountAddressLo(eWho.lo()) + .pAccountAddressHi(highPart(who)) + .pAccountAddressLo(lowPart(who)) .pAccountNonce(Bytes.ofUnsignedLong(oldState.nonce())) .pAccountNonceNew(Bytes.ofUnsignedLong(newState.nonce())) .pAccountBalance(oldState.balance()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 60245dd40b..47d10ef725 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -15,6 +15,9 @@ package net.consensys.linea.zktracer.module.hub.fragment.storage; +import static net.consensys.linea.zktracer.types.AddressUtils.highPart; +import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; + import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; @@ -39,11 +42,10 @@ public final class StorageFragment implements TraceFragment { private final DomSubStampsSubFragment domSubStampsSubFragment; public Trace trace(Trace trace) { - final EWord eAddress = EWord.of(address); return trace .peekAtStorage(true) - .pStorageAddressHi(eAddress.hi().toLong()) - .pStorageAddressLo(eAddress.lo()) + .pStorageAddressHi(highPart(address)) + .pStorageAddressLo(lowPart(address)) .pStorageDeploymentNumber(deploymentNumber) .pStorageStorageKeyHi(key.hi()) .pStorageStorageKeyLo(key.lo()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java index 34c7b2e04a..1e8cd72156 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.types; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import static net.consensys.linea.zktracer.types.Utils.leftPadTo; import java.util.List; @@ -109,4 +110,12 @@ public static Address addressFromBytes(final Bytes input) { ? Address.wrap(input) : Address.wrap(leftPadTo(input.trimLeadingZeros(), Address.SIZE)); } + + public static long highPart(Address address) { + return address.slice(0, 4).toLong(); + } + + public static Bytes lowPart(Address address) { + return address.slice(4, LLARGE); + } } From 28839f27679d03e0616c8b4ac2cac28989c781e2 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 6 Jun 2024 18:04:21 +0400 Subject: [PATCH 071/461] fix: no more java issues --- .../zktracer/module/hub/fragment/CommonFragment.java | 11 ++++++++--- .../zktracer/module/hub/fragment/StackFragment.java | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 54f0010afb..a0b506e259 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -80,7 +80,11 @@ public static CommonFragment fromHub( final long gasActual = hub.remainingGas(); final long gasCost = noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).staticGas() : 0; - final long gasNext = hub.pch().exceptions().any() ? 0 : gasActual - gasCost; + final long gasNext = + hub.pch().exceptions().any() + ? 0 + : Math.max( + gasActual - gasCost, 0); // TODO: ugly, to fix just to not trace negative value final int height = hub.currentFrame().stack().getHeight(); final int heightNew = @@ -136,7 +140,8 @@ private static int computePcNew( } if (opCode.isJump()) { - final BigInteger prospectivePcNew = hub.currentFrame().frame().getStackItem(0).toBigInteger(); + final BigInteger prospectivePcNew = + hub.currentFrame().frame().getStackItem(0).toUnsignedBigInteger(); final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); final int attemptedPcNew = @@ -147,7 +152,7 @@ private static int computePcNew( } if (opCode.equals(OpCode.JUMPI)) { - BigInteger condition = hub.currentFrame().frame().getStackItem(1).toBigInteger(); + BigInteger condition = hub.currentFrame().frame().getStackItem(1).toUnsignedBigInteger(); if (!condition.equals(BigInteger.ZERO)) { return attemptedPcNew; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 594c47bf76..af656c9ed9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -104,14 +104,19 @@ private StackFragment( this.staticGas = gp.staticGas(); if (opCode.isJump() && !exceptions.stackException()) { - final BigInteger prospectivePcNew = hub.currentFrame().frame().getStackItem(0).toBigInteger(); + final BigInteger prospectivePcNew = + hub.currentFrame().frame().getStackItem(0).toUnsignedBigInteger(); final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); boolean prospectivePcNewIsInBounds = codeSize.compareTo(prospectivePcNew) > 0; if (opCode.equals(OpCode.JUMPI)) { boolean nonzeroJumpCondition = - !hub.currentFrame().frame().getStackItem(1).toBigInteger().equals(BigInteger.ZERO); + !hub.currentFrame() + .frame() + .getStackItem(1) + .toUnsignedBigInteger() + .equals(BigInteger.ZERO); prospectivePcNewIsInBounds = prospectivePcNewIsInBounds && nonzeroJumpCondition; } From 4ea074ceb8be92438bd530233dd73c0d8551aba6 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 6 Jun 2024 20:24:17 +0400 Subject: [PATCH 072/461] test: add warming and basic sstore consistency tests --- .../module/hub/SimpleStorageConsistency.java | 157 ++++++++++++++++++ .../linea/zktracer/module/hub/TxSkip.java | 1 + 2 files changed, 158 insertions(+) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java new file mode 100644 index 0000000000..c07ec8c34c --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java @@ -0,0 +1,157 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub; + +import java.util.List; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.EvmExtension; +import net.consensys.linea.zktracer.testing.ToyAccount; +import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; +import net.consensys.linea.zktracer.testing.ToyTransaction; +import net.consensys.linea.zktracer.testing.ToyWorld; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.AccessListEntry; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.TransactionType; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class SimpleStorageConsistency { + + private final Address receiverAddress = Address.wrap(Bytes.random(20)); + + final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); + final Address senderAddress1 = + Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount1 = + ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); + + final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); + final Address senderAddress2 = + Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount2 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); + + final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); + final Address senderAddress3 = + Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount3 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); + + private final String keyString = + "0x00010203040060708090A0B0C0DE0F10101112131415161718191A1B1C1D1E1F"; + private final Bytes32 key = Bytes32.fromHexString(keyString); + private final Bytes32 value1 = Bytes32.repeat((byte) 1); + private final Bytes32 value2 = Bytes32.repeat((byte) 2); + + final List simpleKey = List.of(keyString); + final List duplicateKey = List.of(keyString, keyString); + final List simpleKeyAndTrash = + List.of(keyString, "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); + + final List warmOnlyReceiver = + List.of(AccessListEntry.createAccessListEntry(receiverAddress, simpleKey)); + + final List stupidWarmer = + List.of( + AccessListEntry.createAccessListEntry(receiverAddress, duplicateKey), + AccessListEntry.createAccessListEntry(receiverAddress, simpleKeyAndTrash), + AccessListEntry.createAccessListEntry(senderAddress1, simpleKeyAndTrash), + AccessListEntry.createAccessListEntry(senderAddress3, simpleKey), + AccessListEntry.createAccessListEntry(receiverAddress, duplicateKey)); + + @Test + void test() { + final ToyAccount receiverAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .address(receiverAddress) + .code( + BytecodeCompiler.newProgram() + // SLOAD initial value + .push(key) + .op(OpCode.SLOAD) + .op(OpCode.POP) + // SSTORE value 1 + .push(key) + .push(value1) + .op(OpCode.SSTORE) + // SSTORE value 2 + .push(key) + .push(value2) + .op(OpCode.SSTORE) + .compile()) + .nonce(116) + .address(Address.fromHexString("0xdead000000000000000000000000000beef")) + .build(); + + final Transaction simpleWarm = + ToyTransaction.builder() + .sender(senderAccount1) + .to(receiverAccount) + .keyPair(senderKeyPair1) + .gasLimit(1000000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(warmOnlyReceiver) + .value(Wei.of(50000)) + .build(); + + final Transaction stupidWarm = + ToyTransaction.builder() + .sender(senderAccount2) + .to(receiverAccount) + .keyPair(senderKeyPair2) + .gasLimit(1000000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(stupidWarmer) + .value(Wei.of(50000)) + .build(); + + final Transaction noWarm = + ToyTransaction.builder() + .sender(senderAccount3) + .to(receiverAccount) + .keyPair(senderKeyPair3) + .gasLimit(1000000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(List.of()) + .value(Wei.of(50000)) + .build(); + + final List txs = List.of(simpleWarm, stupidWarm, noWarm); + + ToyWorld toyWorld = + ToyWorld.builder() + .accounts(List.of(receiverAccount, senderAccount1, senderAccount2, senderAccount3)) + .build(); + + ToyExecutionEnvironment.builder() + .toyWorld(toyWorld) + .transactions(txs) + .zkTracerValidator(zkTracer -> {}) + .build() + .run(); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java index 9517c40c20..e075eccb72 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java @@ -120,6 +120,7 @@ void test() { List.of( AccessListEntry.createAccessListEntry( Address.fromHexString("0x1234567890"), listOfKeys)); + final Transaction pureTransferWithUselessAccessList = ToyTransaction.builder() .sender(senderAccount3) From e510c76837487d6c8e3e3ede4fd8f27b3f02be2e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 6 Jun 2024 20:59:35 +0400 Subject: [PATCH 073/461] fix: ras --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 4 ++-- .../linea/zktracer/module/hub/SimpleStorageConsistency.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a5757cada9..945c3451c0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -471,7 +471,7 @@ void processPrewarmingPhase(WorldView world) { AccountSnapshot.fromAccount( world.get(address), true, deploymentNumber, false); - DomSubStampsSubFragment domSubStampsSubFragment = + final DomSubStampsSubFragment domSubStampsSubFragment = new DomSubStampsSubFragment( DomSubStampsSubFragment.DomSubType.STANDARD, this.stamp(), 0, 0, 0, 0, 0); fragments.add( @@ -485,7 +485,7 @@ void processPrewarmingPhase(WorldView world) { seenAddresses.add(address); - List keys = entry.storageKeys(); + final List keys = entry.storageKeys(); for (Bytes32 k : keys) { this.state.stamps().incrementHubStamp(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java index c07ec8c34c..6a4e2d47d3 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java @@ -104,7 +104,7 @@ void test() { .op(OpCode.SSTORE) .compile()) .nonce(116) - .address(Address.fromHexString("0xdead000000000000000000000000000beef")) + .address(Address.fromHexString("0xdead0000000000000000000000000000beef")) .build(); final Transaction simpleWarm = From 023b552ab5713fa02de3e5841c2965a9f534ad0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 6 Jun 2024 21:05:21 +0400 Subject: [PATCH 074/461] First and final rows for storage keys (WIP) --- .../linea/zktracer/module/hub/Hub.java | 74 +- .../linea/zktracer/module/hub/State.java | 40 +- .../linea/zktracer/module/hub/Trace.java | 1179 ++++++----------- .../module/hub/fragment/ContextFragment.java | 2 +- .../hub/fragment/storage/StorageFragment.java | 18 +- .../module/hub/section/CreateSection.java | 4 +- .../module/hub/section/StopSection.java | 8 +- .../module/hub/section/StorageSection.java | 4 +- .../hub/section/calls/NoCodeCallSection.java | 2 +- .../calls/SmartContractCallSection.java | 2 +- 10 files changed, 505 insertions(+), 828 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 945c3451c0..9211dff98c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -495,8 +495,14 @@ void processPrewarmingPhase(WorldView world) { .map(account -> EWord.of(account.getStorageValue(key))) .orElse(EWord.ZERO); - fragments.add( - new StorageFragment( + State.EphemeralStorageSlotIdentifier storageSlotIdentifier = + new State.EphemeralStorageSlotIdentifier( + address, + deploymentInfo.number(address), + k); + + StorageFragment storageFragment = new StorageFragment( + this.state, address, deploymentInfo.number(address), EWord.of(key), @@ -505,7 +511,12 @@ void processPrewarmingPhase(WorldView world) { value, seenKeys.computeIfAbsent(address, x -> new HashSet<>()).contains(key), true, - DomSubStampsSubFragment.standardDomSubStamps(this, 0))); + DomSubStampsSubFragment.standardDomSubStamps(this, 0), + this.state.firstAndLastStorageSlotOccurrences.size()); + + fragments.add(storageFragment); + + state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, storageFragment); seenKeys.get(address).add(key); } @@ -1145,6 +1156,7 @@ private void handleCreate(Address target) { @Override public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { + this.state.firstAndLastStorageSlotOccurrences.add(new HashMap<>()); this.transients.block().blockUpdate(processableBlockHeader); this.txStack.resetBlock(); for (Module m : this.modules) { @@ -1268,16 +1280,16 @@ void traceOperation(MessageFrame frame) { new KeccakSection( this, this.currentFrame(), ImcFragment.forOpcode(this, this.messageFrame()))); case CONTEXT -> this.addTraceSection( - new ContextLogSection(this, ContextFragment.readContextData(this))); + new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); case LOG -> { - this.addTraceSection(new ContextLogSection(this, ContextFragment.readContextData(this))); + this.addTraceSection(new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); LogInvocation.forOpcode(this); } case ACCOUNT -> { TraceSection accountSection = new AccountSection(this); if (this.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { accountSection.addFragment( - this, this.currentFrame(), ContextFragment.readContextData(this)); + this, this.currentFrame(), ContextFragment.readCurrentContextData(this)); } final Bytes rawTargetAddress = @@ -1375,7 +1387,7 @@ void traceOperation(MessageFrame frame) { .make(accountAfter, accountBefore, undoingDomSubStamps)); } } else { - copySection.addFragment(this, this.currentFrame(), ContextFragment.readContextData(this)); + copySection.addFragment(this, this.currentFrame(), ContextFragment.readCurrentContextData(this)); } this.addTraceSection(copySection); } @@ -1387,7 +1399,7 @@ void traceOperation(MessageFrame frame) { final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); this.addTraceSection( - new StackRam(this, imcFragment, ContextFragment.readContextData(this))); + new StackRam(this, imcFragment, ContextFragment.readCurrentContextData(this))); } case MLOAD, MSTORE, MSTORE8 -> this.addTraceSection( new StackRam(this, ImcFragment.forOpcode(this, frame))); @@ -1397,13 +1409,23 @@ void traceOperation(MessageFrame frame) { case STORAGE -> { Address address = this.currentFrame().accountAddress(); EWord key = EWord.of(frame.getStackItem(0)); + + State.EphemeralStorageSlotIdentifier storageSlotIdentifier = + new State.EphemeralStorageSlotIdentifier( + address, + currentFrame().accountDeploymentNumber(), + key + ); + switch (this.currentFrame().opCode()) { case SSTORE -> { EWord valNext = EWord.of(frame.getStackItem(0)); + // doing the SSTORE operation StorageFragment doingStorageFragment = new StorageFragment( + this.state, address, this.currentFrame().accountDeploymentNumber(), key, @@ -1412,16 +1434,19 @@ void traceOperation(MessageFrame frame) { valNext, frame.isStorageWarm(address, key), true, - DomSubStampsSubFragment.standardDomSubStamps(this, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this, 0), + this.state.firstAndLastStorageSlotOccurrences.size() + ); StorageSection storageSection = new StorageSection( - this, ContextFragment.readContextData(this), doingStorageFragment); + this, ContextFragment.readCurrentContextData(this), doingStorageFragment); // undoing the previous changes (value + warmth) if current context will revert if (this.callStack().current().willRevert()) { StorageFragment undoingStorageFragment = new StorageFragment( + this.state, address, this.currentFrame().accountDeploymentNumber(), key, @@ -1430,8 +1455,14 @@ void traceOperation(MessageFrame frame) { EWord.of(frame.getTransientStorageValue(address, key)), true, frame.isStorageWarm(address, key), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), + this.state.firstAndLastStorageSlotOccurrences.size() + ); + storageSection.addFragment(this, undoingStorageFragment); + state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, undoingStorageFragment); + } else { + state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingStorageFragment); } this.addTraceSection(storageSection); @@ -1442,6 +1473,7 @@ void traceOperation(MessageFrame frame) { // doing the SLOAD operation StorageFragment doingStorageFragment = new StorageFragment( + this.state, address, this.currentFrame().accountDeploymentNumber(), key, @@ -1450,16 +1482,19 @@ void traceOperation(MessageFrame frame) { valueCurrent, frame.isStorageWarm(address, key), true, - DomSubStampsSubFragment.standardDomSubStamps(this, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this, 0), + this.state.firstAndLastStorageSlotOccurrences.size() + ); StorageSection storageSection = new StorageSection( - this, ContextFragment.readContextData(this), doingStorageFragment); + this, ContextFragment.readCurrentContextData(this), doingStorageFragment); // undoing the previous changes (warmth) if current context will revert if (this.callStack().current().willRevert()) { StorageFragment undoingStorageFragment = new StorageFragment( + this.state, address, this.currentFrame().accountDeploymentNumber(), key, @@ -1468,9 +1503,14 @@ void traceOperation(MessageFrame frame) { valueCurrent, true, frame.isStorageWarm(address, key), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), + this.state.firstAndLastStorageSlotOccurrences.size() + ); storageSection.addFragment(this, undoingStorageFragment); + state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, undoingStorageFragment); + } else { + state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingStorageFragment); } this.addTraceSection(storageSection); @@ -1538,7 +1578,7 @@ void traceOperation(MessageFrame frame) { this, ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount), - ContextFragment.readContextData(this))); + ContextFragment.readCurrentContextData(this))); } else if (this.pch().exceptions().outOfMemoryExpansion()) { this.addTraceSection( new FailedCallSection( @@ -1568,7 +1608,7 @@ void traceOperation(MessageFrame frame) { this, ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount), - ContextFragment.readContextData(this), + ContextFragment.readCurrentContextData(this), this.factories .accountFragment() .make( @@ -1640,7 +1680,7 @@ void traceOperation(MessageFrame frame) { JumpSection jumpSection = new JumpSection( this, - ContextFragment.readContextData(this), + ContextFragment.readCurrentContextData(this), this.factories .accountFragment() .make( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index 53f6cf9279..502c6579ba 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -15,22 +15,24 @@ package net.consensys.linea.zktracer.module.hub; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Iterator; +import java.util.*; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.State.TxState.Stamps; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; public class State implements StackedContainer { private final Deque state = new ArrayDeque<>(); State() {} + public TxState current() { return this.state.peek(); } @@ -41,6 +43,38 @@ public Stamps stamps() { @Getter @Setter HubProcessingPhase processingPhase; + public record EphemeralStorageSlotIdentifier(Address address, int deploymentNumber, Bytes storageKey) {} + + public void updateOrInsertStorageSlotOccurrence(EphemeralStorageSlotIdentifier slotIdentifier, StorageFragment storageFragment) { + int size = firstAndLastStorageSlotOccurrences.size(); + HashMap current = + firstAndLastStorageSlotOccurrences.get(size - 1); + if (current.containsKey(slotIdentifier)) { + current.get(slotIdentifier).update(storageFragment); + } else { + current.put(slotIdentifier, new State.StorageFragmentPair(storageFragment)); + } + } + + @Getter + public static class StorageFragmentPair { + final StorageFragment firstOccurrence; + @Setter StorageFragment finalOccurrence; + + public StorageFragmentPair(StorageFragment firstOccurrence) { + this.firstOccurrence = firstOccurrence; + this.finalOccurrence = firstOccurrence; + } + + public void update(StorageFragment current) { + setFinalOccurrence(current); + } + } + + // initialized here + public ArrayList> firstAndLastStorageSlotOccurrences + = new ArrayList<>(); + /** * @return the current transaction trace elements */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 5615a082c1..9ea2da88d4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -41,32 +41,24 @@ public class Trace { private final MappedByteBuffer absoluteTransactionNumber; private final MappedByteBuffer accFinal; private final MappedByteBuffer accFirst; - private final MappedByteBuffer - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; - private final MappedByteBuffer - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; + private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; private final MappedByteBuffer alpha; - private final MappedByteBuffer - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; - private final MappedByteBuffer - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; + private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; + private final MappedByteBuffer balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer batchNumber; private final MappedByteBuffer callDataOffsetXorMmuSize; private final MappedByteBuffer callDataSizeXorMmuSrcId; private final MappedByteBuffer callStackDepth; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; + private final MappedByteBuffer codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; private final MappedByteBuffer codeHashHiNewXorExpData5XorValueCurrLoXorValue; - private final MappedByteBuffer - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorValueNextLo; private final MappedByteBuffer codeHashLoXorMmuLimb1XorValueNextHi; - private final MappedByteBuffer - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; - private final MappedByteBuffer - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; + private final MappedByteBuffer codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; + private final MappedByteBuffer codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; private final MappedByteBuffer conAgain; private final MappedByteBuffer conFirst; private final MappedByteBuffer contextGetsReverted; @@ -82,51 +74,37 @@ public class Trace { private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; - private final MappedByteBuffer - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; private final MappedByteBuffer delta; - private final MappedByteBuffer - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; - private final MappedByteBuffer - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; - private final MappedByteBuffer - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; - private final MappedByteBuffer - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment; - private final MappedByteBuffer - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2; - private final MappedByteBuffer - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd; + private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; + private final MappedByteBuffer deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; + private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; + private final MappedByteBuffer deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment; + private final MappedByteBuffer deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2; + private final MappedByteBuffer deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; - private final MappedByteBuffer - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode; - private final MappedByteBuffer - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution; + private final MappedByteBuffer existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode; + private final MappedByteBuffer existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; - private final MappedByteBuffer - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero; - private final MappedByteBuffer - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero; + private final MappedByteBuffer hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig; + private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr; private final MappedByteBuffer hashInfoStamp; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; - private final MappedByteBuffer - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth; + private final MappedByteBuffer isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero; private final MappedByteBuffer logInfoStamp; - private final MappedByteBuffer - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2; - private final MappedByteBuffer - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew; + private final MappedByteBuffer markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth; + private final MappedByteBuffer markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -191,7 +169,7 @@ public class Trace { private final MappedByteBuffer returnFromMessageCallWontTouchRamXorStackItemPop3; private final MappedByteBuffer rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize; private final MappedByteBuffer rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi; - private final MappedByteBuffer rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3; + private final MappedByteBuffer rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew; private final MappedByteBuffer rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo; private final MappedByteBuffer rlpaddrKecLoXorMmuTgtOffsetLo; private final MappedByteBuffer rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4; @@ -246,49 +224,24 @@ static List headers(int length) { new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), - new ColumnHeader( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", - 8, - length), - new ColumnHeader( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", 8, length), + new ColumnHeader("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 32, length), new ColumnHeader("hub.ALPHA", 1, length), - new ColumnHeader( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", - 32, - length), - new ColumnHeader( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 32, length), + new ColumnHeader("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 32, length), new ColumnHeader("hub.BATCH_NUMBER", 4, length), new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), - new ColumnHeader( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", - 8, - length), - new ColumnHeader( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), - new ColumnHeader( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", - 32, - length), + new ColumnHeader("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", 8, length), + new ColumnHeader("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), + new ColumnHeader("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), - new ColumnHeader( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", - 8, - length), - new ColumnHeader( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", - 8, - length), + new ColumnHeader("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", 8, length), + new ColumnHeader("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", 8, length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), @@ -302,83 +255,39 @@ static List headers(int length) { new ColumnHeader("hub.COUNTER_NSR", 2, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX", 1, length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", - 1, - length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), new ColumnHeader("hub.DELTA", 1, length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", - 8, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT", - 1, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2", - 1, - length), - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD", - 1, - length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", 8, length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", 8, length), + new ColumnHeader("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", 8, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT", 1, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2", 1, length), + new ColumnHeader("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD", 1, length), new ColumnHeader("hub.DOM_STAMP", 8, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), - new ColumnHeader( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE", - 1, - length), - new ColumnHeader( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION", - 1, - length), + new ColumnHeader("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE", 1, length), + new ColumnHeader("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION", 1, length), new ColumnHeader("hub.GAS_ACTUAL", 8, length), new ColumnHeader("hub.GAS_COST", 32, length), new ColumnHeader("hub.GAS_EXPECTED", 8, length), new ColumnHeader("hub.GAS_LIMIT", 32, length), new ColumnHeader("hub.GAS_NEXT", 8, length), new ColumnHeader("hub.GAS_PRICE", 32, length), - new ColumnHeader( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO", - 1, - length), - new ColumnHeader( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO", - 1, - length), + new ColumnHeader("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG", 1, length), + new ColumnHeader("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR", 1, length), new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), new ColumnHeader("hub.HEIGHT", 2, length), new ColumnHeader("hub.HEIGHT_NEW", 2, length), new ColumnHeader("hub.HUB_STAMP", 8, length), new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), new ColumnHeader("hub.INSTRUCTION", 32, length), - new ColumnHeader( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH", - 1, - length), + new ColumnHeader("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2", - 1, - length), - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW", - 1, - length), + new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH", 1, length), + new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO", 1, length), new ColumnHeader("hub.MMU_STAMP", 8, length), new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), @@ -392,8 +301,7 @@ static List headers(int length) { new ColumnHeader("hub.NB_REMOVED", 1, length), new ColumnHeader("hub.NON_STACK_ROWS", 2, length), new ColumnHeader("hub.NONCE", 32, length), - new ColumnHeader( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), + new ColumnHeader("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), new ColumnHeader("hub.OOB_DATA_1", 32, length), new ColumnHeader("hub.OOB_DATA_2", 32, length), @@ -437,34 +345,20 @@ static List headers(int length) { new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), - new ColumnHeader( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3", - 1, - length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), + new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), + new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), + new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + new ColumnHeader("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), + new ColumnHeader("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), + new ColumnHeader("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW", 1, length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), - new ColumnHeader( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), - new ColumnHeader( - "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", - 1, - length), + new ColumnHeader("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), @@ -495,8 +389,7 @@ static List headers(int length) { new ColumnHeader("hub.SUB_STAMP", 8, length), new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), - new ColumnHeader( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + new ColumnHeader("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -505,10 +398,7 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", - 1, - length), + new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -517,36 +407,24 @@ public Trace(List buffers) { this.absoluteTransactionNumber = buffers.get(0); this.accFinal = buffers.get(1); this.accFirst = buffers.get(2); - this - .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = - buffers.get(3); - this - .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = - buffers.get(4); + this.addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = buffers.get(3); + this.addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(4); this.alpha = buffers.get(5); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = - buffers.get(6); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = - buffers.get(7); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(6); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = buffers.get(7); this.batchNumber = buffers.get(8); this.callDataOffsetXorMmuSize = buffers.get(9); this.callDataSizeXorMmuSrcId = buffers.get(10); this.callStackDepth = buffers.get(11); this.callerContextNumber = buffers.get(12); this.codeFragmentIndex = buffers.get(13); - this - .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = - buffers.get(14); + this.codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = buffers.get(14); this.codeHashHiNewXorExpData5XorValueCurrLoXorValue = buffers.get(15); - this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = - buffers.get(16); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); this.codeHashLoNewXorMmuLimb2XorValueNextLo = buffers.get(17); this.codeHashLoXorMmuLimb1XorValueNextHi = buffers.get(18); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = - buffers.get(19); - this - .codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = - buffers.get(20); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = buffers.get(19); + this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = buffers.get(20); this.conAgain = buffers.get(21); this.conFirst = buffers.get(22); this.contextGetsReverted = buffers.get(23); @@ -565,48 +443,34 @@ public Trace(List buffers) { this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); this.delta = buffers.get(38); - this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = - buffers.get(39); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = buffers.get(39); this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); - this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = - buffers.get(41); - this - .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment = - buffers.get(42); - this - .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 = - buffers.get(43); - this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd = - buffers.get(44); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = buffers.get(41); + this.deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment = buffers.get(42); + this.deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 = buffers.get(43); + this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd = buffers.get(44); this.domStamp = buffers.get(45); this.exceptionAhoy = buffers.get(46); - this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode = - buffers.get(47); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution = - buffers.get(48); + this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode = buffers.get(47); + this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = buffers.get(48); this.gasActual = buffers.get(49); this.gasCost = buffers.get(50); this.gasExpected = buffers.get(51); this.gasLimit = buffers.get(52); this.gasNext = buffers.get(53); this.gasPrice = buffers.get(54); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero = - buffers.get(55); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero = - buffers.get(56); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig = buffers.get(55); + this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr = buffers.get(56); this.hashInfoStamp = buffers.get(57); this.height = buffers.get(58); this.heightNew = buffers.get(59); this.hubStamp = buffers.get(60); this.hubStampTransactionEnd = buffers.get(61); this.instruction = buffers.get(62); - this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth = - buffers.get(63); + this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero = buffers.get(63); this.logInfoStamp = buffers.get(64); - this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 = - buffers.get(65); - this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew = - buffers.get(66); + this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth = buffers.get(65); + this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero = buffers.get(66); this.mmuStamp = buffers.get(67); this.mxpOffset2Hi = buffers.get(68); this.mxpOffset2Lo = buffers.get(69); @@ -671,7 +535,7 @@ public Trace(List buffers) { this.returnFromMessageCallWontTouchRamXorStackItemPop3 = buffers.get(128); this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(129); this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi = buffers.get(130); - this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3 = buffers.get(131); + this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew = buffers.get(131); this.rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo = buffers.get(132); this.rlpaddrKecLoXorMmuTgtOffsetLo = buffers.get(133); this.rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4 = buffers.get(134); @@ -1125,8 +989,7 @@ public Trace pAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -1140,11 +1003,9 @@ public Trace pAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1158,11 +1019,9 @@ public Trace pAccountBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1176,11 +1035,9 @@ public Trace pAccountBalanceNew(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -1192,8 +1049,7 @@ public Trace pAccountCodeFragmentIndex(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -1209,8 +1065,7 @@ public Trace pAccountCodeHashHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1270,8 +1125,7 @@ public Trace pAccountCodeSize(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -1331,8 +1185,7 @@ public Trace pAccountDeploymentStatus(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -1344,8 +1197,7 @@ public Trace pAccountDeploymentStatusInfty(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -1357,8 +1209,7 @@ public Trace pAccountDeploymentStatusNew(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -1370,8 +1221,7 @@ public Trace pAccountExists(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -1383,8 +1233,7 @@ public Trace pAccountExistsNew(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -1396,8 +1245,7 @@ public Trace pAccountHasCode(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -1409,8 +1257,7 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -1422,8 +1269,7 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -1435,8 +1281,7 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -1448,8 +1293,7 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); return this; } @@ -1521,7 +1365,7 @@ public Trace pAccountRlpaddrFlag(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -1673,8 +1517,7 @@ public Trace pContextAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -1688,11 +1531,9 @@ public Trace pContextAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1704,8 +1545,7 @@ public Trace pContextAccountDeploymentNumber(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -1717,8 +1557,7 @@ public Trace pContextByteCodeAddressHi(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -1732,11 +1571,9 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1836,8 +1673,7 @@ public Trace pContextCallValue(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -1863,11 +1699,9 @@ public Trace pContextCallerAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -1891,8 +1725,7 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -1904,8 +1737,7 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -1977,8 +1809,7 @@ public Trace pContextUpdate(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -1990,8 +1821,7 @@ public Trace pMiscCcrsStamp(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -2003,8 +1833,7 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -2018,11 +1847,9 @@ public Trace pMiscExpData1(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -2036,11 +1863,9 @@ public Trace pMiscExpData2(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -2054,11 +1879,9 @@ public Trace pMiscExpData3(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -2074,8 +1897,7 @@ public Trace pMiscExpData4(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -2103,8 +1925,7 @@ public Trace pMiscExpFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -2116,8 +1937,7 @@ public Trace pMiscExpInst(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -2129,8 +1949,7 @@ public Trace pMiscMmuAuxId(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -2154,8 +1973,7 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -2303,8 +2121,7 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -2344,8 +2161,7 @@ public Trace pMiscMxpDeploys(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -2357,8 +2173,7 @@ public Trace pMiscMxpFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -2398,8 +2213,7 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -2411,8 +2225,7 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -2696,8 +2509,7 @@ public Trace pMiscOobFlag(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -2721,8 +2533,7 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); return this; } @@ -2734,7 +2545,7 @@ public Trace pMiscStpFlag(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -2906,36 +2717,31 @@ public Trace pScenarioCallAbort(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { if (filled.get(53)) { - throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { if (filled.get(54)) { - throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -2947,8 +2753,7 @@ public Trace pScenarioCallException(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -2960,91 +2765,79 @@ public Trace pScenarioCallPrcFailure(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { if (filled.get(57)) { - throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { if (filled.get(58)) { - throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { if (filled.get(59)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); } else { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { if (filled.get(60)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); } else { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { if (filled.get(61)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { if (filled.get(62)) { - throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -3063,8 +2856,7 @@ public Trace pScenarioCreateAbort(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { if (filled.get(64)) { - throw new IllegalStateException( - "hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); } else { filled.set(64); } @@ -3076,8 +2868,7 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { if (filled.get(65)) { - throw new IllegalStateException( - "hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); } else { filled.set(65); } @@ -3101,8 +2892,7 @@ public Trace pScenarioCreateException(final Boolean b) { public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { if (filled.get(67)) { - throw new IllegalStateException( - "hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); } else { filled.set(67); } @@ -3114,8 +2904,7 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { if (filled.get(68)) { - throw new IllegalStateException( - "hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); } else { filled.set(68); } @@ -3127,8 +2916,7 @@ public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { if (filled.get(69)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); } else { filled.set(69); } @@ -3140,8 +2928,7 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { if (filled.get(70)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); } else { filled.set(70); } @@ -3153,22 +2940,19 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { if (filled.get(71)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); } else { filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { if (filled.get(72)) { - throw new IllegalStateException( - "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); } else { filled.set(72); } @@ -3197,8 +2981,7 @@ public Trace pScenarioPrcCalleeGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -3210,8 +2993,7 @@ public Trace pScenarioPrcCallerGas(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -3223,8 +3005,7 @@ public Trace pScenarioPrcCdo(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -3435,8 +3216,7 @@ public Trace pScenarioReturnException(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { if (filled.get(87)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { filled.set(87); } @@ -3448,8 +3228,7 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { if (filled.get(88)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { filled.set(88); } @@ -3461,8 +3240,7 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { if (filled.get(89)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { filled.set(89); } @@ -3474,8 +3252,7 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { if (filled.get(90)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { filled.set(90); } @@ -3487,8 +3264,7 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { if (filled.get(91)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { filled.set(91); } @@ -3500,8 +3276,7 @@ public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { if (filled.get(92)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { filled.set(92); } @@ -3537,8 +3312,7 @@ public Trace pScenarioSelfdestructWillRevert(final Boolean b) { public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { if (filled.get(95)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { filled.set(95); } @@ -3550,8 +3324,7 @@ public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { if (filled.get(96)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { filled.set(96); } @@ -3568,8 +3341,7 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -3581,8 +3353,7 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -3606,8 +3377,7 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -3619,8 +3389,7 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -3632,8 +3401,7 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -3645,8 +3413,7 @@ public Trace pStackConFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -3658,8 +3425,7 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -3671,8 +3437,7 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -3684,8 +3449,7 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -3697,8 +3461,7 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); return this; } @@ -3710,7 +3473,7 @@ public Trace pStackDecFlag3(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -3796,11 +3559,9 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -3814,11 +3575,9 @@ public Trace pStackHashInfoKeccakLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -3870,8 +3629,7 @@ public Trace pStackJumpDestinationVettingRequired(final Boolean b) { filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); return this; } @@ -4065,11 +3823,9 @@ public Trace pStackPushValueHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -4085,8 +3841,7 @@ public Trace pStackPushValueLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4486,8 +4241,7 @@ public Trace pStackStaticGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -4571,8 +4325,7 @@ public Trace pStorageAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -4586,11 +4339,9 @@ public Trace pStorageAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4602,8 +4353,7 @@ public Trace pStorageDeploymentNumber(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -4615,8 +4365,7 @@ public Trace pStorageDeploymentNumberInfty(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -4630,11 +4379,9 @@ public Trace pStorageStorageKeyHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4648,24 +4395,45 @@ public Trace pStorageStorageKeyLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } - public Trace pStorageValueCurrChanges(final Boolean b) { + public Trace pStorageUnconstrainedFinal(final Boolean b) { if (filled.get(52)) { - throw new IllegalStateException("hub.storage/VALUE_CURR_CHANGES already set"); + throw new IllegalStateException("hub.storage/UNCONSTRAINED_FINAL already set"); } else { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageUnconstrainedFirst(final Boolean b) { + if (filled.get(53)) { + throw new IllegalStateException("hub.storage/UNCONSTRAINED_FIRST already set"); + } else { + filled.set(53); + } + + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageValueCurrChanges(final Boolean b) { + if (filled.get(54)) { + throw new IllegalStateException("hub.storage/VALUE_CURR_CHANGES already set"); + } else { + filled.set(54); + } + + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -4681,34 +4449,31 @@ public Trace pStorageValueCurrHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } public Trace pStorageValueCurrIsOrig(final Boolean b) { - if (filled.get(53)) { + if (filled.get(55)) { throw new IllegalStateException("hub.storage/VALUE_CURR_IS_ORIG already set"); } else { - filled.set(53); + filled.set(55); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrIsZero(final Boolean b) { - if (filled.get(54)) { + if (filled.get(56)) { throw new IllegalStateException("hub.storage/VALUE_CURR_IS_ZERO already set"); } else { - filled.set(54); + filled.set(56); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -4746,40 +4511,37 @@ public Trace pStorageValueNextHi(final Bytes b) { } public Trace pStorageValueNextIsCurr(final Boolean b) { - if (filled.get(55)) { + if (filled.get(57)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_CURR already set"); } else { - filled.set(55); + filled.set(57); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextIsOrig(final Boolean b) { - if (filled.get(56)) { + if (filled.get(58)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_ORIG already set"); } else { - filled.set(56); + filled.set(58); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextIsZero(final Boolean b) { - if (filled.get(57)) { + if (filled.get(59)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_ZERO already set"); } else { - filled.set(57); + filled.set(59); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -4817,14 +4579,13 @@ public Trace pStorageValueOrigHi(final Bytes b) { } public Trace pStorageValueOrigIsZero(final Boolean b) { - if (filled.get(58)) { + if (filled.get(60)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_IS_ZERO already set"); } else { - filled.set(58); + filled.set(60); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -4846,27 +4607,25 @@ public Trace pStorageValueOrigLo(final Bytes b) { } public Trace pStorageWarmth(final Boolean b) { - if (filled.get(59)) { + if (filled.get(61)) { throw new IllegalStateException("hub.storage/WARMTH already set"); } else { - filled.set(59); + filled.set(61); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageWarmthNew(final Boolean b) { - if (filled.get(60)) { + if (filled.get(62)) { throw new IllegalStateException("hub.storage/WARMTH_NEW already set"); } else { - filled.set(60); + filled.set(62); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew.put( - (byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); return this; } @@ -4894,8 +4653,7 @@ public Trace pTransactionBatchNum(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); return this; } @@ -4907,8 +4665,7 @@ public Trace pTransactionCallDataSize(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); return this; } @@ -4920,8 +4677,7 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); return this; } @@ -4935,11 +4691,9 @@ public Trace pTransactionCoinbaseAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); return this; } @@ -4951,8 +4705,7 @@ public Trace pTransactionCopyTxcd(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -4978,11 +4731,9 @@ public Trace pTransactionFromAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); return this; } @@ -5072,11 +4823,9 @@ public Trace pTransactionInitialBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); return this; } @@ -5088,8 +4837,7 @@ public Trace pTransactionIsDeployment(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -5101,8 +4849,7 @@ public Trace pTransactionIsType2(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -5178,8 +4925,7 @@ public Trace pTransactionRequiresEvmExecution(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -5191,8 +4937,7 @@ public Trace pTransactionStatusCode(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -5220,8 +4965,7 @@ public Trace pTransactionToAddressLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); return this; } @@ -5496,13 +5240,11 @@ public Trace validateRow() { } if (!filled.get(106)) { - throw new IllegalStateException( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); + throw new IllegalStateException("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } if (!filled.get(131)) { - throw new IllegalStateException( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); + throw new IllegalStateException("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } if (!filled.get(101)) { @@ -5510,13 +5252,11 @@ public Trace validateRow() { } if (!filled.get(133)) { - throw new IllegalStateException( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); + throw new IllegalStateException("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } if (!filled.get(132)) { - throw new IllegalStateException( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); + throw new IllegalStateException("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } if (!filled.get(1)) { @@ -5544,38 +5284,31 @@ public Trace validateRow() { } if (!filled.get(107)) { - throw new IllegalStateException( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); + throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } if (!filled.get(135)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } if (!filled.get(134)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } if (!filled.get(137)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } if (!filled.get(136)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); + throw new IllegalStateException("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } if (!filled.get(109)) { - throw new IllegalStateException( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } if (!filled.get(108)) { - throw new IllegalStateException( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); } if (!filled.get(48)) { @@ -5627,28 +5360,23 @@ public Trace validateRow() { } if (!filled.get(68)) { - throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + throw new IllegalStateException("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); } if (!filled.get(69)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); } if (!filled.get(70)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); } if (!filled.get(71)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); } if (!filled.get(72)) { - throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); + throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); } if (!filled.get(102)) { @@ -5656,33 +5384,27 @@ public Trace validateRow() { } if (!filled.get(111)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } if (!filled.get(112)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } if (!filled.get(110)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } if (!filled.get(53)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_VALUE_CURR_IS_ORIG_xor_IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(54)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_IS_ZERO_xor_IS_TYPE2 has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2 has not been filled"); } if (!filled.get(52)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_VALUE_CURR_CHANGES_xor_COPY_TXCD has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD has not been filled"); } if (!filled.get(13)) { @@ -5694,13 +5416,11 @@ public Trace validateRow() { } if (!filled.get(56)) { - throw new IllegalStateException( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_NEXT_IS_ORIG_xor_STATUS_CODE has not been filled"); + throw new IllegalStateException("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE has not been filled"); } if (!filled.get(55)) { - throw new IllegalStateException( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_NEXT_IS_CURR_xor_REQUIRES_EVM_EXECUTION has not been filled"); + throw new IllegalStateException("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(15)) { @@ -5728,13 +5448,11 @@ public Trace validateRow() { } if (!filled.get(58)) { - throw new IllegalStateException( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); + throw new IllegalStateException("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); } if (!filled.get(57)) { - throw new IllegalStateException( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + throw new IllegalStateException("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); } if (!filled.get(19)) { @@ -5762,8 +5480,7 @@ public Trace validateRow() { } if (!filled.get(59)) { - throw new IllegalStateException( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_WARMTH has not been filled"); + throw new IllegalStateException("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(24)) { @@ -5771,13 +5488,11 @@ public Trace validateRow() { } if (!filled.get(61)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2 has not been filled"); + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH has not been filled"); } if (!filled.get(60)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_WARMTH_NEW has not been filled"); + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(25)) { @@ -5833,8 +5548,7 @@ public Trace validateRow() { } if (!filled.get(123)) { - throw new IllegalStateException( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + throw new IllegalStateException("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } if (!filled.get(122)) { @@ -5914,8 +5628,7 @@ public Trace validateRow() { } if (!filled.get(76)) { - throw new IllegalStateException( - "hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); } if (!filled.get(77)) { @@ -5923,13 +5636,11 @@ public Trace validateRow() { } if (!filled.get(78)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); } if (!filled.get(79)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); } if (!filled.get(80)) { @@ -5949,13 +5660,11 @@ public Trace validateRow() { } if (!filled.get(84)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(85)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); + throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); } if (!filled.get(128)) { @@ -5995,13 +5704,11 @@ public Trace validateRow() { } if (!filled.get(119)) { - throw new IllegalStateException( - "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + throw new IllegalStateException("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } if (!filled.get(120)) { - throw new IllegalStateException( - "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + throw new IllegalStateException("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } if (!filled.get(121)) { @@ -6013,63 +5720,51 @@ public Trace validateRow() { } if (!filled.get(87)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); } if (!filled.get(88)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(89)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(90)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(91)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(92)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } if (!filled.get(113)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } if (!filled.get(138)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } if (!filled.get(62)) { - throw new IllegalStateException( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3 has not been filled"); + throw new IllegalStateException("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW has not been filled"); } if (!filled.get(139)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); + throw new IllegalStateException("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } if (!filled.get(140)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); + throw new IllegalStateException("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } if (!filled.get(63)) { - throw new IllegalStateException( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + throw new IllegalStateException("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } if (!filled.get(141)) { @@ -6077,33 +5772,27 @@ public Trace validateRow() { } if (!filled.get(142)) { - throw new IllegalStateException( - "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); + throw new IllegalStateException("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } if (!filled.get(64)) { - throw new IllegalStateException( - "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + throw new IllegalStateException("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } if (!filled.get(93)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); } if (!filled.get(94)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); } if (!filled.get(95)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); } if (!filled.get(96)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } if (!filled.get(164)) { @@ -6187,8 +5876,7 @@ public Trace validateRow() { } if (!filled.get(124)) { - throw new IllegalStateException( - "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); + throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } if (!filled.get(161)) { @@ -6212,13 +5900,11 @@ public Trace validateRow() { } if (!filled.get(65)) { - throw new IllegalStateException( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + throw new IllegalStateException("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } if (!filled.get(143)) { - throw new IllegalStateException( - "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); + throw new IllegalStateException("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } if (!filled.get(40)) { @@ -6250,13 +5936,11 @@ public Trace validateRow() { } if (!filled.get(67)) { - throw new IllegalStateException( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + throw new IllegalStateException("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); } if (!filled.get(66)) { - throw new IllegalStateException( - "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + throw new IllegalStateException("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } if (!filled.get(100)) { @@ -6283,19 +5967,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(106)) { - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .position( - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .position() - + 8); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position(addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position() + 8); } if (!filled.get(131)) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position( - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position() - + 32); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position(addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position() + 32); } if (!filled.get(101)) { @@ -6303,19 +5979,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(133)) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position( - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position() - + 32); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position(balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position() + 32); } if (!filled.get(132)) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position( - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position() - + 32); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position(balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position() + 32); } if (!filled.get(1)) { @@ -6343,46 +6011,31 @@ public Trace fillAndValidateRow() { } if (!filled.get(107)) { - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .position( - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .position() - + 8); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position(codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position() + 8); } if (!filled.get(135)) { - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position(codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); } if (!filled.get(134)) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() - + 32); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position(codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 32); } if (!filled.get(137)) { - codeHashLoNewXorMmuLimb2XorValueNextLo.position( - codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); + codeHashLoNewXorMmuLimb2XorValueNextLo.position(codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); } if (!filled.get(136)) { - codeHashLoXorMmuLimb1XorValueNextHi.position( - codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); + codeHashLoXorMmuLimb1XorValueNextHi.position(codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); } if (!filled.get(109)) { - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() - + 8); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position(codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + 8); } if (!filled.get(108)) { - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .position( - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .position() - + 8); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position(codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position() + 8); } if (!filled.get(48)) { @@ -6434,28 +6087,23 @@ public Trace fillAndValidateRow() { } if (!filled.get(68)) { - createFailureConditionWontRevertXorIcpx.position( - createFailureConditionWontRevertXorIcpx.position() + 1); + createFailureConditionWontRevertXorIcpx.position(createFailureConditionWontRevertXorIcpx.position() + 1); } if (!filled.get(69)) { - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position( - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position(createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); } if (!filled.get(70)) { - createNonemptyInitCodeFailureWontRevertXorJumpx.position( - createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); + createNonemptyInitCodeFailureWontRevertXorJumpx.position(createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); } if (!filled.get(71)) { - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position( - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position(createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); } if (!filled.get(72)) { - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position( - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position(createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); } if (!filled.get(102)) { @@ -6463,45 +6111,27 @@ public Trace fillAndValidateRow() { } if (!filled.get(111)) { - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi - .position() - + 8); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position(deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position() + 8); } if (!filled.get(112)) { - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position(deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); } if (!filled.get(110)) { - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() - + 8); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position(deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + 8); } if (!filled.get(53)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .position( - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorValueCurrIsOrigXorIsDeployment - .position() - + 1); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.position(deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.position() + 1); } if (!filled.get(54)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .position( - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrIsZeroXorIsType2 - .position() - + 1); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.position(deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.position() + 1); } if (!filled.get(52)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd - .position( - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorValueCurrChangesXorCopyTxcd - .position() - + 1); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.position(deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.position() + 1); } if (!filled.get(13)) { @@ -6513,18 +6143,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(56)) { - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode.position( - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueNextIsOrigXorStatusCode - .position() - + 1); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.position(existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.position() + 1); } if (!filled.get(55)) { - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution - .position( - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueNextIsCurrXorRequiresEvmExecution - .position() - + 1); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.position(existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.position() + 1); } if (!filled.get(15)) { @@ -6552,16 +6175,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(58)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero.position( - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueOrigIsZero - .position() - + 1); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.position(hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.position() + 1); } if (!filled.get(57)) { - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position( - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsZero.position() - + 1); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position(hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position() + 1); } if (!filled.get(19)) { @@ -6589,9 +6207,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(59)) { - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position( - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorWarmth.position() - + 1); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.position(isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.position() + 1); } if (!filled.get(24)) { @@ -6599,18 +6215,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(61)) { - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2.position( - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2 - .position() - + 1); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.position(markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.position() + 1); } if (!filled.get(60)) { - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew - .position( - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorWarmthNew - .position() - + 1); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.position(markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.position() + 1); } if (!filled.get(25)) { @@ -6666,8 +6275,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(123)) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position(nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); } if (!filled.get(122)) { @@ -6779,8 +6387,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(84)) { - prcSuccessCallerWillRevertXorPushpopFlag.position( - prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); + prcSuccessCallerWillRevertXorPushpopFlag.position(prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); } if (!filled.get(85)) { @@ -6824,8 +6431,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(119)) { - returnDataContextNumberXorStpGasStipend.position( - returnDataContextNumberXorStpGasStipend.position() + 8); + returnDataContextNumberXorStpGasStipend.position(returnDataContextNumberXorStpGasStipend.position() + 8); } if (!filled.get(120)) { @@ -6841,53 +6447,43 @@ public Trace fillAndValidateRow() { } if (!filled.get(87)) { - returnFromDeploymentEmptyCodeWillRevertXorSox.position( - returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + returnFromDeploymentEmptyCodeWillRevertXorSox.position(returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); } if (!filled.get(88)) { - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position( - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position(returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); } if (!filled.get(89)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position( - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position(returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); } if (!filled.get(90)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position( - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position(returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); } if (!filled.get(91)) { - returnFromMessageCallWillTouchRamXorStackItemPop2.position( - returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop2.position(returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); } if (!filled.get(92)) { - returnFromMessageCallWontTouchRamXorStackItemPop3.position( - returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); + returnFromMessageCallWontTouchRamXorStackItemPop3.position(returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } if (!filled.get(113)) { - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position(rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); } if (!filled.get(138)) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position(rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); } if (!filled.get(62)) { - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position( - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3.position() + 1); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position(rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position() + 1); } if (!filled.get(139)) { - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position(rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); } if (!filled.get(140)) { @@ -6895,8 +6491,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(63)) { - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position(rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } if (!filled.get(141)) { @@ -6908,13 +6503,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(64)) { - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position(romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } if (!filled.get(93)) { - selfdestructExceptionXorStackItemPop4.position( - selfdestructExceptionXorStackItemPop4.position() + 1); + selfdestructExceptionXorStackItemPop4.position(selfdestructExceptionXorStackItemPop4.position() + 1); } if (!filled.get(94)) { @@ -6922,13 +6515,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(95)) { - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position( - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position(selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); } if (!filled.get(96)) { - selfdestructWontRevertNotYetMarkedXorStoFlag.position( - selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); + selfdestructWontRevertNotYetMarkedXorStoFlag.position(selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } if (!filled.get(164)) { @@ -7012,8 +6603,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(124)) { - stpGasUpfrontGasCostXorGasLeftover.position( - stpGasUpfrontGasCostXorGasLeftover.position() + 32); + stpGasUpfrontGasCostXorGasLeftover.position(stpGasUpfrontGasCostXorGasLeftover.position() + 32); } if (!filled.get(161)) { @@ -7037,8 +6627,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(65)) { - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position(trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } if (!filled.get(143)) { @@ -7074,13 +6663,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(67)) { - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position(warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); } if (!filled.get(66)) { - warmthXorCreateExceptionXorHaltFlag.position( - warmthXorCreateExceptionXorHaltFlag.position() + 1); + warmthXorCreateExceptionXorHaltFlag.position(warmthXorCreateExceptionXorHaltFlag.position() + 1); } if (!filled.get(100)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 391ed4b939..69501a45ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -41,7 +41,7 @@ public record ContextFragment( // TODO: in the spec readContextData accepts an argument // which is _some_ context number, not necessarily that // of the currently executing execution context. - public static ContextFragment readContextData(final Hub hub) { + public static ContextFragment readCurrentContextData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 47d10ef725..e7426c80ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -18,18 +18,23 @@ import static net.consensys.linea.zktracer.types.AddressUtils.highPart; import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; +import com.google.common.base.Preconditions; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; +import java.util.HashMap; + @RequiredArgsConstructor @Getter public final class StorageFragment implements TraceFragment { + private final State hubState; @Setter private StorageFragmentType type; private final Address address; private final int deploymentNumber; @@ -40,8 +45,17 @@ public final class StorageFragment implements TraceFragment { private final boolean oldWarmth; private final boolean newWarmth; private final DomSubStampsSubFragment domSubStampsSubFragment; + private final int blockNumber; public Trace trace(Trace trace) { + + HashMap current = hubState.firstAndLastStorageSlotOccurrences.get(blockNumber); + State.EphemeralStorageSlotIdentifier storageSlotIdentifier = new State.EphemeralStorageSlotIdentifier(address, deploymentNumber, key); + Preconditions.checkArgument(current.containsKey(storageSlotIdentifier)); + + final boolean isFirstOccurrence = current.get(storageSlotIdentifier).getFirstOccurrence() == this; + final boolean isFinalOccurrence = current.get(storageSlotIdentifier).getFinalOccurrence() == this; + return trace .peekAtStorage(true) .pStorageAddressHi(highPart(address)) @@ -62,6 +76,8 @@ public Trace trace(Trace trace) { .pStorageValueCurrIsZero(valCurr.isZero()) .pStorageValueNextIsCurr(valNext == valOrig) .pStorageValueNextIsZero(valNext.isZero()) - .pStorageValueNextIsOrig(valNext == valOrig); + .pStorageValueNextIsOrig(valNext == valOrig) + .pStorageUnconstrainedFirst(isFirstOccurrence) + .pStorageUnconstrainedFinal(isFinalOccurrence); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 64194185ac..8d91ce72e3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -184,7 +184,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces this.addFragmentsWithoutStack( hub, ImcFragment.empty(hub), - ContextFragment.readContextData(hub), + ContextFragment.readCurrentContextData(hub), ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.exceptions.outOfMemoryExpansion()) { this.addFragmentsWithoutStack( @@ -198,7 +198,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces this.addFragmentsWithoutStack( hub, commonImcFragment, - ContextFragment.readContextData(hub), + ContextFragment.readCurrentContextData(hub), accountFragmentFactory.make( oldCreatorSnapshot, newCreatorSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index ff50cd1d71..f48fa8a787 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section; import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.executionProvidesEmptyReturnData; -import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readContextData; +import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readCurrentContextData; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; @@ -30,7 +30,7 @@ public StopSection(Hub hub, TraceFragment... fragments) { } public static StopSection messageCallStopSection(Hub hub) { - return new StopSection(hub, readContextData(hub), executionProvidesEmptyReturnData(hub)); + return new StopSection(hub, readCurrentContextData(hub), executionProvidesEmptyReturnData(hub)); } public static StopSection revertedDeploymentStopSection(Hub hub) { @@ -38,7 +38,7 @@ public static StopSection revertedDeploymentStopSection(Hub hub) { hub.factories().accountFragment(); return new StopSection( hub, - readContextData(hub), + readCurrentContextData(hub), // current (under deployment => deployed with empty byte code) // undoing of the above executionProvidesEmptyReturnData(hub)); @@ -47,7 +47,7 @@ public static StopSection revertedDeploymentStopSection(Hub hub) { public static StopSection unrevertedDeploymentStopSection(Hub hub) { return new StopSection( hub, - readContextData(hub), + readCurrentContextData(hub), // current (under deployment => deployed with empty byte code) executionProvidesEmptyReturnData(hub)); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java index 4d2ef0ad6a..b6c9d48781 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java @@ -19,11 +19,11 @@ import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; public class StorageSection extends TraceSection { - public StorageSection(Hub hub, TraceFragment... chunks) { + public StorageSection(Hub hub, final TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - public void addFragment(Hub hub, TraceFragment fragment) { + public void addFragment(Hub hub, final TraceFragment fragment) { this.addFragmentsWithoutStack(hub, fragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index 8335f21237..bbb628bf9c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -122,7 +122,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces callerCallFrame, this.scenarioFragment, this.imcFragment, - ContextFragment.readContextData(hub), + ContextFragment.readCurrentContextData(hub), accountFragmentFactory.make( this.preCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index 1a99025e5f..c2a74ad374 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -134,7 +134,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, callerCallFrame, this.scenarioFragment, - ContextFragment.readContextData(hub), + ContextFragment.readCurrentContextData(hub), this.imcFragment, accountFragmentFactory.make( this.preCallCallerAccountSnapshot, From f779f662f654752bb3fa0f1526b0ec924fe69171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 7 Jun 2024 00:25:25 +0400 Subject: [PATCH 075/461] storage: implementation of UNCONSTRAINED_FIRST / FINAL not working atm --- .../linea/zktracer/module/hub/Hub.java | 86 +- .../linea/zktracer/module/hub/State.java | 25 +- .../linea/zktracer/module/hub/Trace.java | 1137 ++++++++++++----- .../hub/fragment/storage/StorageFragment.java | 33 +- .../module/hub/SimpleStorageConsistency.java | 4 +- 5 files changed, 868 insertions(+), 417 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 9211dff98c..33cc72f829 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -495,17 +495,15 @@ void processPrewarmingPhase(WorldView world) { .map(account -> EWord.of(account.getStorageValue(key))) .orElse(EWord.ZERO); - State.EphemeralStorageSlotIdentifier storageSlotIdentifier = - new State.EphemeralStorageSlotIdentifier( - address, - deploymentInfo.number(address), - k); + State.StorageSlotIdentifier storageSlotIdentifier = + new State.StorageSlotIdentifier( + address, deploymentInfo.number(address), EWord.of(k)); - StorageFragment storageFragment = new StorageFragment( + StorageFragment storageFragment = + new StorageFragment( this.state, - address, - deploymentInfo.number(address), - EWord.of(key), + new State.StorageSlotIdentifier( + address, deploymentInfo.number(address), EWord.of(key)), value, value, value, @@ -516,7 +514,8 @@ void processPrewarmingPhase(WorldView world) { fragments.add(storageFragment); - state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, storageFragment); + state.updateOrInsertStorageSlotOccurrence( + storageSlotIdentifier, storageFragment); seenKeys.get(address).add(key); } @@ -1282,7 +1281,8 @@ void traceOperation(MessageFrame frame) { case CONTEXT -> this.addTraceSection( new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); case LOG -> { - this.addTraceSection(new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); + this.addTraceSection( + new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); LogInvocation.forOpcode(this); } case ACCOUNT -> { @@ -1387,7 +1387,8 @@ void traceOperation(MessageFrame frame) { .make(accountAfter, accountBefore, undoingDomSubStamps)); } } else { - copySection.addFragment(this, this.currentFrame(), ContextFragment.readCurrentContextData(this)); + copySection.addFragment( + this, this.currentFrame(), ContextFragment.readCurrentContextData(this)); } this.addTraceSection(copySection); } @@ -1410,33 +1411,26 @@ void traceOperation(MessageFrame frame) { Address address = this.currentFrame().accountAddress(); EWord key = EWord.of(frame.getStackItem(0)); - State.EphemeralStorageSlotIdentifier storageSlotIdentifier = - new State.EphemeralStorageSlotIdentifier( - address, - currentFrame().accountDeploymentNumber(), - key - ); + State.StorageSlotIdentifier storageSlotIdentifier = + new State.StorageSlotIdentifier(address, currentFrame().accountDeploymentNumber(), key); switch (this.currentFrame().opCode()) { case SSTORE -> { EWord valNext = EWord.of(frame.getStackItem(0)); - // doing the SSTORE operation StorageFragment doingStorageFragment = new StorageFragment( - this.state, - address, - this.currentFrame().accountDeploymentNumber(), - key, + this.state, + new State.StorageSlotIdentifier( + address, this.currentFrame().accountDeploymentNumber(), key), this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), EWord.of(frame.getTransientStorageValue(address, key)), valNext, frame.isStorageWarm(address, key), true, DomSubStampsSubFragment.standardDomSubStamps(this, 0), - this.state.firstAndLastStorageSlotOccurrences.size() - ); + this.state.firstAndLastStorageSlotOccurrences.size()); StorageSection storageSection = new StorageSection( @@ -1446,23 +1440,23 @@ void traceOperation(MessageFrame frame) { if (this.callStack().current().willRevert()) { StorageFragment undoingStorageFragment = new StorageFragment( - this.state, - address, - this.currentFrame().accountDeploymentNumber(), - key, + this.state, + new State.StorageSlotIdentifier( + address, this.currentFrame().accountDeploymentNumber(), key), this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), valNext, EWord.of(frame.getTransientStorageValue(address, key)), true, frame.isStorageWarm(address, key), DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), - this.state.firstAndLastStorageSlotOccurrences.size() - ); + this.state.firstAndLastStorageSlotOccurrences.size()); storageSection.addFragment(this, undoingStorageFragment); - state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, undoingStorageFragment); + state.updateOrInsertStorageSlotOccurrence( + storageSlotIdentifier, undoingStorageFragment); } else { - state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingStorageFragment); + state.updateOrInsertStorageSlotOccurrence( + storageSlotIdentifier, doingStorageFragment); } this.addTraceSection(storageSection); @@ -1473,18 +1467,16 @@ void traceOperation(MessageFrame frame) { // doing the SLOAD operation StorageFragment doingStorageFragment = new StorageFragment( - this.state, - address, - this.currentFrame().accountDeploymentNumber(), - key, + this.state, + new State.StorageSlotIdentifier( + address, this.currentFrame().accountDeploymentNumber(), key), this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), valueCurrent, valueCurrent, frame.isStorageWarm(address, key), true, DomSubStampsSubFragment.standardDomSubStamps(this, 0), - this.state.firstAndLastStorageSlotOccurrences.size() - ); + this.state.firstAndLastStorageSlotOccurrences.size()); StorageSection storageSection = new StorageSection( @@ -1494,23 +1486,23 @@ void traceOperation(MessageFrame frame) { if (this.callStack().current().willRevert()) { StorageFragment undoingStorageFragment = new StorageFragment( - this.state, - address, - this.currentFrame().accountDeploymentNumber(), - key, + this.state, + new State.StorageSlotIdentifier( + address, this.currentFrame().accountDeploymentNumber(), key), this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), valueCurrent, valueCurrent, true, frame.isStorageWarm(address, key), DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), - this.state.firstAndLastStorageSlotOccurrences.size() - ); + this.state.firstAndLastStorageSlotOccurrences.size()); storageSection.addFragment(this, undoingStorageFragment); - state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, undoingStorageFragment); + state.updateOrInsertStorageSlotOccurrence( + storageSlotIdentifier, undoingStorageFragment); } else { - state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingStorageFragment); + state.updateOrInsertStorageSlotOccurrence( + storageSlotIdentifier, doingStorageFragment); } this.addTraceSection(storageSection); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index 502c6579ba..379c02e11b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -17,14 +17,16 @@ import java.util.*; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.State.TxState.Stamps; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; -import org.apache.tuweni.bytes.Bytes; +import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; public class State implements StackedContainer { @@ -32,7 +34,6 @@ public class State implements StackedContainer { State() {} - public TxState current() { return this.state.peek(); } @@ -43,12 +44,20 @@ public Stamps stamps() { @Getter @Setter HubProcessingPhase processingPhase; - public record EphemeralStorageSlotIdentifier(Address address, int deploymentNumber, Bytes storageKey) {} + @RequiredArgsConstructor + @EqualsAndHashCode + @Getter + public static class StorageSlotIdentifier { + final Address address; + final int deploymentNumber; + final EWord storageKey; + } - public void updateOrInsertStorageSlotOccurrence(EphemeralStorageSlotIdentifier slotIdentifier, StorageFragment storageFragment) { + public void updateOrInsertStorageSlotOccurrence( + StorageSlotIdentifier slotIdentifier, StorageFragment storageFragment) { int size = firstAndLastStorageSlotOccurrences.size(); - HashMap current = - firstAndLastStorageSlotOccurrences.get(size - 1); + HashMap current = + firstAndLastStorageSlotOccurrences.get(size - 1); if (current.containsKey(slotIdentifier)) { current.get(slotIdentifier).update(storageFragment); } else { @@ -72,8 +81,8 @@ public void update(StorageFragment current) { } // initialized here - public ArrayList> firstAndLastStorageSlotOccurrences - = new ArrayList<>(); + public ArrayList> + firstAndLastStorageSlotOccurrences = new ArrayList<>(); /** * @return the current transaction trace elements diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 9ea2da88d4..208b27c5bb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -41,24 +41,32 @@ public class Trace { private final MappedByteBuffer absoluteTransactionNumber; private final MappedByteBuffer accFinal; private final MappedByteBuffer accFirst; - private final MappedByteBuffer addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; - private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum; + private final MappedByteBuffer + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; private final MappedByteBuffer alpha; - private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; - private final MappedByteBuffer balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; + private final MappedByteBuffer + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; + private final MappedByteBuffer + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer batchNumber; private final MappedByteBuffer callDataOffsetXorMmuSize; private final MappedByteBuffer callDataSizeXorMmuSrcId; private final MappedByteBuffer callStackDepth; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; + private final MappedByteBuffer + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize; private final MappedByteBuffer codeHashHiNewXorExpData5XorValueCurrLoXorValue; - private final MappedByteBuffer codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorValueNextLo; private final MappedByteBuffer codeHashLoXorMmuLimb1XorValueNextHi; - private final MappedByteBuffer codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; - private final MappedByteBuffer codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; + private final MappedByteBuffer + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi; + private final MappedByteBuffer + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi; private final MappedByteBuffer conAgain; private final MappedByteBuffer conFirst; private final MappedByteBuffer contextGetsReverted; @@ -74,37 +82,51 @@ public class Trace { private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; - private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; private final MappedByteBuffer delta; - private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; - private final MappedByteBuffer deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; - private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; - private final MappedByteBuffer deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment; - private final MappedByteBuffer deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2; - private final MappedByteBuffer deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd; + private final MappedByteBuffer + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; + private final MappedByteBuffer + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; + private final MappedByteBuffer + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; + private final MappedByteBuffer + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment; + private final MappedByteBuffer + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2; + private final MappedByteBuffer + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; - private final MappedByteBuffer existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode; - private final MappedByteBuffer existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution; + private final MappedByteBuffer + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode; + private final MappedByteBuffer + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; - private final MappedByteBuffer hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig; - private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr; + private final MappedByteBuffer + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig; + private final MappedByteBuffer + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr; private final MappedByteBuffer hashInfoStamp; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; - private final MappedByteBuffer isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero; + private final MappedByteBuffer + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero; private final MappedByteBuffer logInfoStamp; - private final MappedByteBuffer markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth; - private final MappedByteBuffer markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero; + private final MappedByteBuffer + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth; + private final MappedByteBuffer + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -169,7 +191,8 @@ public class Trace { private final MappedByteBuffer returnFromMessageCallWontTouchRamXorStackItemPop3; private final MappedByteBuffer rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize; private final MappedByteBuffer rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi; - private final MappedByteBuffer rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew; + private final MappedByteBuffer + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew; private final MappedByteBuffer rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo; private final MappedByteBuffer rlpaddrKecLoXorMmuTgtOffsetLo; private final MappedByteBuffer rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4; @@ -224,24 +247,49 @@ static List headers(int length) { new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), - new ColumnHeader("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", 8, length), - new ColumnHeader("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", + 8, + length), + new ColumnHeader( + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.ALPHA", 1, length), - new ColumnHeader("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 32, length), - new ColumnHeader("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", + 32, + length), + new ColumnHeader( + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.BATCH_NUMBER", 4, length), new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), - new ColumnHeader("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", 8, length), - new ColumnHeader("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), - new ColumnHeader("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 32, length), + new ColumnHeader( + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", + 8, + length), + new ColumnHeader( + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), + new ColumnHeader( + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", + 32, + length), new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), - new ColumnHeader("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", 8, length), - new ColumnHeader("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", 8, length), + new ColumnHeader( + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", + 8, + length), + new ColumnHeader( + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", + 8, + length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), @@ -255,39 +303,83 @@ static List headers(int length) { new ColumnHeader("hub.COUNTER_NSR", 2, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", + 1, + length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), new ColumnHeader("hub.DELTA", 1, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", 8, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", 8, length), - new ColumnHeader("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", 8, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT", 1, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2", 1, length), - new ColumnHeader("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD", 1, length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", + 8, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT", + 1, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2", + 1, + length), + new ColumnHeader( + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD", + 1, + length), new ColumnHeader("hub.DOM_STAMP", 8, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), - new ColumnHeader("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE", 1, length), - new ColumnHeader("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION", 1, length), + new ColumnHeader( + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE", + 1, + length), + new ColumnHeader( + "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION", + 1, + length), new ColumnHeader("hub.GAS_ACTUAL", 8, length), new ColumnHeader("hub.GAS_COST", 32, length), new ColumnHeader("hub.GAS_EXPECTED", 8, length), new ColumnHeader("hub.GAS_LIMIT", 32, length), new ColumnHeader("hub.GAS_NEXT", 8, length), new ColumnHeader("hub.GAS_PRICE", 32, length), - new ColumnHeader("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG", 1, length), - new ColumnHeader("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR", 1, length), + new ColumnHeader( + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG", + 1, + length), + new ColumnHeader( + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR", + 1, + length), new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), new ColumnHeader("hub.HEIGHT", 2, length), new ColumnHeader("hub.HEIGHT_NEW", 2, length), new ColumnHeader("hub.HUB_STAMP", 8, length), new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), new ColumnHeader("hub.INSTRUCTION", 32, length), - new ColumnHeader("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), + new ColumnHeader( + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO", + 1, + length), new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), - new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH", 1, length), - new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO", 1, length), + new ColumnHeader( + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH", + 1, + length), + new ColumnHeader( + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO", + 1, + length), new ColumnHeader("hub.MMU_STAMP", 8, length), new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), @@ -301,7 +393,8 @@ static List headers(int length) { new ColumnHeader("hub.NB_REMOVED", 1, length), new ColumnHeader("hub.NON_STACK_ROWS", 2, length), new ColumnHeader("hub.NONCE", 32, length), - new ColumnHeader("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), + new ColumnHeader( + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), new ColumnHeader("hub.OOB_DATA_1", 32, length), new ColumnHeader("hub.OOB_DATA_2", 32, length), @@ -345,20 +438,34 @@ static List headers(int length) { new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), - new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), - new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), - new ColumnHeader("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), - new ColumnHeader("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), - new ColumnHeader("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + new ColumnHeader( + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), + new ColumnHeader( + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), + new ColumnHeader( + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW", + 1, + length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), - new ColumnHeader("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader( + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), - new ColumnHeader("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, length), + new ColumnHeader( + "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", + 1, + length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), @@ -389,7 +496,8 @@ static List headers(int length) { new ColumnHeader("hub.SUB_STAMP", 8, length), new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), - new ColumnHeader("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + new ColumnHeader( + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -398,7 +506,10 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), + new ColumnHeader( + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", + 1, + length), new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -407,24 +518,36 @@ public Trace(List buffers) { this.absoluteTransactionNumber = buffers.get(0); this.accFinal = buffers.get(1); this.accFirst = buffers.get(2); - this.addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = buffers.get(3); - this.addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(4); + this + .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum = + buffers.get(3); + this + .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = + buffers.get(4); this.alpha = buffers.get(5); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(6); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = buffers.get(7); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = + buffers.get(6); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = + buffers.get(7); this.batchNumber = buffers.get(8); this.callDataOffsetXorMmuSize = buffers.get(9); this.callDataSizeXorMmuSrcId = buffers.get(10); this.callStackDepth = buffers.get(11); this.callerContextNumber = buffers.get(12); this.codeFragmentIndex = buffers.get(13); - this.codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = buffers.get(14); + this + .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize = + buffers.get(14); this.codeHashHiNewXorExpData5XorValueCurrLoXorValue = buffers.get(15); - this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = + buffers.get(16); this.codeHashLoNewXorMmuLimb2XorValueNextLo = buffers.get(17); this.codeHashLoXorMmuLimb1XorValueNextHi = buffers.get(18); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = buffers.get(19); - this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = buffers.get(20); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi = + buffers.get(19); + this + .codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi = + buffers.get(20); this.conAgain = buffers.get(21); this.conFirst = buffers.get(22); this.contextGetsReverted = buffers.get(23); @@ -443,34 +566,50 @@ public Trace(List buffers) { this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); this.delta = buffers.get(38); - this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = buffers.get(39); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = + buffers.get(39); this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); - this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = buffers.get(41); - this.deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment = buffers.get(42); - this.deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 = buffers.get(43); - this.deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd = buffers.get(44); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = + buffers.get(41); + this + .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment = + buffers.get(42); + this + .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 = + buffers.get(43); + this + .deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd = + buffers.get(44); this.domStamp = buffers.get(45); this.exceptionAhoy = buffers.get(46); - this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode = buffers.get(47); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = buffers.get(48); + this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode = + buffers.get(47); + this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = + buffers.get(48); this.gasActual = buffers.get(49); this.gasCost = buffers.get(50); this.gasExpected = buffers.get(51); this.gasLimit = buffers.get(52); this.gasNext = buffers.get(53); this.gasPrice = buffers.get(54); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig = buffers.get(55); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr = buffers.get(56); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig = + buffers.get(55); + this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr = + buffers.get(56); this.hashInfoStamp = buffers.get(57); this.height = buffers.get(58); this.heightNew = buffers.get(59); this.hubStamp = buffers.get(60); this.hubStampTransactionEnd = buffers.get(61); this.instruction = buffers.get(62); - this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero = buffers.get(63); + this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero = + buffers.get(63); this.logInfoStamp = buffers.get(64); - this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth = buffers.get(65); - this.markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero = buffers.get(66); + this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth = + buffers.get(65); + this + .markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero = + buffers.get(66); this.mmuStamp = buffers.get(67); this.mxpOffset2Hi = buffers.get(68); this.mxpOffset2Lo = buffers.get(69); @@ -535,7 +674,8 @@ public Trace(List buffers) { this.returnFromMessageCallWontTouchRamXorStackItemPop3 = buffers.get(128); this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(129); this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi = buffers.get(130); - this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew = buffers.get(131); + this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew = + buffers.get(131); this.rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo = buffers.get(132); this.rlpaddrKecLoXorMmuTgtOffsetLo = buffers.get(133); this.rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4 = buffers.get(134); @@ -989,7 +1129,8 @@ public Trace pAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1003,9 +1144,11 @@ public Trace pAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1019,9 +1162,11 @@ public Trace pAccountBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1035,9 +1180,11 @@ public Trace pAccountBalanceNew(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1049,7 +1196,8 @@ public Trace pAccountCodeFragmentIndex(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1065,7 +1213,8 @@ public Trace pAccountCodeHashHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1125,7 +1274,8 @@ public Trace pAccountCodeSize(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1185,7 +1335,8 @@ public Trace pAccountDeploymentStatus(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1197,7 +1348,8 @@ public Trace pAccountDeploymentStatusInfty(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1209,7 +1361,8 @@ public Trace pAccountDeploymentStatusNew(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -1221,7 +1374,8 @@ public Trace pAccountExists(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -1233,7 +1387,8 @@ public Trace pAccountExistsNew(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -1245,7 +1400,8 @@ public Trace pAccountHasCode(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } @@ -1257,7 +1413,8 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + (byte) (b ? 1 : 0)); return this; } @@ -1269,7 +1426,8 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -1281,7 +1439,8 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + .put((byte) (b ? 1 : 0)); return this; } @@ -1293,7 +1452,8 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -1365,7 +1525,8 @@ public Trace pAccountRlpaddrFlag(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -1517,7 +1678,8 @@ public Trace pContextAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1531,9 +1693,11 @@ public Trace pContextAccountAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1545,7 +1709,8 @@ public Trace pContextAccountDeploymentNumber(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1557,7 +1722,8 @@ public Trace pContextByteCodeAddressHi(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1571,9 +1737,11 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1673,7 +1841,8 @@ public Trace pContextCallValue(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1699,9 +1868,11 @@ public Trace pContextCallerAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1725,7 +1896,8 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1737,7 +1909,8 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1809,7 +1982,8 @@ public Trace pContextUpdate(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -1821,7 +1995,8 @@ public Trace pMiscCcrsStamp(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -1833,7 +2008,8 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -1847,9 +2023,11 @@ public Trace pMiscExpData1(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1863,9 +2041,11 @@ public Trace pMiscExpData2(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1879,9 +2059,11 @@ public Trace pMiscExpData3(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -1897,7 +2079,8 @@ public Trace pMiscExpData4(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -1925,7 +2108,8 @@ public Trace pMiscExpFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -1937,7 +2121,8 @@ public Trace pMiscExpInst(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -1949,7 +2134,8 @@ public Trace pMiscMmuAuxId(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -1973,7 +2159,8 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -2121,7 +2308,8 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -2161,7 +2349,8 @@ public Trace pMiscMxpDeploys(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -2173,7 +2362,8 @@ public Trace pMiscMxpFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } @@ -2213,7 +2403,8 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + (byte) (b ? 1 : 0)); return this; } @@ -2225,7 +2416,8 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -2509,7 +2701,8 @@ public Trace pMiscOobFlag(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + .put((byte) (b ? 1 : 0)); return this; } @@ -2533,7 +2726,8 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -2545,7 +2739,8 @@ public Trace pMiscStpFlag(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -2717,31 +2912,36 @@ public Trace pScenarioCallAbort(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { if (filled.get(53)) { - throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { if (filled.get(54)) { - throw new IllegalStateException("hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -2753,7 +2953,8 @@ public Trace pScenarioCallException(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -2765,79 +2966,92 @@ public Trace pScenarioCallPrcFailure(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { if (filled.get(57)) { - throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { if (filled.get(58)) { - throw new IllegalStateException("hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { if (filled.get(59)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); } else { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { if (filled.get(60)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); } else { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + .put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { if (filled.get(61)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { if (filled.get(62)) { - throw new IllegalStateException("hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -2856,7 +3070,8 @@ public Trace pScenarioCreateAbort(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { if (filled.get(64)) { - throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); } else { filled.set(64); } @@ -2868,7 +3083,8 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { if (filled.get(65)) { - throw new IllegalStateException("hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); } else { filled.set(65); } @@ -2892,7 +3108,8 @@ public Trace pScenarioCreateException(final Boolean b) { public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { if (filled.get(67)) { - throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); } else { filled.set(67); } @@ -2904,7 +3121,8 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { if (filled.get(68)) { - throw new IllegalStateException("hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); } else { filled.set(68); } @@ -2916,7 +3134,8 @@ public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { if (filled.get(69)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); } else { filled.set(69); } @@ -2928,7 +3147,8 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { if (filled.get(70)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); } else { filled.set(70); } @@ -2940,19 +3160,22 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { if (filled.get(71)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); } else { filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { if (filled.get(72)) { - throw new IllegalStateException("hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); } else { filled.set(72); } @@ -2981,7 +3204,8 @@ public Trace pScenarioPrcCalleeGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -2993,7 +3217,8 @@ public Trace pScenarioPrcCallerGas(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -3005,7 +3230,8 @@ public Trace pScenarioPrcCdo(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -3216,7 +3442,8 @@ public Trace pScenarioReturnException(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { if (filled.get(87)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { filled.set(87); } @@ -3228,7 +3455,8 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { if (filled.get(88)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { filled.set(88); } @@ -3240,7 +3468,8 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { if (filled.get(89)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { filled.set(89); } @@ -3252,7 +3481,8 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { if (filled.get(90)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { filled.set(90); } @@ -3264,7 +3494,8 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { if (filled.get(91)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { filled.set(91); } @@ -3276,7 +3507,8 @@ public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { if (filled.get(92)) { - throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); + throw new IllegalStateException( + "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { filled.set(92); } @@ -3312,7 +3544,8 @@ public Trace pScenarioSelfdestructWillRevert(final Boolean b) { public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { if (filled.get(95)) { - throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); + throw new IllegalStateException( + "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { filled.set(95); } @@ -3324,7 +3557,8 @@ public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { if (filled.get(96)) { - throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); + throw new IllegalStateException( + "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { filled.set(96); } @@ -3341,7 +3575,8 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -3353,7 +3588,8 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -3377,7 +3613,8 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -3389,7 +3626,8 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -3401,7 +3639,8 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -3413,7 +3652,8 @@ public Trace pStackConFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } @@ -3425,7 +3665,8 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + (byte) (b ? 1 : 0)); return this; } @@ -3437,7 +3678,8 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -3449,7 +3691,8 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + .put((byte) (b ? 1 : 0)); return this; } @@ -3461,7 +3704,8 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -3473,7 +3717,8 @@ public Trace pStackDecFlag3(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -3559,9 +3804,11 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -3575,9 +3822,11 @@ public Trace pStackHashInfoKeccakLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -3629,7 +3878,8 @@ public Trace pStackJumpDestinationVettingRequired(final Boolean b) { filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( + (byte) (b ? 1 : 0)); return this; } @@ -3823,9 +4073,11 @@ public Trace pStackPushValueHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -3841,7 +4093,8 @@ public Trace pStackPushValueLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4241,7 +4494,8 @@ public Trace pStackStaticGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4325,7 +4579,8 @@ public Trace pStorageAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4339,9 +4594,11 @@ public Trace pStorageAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4353,7 +4610,8 @@ public Trace pStorageDeploymentNumber(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -4365,7 +4623,8 @@ public Trace pStorageDeploymentNumberInfty(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -4379,9 +4638,11 @@ public Trace pStorageStorageKeyHi(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4395,9 +4656,11 @@ public Trace pStorageStorageKeyLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -4409,7 +4672,8 @@ public Trace pStorageUnconstrainedFinal(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4421,7 +4685,8 @@ public Trace pStorageUnconstrainedFirst(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -4433,7 +4698,8 @@ public Trace pStorageValueCurrChanges(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -4449,7 +4715,8 @@ public Trace pStorageValueCurrHi(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4461,7 +4728,8 @@ public Trace pStorageValueCurrIsOrig(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -4473,7 +4741,8 @@ public Trace pStorageValueCurrIsZero(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -4517,7 +4786,8 @@ public Trace pStorageValueNextIsCurr(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } @@ -4529,7 +4799,8 @@ public Trace pStorageValueNextIsOrig(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + (byte) (b ? 1 : 0)); return this; } @@ -4541,7 +4812,8 @@ public Trace pStorageValueNextIsZero(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put((byte) (b ? 1 : 0)); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4585,7 +4857,8 @@ public Trace pStorageValueOrigIsZero(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + .put((byte) (b ? 1 : 0)); return this; } @@ -4613,7 +4886,8 @@ public Trace pStorageWarmth(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -4625,7 +4899,8 @@ public Trace pStorageWarmthNew(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put((byte) (b ? 1 : 0)); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + (byte) (b ? 1 : 0)); return this; } @@ -4653,7 +4928,8 @@ public Trace pTransactionBatchNum(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.putLong(b); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .putLong(b); return this; } @@ -4665,7 +4941,8 @@ public Trace pTransactionCallDataSize(final long b) { filled.set(107); } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.putLong(b); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .putLong(b); return this; } @@ -4677,7 +4954,8 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { filled.set(108); } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.putLong(b); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .putLong(b); return this; } @@ -4691,9 +4969,11 @@ public Trace pTransactionCoinbaseAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put(b.toArrayUnsafe()); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4705,7 +4985,8 @@ public Trace pTransactionCopyTxcd(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put((byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4731,9 +5012,11 @@ public Trace pTransactionFromAddressLo(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put(b.toArrayUnsafe()); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -4823,9 +5106,11 @@ public Trace pTransactionInitialBalance(final Bytes b) { final byte[] bs = b.toArrayUnsafe(); for (int i = bs.length; i < 32; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put(b.toArrayUnsafe()); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + b.toArrayUnsafe()); return this; } @@ -4837,7 +5122,8 @@ public Trace pTransactionIsDeployment(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .put((byte) (b ? 1 : 0)); return this; } @@ -4849,7 +5135,8 @@ public Trace pTransactionIsType2(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .put((byte) (b ? 1 : 0)); return this; } @@ -4925,7 +5212,8 @@ public Trace pTransactionRequiresEvmExecution(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( + (byte) (b ? 1 : 0)); return this; } @@ -4937,7 +5225,8 @@ public Trace pTransactionStatusCode(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put((byte) (b ? 1 : 0)); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } @@ -4965,7 +5254,8 @@ public Trace pTransactionToAddressLo(final Bytes b) { for (int i = bs.length; i < 32; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(b.toArrayUnsafe()); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( + b.toArrayUnsafe()); return this; } @@ -5240,11 +5530,13 @@ public Trace validateRow() { } if (!filled.get(106)) { - throw new IllegalStateException("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); + throw new IllegalStateException( + "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } if (!filled.get(131)) { - throw new IllegalStateException("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } if (!filled.get(101)) { @@ -5252,11 +5544,13 @@ public Trace validateRow() { } if (!filled.get(133)) { - throw new IllegalStateException("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); + throw new IllegalStateException( + "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } if (!filled.get(132)) { - throw new IllegalStateException("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } if (!filled.get(1)) { @@ -5284,31 +5578,38 @@ public Trace validateRow() { } if (!filled.get(107)) { - throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); + throw new IllegalStateException( + "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } if (!filled.get(135)) { - throw new IllegalStateException("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } if (!filled.get(134)) { - throw new IllegalStateException("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } if (!filled.get(137)) { - throw new IllegalStateException("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } if (!filled.get(136)) { - throw new IllegalStateException("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } if (!filled.get(109)) { - throw new IllegalStateException("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } if (!filled.get(108)) { - throw new IllegalStateException("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); } if (!filled.get(48)) { @@ -5360,23 +5661,28 @@ public Trace validateRow() { } if (!filled.get(68)) { - throw new IllegalStateException("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + throw new IllegalStateException( + "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); } if (!filled.get(69)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); } if (!filled.get(70)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); } if (!filled.get(71)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); } if (!filled.get(72)) { - throw new IllegalStateException("hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); } if (!filled.get(102)) { @@ -5384,27 +5690,33 @@ public Trace validateRow() { } if (!filled.get(111)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } if (!filled.get(112)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } if (!filled.get(110)) { - throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } if (!filled.get(53)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(54)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2 has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2 has not been filled"); } if (!filled.get(52)) { - throw new IllegalStateException("hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD has not been filled"); + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD has not been filled"); } if (!filled.get(13)) { @@ -5416,11 +5728,13 @@ public Trace validateRow() { } if (!filled.get(56)) { - throw new IllegalStateException("hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE has not been filled"); + throw new IllegalStateException( + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE has not been filled"); } if (!filled.get(55)) { - throw new IllegalStateException("hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION has not been filled"); + throw new IllegalStateException( + "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(15)) { @@ -5448,11 +5762,13 @@ public Trace validateRow() { } if (!filled.get(58)) { - throw new IllegalStateException("hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); + throw new IllegalStateException( + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); } if (!filled.get(57)) { - throw new IllegalStateException("hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); + throw new IllegalStateException( + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); } if (!filled.get(19)) { @@ -5480,7 +5796,8 @@ public Trace validateRow() { } if (!filled.get(59)) { - throw new IllegalStateException("hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + throw new IllegalStateException( + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(24)) { @@ -5488,11 +5805,13 @@ public Trace validateRow() { } if (!filled.get(61)) { - throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH has not been filled"); + throw new IllegalStateException( + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH has not been filled"); } if (!filled.get(60)) { - throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO has not been filled"); + throw new IllegalStateException( + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(25)) { @@ -5548,7 +5867,8 @@ public Trace validateRow() { } if (!filled.get(123)) { - throw new IllegalStateException("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + throw new IllegalStateException( + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } if (!filled.get(122)) { @@ -5628,7 +5948,8 @@ public Trace validateRow() { } if (!filled.get(76)) { - throw new IllegalStateException("hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); } if (!filled.get(77)) { @@ -5636,11 +5957,13 @@ public Trace validateRow() { } if (!filled.get(78)) { - throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); } if (!filled.get(79)) { - throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); } if (!filled.get(80)) { @@ -5660,11 +5983,13 @@ public Trace validateRow() { } if (!filled.get(84)) { - throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(85)) { - throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); + throw new IllegalStateException( + "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); } if (!filled.get(128)) { @@ -5704,11 +6029,13 @@ public Trace validateRow() { } if (!filled.get(119)) { - throw new IllegalStateException("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + throw new IllegalStateException( + "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } if (!filled.get(120)) { - throw new IllegalStateException("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + throw new IllegalStateException( + "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } if (!filled.get(121)) { @@ -5720,51 +6047,63 @@ public Trace validateRow() { } if (!filled.get(87)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); } if (!filled.get(88)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(89)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(90)) { - throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(91)) { - throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(92)) { - throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + throw new IllegalStateException( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } if (!filled.get(113)) { - throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } if (!filled.get(138)) { - throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } if (!filled.get(62)) { - throw new IllegalStateException("hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW has not been filled"); } if (!filled.get(139)) { - throw new IllegalStateException("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } if (!filled.get(140)) { - throw new IllegalStateException("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } if (!filled.get(63)) { - throw new IllegalStateException("hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } if (!filled.get(141)) { @@ -5772,27 +6111,33 @@ public Trace validateRow() { } if (!filled.get(142)) { - throw new IllegalStateException("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); + throw new IllegalStateException( + "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } if (!filled.get(64)) { - throw new IllegalStateException("hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + throw new IllegalStateException( + "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } if (!filled.get(93)) { - throw new IllegalStateException("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); } if (!filled.get(94)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); } if (!filled.get(95)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); } if (!filled.get(96)) { - throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); + throw new IllegalStateException( + "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } if (!filled.get(164)) { @@ -5876,7 +6221,8 @@ public Trace validateRow() { } if (!filled.get(124)) { - throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); + throw new IllegalStateException( + "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } if (!filled.get(161)) { @@ -5900,11 +6246,13 @@ public Trace validateRow() { } if (!filled.get(65)) { - throw new IllegalStateException("hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + throw new IllegalStateException( + "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } if (!filled.get(143)) { - throw new IllegalStateException("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); + throw new IllegalStateException( + "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } if (!filled.get(40)) { @@ -5936,11 +6284,13 @@ public Trace validateRow() { } if (!filled.get(67)) { - throw new IllegalStateException("hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + throw new IllegalStateException( + "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); } if (!filled.get(66)) { - throw new IllegalStateException("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + throw new IllegalStateException( + "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } if (!filled.get(100)) { @@ -5967,11 +6317,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(106)) { - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position(addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.position() + 8); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .position( + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum + .position() + + 8); } if (!filled.get(131)) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position(addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position() + 32); + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position( + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .position() + + 32); } if (!filled.get(101)) { @@ -5979,11 +6337,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(133)) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position(balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position() + 32); + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance + .position( + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance + .position() + + 32); } if (!filled.get(132)) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position(balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position() + 32); + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo + .position( + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo + .position() + + 32); } if (!filled.get(1)) { @@ -6011,31 +6377,46 @@ public Trace fillAndValidateRow() { } if (!filled.get(107)) { - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position(codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize.position() + 8); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .position( + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .position() + + 8); } if (!filled.get(135)) { - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position(codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); } if (!filled.get(134)) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position(codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 32); + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + + 32); } if (!filled.get(137)) { - codeHashLoNewXorMmuLimb2XorValueNextLo.position(codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); + codeHashLoNewXorMmuLimb2XorValueNextLo.position( + codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); } if (!filled.get(136)) { - codeHashLoXorMmuLimb1XorValueNextHi.position(codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); + codeHashLoXorMmuLimb1XorValueNextHi.position( + codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); } if (!filled.get(109)) { - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position(codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + 8); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + + 8); } if (!filled.get(108)) { - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position(codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi.position() + 8); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position( + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .position() + + 8); } if (!filled.get(48)) { @@ -6087,23 +6468,28 @@ public Trace fillAndValidateRow() { } if (!filled.get(68)) { - createFailureConditionWontRevertXorIcpx.position(createFailureConditionWontRevertXorIcpx.position() + 1); + createFailureConditionWontRevertXorIcpx.position( + createFailureConditionWontRevertXorIcpx.position() + 1); } if (!filled.get(69)) { - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position(createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position( + createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); } if (!filled.get(70)) { - createNonemptyInitCodeFailureWontRevertXorJumpx.position(createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); + createNonemptyInitCodeFailureWontRevertXorJumpx.position( + createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); } if (!filled.get(71)) { - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position(createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position( + createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); } if (!filled.get(72)) { - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position(createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position( + createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); } if (!filled.get(102)) { @@ -6111,27 +6497,45 @@ public Trace fillAndValidateRow() { } if (!filled.get(111)) { - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position(deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position() + 8); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi + .position() + + 8); } if (!filled.get(112)) { - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position(deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); } if (!filled.get(110)) { - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position(deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + 8); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + + 8); } if (!filled.get(53)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.position(deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment.position() + 1); + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .position( + deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + .position() + + 1); } if (!filled.get(54)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.position(deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2.position() + 1); + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .position( + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + .position() + + 1); } if (!filled.get(52)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.position(deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.position() + 1); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .position( + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .position() + + 1); } if (!filled.get(13)) { @@ -6143,11 +6547,18 @@ public Trace fillAndValidateRow() { } if (!filled.get(56)) { - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.position(existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.position() + 1); + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.position( + existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode + .position() + + 1); } if (!filled.get(55)) { - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.position(existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.position() + 1); + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .position( + existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .position() + + 1); } if (!filled.get(15)) { @@ -6175,11 +6586,16 @@ public Trace fillAndValidateRow() { } if (!filled.get(58)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.position(hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.position() + 1); + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.position( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig + .position() + + 1); } if (!filled.get(57)) { - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position(hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position() + 1); + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position( + hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position() + + 1); } if (!filled.get(19)) { @@ -6207,7 +6623,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(59)) { - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.position(isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.position() + 1); + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero + .position( + isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero + .position() + + 1); } if (!filled.get(24)) { @@ -6215,11 +6635,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(61)) { - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.position(markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.position() + 1); + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth + .position( + markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth + .position() + + 1); } if (!filled.get(60)) { - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.position(markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero.position() + 1); + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + .position( + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + .position() + + 1); } if (!filled.get(25)) { @@ -6275,7 +6703,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(123)) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position(nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); } if (!filled.get(122)) { @@ -6387,7 +6816,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(84)) { - prcSuccessCallerWillRevertXorPushpopFlag.position(prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); + prcSuccessCallerWillRevertXorPushpopFlag.position( + prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); } if (!filled.get(85)) { @@ -6431,7 +6861,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(119)) { - returnDataContextNumberXorStpGasStipend.position(returnDataContextNumberXorStpGasStipend.position() + 8); + returnDataContextNumberXorStpGasStipend.position( + returnDataContextNumberXorStpGasStipend.position() + 8); } if (!filled.get(120)) { @@ -6447,43 +6878,54 @@ public Trace fillAndValidateRow() { } if (!filled.get(87)) { - returnFromDeploymentEmptyCodeWillRevertXorSox.position(returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + returnFromDeploymentEmptyCodeWillRevertXorSox.position( + returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); } if (!filled.get(88)) { - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position(returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position( + returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); } if (!filled.get(89)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position(returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position( + returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); } if (!filled.get(90)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position(returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position( + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); } if (!filled.get(91)) { - returnFromMessageCallWillTouchRamXorStackItemPop2.position(returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop2.position( + returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); } if (!filled.get(92)) { - returnFromMessageCallWontTouchRamXorStackItemPop3.position(returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); + returnFromMessageCallWontTouchRamXorStackItemPop3.position( + returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } if (!filled.get(113)) { - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position(rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); } if (!filled.get(138)) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position(rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); } if (!filled.get(62)) { - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position(rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position() + 1); + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position() + + 1); } if (!filled.get(139)) { - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position(rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); } if (!filled.get(140)) { @@ -6491,7 +6933,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(63)) { - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position(rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( + rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } if (!filled.get(141)) { @@ -6503,11 +6946,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(64)) { - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position(romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( + romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } if (!filled.get(93)) { - selfdestructExceptionXorStackItemPop4.position(selfdestructExceptionXorStackItemPop4.position() + 1); + selfdestructExceptionXorStackItemPop4.position( + selfdestructExceptionXorStackItemPop4.position() + 1); } if (!filled.get(94)) { @@ -6515,11 +6960,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(95)) { - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position(selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position( + selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); } if (!filled.get(96)) { - selfdestructWontRevertNotYetMarkedXorStoFlag.position(selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); + selfdestructWontRevertNotYetMarkedXorStoFlag.position( + selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } if (!filled.get(164)) { @@ -6603,7 +7050,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(124)) { - stpGasUpfrontGasCostXorGasLeftover.position(stpGasUpfrontGasCostXorGasLeftover.position() + 32); + stpGasUpfrontGasCostXorGasLeftover.position( + stpGasUpfrontGasCostXorGasLeftover.position() + 32); } if (!filled.get(161)) { @@ -6627,7 +7075,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(65)) { - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position(trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( + trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } if (!filled.get(143)) { @@ -6663,11 +7112,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(67)) { - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position(warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( + warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); } if (!filled.get(66)) { - warmthXorCreateExceptionXorHaltFlag.position(warmthXorCreateExceptionXorHaltFlag.position() + 1); + warmthXorCreateExceptionXorHaltFlag.position( + warmthXorCreateExceptionXorHaltFlag.position() + 1); } if (!filled.get(100)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index e7426c80ab..fc8c071581 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -18,6 +18,8 @@ import static net.consensys.linea.zktracer.types.AddressUtils.highPart; import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; +import java.util.HashMap; + import com.google.common.base.Preconditions; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -27,18 +29,13 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.types.EWord; -import org.hyperledger.besu.datatypes.Address; - -import java.util.HashMap; @RequiredArgsConstructor @Getter public final class StorageFragment implements TraceFragment { private final State hubState; @Setter private StorageFragmentType type; - private final Address address; - private final int deploymentNumber; - private final EWord key; + private final State.StorageSlotIdentifier storageSlotIdentifier; private final EWord valOrig; private final EWord valCurr; private final EWord valNext; @@ -49,20 +46,22 @@ public final class StorageFragment implements TraceFragment { public Trace trace(Trace trace) { - HashMap current = hubState.firstAndLastStorageSlotOccurrences.get(blockNumber); - State.EphemeralStorageSlotIdentifier storageSlotIdentifier = new State.EphemeralStorageSlotIdentifier(address, deploymentNumber, key); + HashMap current = + hubState.firstAndLastStorageSlotOccurrences.get(blockNumber - 1); Preconditions.checkArgument(current.containsKey(storageSlotIdentifier)); - final boolean isFirstOccurrence = current.get(storageSlotIdentifier).getFirstOccurrence() == this; - final boolean isFinalOccurrence = current.get(storageSlotIdentifier).getFinalOccurrence() == this; + final boolean isFirstOccurrence = + current.get(storageSlotIdentifier).getFirstOccurrence() == this; + final boolean isFinalOccurrence = + current.get(storageSlotIdentifier).getFinalOccurrence() == this; return trace .peekAtStorage(true) - .pStorageAddressHi(highPart(address)) - .pStorageAddressLo(lowPart(address)) - .pStorageDeploymentNumber(deploymentNumber) - .pStorageStorageKeyHi(key.hi()) - .pStorageStorageKeyLo(key.lo()) + .pStorageAddressHi(highPart(storageSlotIdentifier.getAddress())) + .pStorageAddressLo(lowPart(storageSlotIdentifier.getAddress())) + .pStorageDeploymentNumber(storageSlotIdentifier.getDeploymentNumber()) + .pStorageStorageKeyHi(EWord.of(storageSlotIdentifier.getStorageKey()).hi()) + .pStorageStorageKeyLo(EWord.of(storageSlotIdentifier.getStorageKey()).lo()) .pStorageValueOrigHi(valOrig.hi()) .pStorageValueOrigLo(valOrig.lo()) .pStorageValueCurrHi(valCurr.hi()) @@ -77,7 +76,7 @@ public Trace trace(Trace trace) { .pStorageValueNextIsCurr(valNext == valOrig) .pStorageValueNextIsZero(valNext.isZero()) .pStorageValueNextIsOrig(valNext == valOrig) - .pStorageUnconstrainedFirst(isFirstOccurrence) - .pStorageUnconstrainedFinal(isFinalOccurrence); + .pStorageUnconstrainedFirst(isFirstOccurrence) + .pStorageUnconstrainedFinal(isFinalOccurrence); } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java index 6a4e2d47d3..c85b18361f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java @@ -95,12 +95,12 @@ void test() { .op(OpCode.SLOAD) .op(OpCode.POP) // SSTORE value 1 - .push(key) .push(value1) + .push(key) .op(OpCode.SSTORE) // SSTORE value 2 - .push(key) .push(value2) + .push(key) .op(OpCode.SSTORE) .compile()) .nonce(116) From 6ab5a158569d79285634eecf31980202f8b83582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 7 Jun 2024 03:18:46 +0400 Subject: [PATCH 076/461] moved NON_STACK_ROWS from the common fragment to the section level + set it for SSTORE/SLOAD instructions --- .../linea/zktracer/module/hub/Hub.java | 11 +++++++++- .../linea/zktracer/module/hub/TxTrace.java | 3 ++- .../module/hub/fragment/CommonFragment.java | 10 ++++----- .../module/hub/fragment/ContextFragment.java | 22 ++++++++++++++----- .../module/hub/section/TraceSection.java | 16 ++++++++------ 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 33cc72f829..4e54fadf6e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1437,7 +1437,13 @@ void traceOperation(MessageFrame frame) { this, ContextFragment.readCurrentContextData(this), doingStorageFragment); // undoing the previous changes (value + warmth) if current context will revert - if (this.callStack().current().willRevert()) { + if (this.pch.exceptions().staticFault()) { + // TODO: make sure that whenever we enounter an exception _of any kind_ + // we trace the final context row where we update the caller return data + // to be empty. + storageSection.nonStackRows = 1 + 1; + } else if (this.callStack().current().willRevert()) { + storageSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); StorageFragment undoingStorageFragment = new StorageFragment( this.state, @@ -1455,6 +1461,7 @@ void traceOperation(MessageFrame frame) { state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, undoingStorageFragment); } else { + storageSection.nonStackRows = 1 + 1; state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, doingStorageFragment); } @@ -1484,6 +1491,7 @@ void traceOperation(MessageFrame frame) { // undoing the previous changes (warmth) if current context will revert if (this.callStack().current().willRevert()) { + storageSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); StorageFragment undoingStorageFragment = new StorageFragment( this.state, @@ -1501,6 +1509,7 @@ void traceOperation(MessageFrame frame) { state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, undoingStorageFragment); } else { + storageSection.nonStackRows = 1 + 1; state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, doingStorageFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 6e432fbc4a..45d5e7145e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -94,7 +94,8 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces public void commit(Trace hubTrace) { for (TraceSection opSection : this.trace) { for (TraceSection.TraceLine line : opSection.lines()) { - line.trace(hubTrace, opSection.stackHeight(), opSection.stackHeightNew()); + line.trace( + hubTrace, opSection.stackHeight(), opSection.stackHeightNew(), opSection.nonStackRows); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index a0b506e259..4ff32b3b76 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -69,7 +69,7 @@ public final class CommonFragment implements TraceFragment { @Getter @Setter private int nonStackRowsCounter; public static CommonFragment fromHub( - final Hub hub, final CallFrame frame, boolean tliCounter, int nonStackRowCounter) { + final Hub hub, final CallFrame frame, boolean counterTli, int counterNsr) { final boolean noStackException = hub.pch().exceptions().noStackException(); final long refundDelta = @@ -123,8 +123,8 @@ public static CommonFragment fromHub( .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) .refundDelta(refundDelta) .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) - .twoLineInstructionCounter(tliCounter) - .nonStackRowsCounter(nonStackRowCounter) + .twoLineInstructionCounter(counterTli) + .nonStackRowsCounter(counterNsr) .build(); } @@ -174,7 +174,7 @@ public Trace trace(Trace trace) { throw new UnsupportedOperationException("should never be called"); } - public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { + public Trace trace(Trace trace, int stackHeight, int stackHeightNew, short nonStackRows) { final CallFrame frame = this.hub.callStack().getById(this.callFrameId); final TransactionProcessingMetadata tx = hub.txStack().getByAbsoluteTransactionNumber(this.absoluteTransactionNumber); @@ -231,7 +231,7 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .refundCounterNew(gasRefund + (willRevert ? 0 : refundDelta)) .twoLineInstruction(twoLineInstruction) .counterTli(twoLineInstructionCounter) - .nonStackRows((short) numberOfNonStackRows) + .nonStackRows(nonStackRows) .counterNsr((short) nonStackRowsCounter); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 69501a45ab..60de42761f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -38,19 +38,31 @@ public record ContextFragment( boolean updateCallerReturndata) implements TraceFragment { - // TODO: in the spec readContextData accepts an argument - // which is _some_ context number, not necessarily that - // of the currently executing execution context. - public static ContextFragment readCurrentContextData(final Hub hub) { + public static ContextFragment readContextDataByContextNumber( + final Hub hub, final int contextNumber) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, callStack, - Either.left(callStack.current().id()), + Either.right(contextNumber), callStack.current().latestReturnDataSource().snapshot(), false); } + public static ContextFragment readContextDataById(final Hub hub, final int contextId) { + CallStack callStack = hub.callStack(); + return new ContextFragment( + hub, + callStack, + Either.left(contextId), + callStack.current().latestReturnDataSource().snapshot(), + false); + } + + public static ContextFragment readCurrentContextData(final Hub hub) { + return readContextDataById(hub, hub.callStack().current().id()); + } + public static ContextFragment initializeExecutionContext(final Hub hub) { return new ContextFragment( 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 7d9f4de76f..3ed08d92d7 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 @@ -54,11 +54,11 @@ public record TraceLine(CommonFragment common, TraceFragment specific) { * @param trace where to trace the line * @return the trace builder */ - public Trace trace(Trace trace, int stackInt, int stackHeight) { + public Trace trace(Trace trace, int stackInt, int stackHeight, short nonStackRows) { Preconditions.checkNotNull(common); Preconditions.checkNotNull(specific); - common.trace(trace, stackInt, stackHeight); + common.trace(trace, stackInt, stackHeight, nonStackRows); specific.trace(trace); return trace.fillAndValidateRow(); @@ -66,9 +66,11 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { } /** Count the stack lines */ - @Getter private int stackRowsCounter; + @Getter private int stackRowCounter; /** Count the non-stack lines */ - private int nonStackRowsCounter; + public int nonStackRowCounter; + + @Setter public short nonStackRows; @Getter @Setter private TxTrace parentTrace; @@ -81,7 +83,7 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { * @return a {@link CommonFragment} representing the shared columns */ private CommonFragment traceCommon(Hub hub, CallFrame frame) { - return CommonFragment.fromHub(hub, frame, this.stackRowsCounter == 2, this.nonStackRowsCounter); + return CommonFragment.fromHub(hub, frame, this.stackRowCounter == 2, this.nonStackRowCounter); } /** Default creator for an empty section. */ @@ -97,11 +99,11 @@ public final void addFragment(Hub hub, CallFrame callFrame, TraceFragment fragme Preconditions.checkArgument(!(fragment instanceof CommonFragment)); if (fragment instanceof StackFragment) { - this.stackRowsCounter++; + this.stackRowCounter++; } else if (fragment instanceof TransactionFragment f) { f.setParentSection(this); } else { - this.nonStackRowsCounter++; + this.nonStackRowCounter++; } this.lines.add(new TraceLine(traceCommon(hub, callFrame), fragment)); From 63158c78c7ef9fb0d7de084337e832918170f1e9 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 7 Jun 2024 08:45:03 +0400 Subject: [PATCH 077/461] fix(hub:-preWarming-phase): fix hub stamp not incrementing + move from hub to new class --- .../linea/zktracer/module/hub/Hub.java | 133 +---------------- .../linea/zktracer/module/hub/State.java | 2 +- .../txPreWarming/PreWarmingMacroSection.java | 139 ++++++++++++++++++ .../TxPrewarmingSection.java | 9 +- zkevm-constraints | 2 +- 5 files changed, 152 insertions(+), 133 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{ => txPreWarming}/TxPrewarmingSection.java (82%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 4e54fadf6e..b682834377 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -23,16 +23,11 @@ import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; -import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; import java.nio.MappedByteBuffer; -import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; @@ -63,6 +58,7 @@ import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; import net.consensys.linea.zktracer.module.hub.section.txFinalization.TxFinalizationPostTxDefer; +import net.consensys.linea.zktracer.module.hub.section.txPreWarming.PreWarmingMacroSection; import net.consensys.linea.zktracer.module.hub.section.txSkipippedSection.SkippedPostTransactionDefer; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; @@ -112,9 +108,6 @@ import net.consensys.linea.zktracer.runtime.stack.StackLine; import net.consensys.linea.zktracer.types.*; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.AccessListEntry; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; @@ -420,122 +413,6 @@ public int getCfiByMetaData( ContractMetadata.make(address, deploymentNumber, deploymentStatus)); } - /** - * Traces a skipped transaction, i.e. a “pure” transaction without EVM execution. - * - * @param world a view onto the state - */ - void processStateSkip(WorldView world) { - this.state.setProcessingPhase(TX_SKIP); - this.state.stamps().incrementHubStamp(); - this.defers.postTx( - new SkippedPostTransactionDefer(world, this.txStack.current(), this.transients)); - } - - /** - * Traces the isWarm-up information of a transaction - * - * @param world a view onto the state - */ - void processPrewarmingPhase(WorldView world) { - this.state.setProcessingPhase(TX_WARM); - this.txStack - .current() - .getBesuTransaction() - .getAccessList() - .ifPresent( - accessList -> { - if (!accessList.isEmpty()) { - Set
seenAddresses = new HashSet<>(precompileAddress); - Map> seenKeys = new HashMap<>(); - List fragments = new ArrayList<>(); - - for (AccessListEntry entry : accessList) { - this.state.stamps().incrementHubStamp(); - final Address address = entry.address(); - - final DeploymentInfo deploymentInfo = - this.transients.conflation().deploymentInfo(); - - final int deploymentNumber = deploymentInfo.number(address); - Preconditions.checkArgument( - !deploymentInfo.isDeploying(address), - "Deployment status during TX_INIT phase of any address should always be false"); - - final boolean isAccountWarm = seenAddresses.contains(address); - final AccountSnapshot preWarmingAccountSnapshot = - AccountSnapshot.fromAccount( - world.get(address), isAccountWarm, deploymentNumber, false); - - final AccountSnapshot postWarmingAccountSnapshot = - AccountSnapshot.fromAccount( - world.get(address), true, deploymentNumber, false); - - final DomSubStampsSubFragment domSubStampsSubFragment = - new DomSubStampsSubFragment( - DomSubStampsSubFragment.DomSubType.STANDARD, this.stamp(), 0, 0, 0, 0, 0); - fragments.add( - this.factories - .accountFragment() - .makeWithTrm( - preWarmingAccountSnapshot, - postWarmingAccountSnapshot, - address, - domSubStampsSubFragment)); - - seenAddresses.add(address); - - final List keys = entry.storageKeys(); - for (Bytes32 k : keys) { - this.state.stamps().incrementHubStamp(); - - final UInt256 key = UInt256.fromBytes(k); - final EWord value = - Optional.ofNullable(world.get(address)) - .map(account -> EWord.of(account.getStorageValue(key))) - .orElse(EWord.ZERO); - - State.StorageSlotIdentifier storageSlotIdentifier = - new State.StorageSlotIdentifier( - address, deploymentInfo.number(address), EWord.of(k)); - - StorageFragment storageFragment = - new StorageFragment( - this.state, - new State.StorageSlotIdentifier( - address, deploymentInfo.number(address), EWord.of(key)), - value, - value, - value, - seenKeys.computeIfAbsent(address, x -> new HashSet<>()).contains(key), - true, - DomSubStampsSubFragment.standardDomSubStamps(this, 0), - this.state.firstAndLastStorageSlotOccurrences.size()); - - fragments.add(storageFragment); - - state.updateOrInsertStorageSlotOccurrence( - storageSlotIdentifier, storageFragment); - - seenKeys.get(address).add(key); - } - } - - final TransactionProcessingMetadata transactionProcessingMetadata = - this.txStack.current(); - final Transaction besuTx = transactionProcessingMetadata.getBesuTransaction(); - final Address senderAddress = besuTx.getSender(); - final Address receiverAddress = effectiveToAddress(besuTx); - transactionProcessingMetadata.isSenderPreWarmed( - seenAddresses.contains(senderAddress)); - transactionProcessingMetadata.isReceiverPreWarmed( - seenAddresses.contains(receiverAddress)); - - this.addTraceSection(new TxPrewarmingSection(this, fragments)); - } - }); - } - /** * Trace the preamble of a transaction * @@ -797,10 +674,14 @@ public void traceStartTx(final WorldView world, final Transaction tx) { this.enterTransaction(); if (!this.txStack.current().requiresEvmExecution()) { - this.processStateSkip(world); + this.state.setProcessingPhase(TX_SKIP); + this.state.stamps().incrementHubStamp(); + this.defers.postTx( + new SkippedPostTransactionDefer(world, this.txStack.current(), this.transients)); } else { if (this.txStack.current().requiresPrewarming()) { - this.processPrewarmingPhase(world); + this.state.setProcessingPhase(TX_WARM); + new PreWarmingMacroSection(world, this); } this.processStateInit(world); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index 379c02e11b..ea1c376772 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -178,7 +178,7 @@ public Stamps snapshot() { return new Stamps(this.hub, this.mmu, this.mxp, this.hashInfo); } - void incrementHubStamp() { + public void incrementHubStamp() { this.hub++; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java new file mode 100644 index 0000000000..52e08a6811 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java @@ -0,0 +1,139 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use hub file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.txPreWarming; + +import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; +import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.State; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt256; +import org.hyperledger.besu.datatypes.AccessListEntry; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class PreWarmingMacroSection { + public PreWarmingMacroSection(WorldView world, Hub hub) { + + final TransactionProcessingMetadata currentTxMetadata = hub.txStack().current(); + + currentTxMetadata + .getBesuTransaction() + .getAccessList() + .ifPresent( + accessList -> { + if (!accessList.isEmpty()) { + Set
seenAddresses = new HashSet<>(precompileAddress); + Map> seenKeys = new HashMap<>(); + + for (AccessListEntry entry : accessList) { + hub.state.stamps().incrementHubStamp(); + final Address address = entry.address(); + + final DeploymentInfo deploymentInfo = + hub.transients().conflation().deploymentInfo(); + + final int deploymentNumber = deploymentInfo.number(address); + Preconditions.checkArgument( + !deploymentInfo.isDeploying(address), + "Deployment status during TX_INIT phase of any address should always be false"); + + final boolean isAccountWarm = seenAddresses.contains(address); + final AccountSnapshot preWarmingAccountSnapshot = + AccountSnapshot.fromAccount( + world.get(address), isAccountWarm, deploymentNumber, false); + + final AccountSnapshot postWarmingAccountSnapshot = + AccountSnapshot.fromAccount( + world.get(address), true, deploymentNumber, false); + + final DomSubStampsSubFragment domSubStampsSubFragment = + new DomSubStampsSubFragment( + DomSubStampsSubFragment.DomSubType.STANDARD, hub.stamp(), 0, 0, 0, 0, 0); + + hub.addTraceSection( + new TxPrewarmingSection( + hub, + hub.factories() + .accountFragment() + .makeWithTrm( + preWarmingAccountSnapshot, + postWarmingAccountSnapshot, + address, + domSubStampsSubFragment))); + + seenAddresses.add(address); + + final List keys = entry.storageKeys(); + for (Bytes32 k : keys) { + hub.state.stamps().incrementHubStamp(); + + final UInt256 key = UInt256.fromBytes(k); + final EWord value = + Optional.ofNullable(world.get(address)) + .map(account -> EWord.of(account.getStorageValue(key))) + .orElse(EWord.ZERO); + + State.StorageSlotIdentifier storageSlotIdentifier = + new State.StorageSlotIdentifier( + address, deploymentInfo.number(address), EWord.of(k)); + + final StorageFragment storageFragment = + new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + address, deploymentInfo.number(address), EWord.of(key)), + value, + value, + value, + seenKeys.computeIfAbsent(address, x -> new HashSet<>()).contains(key), + true, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0), + hub.state.firstAndLastStorageSlotOccurrences.size()); + + hub.addTraceSection(new TxPrewarmingSection(hub, storageFragment)); + hub.state.updateOrInsertStorageSlotOccurrence( + storageSlotIdentifier, storageFragment); + + seenKeys.get(address).add(key); + } + } + + final Transaction besuTx = currentTxMetadata.getBesuTransaction(); + final Address senderAddress = besuTx.getSender(); + final Address receiverAddress = effectiveToAddress(besuTx); + currentTxMetadata.isSenderPreWarmed(seenAddresses.contains(senderAddress)); + currentTxMetadata.isReceiverPreWarmed(seenAddresses.contains(receiverAddress)); + } + }); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/TxPrewarmingSection.java similarity index 82% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/TxPrewarmingSection.java index 25f539404c..69d0d5ef05 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPrewarmingSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/TxPrewarmingSection.java @@ -13,14 +13,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section; - -import java.util.List; +package net.consensys.linea.zktracer.module.hub.section.txPreWarming; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; /** * A warmup section is generated if a transaction features pre-warmed addresses and/or keys. It @@ -28,7 +27,7 @@ * pre-warmed addresses and eventual keys. */ public class TxPrewarmingSection extends TraceSection { - public TxPrewarmingSection(Hub hub, List fragments) { - this.addFragmentsWithoutStack(hub, fragments.toArray(new TraceFragment[0])); + public TxPrewarmingSection(Hub hub, TraceFragment fragment) { + this.addFragmentsWithoutStack(hub, fragment); } } diff --git a/zkevm-constraints b/zkevm-constraints index 5e42309d55..f7d0b9afdc 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 5e42309d551c8dda4c1eb1824bdb66ecd08eb744 +Subproject commit f7d0b9afdce60607c5b2a34d07f90661f2b4093e From a43247bd516f8ce0aeecd7c61781d5dd6f5053db Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 7 Jun 2024 10:01:37 +0400 Subject: [PATCH 078/461] fix: just minor stuff --- .../linea/zktracer/module/hub/Hub.java | 22 +++++++++---------- .../module/hub/fragment/CommonFragment.java | 2 +- .../hub/fragment/storage/StorageFragment.java | 2 +- .../txPreWarming/PreWarmingMacroSection.java | 5 +++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index b682834377..cd9024ba13 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1289,18 +1289,18 @@ void traceOperation(MessageFrame frame) { } } case STORAGE -> { - Address address = this.currentFrame().accountAddress(); - EWord key = EWord.of(frame.getStackItem(0)); + final Address address = this.currentFrame().accountAddress(); + final EWord key = EWord.of(frame.getStackItem(0)); - State.StorageSlotIdentifier storageSlotIdentifier = + final State.StorageSlotIdentifier storageSlotIdentifier = new State.StorageSlotIdentifier(address, currentFrame().accountDeploymentNumber(), key); switch (this.currentFrame().opCode()) { case SSTORE -> { - EWord valNext = EWord.of(frame.getStackItem(0)); + final EWord valNext = EWord.of(frame.getStackItem(0)); // doing the SSTORE operation - StorageFragment doingStorageFragment = + final StorageFragment doingStorageFragment = new StorageFragment( this.state, new State.StorageSlotIdentifier( @@ -1313,7 +1313,7 @@ void traceOperation(MessageFrame frame) { DomSubStampsSubFragment.standardDomSubStamps(this, 0), this.state.firstAndLastStorageSlotOccurrences.size()); - StorageSection storageSection = + final StorageSection storageSection = new StorageSection( this, ContextFragment.readCurrentContextData(this), doingStorageFragment); @@ -1325,7 +1325,7 @@ void traceOperation(MessageFrame frame) { storageSection.nonStackRows = 1 + 1; } else if (this.callStack().current().willRevert()) { storageSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); - StorageFragment undoingStorageFragment = + final StorageFragment undoingStorageFragment = new StorageFragment( this.state, new State.StorageSlotIdentifier( @@ -1350,10 +1350,10 @@ void traceOperation(MessageFrame frame) { this.addTraceSection(storageSection); } case SLOAD -> { - EWord valueCurrent = EWord.of(frame.getTransientStorageValue(address, key)); + final EWord valueCurrent = EWord.of(frame.getTransientStorageValue(address, key)); // doing the SLOAD operation - StorageFragment doingStorageFragment = + final StorageFragment doingStorageFragment = new StorageFragment( this.state, new State.StorageSlotIdentifier( @@ -1366,14 +1366,14 @@ void traceOperation(MessageFrame frame) { DomSubStampsSubFragment.standardDomSubStamps(this, 0), this.state.firstAndLastStorageSlotOccurrences.size()); - StorageSection storageSection = + final StorageSection storageSection = new StorageSection( this, ContextFragment.readCurrentContextData(this), doingStorageFragment); // undoing the previous changes (warmth) if current context will revert if (this.callStack().current().willRevert()) { storageSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); - StorageFragment undoingStorageFragment = + final StorageFragment undoingStorageFragment = new StorageFragment( this.state, new State.StorageSlotIdentifier( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 4ff32b3b76..d336ad0203 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -108,7 +108,7 @@ public static CommonFragment fromHub( .abortingConditions(hub.pch().abortingConditions().snapshot()) .failureConditions(hub.pch().failureConditions().snapshot()) .callFrameId(frame.id()) - .contextNumber(frame.contextNumber()) + .contextNumber(hubInExecPhase ? frame.contextNumber() : 0) .contextNumberNew(hub.contextNumberNew(frame)) .pc(pc) .pcNew(pcNew) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index fc8c071581..d75f7215e0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -46,7 +46,7 @@ public final class StorageFragment implements TraceFragment { public Trace trace(Trace trace) { - HashMap current = + final HashMap current = hubState.firstAndLastStorageSlotOccurrences.get(blockNumber - 1); Preconditions.checkArgument(current.containsKey(storageSlotIdentifier)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java index 52e08a6811..57d33c7bb1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; @@ -34,6 +33,7 @@ import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.AccessListEntry; @@ -53,7 +53,7 @@ public PreWarmingMacroSection(WorldView world, Hub hub) { accessList -> { if (!accessList.isEmpty()) { Set
seenAddresses = new HashSet<>(precompileAddress); - Map> seenKeys = new HashMap<>(); + HashMap> seenKeys = new HashMap<>(); for (AccessListEntry entry : accessList) { hub.state.stamps().incrementHubStamp(); @@ -68,6 +68,7 @@ public PreWarmingMacroSection(WorldView world, Hub hub) { "Deployment status during TX_INIT phase of any address should always be false"); final boolean isAccountWarm = seenAddresses.contains(address); + final AccountSnapshot preWarmingAccountSnapshot = AccountSnapshot.fromAccount( world.get(address), isAccountWarm, deploymentNumber, false); From 52a51b89b9364eb0b61f595205773ab0309a3a74 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 7 Jun 2024 12:00:02 +0400 Subject: [PATCH 079/461] test: stupid mistake in the test --- .../hub/fragment/account/AccountFragment.java | 18 ++++++++---------- .../module/hub/SimpleStorageConsistency.java | 5 ++--- zkevm-constraints | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 9581483238..ab90f5e247 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -22,7 +22,6 @@ import java.util.Optional; import com.google.common.base.Preconditions; -import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; @@ -37,7 +36,6 @@ import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -72,7 +70,6 @@ public AccountFragment makeWithTrm( } } - @Getter private final Address who; private final AccountSnapshot oldState; private final AccountSnapshot newState; @Setter private int deploymentNumberInfinity = 0; // retconned on conflation end @@ -92,7 +89,6 @@ public AccountFragment( DomSubStampsSubFragment domSubStampsSubFragment) { Preconditions.checkArgument(oldState.address().equals(newState.address())); - this.who = oldState.address(); this.oldState = oldState; this.newState = newState; this.deploymentNumber = newState.deploymentNumber(); @@ -113,8 +109,8 @@ public Trace trace(Trace trace) { return trace .peekAtAccount(true) - .pAccountAddressHi(highPart(who)) - .pAccountAddressLo(lowPart(who)) + .pAccountAddressHi(highPart(oldState.address())) + .pAccountAddressLo(lowPart(oldState.address())) .pAccountNonce(Bytes.ofUnsignedLong(oldState.nonce())) .pAccountNonceNew(Bytes.ofUnsignedLong(newState.nonce())) .pAccountBalance(oldState.balance()) @@ -149,7 +145,7 @@ public Trace trace(Trace trace) { .pAccountDeploymentStatusInfty(existsInfinity) .pAccountTrmFlag(this.addressToTrim.isPresent()) .pAccountTrmRawAddressHi(this.addressToTrim.map(a -> EWord.of(a).hi()).orElse(Bytes.EMPTY)) - .pAccountIsPrecompile(isPrecompile(who)) + .pAccountIsPrecompile(isPrecompile(oldState.address())) .pAccountRlpaddrFlag(false) // TODO .pAccountRlpaddrRecipe(false) // TODO .pAccountRlpaddrDepAddrHi(0) // TODO @@ -166,13 +162,15 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces @Override public void runPostConflation(Hub hub, WorldView world) { - this.deploymentNumberInfinity = hub.transients().conflation().deploymentInfo().number(this.who); - this.existsInfinity = world.get(this.who) != null; + this.deploymentNumberInfinity = + hub.transients().conflation().deploymentInfo().number(this.oldState.address()); + this.existsInfinity = world.get(this.oldState.address()) != null; this.codeFragmentIndex = this.requiresRomlex ? hub.romLex() .getCodeFragmentIndexByMetadata( - ContractMetadata.make(this.who, this.deploymentNumber, this.isDeployment)) + ContractMetadata.make( + this.oldState.address(), this.deploymentNumber, this.isDeployment)) : 0; } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java index c85b18361f..0a4fb79285 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java @@ -24,7 +24,6 @@ import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import net.consensys.linea.zktracer.testing.ToyTransaction; import net.consensys.linea.zktracer.testing.ToyWorld; -import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; @@ -40,7 +39,8 @@ @ExtendWith(EvmExtension.class) public class SimpleStorageConsistency { - private final Address receiverAddress = Address.wrap(Bytes.random(20)); + private final Address receiverAddress = + Address.fromHexString("0x00000bad0000000000000000000000000000b077"); final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); final Address senderAddress1 = @@ -104,7 +104,6 @@ void test() { .op(OpCode.SSTORE) .compile()) .nonce(116) - .address(Address.fromHexString("0xdead0000000000000000000000000000beef")) .build(); final Transaction simpleWarm = diff --git a/zkevm-constraints b/zkevm-constraints index f7d0b9afdc..66c3e2894d 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit f7d0b9afdce60607c5b2a34d07f90661f2b4093e +Subproject commit 66c3e2894d353c659849989819fbae7a1ca65c5e From 90a8fe11efee8b03fd60062dc97eb2ef7c23cf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 7 Jun 2024 12:36:37 +0400 Subject: [PATCH 080/461] StorageFragment's now trace DOM/SUB stamps --- .../zktracer/module/hub/fragment/storage/StorageFragment.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index d75f7215e0..57e4eabf4f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -55,6 +55,9 @@ public Trace trace(Trace trace) { final boolean isFinalOccurrence = current.get(storageSlotIdentifier).getFinalOccurrence() == this; + // tracing + this.domSubStampsSubFragment.trace(trace); + return trace .peekAtStorage(true) .pStorageAddressHi(highPart(storageSlotIdentifier.getAddress())) From b55deae7e983e5340da865bf1ace8ba25cf88045 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 7 Jun 2024 18:02:53 +0400 Subject: [PATCH 081/461] fix: fix rlptxn - hub lookups constraints --- .../zktracer/module/hub/StupidCreateTBD.java | 63 +++++++++++++++++++ zkevm-constraints | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java new file mode 100644 index 0000000000..320b0aff27 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java @@ -0,0 +1,63 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import net.consensys.linea.zktracer.testing.EvmExtension; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class StupidCreateTBD { + + @Test + void testStupidCreateTBD() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push(Bytes.fromHexString("0x63deadbeef000000000000000000000000000000000000000000000000000000")) + .push(Bytes.of(0x00)) + .op(OpCode.MSTORE) + .push(0x05) + .push(0x00) + .push(0x00) + .op(OpCode.CREATE) + .op(OpCode.DUP1) + .compile()) + .run(); + } + + @Test + void TestReturnDataCopyAlternative() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + + program + .push("63deadbeef000000000000000000000000000000000000000000000000000000") + .push(0) + .op(OpCode.MSTORE) + .push(0x04) + .push(0) + .push(0) + .op(OpCode.CREATE) + .op(OpCode.DUP1); + + BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); + bytecodeRunner.run(); + } + +} diff --git a/zkevm-constraints b/zkevm-constraints index 66c3e2894d..061b9448fb 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 66c3e2894d353c659849989819fbae7a1ca65c5e +Subproject commit 061b9448fb61a8900fe7b62776cdce30e22bf71c From 5e63e76fc885fcbaaccb17f8c8f156bcf426cafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 9 Jun 2024 02:23:41 +0400 Subject: [PATCH 082/461] SLOAD section --- .../zktracer/module/hub/AccountSnapshot.java | 16 +++- .../linea/zktracer/module/hub/Hub.java | 69 +++------------- ...{StorageSection.java => SloadSection.java} | 17 +--- .../module/hub/section/SstoreSection.java | 68 ++++++++++++++++ .../module/hub/section/StopSection.java | 78 ++++++++++++++++--- .../zktracer/module/hub/StupidCreateTBD.java | 41 +++++----- 6 files changed, 183 insertions(+), 106 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{StorageSection.java => SloadSection.java} (60%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 36b1cbad0a..59fa034a0c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -124,7 +124,7 @@ public AccountSnapshot debit(Wei quantity, boolean isWarm) { this.deploymentStatus); } - public AccountSnapshot deploy(Wei value) { + public AccountSnapshot initiateDeployment(Wei value) { return new AccountSnapshot( this.address, this.nonce + 1, @@ -135,9 +135,11 @@ public AccountSnapshot deploy(Wei value) { this.deploymentStatus); } - public AccountSnapshot deploy(Wei value, Bytecode code) { + // TODO: does this update the deployment number in the deploymentInfo object ? + public AccountSnapshot initiateDeployment(Wei value, Bytecode code) { Preconditions.checkState( - !this.deploymentStatus, "Deployment status should be false before deploying."); + !this.deploymentStatus, + "Deployment status should be false before initiating a deployment."); return new AccountSnapshot( this.address, this.nonce + 1, @@ -148,6 +150,14 @@ public AccountSnapshot deploy(Wei value, Bytecode code) { true); } + public AccountSnapshot deployByteCode(Bytecode code) { + Preconditions.checkState( + this.deploymentStatus, "Deployment status should be true before deploying byte code."); + + return new AccountSnapshot( + this.address, this.nonce, this.balance, true, code, this.deploymentNumber, false); + } + public AccountSnapshot credit(Wei value) { return new AccountSnapshot( this.address, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index cd9024ba13..66f02f0cfd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -464,7 +464,7 @@ void processStateInit(WorldView world) { new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); final AccountSnapshot recipientAfterValueTransfer = isDeployment - ? recipientBeforeValueTransfer.deploy(value, initBytecode) + ? recipientBeforeValueTransfer.initiateDeployment(value, initBytecode) : recipientBeforeValueTransfer.credit(value, true); final DomSubStampsSubFragment recipientDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 1); @@ -1146,9 +1146,7 @@ void traceOperation(MessageFrame frame) { } case STOP -> { parentFrame.latestReturnData(Bytes.EMPTY); - if (!currentFrame().underDeployment()) { - this.addTraceSection(StopSection.messageCallStopSection(this)); - } + StopSection.appendTo(this); } case SELFDESTRUCT -> { parentFrame.latestReturnData(Bytes.EMPTY); @@ -1297,7 +1295,7 @@ void traceOperation(MessageFrame frame) { switch (this.currentFrame().opCode()) { case SSTORE -> { - final EWord valNext = EWord.of(frame.getStackItem(0)); + final EWord valNext = EWord.of(frame.getStackItem(1)); // doing the SSTORE operation final StorageFragment doingStorageFragment = @@ -1313,8 +1311,8 @@ void traceOperation(MessageFrame frame) { DomSubStampsSubFragment.standardDomSubStamps(this, 0), this.state.firstAndLastStorageSlotOccurrences.size()); - final StorageSection storageSection = - new StorageSection( + final SstoreSection SStoreSection = + new SstoreSection( this, ContextFragment.readCurrentContextData(this), doingStorageFragment); // undoing the previous changes (value + warmth) if current context will revert @@ -1322,9 +1320,9 @@ void traceOperation(MessageFrame frame) { // TODO: make sure that whenever we enounter an exception _of any kind_ // we trace the final context row where we update the caller return data // to be empty. - storageSection.nonStackRows = 1 + 1; + SStoreSection.nonStackRows = 1 + 1; } else if (this.callStack().current().willRevert()) { - storageSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); + SStoreSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); final StorageFragment undoingStorageFragment = new StorageFragment( this.state, @@ -1338,64 +1336,19 @@ void traceOperation(MessageFrame frame) { DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), this.state.firstAndLastStorageSlotOccurrences.size()); - storageSection.addFragment(this, undoingStorageFragment); + SStoreSection.addFragment(this, undoingStorageFragment); state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, undoingStorageFragment); } else { - storageSection.nonStackRows = 1 + 1; + SStoreSection.nonStackRows = 1 + 1; state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, doingStorageFragment); } - this.addTraceSection(storageSection); + this.addTraceSection(SStoreSection); } case SLOAD -> { - final EWord valueCurrent = EWord.of(frame.getTransientStorageValue(address, key)); - - // doing the SLOAD operation - final StorageFragment doingStorageFragment = - new StorageFragment( - this.state, - new State.StorageSlotIdentifier( - address, this.currentFrame().accountDeploymentNumber(), key), - this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - valueCurrent, - valueCurrent, - frame.isStorageWarm(address, key), - true, - DomSubStampsSubFragment.standardDomSubStamps(this, 0), - this.state.firstAndLastStorageSlotOccurrences.size()); - - final StorageSection storageSection = - new StorageSection( - this, ContextFragment.readCurrentContextData(this), doingStorageFragment); - - // undoing the previous changes (warmth) if current context will revert - if (this.callStack().current().willRevert()) { - storageSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); - final StorageFragment undoingStorageFragment = - new StorageFragment( - this.state, - new State.StorageSlotIdentifier( - address, this.currentFrame().accountDeploymentNumber(), key), - this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - valueCurrent, - valueCurrent, - true, - frame.isStorageWarm(address, key), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), - this.state.firstAndLastStorageSlotOccurrences.size()); - - storageSection.addFragment(this, undoingStorageFragment); - state.updateOrInsertStorageSlotOccurrence( - storageSlotIdentifier, undoingStorageFragment); - } else { - storageSection.nonStackRows = 1 + 1; - state.updateOrInsertStorageSlotOccurrence( - storageSlotIdentifier, doingStorageFragment); - } - - this.addTraceSection(storageSection); + SloadSection.appendSection(this); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java similarity index 60% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index b6c9d48781..fbc4451707 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StorageSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -12,21 +12,6 @@ * * SPDX-License-Identifier: Apache-2.0 */ - package net.consensys.linea.zktracer.module.hub.section; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; - -public class StorageSection extends TraceSection { - public StorageSection(Hub hub, final TraceFragment... chunks) { - this.addFragmentsAndStack(hub, chunks); - } - - public void addFragment(Hub hub, final TraceFragment fragment) { - this.addFragmentsWithoutStack(hub, fragment); - } - - @Override - public void seal(Hub hub) {} +public class SloadSection { } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java new file mode 100644 index 0000000000..c149ab1d49 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -0,0 +1,68 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; + +public class SstoreSection extends TraceSection { + + public static void appendTo(Hub hub) { + + if (hub.pch().exceptions().staticFault()) { + // static exception SSTORE section + hub.addTraceSection(staticxSstoreSection(hub)); + } else if (hub.pch().exceptions().outOfGas()) { + // out of gas exception SSTORE section + hub.addTraceSection(oogxSstoreSection(hub)); + } else if (hub.callStack().current().willRevert()) { + // reverted SSTORE section + hub.addTraceSection(revertedSstoreSection(hub)); + } else { + // reverted SSTORE section + hub.addTraceSection(unrevertedSstoreSection(hub)); + } + } + + private SstoreSection() {} + + private static SstoreSection staticxSstoreSection(Hub hub) { + return new SstoreSection(); + } + + private static SstoreSection oogxSstoreSection(Hub hub) { + return new SstoreSection(); + } + + private static SstoreSection revertedSstoreSection(Hub hub) { + return new SstoreSection(); + } + + private static SstoreSection unrevertedSstoreSection(Hub hub) { + return new SstoreSection(); + } + + public SstoreSection(Hub hub, final TraceFragment... chunks) { + this.addFragmentsAndStack(hub, chunks); + } + + public void addFragment(Hub hub, final TraceFragment fragment) { + this.addFragmentsWithoutStack(hub, fragment); + } + + @Override + public void seal(Hub hub) {} +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index f48fa8a787..6ed5511a64 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -17,34 +17,94 @@ import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.executionProvidesEmptyReturnData; import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readCurrentContextData; +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.types.Bytecode; +import org.hyperledger.besu.datatypes.Address; public class StopSection extends TraceSection { - public StopSection() {} + public static void appendTo(Hub hub) { + if (!hub.currentFrame().underDeployment()) { + hub.addTraceSection(messageCallStopSection(hub)); + } else if (hub.currentFrame().willRevert()) { + hub.addTraceSection(deploymentStopSection(hub)); + } + } public StopSection(Hub hub, TraceFragment... fragments) { this.addFragmentsAndStack(hub, fragments); } public static StopSection messageCallStopSection(Hub hub) { - return new StopSection(hub, readCurrentContextData(hub), executionProvidesEmptyReturnData(hub)); + StopSection messageCallStopSetion = + new StopSection(hub, readCurrentContextData(hub), executionProvidesEmptyReturnData(hub)); + messageCallStopSetion.nonStackRows = 2; + return messageCallStopSetion; } - public static StopSection revertedDeploymentStopSection(Hub hub) { + public static StopSection deploymentStopSection(Hub hub) { AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); - return new StopSection( - hub, - readCurrentContextData(hub), - // current (under deployment => deployed with empty byte code) - // undoing of the above - executionProvidesEmptyReturnData(hub)); + + final Address address = hub.currentFrame().accountAddress(); + final int deploymentNumber = hub.transients().conflation().deploymentInfo().number(address); + final boolean deploymentStatus = + hub.transients().conflation().deploymentInfo().isDeploying(address); + + // we should be deploying + Preconditions.checkArgument(deploymentStatus); + + AccountSnapshot beforeEmptyDeployment = + AccountSnapshot.fromAddress(address, true, deploymentNumber, deploymentStatus); + AccountSnapshot afterEmptyDeployment = beforeEmptyDeployment.deployByteCode(Bytecode.EMPTY); + StopSection stopWhileDeploying = + new StopSection( + hub, + readCurrentContextData(hub), + // current (under deployment => deployed with empty byte code) + accountFragmentFactory.make( + beforeEmptyDeployment, + afterEmptyDeployment, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0))); + + if (hub.currentFrame().willRevert()) { + // undoing of the above + stopWhileDeploying.addFragmentsWithoutStack( + hub, + accountFragmentFactory.make( + afterEmptyDeployment, + beforeEmptyDeployment, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1)), + executionProvidesEmptyReturnData(hub)); + + stopWhileDeploying.nonStackRows = 4; + } else { + stopWhileDeploying.addFragmentsWithoutStack(hub, executionProvidesEmptyReturnData(hub)); + + stopWhileDeploying.nonStackRows = 3; + } + + return stopWhileDeploying; } public static StopSection unrevertedDeploymentStopSection(Hub hub) { + + AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final Address address = hub.currentFrame().accountAddress(); + final int deploymentNumber = hub.transients().conflation().deploymentInfo().number(address); + final boolean deploymentStatus = + hub.transients().conflation().deploymentInfo().isDeploying(address); + + // we should be deploying + Preconditions.checkArgument(deploymentStatus); + return new StopSection( hub, readCurrentContextData(hub), diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java index 320b0aff27..9ac0c78e56 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java @@ -29,17 +29,19 @@ public class StupidCreateTBD { @Test void testStupidCreateTBD() { BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(Bytes.fromHexString("0x63deadbeef000000000000000000000000000000000000000000000000000000")) - .push(Bytes.of(0x00)) - .op(OpCode.MSTORE) - .push(0x05) - .push(0x00) - .push(0x00) - .op(OpCode.CREATE) - .op(OpCode.DUP1) - .compile()) - .run(); + BytecodeCompiler.newProgram() + .push( + Bytes.fromHexString( + "0x63deadbeef000000000000000000000000000000000000000000000000000000")) + .push(Bytes.of(0x00)) + .op(OpCode.MSTORE) + .push(0x05) + .push(0x00) + .push(0x00) + .op(OpCode.CREATE) + .op(OpCode.DUP1) + .compile()) + .run(); } @Test @@ -47,17 +49,16 @@ void TestReturnDataCopyAlternative() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push("63deadbeef000000000000000000000000000000000000000000000000000000") - .push(0) - .op(OpCode.MSTORE) - .push(0x04) - .push(0) - .push(0) - .op(OpCode.CREATE) - .op(OpCode.DUP1); + .push("63deadbeef000000000000000000000000000000000000000000000000000000") + .push(0) + .op(OpCode.MSTORE) + .push(0x04) + .push(0) + .push(0) + .op(OpCode.CREATE) + .op(OpCode.DUP1); BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); bytecodeRunner.run(); } - } From 13dfa0bda9ba430a76fbeaaad5b3599263922a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 10 Jun 2024 07:22:24 +0200 Subject: [PATCH 083/461] work on SSTORE / SLOAD --- .../linea/zktracer/module/hub/Hub.java | 9 +- .../module/hub/fragment/StackFragment.java | 6 +- .../module/hub/fragment/imc/ImcFragment.java | 2 +- .../hub/fragment/storage/StorageFragment.java | 4 +- .../module/hub/section/CreateSection.java | 6 +- .../module/hub/section/SloadSection.java | 98 +++++++++++++- .../module/hub/section/SstoreSection.java | 125 ++++++++++++++---- .../module/hub/signals/Exceptions.java | 76 +++++------ .../zktracer/module/hub/signals/Signals.java | 42 +++--- 9 files changed, 273 insertions(+), 95 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 66f02f0cfd..20545b6153 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1295,6 +1295,8 @@ void traceOperation(MessageFrame frame) { switch (this.currentFrame().opCode()) { case SSTORE -> { + SstoreSection.appendSection(this); + /** final EWord valNext = EWord.of(frame.getStackItem(1)); // doing the SSTORE operation @@ -1316,7 +1318,7 @@ void traceOperation(MessageFrame frame) { this, ContextFragment.readCurrentContextData(this), doingStorageFragment); // undoing the previous changes (value + warmth) if current context will revert - if (this.pch.exceptions().staticFault()) { + if (this.pch.exceptions().staticException()) { // TODO: make sure that whenever we enounter an exception _of any kind_ // we trace the final context row where we update the caller return data // to be empty. @@ -1346,6 +1348,7 @@ void traceOperation(MessageFrame frame) { } this.addTraceSection(SStoreSection); + */ } case SLOAD -> { SloadSection.appendSection(this); @@ -1407,7 +1410,7 @@ void traceOperation(MessageFrame frame) { // // THERE IS AN EXCEPTION // - if (this.pch().exceptions().staticFault()) { + if (this.pch().exceptions().staticException()) { this.addTraceSection( new FailedCallSection( this, @@ -1420,7 +1423,7 @@ void traceOperation(MessageFrame frame) { this, ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount))); - } else if (this.pch().exceptions().outOfGas()) { + } else if (this.pch().exceptions().outOfGasException()) { this.addTraceSection( new FailedCallSection( this, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index af656c9ed9..e261319719 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -291,11 +291,11 @@ public Trace trace(Trace trace) { .pStackSux(exceptions.stackUnderflow()) .pStackSox(exceptions.stackOverflow()) .pStackMxpx(exceptions.outOfMemoryExpansion()) - .pStackOogx(exceptions.outOfGas()) + .pStackOogx(exceptions.outOfGasException()) .pStackRdcx(exceptions.returnDataCopyFault()) .pStackJumpx(exceptions.jumpFault()) - .pStackStaticx(exceptions.staticFault()) - .pStackSstorex(exceptions.outOfSStore()) + .pStackStaticx(exceptions.staticException()) + .pStackSstorex(exceptions.sstoreException()) .pStackIcpx(contextExceptions.invalidCodePrefix()) .pStackMaxcsx(contextExceptions.codeSizeOverflow()) // Hash data diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index c4a8d0442f..77e8e7016b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -155,7 +155,7 @@ public static ImcFragment forCall( calledAccount .map(a -> hub.messageFrame().isAddressWarm(a.getAddress())) .orElse(false), - hub.pch().exceptions().outOfGas(), + hub.pch().exceptions().outOfGasException(), upfrontCost, Math.max( Words.unsignedMin( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 57e4eabf4f..7d2cc751b2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -76,9 +76,9 @@ public Trace trace(Trace trace) { .pStorageValueOrigIsZero(valOrig.isZero()) .pStorageValueCurrIsOrig(valCurr.equals(valOrig)) .pStorageValueCurrIsZero(valCurr.isZero()) - .pStorageValueNextIsCurr(valNext == valOrig) + .pStorageValueNextIsCurr(valNext.equals(valCurr)) .pStorageValueNextIsZero(valNext.isZero()) - .pStorageValueNextIsOrig(valNext == valOrig) + .pStorageValueNextIsOrig(valNext.equals(valOrig)) .pStorageUnconstrainedFirst(isFirstOccurrence) .pStorageUnconstrainedFinal(isFinalOccurrence); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 8d91ce72e3..88d768d5f4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -173,14 +173,14 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces EWord.ZERO, false, oldCreatedSnapshot.isWarm(), - this.exceptions.outOfGas(), + this.exceptions.outOfGasException(), upfrontCost, allButOneSixtyFourth(this.initialGas - upfrontCost), 0)); this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); this.addFragmentsWithoutStack(hub, scenarioFragment); - if (this.exceptions.staticFault()) { + if (this.exceptions.staticException()) { this.addFragmentsWithoutStack( hub, ImcFragment.empty(hub), @@ -191,7 +191,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces hub, ImcFragment.empty(hub).callMxp(MxpCall.build(hub)), ContextFragment.executionProvidesEmptyReturnData(hub)); - } else if (this.exceptions.outOfGas()) { + } else if (this.exceptions.outOfGasException()) { this.addFragmentsWithoutStack( hub, commonImcFragment, ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.aborts.any()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index fbc4451707..c909b13d99 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -13,5 +13,101 @@ * SPDX-License-Identifier: Apache-2.0 */ package net.consensys.linea.zktracer.module.hub.section; -public class SloadSection { + +import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.State; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.types.EWord; +import org.hyperledger.besu.datatypes.Address; + +@RequiredArgsConstructor +public class SloadSection extends TraceSection { + + final Hub hub; + final State.StorageSlotIdentifier storageSlotIdentifier; + final EWord valueCurrent; + + private SloadSection(Hub hub) { + this.hub = hub; + Address address = hub.currentFrame().accountAddress(); + EWord key = EWord.of(hub.messageFrame().getStackItem(0)); + this.storageSlotIdentifier = + new State.StorageSlotIdentifier(address, hub.currentFrame().accountDeploymentNumber(), key); + this.valueCurrent = EWord.of(hub.messageFrame().getTransientStorageValue(address, key)); + } + + public static void appendSection(Hub hub) { + + final SloadSection sloadSection = new SloadSection(hub); + hub.addTraceSection(sloadSection); + + final State.StorageSlotIdentifier storageSlotIdentifier = sloadSection.storageSlotIdentifier; + final Address address = storageSlotIdentifier.getAddress(); + final EWord storageKey = storageSlotIdentifier.getStorageKey(); + final EWord valueOriginal = + hub.txStack().current().getStorage().getOriginalValueOrUpdate(address, storageKey); + final EWord valueCurrent = sloadSection.valueCurrent; + + ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); + ImcFragment miscFragmentForSload = ImcFragment.empty(hub); + StorageFragment doingSload = + doingSload(hub, address, storageKey, valueOriginal, valueCurrent); + + sloadSection.addFragmentsAndStack( + hub, hub.currentFrame(), readCurrentContext, miscFragmentForSload, doingSload); + + final boolean outOfGasException = hub.pch().exceptions().outOfGasException(); + final boolean contextWillRevert = hub.callStack().current().willRevert(); + + if (outOfGasException || contextWillRevert) { + + final StorageFragment undoingSload = + undoingSload(hub, address, storageKey, valueOriginal, valueCurrent); + + // TODO: make sure we trace a context when there is an exception + sloadSection.nonStackRowCounter = outOfGasException ? 5 : 4; + sloadSection.addFragment(hub, hub.currentFrame(), undoingSload); + hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, undoingSload); + return; + } + + hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingSload); + sloadSection.nonStackRows = 3; + } + + private static StorageFragment doingSload( + Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent) { + + return new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + address, hub.currentFrame().accountDeploymentNumber(), storageKey), + valueOriginal, + valueCurrent, + valueCurrent, + hub.currentFrame().frame().isStorageWarm(address, storageKey), + true, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0), + hub.state.firstAndLastStorageSlotOccurrences.size()); + } + + private static StorageFragment undoingSload( + Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent) { + + return new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + address, hub.currentFrame().accountDeploymentNumber(), storageKey), + valueOriginal, + valueCurrent, + valueCurrent, + true, + hub.currentFrame().frame().isStorageWarm(address, storageKey), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), + hub.state.firstAndLastStorageSlotOccurrences.size()); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index c149ab1d49..fc3b67f51f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -16,51 +16,130 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.State; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.types.EWord; +import org.hyperledger.besu.datatypes.Address; public class SstoreSection extends TraceSection { + final Hub hub; + final State.StorageSlotIdentifier storageSlotIdentifier; + final EWord valueCurrent; + final EWord valueNext; + public static void appendTo(Hub hub) { - if (hub.pch().exceptions().staticFault()) { + if (hub.pch().exceptions().staticException()) { // static exception SSTORE section - hub.addTraceSection(staticxSstoreSection(hub)); - } else if (hub.pch().exceptions().outOfGas()) { + } else if (hub.pch().exceptions().sstoreException()) { + // SSTORE specific exception (avaible gas <= G_callstipend = 2300) + } else if (hub.pch().exceptions().outOfGasException()) { // out of gas exception SSTORE section - hub.addTraceSection(oogxSstoreSection(hub)); } else if (hub.callStack().current().willRevert()) { // reverted SSTORE section - hub.addTraceSection(revertedSstoreSection(hub)); } else { // reverted SSTORE section - hub.addTraceSection(unrevertedSstoreSection(hub)); } } - private SstoreSection() {} - - private static SstoreSection staticxSstoreSection(Hub hub) { - return new SstoreSection(); + private SstoreSection(Hub hub) { + this.hub = hub; + Address address = hub.currentFrame().accountAddress(); + EWord key = EWord.of(hub.messageFrame().getStackItem(0)); + this.storageSlotIdentifier = + new State.StorageSlotIdentifier(address, hub.currentFrame().accountDeploymentNumber(), key); + this.valueCurrent = EWord.of(hub.messageFrame().getTransientStorageValue(address, key)); + this.valueNext = EWord.of(hub.messageFrame().getStackItem(1)); } - private static SstoreSection oogxSstoreSection(Hub hub) { - return new SstoreSection(); - } + public static void appendSection(Hub hub) { - private static SstoreSection revertedSstoreSection(Hub hub) { - return new SstoreSection(); - } + final SstoreSection sstoreSection = new SstoreSection(hub); + hub.addTraceSection(sstoreSection); + + final State.StorageSlotIdentifier storageSlotIdentifier = sstoreSection.storageSlotIdentifier; + final Address address = storageSlotIdentifier.getAddress(); + final EWord storageKey = storageSlotIdentifier.getStorageKey(); + final EWord valueOriginal = + hub.txStack().current().getStorage().getOriginalValueOrUpdate(address, storageKey); + final EWord valueCurrent = sstoreSection.valueCurrent; + final EWord valueNext = sstoreSection.valueNext; + + final boolean staticContextException = hub.pch().exceptions().staticException(); + final boolean sstoreException = hub.pch().exceptions().sstoreException(); + final boolean outOfGasException = hub.pch().exceptions().outOfGasException(); + final boolean contextWillRevert = hub.callStack().current().willRevert(); + + ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); + sstoreSection.addFragmentsAndStack( + hub, hub.currentFrame(), readCurrentContext); + + // TODO: make sure we trace a context when there is an exception + if (staticContextException) { + sstoreSection.nonStackRows = 2; + return; + } - private static SstoreSection unrevertedSstoreSection(Hub hub) { - return new SstoreSection(); + ImcFragment miscForSstore = ImcFragment.forOpcode(hub, hub.messageFrame()); + sstoreSection.addFragment(hub, hub.currentFrame(), miscForSstore); + + // TODO: make sure we trace a context when there is an exception + if (sstoreException) { + sstoreSection.nonStackRows = 3; + return; + } + + StorageFragment doingSstore = + doingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); + StorageFragment undoingSstore = + undoingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); + + sstoreSection.addFragment(hub, hub.currentFrame(), doingSstore); + + // TODO: make sure we trace a context when there is an exception (oogx case) + if (outOfGasException || contextWillRevert) { + sstoreSection.addFragment(hub, hub.currentFrame(), undoingSstore); + sstoreSection.nonStackRows = (short) (4 + (hub.pch().exceptions().any() ? 1 :0)); + return; + } + + sstoreSection.nonStackRows = 3; } - public SstoreSection(Hub hub, final TraceFragment... chunks) { - this.addFragmentsAndStack(hub, chunks); + private static StorageFragment doingSstore( + Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent, EWord valueNext) { + + return new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + address, hub.currentFrame().accountDeploymentNumber(), storageKey), + valueOriginal, + valueCurrent, + valueNext, + hub.currentFrame().frame().isStorageWarm(address, storageKey), + true, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0), + hub.state.firstAndLastStorageSlotOccurrences.size()); } - public void addFragment(Hub hub, final TraceFragment fragment) { - this.addFragmentsWithoutStack(hub, fragment); + private static StorageFragment undoingSstore( + Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent, EWord valueNext) { + + return new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + address, hub.currentFrame().accountDeploymentNumber(), storageKey), + valueOriginal, + valueNext, + valueCurrent, + true, + hub.currentFrame().frame().isStorageWarm(address, storageKey), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), + hub.state.firstAndLastStorageSlotOccurrences.size()); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java index 78853083ef..1755967d90 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java @@ -42,11 +42,11 @@ public final class Exceptions { private boolean stackUnderflow; private boolean stackOverflow; private boolean outOfMemoryExpansion; - private boolean outOfGas; + private boolean outOfGasException; private boolean returnDataCopyFault; private boolean jumpFault; - private boolean staticFault; - private boolean outOfSStore; + private boolean staticException; + private boolean sstoreException; private boolean invalidCodePrefix; private boolean codeSizeOverflow; @@ -55,22 +55,22 @@ public final class Exceptions { * @param stackUnderflow stack underflow * @param stackOverflow stack overflow * @param outOfMemoryExpansion tried to use memory too far away - * @param outOfGas not enough gas for instruction + * @param outOfGasException not enough gas for instruction * @param returnDataCopyFault trying to read pas the RETURNDATA end * @param jumpFault jumping to an invalid destination - * @param staticFault trying to execute a non-static instruction in a static context - * @param outOfSStore not enough gas to execute an SSTORE + * @param staticException trying to execute a non-static instruction in a static context + * @param sstoreException not enough gas to execute an SSTORE */ public Exceptions( boolean invalidOpcode, boolean stackUnderflow, boolean stackOverflow, boolean outOfMemoryExpansion, - boolean outOfGas, + boolean outOfGasException, boolean returnDataCopyFault, boolean jumpFault, - boolean staticFault, - boolean outOfSStore, + boolean staticException, + boolean sstoreException, boolean invalidCodePrefix, boolean codeSizeOverflow) { this.hub = null; @@ -78,11 +78,11 @@ public Exceptions( this.stackUnderflow = stackUnderflow; this.stackOverflow = stackOverflow; this.outOfMemoryExpansion = outOfMemoryExpansion; - this.outOfGas = outOfGas; + this.outOfGasException = outOfGasException; this.returnDataCopyFault = returnDataCopyFault; this.jumpFault = jumpFault; - this.staticFault = staticFault; - this.outOfSStore = outOfSStore; + this.staticException = staticException; + this.sstoreException = sstoreException; this.invalidCodePrefix = invalidCodePrefix; this.codeSizeOverflow = codeSizeOverflow; } @@ -101,7 +101,7 @@ public String toString() { if (this.outOfMemoryExpansion) { return "Out of MXP"; } - if (this.outOfGas) { + if (this.outOfGasException) { return "Out of gas"; } if (this.returnDataCopyFault) { @@ -110,10 +110,10 @@ public String toString() { if (this.jumpFault) { return "JMP fault"; } - if (this.staticFault) { + if (this.staticException) { return "Static fault"; } - if (this.outOfSStore) { + if (this.sstoreException) { return "Out of SSTORE"; } if (this.invalidCodePrefix) { @@ -130,11 +130,11 @@ public void reset() { this.stackUnderflow = false; this.stackOverflow = false; this.outOfMemoryExpansion = false; - this.outOfGas = false; + this.outOfGasException = false; this.returnDataCopyFault = false; this.jumpFault = false; - this.staticFault = false; - this.outOfSStore = false; + this.staticException = false; + this.sstoreException = false; this.invalidCodePrefix = false; this.codeSizeOverflow = false; } @@ -160,11 +160,11 @@ public Exceptions snapshot() { stackUnderflow, stackOverflow, outOfMemoryExpansion, - outOfGas, + outOfGasException, returnDataCopyFault, jumpFault, - staticFault, - outOfSStore, + staticException, + sstoreException, invalidCodePrefix, codeSizeOverflow); } @@ -177,11 +177,11 @@ public boolean any() { || this.stackUnderflow || this.stackOverflow || this.outOfMemoryExpansion - || this.outOfGas + || this.outOfGasException || this.returnDataCopyFault || this.jumpFault - || this.staticFault - || this.outOfSStore + || this.staticException + || this.sstoreException || this.invalidCodePrefix || this.codeSizeOverflow; } @@ -318,8 +318,8 @@ public void prepare(final MessageFrame frame, GasProjector gp) { return; } - this.staticFault = isStaticFault(frame, opCodeData); - if (this.staticFault) { + this.staticException = isStaticFault(frame, opCodeData); + if (this.staticException) { return; } @@ -355,8 +355,8 @@ public void prepare(final MessageFrame frame, GasProjector gp) { return; } - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { + this.outOfGasException = isOutOfGas(frame, opCode, gp); + if (this.outOfGasException) { return; } } @@ -371,15 +371,15 @@ public void prepare(final MessageFrame frame, GasProjector gp) { return; } - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { + this.outOfGasException = isOutOfGas(frame, opCode, gp); + if (this.outOfGasException) { return; } } case STOP -> {} case JUMP, JUMPI -> { - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { + this.outOfGasException = isOutOfGas(frame, opCode, gp); + if (this.outOfGasException) { return; } @@ -389,19 +389,19 @@ public void prepare(final MessageFrame frame, GasProjector gp) { } } case SSTORE -> { - this.outOfSStore = isOutOfSStore(frame, opCode); - if (this.outOfSStore) { + this.sstoreException = isOutOfSStore(frame, opCode); + if (this.sstoreException) { return; } - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { + this.outOfGasException = isOutOfGas(frame, opCode, gp); + if (this.outOfGasException) { return; } } default -> { - this.outOfGas = isOutOfGas(frame, opCode, gp); - if (this.outOfGas) { + this.outOfGasException = isOutOfGas(frame, opCode, gp); + if (this.outOfGasException) { return; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index 8e7f575fed..f9911f823a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -142,20 +142,20 @@ public void prepare(MessageFrame frame, PlatformController platformController, H switch (opCode) { case CALLDATACOPY, CODECOPY -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); + this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); this.mmu = ex.none() && !frame.getStackItem(2).isZero(); } case RETURNDATACOPY -> { this.oob = ex.none() || ex.returnDataCopyFault(); - this.mxp = ex.none() || ex.outOfMemoryExpansion() || ex.outOfGas(); + this.mxp = ex.none() || ex.outOfMemoryExpansion() || ex.outOfGasException(); this.mmu = ex.none() && !frame.getStackItem(2).isZero(); } case EXTCODECOPY -> { final boolean nonzeroSize = !frame.getStackItem(3).isZero(); - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); - this.trm = ex.outOfGas() || ex.none(); + this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); + this.trm = ex.outOfGasException() || ex.none(); this.mmu = ex.none() && nonzeroSize; final Address address = Words.toAddress(frame.getStackItem(0)); @@ -168,7 +168,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H } case LOG0, LOG1, LOG2, LOG3, LOG4 -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); + this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); this.mmu = ex.none() && !frame @@ -179,10 +179,10 @@ public void prepare(MessageFrame frame, PlatformController platformController, H } case CALL, DELEGATECALL, STATICCALL, CALLCODE -> { - this.mxp = !ex.staticFault(); - this.stp = ex.outOfGas() || ex.none(); - this.oob = opCode.equals(OpCode.CALL) && ex.staticFault() || ex.none(); - this.trm = ex.outOfGas() || ex.none(); + this.mxp = !ex.staticException(); + this.stp = ex.outOfGasException() || ex.none(); + this.oob = opCode.equals(OpCode.CALL) && ex.staticException() || ex.none(); + this.trm = ex.outOfGasException() || ex.none(); final boolean triggersAbortingCondition = ex.none() && this.platformController.abortingConditions().any(); @@ -213,8 +213,8 @@ public void prepare(MessageFrame frame, PlatformController platformController, H final boolean nonzeroSize = !frame.getStackItem(2).isZero(); final boolean isCreate2 = opCode == OpCode.CREATE2; - this.mxp = !ex.staticFault(); - this.stp = ex.outOfGas() || ex.none(); + this.mxp = !ex.staticException(); + this.stp = ex.outOfGasException() || ex.none(); this.oob = ex.none(); this.rlpAddr = ex.none() && !triggersAbortingCondition; this.hashInfo = ex.none() && !triggersAbortingCondition && nonzeroSize && isCreate2; @@ -224,7 +224,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H } case REVERT -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGas() || ex.none(); + this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); this.mmu = ex.none() && !frame.getStackItem(1).isZero() @@ -237,7 +237,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H // WARN: Static part, other modules may be dynamically requested in the hub this.mxp = - ex.outOfMemoryExpansion() || ex.outOfGas() || ex.invalidCodePrefix() || ex.none(); + ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.invalidCodePrefix() || ex.none(); this.oob = isDeployment && (ex.codeSizeOverflow() || ex.none()); this.mmu = (isDeployment && ex.invalidCodePrefix()) @@ -251,17 +251,17 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case EXP -> { this.exp = true; - this.mul = !ex.outOfGas(); + this.mul = !ex.outOfGasException(); } // other opcodes - case ADD, SUB -> this.add = !ex.outOfGas(); - case MUL -> this.mul = !ex.outOfGas(); - case DIV, SDIV, MOD, SMOD -> this.mod = !ex.outOfGas(); - case ADDMOD, MULMOD -> this.ext = !ex.outOfGas(); - case LT, GT, SLT, SGT, EQ, ISZERO -> this.wcp = !ex.outOfGas(); - case AND, OR, XOR, NOT, SIGNEXTEND, BYTE -> this.bin = !ex.outOfGas(); - case SHL, SHR, SAR -> this.shf = !ex.outOfGas(); + case ADD, SUB -> this.add = !ex.outOfGasException(); + case MUL -> this.mul = !ex.outOfGasException(); + case DIV, SDIV, MOD, SMOD -> this.mod = !ex.outOfGasException(); + case ADDMOD, MULMOD -> this.ext = !ex.outOfGasException(); + case LT, GT, SLT, SGT, EQ, ISZERO -> this.wcp = !ex.outOfGasException(); + case AND, OR, XOR, NOT, SIGNEXTEND, BYTE -> this.bin = !ex.outOfGasException(); + case SHL, SHR, SAR -> this.shf = !ex.outOfGasException(); case SHA3 -> { this.mxp = true; this.hashInfo = ex.none() && !frame.getStackItem(1).isZero(); From 9e3e4c371f646ffd2fe44d5e0cced24cacdd0446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 10 Jun 2024 08:49:03 +0200 Subject: [PATCH 084/461] seal now computes NSR and COUNTER_NSR correctly --- .../linea/zktracer/module/hub/Hub.java | 88 ++++++++----------- .../linea/zktracer/module/hub/TxTrace.java | 4 +- .../module/hub/fragment/CommonFragment.java | 11 ++- .../module/hub/section/AccountSection.java | 3 - .../module/hub/section/ContextLogSection.java | 3 - .../module/hub/section/CopySection.java | 3 - .../module/hub/section/JumpSection.java | 3 - .../module/hub/section/SloadSection.java | 5 +- .../module/hub/section/SstoreSection.java | 74 ++++++++-------- .../module/hub/section/StackOnlySection.java | 3 - .../zktracer/module/hub/section/StackRam.java | 3 - .../module/hub/section/StopSection.java | 5 -- .../module/hub/section/TraceSection.java | 27 ++---- .../hub/section/TransactionSection.java | 3 - .../module/hub/signals/Exceptions.java | 6 +- .../zktracer/module/hub/signals/Signals.java | 5 +- zkevm-constraints | 2 +- 17 files changed, 99 insertions(+), 149 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 20545b6153..5de8bf2937 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -51,7 +51,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; -import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.section.*; import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; @@ -189,7 +188,6 @@ public void addFragmentsAndStack(TraceFragment... fragments) { } public void addTraceSection(TraceSection section) { - section.seal(this); this.state.currentTxTrace().add(section); } @@ -1297,57 +1295,41 @@ void traceOperation(MessageFrame frame) { case SSTORE -> { SstoreSection.appendSection(this); /** - final EWord valNext = EWord.of(frame.getStackItem(1)); - - // doing the SSTORE operation - final StorageFragment doingStorageFragment = - new StorageFragment( - this.state, - new State.StorageSlotIdentifier( - address, this.currentFrame().accountDeploymentNumber(), key), - this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - EWord.of(frame.getTransientStorageValue(address, key)), - valNext, - frame.isStorageWarm(address, key), - true, - DomSubStampsSubFragment.standardDomSubStamps(this, 0), - this.state.firstAndLastStorageSlotOccurrences.size()); - - final SstoreSection SStoreSection = - new SstoreSection( - this, ContextFragment.readCurrentContextData(this), doingStorageFragment); - - // undoing the previous changes (value + warmth) if current context will revert - if (this.pch.exceptions().staticException()) { - // TODO: make sure that whenever we enounter an exception _of any kind_ - // we trace the final context row where we update the caller return data - // to be empty. - SStoreSection.nonStackRows = 1 + 1; - } else if (this.callStack().current().willRevert()) { - SStoreSection.nonStackRows = (short) (1 + 2 + (this.pch.exceptions().any() ? 1 : 0)); - final StorageFragment undoingStorageFragment = - new StorageFragment( - this.state, - new State.StorageSlotIdentifier( - address, this.currentFrame().accountDeploymentNumber(), key), - this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - valNext, - EWord.of(frame.getTransientStorageValue(address, key)), - true, - frame.isStorageWarm(address, key), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), - this.state.firstAndLastStorageSlotOccurrences.size()); - - SStoreSection.addFragment(this, undoingStorageFragment); - state.updateOrInsertStorageSlotOccurrence( - storageSlotIdentifier, undoingStorageFragment); - } else { - SStoreSection.nonStackRows = 1 + 1; - state.updateOrInsertStorageSlotOccurrence( - storageSlotIdentifier, doingStorageFragment); - } - - this.addTraceSection(SStoreSection); + * final EWord valNext = EWord.of(frame.getStackItem(1)); + * + *

// doing the SSTORE operation final StorageFragment doingStorageFragment = new + * StorageFragment( this.state, new State.StorageSlotIdentifier( address, + * this.currentFrame().accountDeploymentNumber(), key), + * this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), + * EWord.of(frame.getTransientStorageValue(address, key)), valNext, + * frame.isStorageWarm(address, key), true, + * DomSubStampsSubFragment.standardDomSubStamps(this, 0), + * this.state.firstAndLastStorageSlotOccurrences.size()); + * + *

final SstoreSection SStoreSection = new SstoreSection( this, + * ContextFragment.readCurrentContextData(this), doingStorageFragment); + * + *

// undoing the previous changes (value + warmth) if current context will revert if + * (this.pch.exceptions().staticException()) { // TODO: make sure that whenever we + * enounter an exception _of any kind_ // we trace the final context row where we update + * the caller return data // to be empty. SStoreSection.nonStackRows = 1 + 1; } else if + * (this.callStack().current().willRevert()) { SStoreSection.nonStackRows = (short) (1 + + * 2 + (this.pch.exceptions().any() ? 1 : 0)); final StorageFragment + * undoingStorageFragment = new StorageFragment( this.state, new + * State.StorageSlotIdentifier( address, this.currentFrame().accountDeploymentNumber(), + * key), this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), + * valNext, EWord.of(frame.getTransientStorageValue(address, key)), true, + * frame.isStorageWarm(address, key), + * DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), + * this.state.firstAndLastStorageSlotOccurrences.size()); + * + *

SStoreSection.addFragment(this, undoingStorageFragment); + * state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, + * undoingStorageFragment); } else { SStoreSection.nonStackRows = 1 + 1; + * state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, + * doingStorageFragment); } + * + *

this.addTraceSection(SStoreSection); */ } case SLOAD -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 45d5e7145e..90763fc26e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -93,9 +93,9 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces */ public void commit(Trace hubTrace) { for (TraceSection opSection : this.trace) { + opSection.seal(); for (TraceSection.TraceLine line : opSection.lines()) { - line.trace( - hubTrace, opSection.stackHeight(), opSection.stackHeightNew(), opSection.nonStackRows); + line.trace(hubTrace, opSection.stackHeight(), opSection.stackHeightNew()); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index d336ad0203..e8b697364a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -69,7 +69,11 @@ public final class CommonFragment implements TraceFragment { @Getter @Setter private int nonStackRowsCounter; public static CommonFragment fromHub( - final Hub hub, final CallFrame frame, boolean counterTli, int counterNsr) { + final Hub hub, + final CallFrame frame, + boolean counterTli, + int counterNsr, + int numberOfNonStackRows) { final boolean noStackException = hub.pch().exceptions().noStackException(); final long refundDelta = @@ -125,6 +129,7 @@ public static CommonFragment fromHub( .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) .twoLineInstructionCounter(counterTli) .nonStackRowsCounter(counterNsr) + .numberOfNonStackRows(numberOfNonStackRows) .build(); } @@ -174,7 +179,7 @@ public Trace trace(Trace trace) { throw new UnsupportedOperationException("should never be called"); } - public Trace trace(Trace trace, int stackHeight, int stackHeightNew, short nonStackRows) { + public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final CallFrame frame = this.hub.callStack().getById(this.callFrameId); final TransactionProcessingMetadata tx = hub.txStack().getByAbsoluteTransactionNumber(this.absoluteTransactionNumber); @@ -231,7 +236,7 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew, short nonSt .refundCounterNew(gasRefund + (willRevert ? 0 : refundDelta)) .twoLineInstruction(twoLineInstruction) .counterTli(twoLineInstructionCounter) - .nonStackRows(nonStackRows) + .nonStackRows((short) numberOfNonStackRows) .counterNsr((short) nonStackRowsCounter); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index ae9aa540e4..d4d595b806 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -22,7 +22,4 @@ public class AccountSection extends TraceSection { public AccountSection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - - @Override - public void seal(Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java index 49fca78ed9..a9ca7cde22 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java @@ -22,7 +22,4 @@ public class ContextLogSection extends TraceSection { public ContextLogSection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - - @Override - public void seal(Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java index 9f7f0f1a35..f282066d9f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java @@ -22,7 +22,4 @@ public class CopySection extends TraceSection { public CopySection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - - @Override - public void seal(Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index dff6887799..fc4c2a6d63 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -22,7 +22,4 @@ public class JumpSection extends TraceSection { public JumpSection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - - @Override - public void seal(Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index c909b13d99..849f20c53a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -54,8 +54,7 @@ public static void appendSection(Hub hub) { ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); ImcFragment miscFragmentForSload = ImcFragment.empty(hub); - StorageFragment doingSload = - doingSload(hub, address, storageKey, valueOriginal, valueCurrent); + StorageFragment doingSload = doingSload(hub, address, storageKey, valueOriginal, valueCurrent); sloadSection.addFragmentsAndStack( hub, hub.currentFrame(), readCurrentContext, miscFragmentForSload, doingSload); @@ -69,14 +68,12 @@ public static void appendSection(Hub hub) { undoingSload(hub, address, storageKey, valueOriginal, valueCurrent); // TODO: make sure we trace a context when there is an exception - sloadSection.nonStackRowCounter = outOfGasException ? 5 : 4; sloadSection.addFragment(hub, hub.currentFrame(), undoingSload); hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, undoingSload); return; } hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingSload); - sloadSection.nonStackRows = 3; } private static StorageFragment doingSload( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index fc3b67f51f..307f6df964 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -51,7 +51,7 @@ private SstoreSection(Hub hub) { Address address = hub.currentFrame().accountAddress(); EWord key = EWord.of(hub.messageFrame().getStackItem(0)); this.storageSlotIdentifier = - new State.StorageSlotIdentifier(address, hub.currentFrame().accountDeploymentNumber(), key); + new State.StorageSlotIdentifier(address, hub.currentFrame().accountDeploymentNumber(), key); this.valueCurrent = EWord.of(hub.messageFrame().getTransientStorageValue(address, key)); this.valueNext = EWord.of(hub.messageFrame().getStackItem(1)); } @@ -65,7 +65,7 @@ public static void appendSection(Hub hub) { final Address address = storageSlotIdentifier.getAddress(); final EWord storageKey = storageSlotIdentifier.getStorageKey(); final EWord valueOriginal = - hub.txStack().current().getStorage().getOriginalValueOrUpdate(address, storageKey); + hub.txStack().current().getStorage().getOriginalValueOrUpdate(address, storageKey); final EWord valueCurrent = sstoreSection.valueCurrent; final EWord valueNext = sstoreSection.valueNext; @@ -75,12 +75,10 @@ public static void appendSection(Hub hub) { final boolean contextWillRevert = hub.callStack().current().willRevert(); ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); - sstoreSection.addFragmentsAndStack( - hub, hub.currentFrame(), readCurrentContext); + sstoreSection.addFragmentsAndStack(hub, hub.currentFrame(), readCurrentContext); // TODO: make sure we trace a context when there is an exception if (staticContextException) { - sstoreSection.nonStackRows = 2; return; } @@ -89,59 +87,61 @@ public static void appendSection(Hub hub) { // TODO: make sure we trace a context when there is an exception if (sstoreException) { - sstoreSection.nonStackRows = 3; return; } StorageFragment doingSstore = - doingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); + doingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); StorageFragment undoingSstore = - undoingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); + undoingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); sstoreSection.addFragment(hub, hub.currentFrame(), doingSstore); // TODO: make sure we trace a context when there is an exception (oogx case) if (outOfGasException || contextWillRevert) { sstoreSection.addFragment(hub, hub.currentFrame(), undoingSstore); - sstoreSection.nonStackRows = (short) (4 + (hub.pch().exceptions().any() ? 1 :0)); - return; } - - sstoreSection.nonStackRows = 3; } private static StorageFragment doingSstore( - Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent, EWord valueNext) { + Hub hub, + Address address, + EWord storageKey, + EWord valueOriginal, + EWord valueCurrent, + EWord valueNext) { return new StorageFragment( - hub.state, - new State.StorageSlotIdentifier( - address, hub.currentFrame().accountDeploymentNumber(), storageKey), - valueOriginal, - valueCurrent, - valueNext, - hub.currentFrame().frame().isStorageWarm(address, storageKey), - true, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0), - hub.state.firstAndLastStorageSlotOccurrences.size()); + hub.state, + new State.StorageSlotIdentifier( + address, hub.currentFrame().accountDeploymentNumber(), storageKey), + valueOriginal, + valueCurrent, + valueNext, + hub.currentFrame().frame().isStorageWarm(address, storageKey), + true, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0), + hub.state.firstAndLastStorageSlotOccurrences.size()); } private static StorageFragment undoingSstore( - Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent, EWord valueNext) { + Hub hub, + Address address, + EWord storageKey, + EWord valueOriginal, + EWord valueCurrent, + EWord valueNext) { return new StorageFragment( - hub.state, - new State.StorageSlotIdentifier( - address, hub.currentFrame().accountDeploymentNumber(), storageKey), - valueOriginal, - valueNext, - valueCurrent, - true, - hub.currentFrame().frame().isStorageWarm(address, storageKey), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), - hub.state.firstAndLastStorageSlotOccurrences.size()); + hub.state, + new State.StorageSlotIdentifier( + address, hub.currentFrame().accountDeploymentNumber(), storageKey), + valueOriginal, + valueNext, + valueCurrent, + true, + hub.currentFrame().frame().isStorageWarm(address, storageKey), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), + hub.state.firstAndLastStorageSlotOccurrences.size()); } - - @Override - public void seal(Hub hub) {} } 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 29e6e710da..35ec4baa13 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 @@ -22,7 +22,4 @@ public class StackOnlySection extends TraceSection { public StackOnlySection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - - @Override - public void seal(Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java index a0923a0960..4a0afc2e71 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java @@ -22,7 +22,4 @@ public class StackRam extends TraceSection { public StackRam(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - - @Override - public void seal(Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index 6ed5511a64..dd32b0b295 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -43,7 +43,6 @@ public StopSection(Hub hub, TraceFragment... fragments) { public static StopSection messageCallStopSection(Hub hub) { StopSection messageCallStopSetion = new StopSection(hub, readCurrentContextData(hub), executionProvidesEmptyReturnData(hub)); - messageCallStopSetion.nonStackRows = 2; return messageCallStopSetion; } @@ -81,12 +80,8 @@ public static StopSection deploymentStopSection(Hub hub) { beforeEmptyDeployment, DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1)), executionProvidesEmptyReturnData(hub)); - - stopWhileDeploying.nonStackRows = 4; } else { stopWhileDeploying.addFragmentsWithoutStack(hub, executionProvidesEmptyReturnData(hub)); - - stopWhileDeploying.nonStackRows = 3; } return stopWhileDeploying; 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 3ed08d92d7..950b4f0b0a 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 @@ -29,7 +29,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.CommonFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.stack.StackLine; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -54,11 +53,11 @@ public record TraceLine(CommonFragment common, TraceFragment specific) { * @param trace where to trace the line * @return the trace builder */ - public Trace trace(Trace trace, int stackInt, int stackHeight, short nonStackRows) { + public Trace trace(Trace trace, int stackInt, int stackHeight) { Preconditions.checkNotNull(common); Preconditions.checkNotNull(specific); - common.trace(trace, stackInt, stackHeight, nonStackRows); + common.trace(trace, stackInt, stackHeight); specific.trace(trace); return trace.fillAndValidateRow(); @@ -70,7 +69,7 @@ public Trace trace(Trace trace, int stackInt, int stackHeight, short nonStackRow /** Count the non-stack lines */ public int nonStackRowCounter; - @Setter public short nonStackRows; + public int numberOfNonStackRows; @Getter @Setter private TxTrace parentTrace; @@ -83,7 +82,8 @@ public Trace trace(Trace trace, int stackInt, int stackHeight, short nonStackRow * @return a {@link CommonFragment} representing the shared columns */ private CommonFragment traceCommon(Hub hub, CallFrame frame) { - return CommonFragment.fromHub(hub, frame, this.stackRowCounter == 2, this.nonStackRowCounter); + return CommonFragment.fromHub( + hub, frame, this.stackRowCounter == 2, this.nonStackRowCounter, this.numberOfNonStackRows); } /** Default creator for an empty section. */ @@ -97,15 +97,6 @@ public TraceSection() {} */ public final void addFragment(Hub hub, CallFrame callFrame, TraceFragment fragment) { Preconditions.checkArgument(!(fragment instanceof CommonFragment)); - - if (fragment instanceof StackFragment) { - this.stackRowCounter++; - } else if (fragment instanceof TransactionFragment f) { - f.setParentSection(this); - } else { - this.nonStackRowCounter++; - } - this.lines.add(new TraceLine(traceCommon(hub, callFrame), fragment)); } @@ -194,11 +185,9 @@ public final int pc() { /** * This method is called when the TraceSection is finished, to build required information * post-hoc. - * - * @param hub the linked {@link Hub} context */ - public void seal(Hub hub) { - int nonStackLineNumbers = + public void seal() { + int numberOfNonStackRows = (int) this.lines.stream().filter(l -> !(l.specific instanceof StackFragment)).count(); int nonStackLineCounter = 0; for (TraceLine line : this.lines) { @@ -209,7 +198,7 @@ public void seal(Hub hub) { // TODO: delete as both are computed in CommonFragment ... // line.common.pcNew(); // line.common.contextNumberNew(hub.lastContextNumber()); - line.common.numberOfNonStackRows(nonStackLineNumbers); + line.common.numberOfNonStackRows(numberOfNonStackRows); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java index fa65a41bb8..4e235bd859 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java @@ -22,7 +22,4 @@ public class TransactionSection extends TraceSection { public TransactionSection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } - - @Override - public void seal(Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java index 1755967d90..2a01cf19c0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java @@ -160,11 +160,11 @@ public Exceptions snapshot() { stackUnderflow, stackOverflow, outOfMemoryExpansion, - outOfGasException, + outOfGasException, returnDataCopyFault, jumpFault, - staticException, - sstoreException, + staticException, + sstoreException, invalidCodePrefix, codeSizeOverflow); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index f9911f823a..99da6c2919 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -237,7 +237,10 @@ public void prepare(MessageFrame frame, PlatformController platformController, H // WARN: Static part, other modules may be dynamically requested in the hub this.mxp = - ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.invalidCodePrefix() || ex.none(); + ex.outOfMemoryExpansion() + || ex.outOfGasException() + || ex.invalidCodePrefix() + || ex.none(); this.oob = isDeployment && (ex.codeSizeOverflow() || ex.none()); this.mmu = (isDeployment && ex.invalidCodePrefix()) diff --git a/zkevm-constraints b/zkevm-constraints index 061b9448fb..f7d0b9afdc 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 061b9448fb61a8900fe7b62776cdce30e22bf71c +Subproject commit f7d0b9afdce60607c5b2a34d07f90661f2b4093e From efd2a92950767b6c5e1881ceb68f16ceb67a5fdb Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 10 Jun 2024 12:24:34 +0530 Subject: [PATCH 085/461] style: cleaning --- .../module/hub/section/TraceSection.java | 23 +------------------ zkevm-constraints | 2 +- 2 files changed, 2 insertions(+), 23 deletions(-) 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 950b4f0b0a..21c299615b 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 @@ -164,30 +164,12 @@ public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { this.addFragmentsWithoutStack(hub, hub.currentFrame(), fragments); } - /** - * Returns the context number associated with the operation encoded by this TraceLine. - * - * @return the CN - */ - public final int contextNumber() { - return this.lines.get(0).common.contextNumber(); - } - - /** - * Returns the program counter associated with the operation encoded by this TraceSection. - * - * @return the PC - */ - public final int pc() { - return this.lines.get(0).common.pc(); - } - /** * This method is called when the TraceSection is finished, to build required information * post-hoc. */ public void seal() { - int numberOfNonStackRows = + final int numberOfNonStackRows = (int) this.lines.stream().filter(l -> !(l.specific instanceof StackFragment)).count(); int nonStackLineCounter = 0; for (TraceLine line : this.lines) { @@ -195,9 +177,6 @@ public void seal() { nonStackLineCounter++; line.common.nonStackRowsCounter(nonStackLineCounter); } - // TODO: delete as both are computed in CommonFragment ... - // line.common.pcNew(); - // line.common.contextNumberNew(hub.lastContextNumber()); line.common.numberOfNonStackRows(numberOfNonStackRows); } } diff --git a/zkevm-constraints b/zkevm-constraints index f7d0b9afdc..3999fb7ed0 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit f7d0b9afdce60607c5b2a34d07f90661f2b4093e +Subproject commit 3999fb7ed0491ad4e474cd773030d421485c3061 From ab38e26c1be6a2b494d3a6c84703ca17e14d55fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 10 Jun 2024 20:42:45 +0200 Subject: [PATCH 086/461] ras --- .../module/hub/DeploymentExceptions.java | 2 +- .../linea/zktracer/module/hub/Hub.java | 55 ++----------------- .../module/hub/fragment/CommonFragment.java | 4 +- .../module/hub/fragment/ContextFragment.java | 10 ++-- .../module/hub/fragment/imc/ImcFragment.java | 4 +- .../module/hub/fragment/imc/call/MxpCall.java | 2 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 2 +- .../module/hub/section/StopSection.java | 10 +++- .../module/hub/section/TraceSection.java | 4 +- .../linea/zktracer/module/limits/Keccak.java | 2 +- .../linea/zktracer/module/mxp/MxpData.java | 2 +- .../zktracer/runtime/callstack/CallFrame.java | 23 ++++++-- 12 files changed, 47 insertions(+), 73 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentExceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentExceptions.java index 2de9fe2d45..c9233f9f41 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentExceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/DeploymentExceptions.java @@ -46,7 +46,7 @@ public static DeploymentExceptions empty() { public static DeploymentExceptions fromFrame( final CallFrame callFrame, final MessageFrame frame) { - if (callFrame.underDeployment()) { + if (callFrame.isDeployment()) { return new DeploymentExceptions(isInvalidCodePrefix(frame), isCodeSizeOverflow(frame)); } else { return new DeploymentExceptions(false, false); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 5de8bf2937..ae8c97a700 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1124,7 +1124,7 @@ void traceOperation(MessageFrame frame) { } this.currentFrame().returnDataSource(transients.op().returnDataSegment()); this.currentFrame().returnData(returnData); - if (!this.pch.exceptions().any() && !this.currentFrame().underDeployment()) { + if (!this.pch.exceptions().any() && !this.currentFrame().isDeployment()) { parentFrame.latestReturnData(returnData); } else { parentFrame.latestReturnData(Bytes.EMPTY); @@ -1285,56 +1285,9 @@ void traceOperation(MessageFrame frame) { } } case STORAGE -> { - final Address address = this.currentFrame().accountAddress(); - final EWord key = EWord.of(frame.getStackItem(0)); - - final State.StorageSlotIdentifier storageSlotIdentifier = - new State.StorageSlotIdentifier(address, currentFrame().accountDeploymentNumber(), key); - switch (this.currentFrame().opCode()) { - case SSTORE -> { - SstoreSection.appendSection(this); - /** - * final EWord valNext = EWord.of(frame.getStackItem(1)); - * - *

// doing the SSTORE operation final StorageFragment doingStorageFragment = new - * StorageFragment( this.state, new State.StorageSlotIdentifier( address, - * this.currentFrame().accountDeploymentNumber(), key), - * this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - * EWord.of(frame.getTransientStorageValue(address, key)), valNext, - * frame.isStorageWarm(address, key), true, - * DomSubStampsSubFragment.standardDomSubStamps(this, 0), - * this.state.firstAndLastStorageSlotOccurrences.size()); - * - *

final SstoreSection SStoreSection = new SstoreSection( this, - * ContextFragment.readCurrentContextData(this), doingStorageFragment); - * - *

// undoing the previous changes (value + warmth) if current context will revert if - * (this.pch.exceptions().staticException()) { // TODO: make sure that whenever we - * enounter an exception _of any kind_ // we trace the final context row where we update - * the caller return data // to be empty. SStoreSection.nonStackRows = 1 + 1; } else if - * (this.callStack().current().willRevert()) { SStoreSection.nonStackRows = (short) (1 + - * 2 + (this.pch.exceptions().any() ? 1 : 0)); final StorageFragment - * undoingStorageFragment = new StorageFragment( this.state, new - * State.StorageSlotIdentifier( address, this.currentFrame().accountDeploymentNumber(), - * key), this.txStack.current().getStorage().getOriginalValueOrUpdate(address, key), - * valNext, EWord.of(frame.getTransientStorageValue(address, key)), true, - * frame.isStorageWarm(address, key), - * DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 1), - * this.state.firstAndLastStorageSlotOccurrences.size()); - * - *

SStoreSection.addFragment(this, undoingStorageFragment); - * state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, - * undoingStorageFragment); } else { SStoreSection.nonStackRows = 1 + 1; - * state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, - * doingStorageFragment); } - * - *

this.addTraceSection(SStoreSection); - */ - } - case SLOAD -> { - SloadSection.appendSection(this); - } + case SSTORE -> { SstoreSection.appendSection(this); } + case SLOAD -> { SloadSection.appendSection(this); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); } } @@ -1495,7 +1448,7 @@ void traceOperation(MessageFrame frame) { .conflation() .deploymentInfo() .number(this.currentFrame().byteCodeAddress()), - this.currentFrame().underDeployment()); + this.currentFrame().isDeployment()); JumpSection jumpSection = new JumpSection( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index e8b697364a..e9a803808f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -119,7 +119,7 @@ public static CommonFragment fromHub( .height((short) height) .heightNew((short) heightNew) .codeDeploymentNumber(frame.codeDeploymentNumber()) - .codeDeploymentStatus(frame.underDeployment()) + .codeDeploymentStatus(frame.isDeployment()) .gasExpected(gasExpected) .gasActual(gasActual) .gasCost(gasCost) @@ -186,7 +186,7 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { final int codeFragmentIndex = this.hubProcessingPhase == HubProcessingPhase.TX_EXEC ? this.hub.getCfiByMetaData( - frame.byteCodeAddress(), frame.codeDeploymentNumber(), frame.underDeployment()) + frame.byteCodeAddress(), frame.codeDeploymentNumber(), frame.isDeployment()) : 0; final boolean selfReverts = frame.selfReverts(); final boolean getsReverted = frame.getsReverted(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 60de42761f..b71fa95776 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -20,6 +20,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.opcode.gas.projector.Call; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.runtime.callstack.CallStack; @@ -35,7 +36,7 @@ public record ContextFragment( // Left: callFrameId, Right: contextNumber Either callFrameReference, MemorySpan returnDataSegment, - boolean updateCallerReturndata) + boolean updateReturnData) implements TraceFragment { public static ContextFragment readContextDataByContextNumber( @@ -127,8 +128,9 @@ public Trace trace(Trace trace) { : hub.getCfiByMetaData( Words.toAddress(codeAddress), callFrame.codeDeploymentNumber(), - callFrame.underDeployment()); + callFrame.isDeployment()); + hub.callStack().parent().returnDataContextNumber(); return trace .peekAtContext(true) .pContextContextNumber(callFrame.contextNumber()) @@ -141,7 +143,7 @@ public Trace trace(Trace trace) { .pContextByteCodeAddressHi(highPart(codeAddress)) .pContextByteCodeAddressLo(lowPart(codeAddress)) .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) - .pContextByteCodeDeploymentStatus(callFrame.underDeployment() ? 1 : 0) + .pContextByteCodeDeploymentStatus(callFrame.isDeployment() ? 1 : 0) .pContextByteCodeCodeFragmentIndex(cfi) .pContextCallerAddressHi(highPart(callerAddress)) .pContextCallerAddressLo(lowPart(callerAddress)) @@ -151,7 +153,7 @@ public Trace trace(Trace trace) { .pContextCallDataSize(callFrame.callDataInfo().memorySpan().length()) .pContextReturnAtOffset(callFrame.requestedReturnDataTarget().offset()) .pContextReturnAtCapacity(callFrame.requestedReturnDataTarget().length()) - .pContextUpdate(updateCallerReturndata) + .pContextUpdate(updateReturnData) .pContextReturnDataContextNumber( callFrame.id() == 0 ? callFrame.universalParentReturnDataContextNumber diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 77e8e7016b..fca3654423 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -197,7 +197,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { case LOG0, LOG1, LOG2, LOG3, LOG4 -> r.callMmu(MmuCall.log(hub)); case CREATE -> r.callMmu(MmuCall.create(hub)); case RETURN -> r.callMmu( - hub.currentFrame().underDeployment() + hub.currentFrame().isDeployment() ? MmuCall.returnFromDeployment( hub) // TODO Add a MMU call to MMU_INST_INVALID_CODE8PREFIX : MmuCall.returnFromCall(hub)); @@ -234,7 +234,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { hub.pch().abortingConditions().any())); } case RETURN -> { - if (hub.currentFrame().underDeployment()) { + if (hub.currentFrame().isDeployment()) { r.callOob(new DeploymentReturn(EWord.of(frame.getStackItem(1)))); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index 65796cc230..6f0522edfa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -48,7 +48,7 @@ public static MxpCall build(Hub hub) { return new MxpCall( hub.pch().exceptions().outOfMemoryExpansion(), hub.currentFrame().opCodeData().value(), - opCode == OpCode.RETURN && hub.currentFrame().underDeployment(), + opCode == OpCode.RETURN && hub.currentFrame().isDeployment(), hub.currentFrame().frame().memoryWordSize(), gasMxp, offset1, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index b846122368..1b02fbd36e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -230,7 +230,7 @@ public static MmuCall extCodeCopy(final Hub hub) { public static MmuCall returnDataCopy(final Hub hub) { final MemorySpan returnDataSegment = hub.currentFrame().latestReturnDataSource(); return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) - .sourceId(hub.callStack().getById(hub.currentFrame().currentReturner()).contextNumber()) + .sourceId(hub.callStack().getById(hub.currentFrame().returnDataContextNumber()).contextNumber()) .targetId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .targetOffset(EWord.of(hub.messageFrame().getStackItem(0))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index dd32b0b295..87369d0d5f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -23,17 +23,21 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.Bytecode; import org.hyperledger.besu.datatypes.Address; public class StopSection extends TraceSection { public static void appendTo(Hub hub) { - if (!hub.currentFrame().underDeployment()) { + CallFrame.provideParentContextWithEmptyReturnData(hub); + + if (hub.currentFrame().isMessageCall()) { hub.addTraceSection(messageCallStopSection(hub)); - } else if (hub.currentFrame().willRevert()) { - hub.addTraceSection(deploymentStopSection(hub)); + return; } + + hub.addTraceSection(deploymentStopSection(hub)); } public StopSection(Hub hub, TraceFragment... fragments) { 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 21c299615b..dd6dadbae8 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 @@ -226,7 +226,7 @@ private List makeStackFragments(final Hub hub, CallFrame f) { hub.pch().exceptions().snapshot(), hub.pch().abortingConditions().snapshot(), Hub.GAS_PROJECTOR.of(f.frame(), f.opCode()), - f.underDeployment(), + f.isDeployment(), f.willRevert())); } } else { @@ -239,7 +239,7 @@ private List makeStackFragments(final Hub hub, CallFrame f) { hub.pch().exceptions().snapshot(), hub.pch().abortingConditions().snapshot(), Hub.GAS_PROJECTOR.of(f.frame(), f.opCode()), - f.underDeployment(), + f.isDeployment(), f.willRevert())); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java index 2fe7b9e1b1..0cf1911443 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java @@ -95,7 +95,7 @@ public void tracePreOpcode(final MessageFrame frame) { // Capture contract deployment // TODO: compute the gas cost if we are under deployment. - if (opCode == OpCode.RETURN && hub.currentFrame().underDeployment()) { + if (opCode == OpCode.RETURN && hub.currentFrame().isDeployment()) { callShakira(frame, 0, 1, this.deployedCodeSizes); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpData.java index 430e907dbd..c58de2b7ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpData.java @@ -99,7 +99,7 @@ public MxpData(final MessageFrame frame, final Hub hub) { this.wordsNew = frame.memoryWordSize(); this.cMem = memoryCost(frame.memoryWordSize()); this.cMemNew = memoryCost(frame.memoryWordSize()); - this.deploys = hub.currentFrame().underDeployment(); + this.deploys = hub.currentFrame().isDeployment(); setOffsetsAndSizes(frame); setRoob(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index a09c37198e..f4907c335e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -56,7 +56,11 @@ public class CallFrame { /** */ @Getter private int codeDeploymentNumber; /** */ - @Getter private boolean underDeployment; + @Getter private boolean isDeployment; + + public boolean isMessageCall() { + return !isDeployment; + } @Getter @Setter private TraceSection needsUnlatchingAtReEntry = null; @@ -110,7 +114,7 @@ public class CallFrame { @Getter private MemorySpan requestedReturnDataTarget = MemorySpan.empty(); /** the latest child context to have been called from this frame */ - @Getter private int currentReturner = -1; + @Getter @Setter private int returnDataContextNumber = -1; @Getter @Setter private int selfRevertsAt = 0; @Getter @Setter private int getsRevertedAt = 0; @@ -120,6 +124,17 @@ public class CallFrame { /** the latched context of this callframe stack. */ @Getter @Setter private StackContext pending; + public static void provideParentContextWithEmptyReturnData(Hub hub) { + updateParentContextReturnData(hub, Bytes.EMPTY, MemorySpan.empty()); + } + + public static void updateParentContextReturnData(Hub hub, Bytes returnData, MemorySpan returnDataSource) { + CallFrame parent = hub.callStack().parent(); + parent.returnDataContextNumber = hub.currentFrame().contextNumber; + parent.latestReturnData = returnData; + parent.returnDataSource(returnDataSource); + } + /** Create a MANTLE call frame. */ CallFrame(final Address origin, final Bytes callData, final int contextNumber) { this.type = CallFrameType.MANTLE; @@ -189,7 +204,7 @@ public class CallFrame { int depth) { this.accountDeploymentNumber = accountDeploymentNumber; this.codeDeploymentNumber = codeDeploymentNumber; - this.underDeployment = isDeployment; + this.isDeployment = isDeployment; this.id = id; this.contextNumber = hubStamp + 1; this.accountAddress = accountAddress; @@ -256,7 +271,7 @@ public Optional lastCallee() { */ public ContractMetadata metadata() { return ContractMetadata.make( - this.byteCodeAddress, this.codeDeploymentNumber, this.underDeployment); + this.byteCodeAddress, this.codeDeploymentNumber, this.isDeployment); } private void revertChildren(CallStack callStack, int stamp) { From 8da56d0311fccd449c8da2d1417fbe532933872e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 11 Jun 2024 00:27:01 +0200 Subject: [PATCH 087/461] SSTORE / SLOAD work --- .../linea/zktracer/module/hub/Hub.java | 10 +- .../module/hub/fragment/ContextFragment.java | 55 ++++--- .../module/hub/fragment/StackFragment.java | 3 +- .../precompiles/PrecompileLinesGenerator.java | 10 +- .../module/hub/section/SstoreSection.java | 15 -- .../module/hub/section/StopSection.java | 2 + .../zktracer/runtime/callstack/CallFrame.java | 13 +- .../linea/zktracer/runtime/stack/Stack.java | 151 ++++++++---------- .../src/main/resources/opcodes.yml | 4 +- zkevm-constraints | 2 +- 10 files changed, 134 insertions(+), 131 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index ae8c97a700..eb9e9a44a9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -494,6 +494,10 @@ void processStateInit(WorldView world) { this.state.setProcessingPhase(TX_EXEC); } + public int newChildContextNumber() { + return 1 + this.stamp(); + } + public CallFrame currentFrame() { if (this.callStack().isEmpty()) { return CallFrame.EMPTY; @@ -507,7 +511,7 @@ public int contextNumberNew(CallFrame frame) { return 0; } case TX_INIT -> { - return this.state.stamps().hub() + 1; + return newChildContextNumber(); } case TX_EXEC -> { final OpCode opCode = this.opCode(); @@ -535,7 +539,7 @@ public int contextNumberNew(CallFrame frame) { .ifPresent( byteCode -> { if (!byteCode.isEmpty()) { - newContext.set(1 + this.stamp()); + newContext.set(newChildContextNumber()); } }); return newContext.get(); @@ -547,7 +551,7 @@ public int contextNumberNew(CallFrame frame) { } final int initCodeSize = this.currentFrame().frame().getStackItem(2).toInt(); if (initCodeSize != 0) { - return 1 + stamp(); + return newChildContextNumber(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index b71fa95776..7f41b70f05 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -20,7 +20,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.opcode.gas.projector.Call; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.runtime.callstack.CallStack; @@ -35,6 +34,7 @@ public record ContextFragment( CallStack callStack, // Left: callFrameId, Right: contextNumber Either callFrameReference, + int returnDataContextNumber, MemorySpan returnDataSegment, boolean updateReturnData) implements TraceFragment { @@ -46,6 +46,7 @@ public static ContextFragment readContextDataByContextNumber( hub, callStack, Either.right(contextNumber), + callStack.getByContextNumber(contextNumber).returnDataContextNumber(), callStack.current().latestReturnDataSource().snapshot(), false); } @@ -56,6 +57,7 @@ public static ContextFragment readContextDataById(final Hub hub, final int conte hub, callStack, Either.left(contextId), + callStack.getById(contextId).returnDataContextNumber(), callStack.current().latestReturnDataSource().snapshot(), false); } @@ -69,21 +71,31 @@ public static ContextFragment initializeExecutionContext(final Hub hub) { hub, hub.callStack(), Either.right(hub.stamp() + 1), - MemorySpan.fromStartEnd( - 0, hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)), + 0, + MemorySpan.fromStartEnd(0, hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)), false); } public static ContextFragment executionProvidesEmptyReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( - hub, callStack, Either.left(callStack.parent().id()), MemorySpan.empty(), true); + hub, + callStack, + Either.left(callStack.parent().id()), + hub.callStack().current().contextNumber(), + MemorySpan.empty(), + true); } public static ContextFragment nonExecutionEmptyReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( - hub, callStack, Either.left(callStack.parent().id()), MemorySpan.empty(), true); + hub, + callStack, + Either.left(callStack.current().id()), + hub.newChildContextNumber(), + MemorySpan.empty(), + true); } public static ContextFragment executionReturnData(final Hub hub) { @@ -92,6 +104,7 @@ public static ContextFragment executionReturnData(final Hub hub) { hub, callStack, Either.left(callStack.parent().id()), + hub.currentFrame().contextNumber(), callStack.current().returnDataSource(), true); } @@ -99,16 +112,22 @@ public static ContextFragment executionReturnData(final Hub hub) { public static ContextFragment enterContext(final Hub hub, final CallFrame calledCallFrame) { CallStack callStack = hub.callStack(); return new ContextFragment( - hub, callStack, Either.left(calledCallFrame.id()), MemorySpan.empty(), false); + hub, + callStack, + Either.left(calledCallFrame.id()), + 0, + MemorySpan.empty(), + false); } - public static ContextFragment providesReturnData(final Hub hub) { + public static ContextFragment providesReturnData(final Hub hub, int receiverContextNumber, int providerContextNumber) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, callStack, - Either.left(callStack.current().id()), - callStack.current().latestReturnDataSource().snapshot(), + Either.right(receiverContextNumber), + providerContextNumber, + callStack.current().latestReturnDataSource().snapshot(), // TODO: is this what we want ? true); } @@ -122,15 +141,7 @@ public Trace trace(Trace trace) { final Address codeAddress = callFrame.byteCodeAddress(); final Address callerAddress = callFrame.callerAddress(); - final int cfi = - callFrame == CallFrame.EMPTY || callFrame.type() == CallFrameType.MANTLE - ? 0 - : hub.getCfiByMetaData( - Words.toAddress(codeAddress), - callFrame.codeDeploymentNumber(), - callFrame.isDeployment()); - hub.callStack().parent().returnDataContextNumber(); return trace .peekAtContext(true) .pContextContextNumber(callFrame.contextNumber()) @@ -144,7 +155,7 @@ public Trace trace(Trace trace) { .pContextByteCodeAddressLo(lowPart(codeAddress)) .pContextByteCodeDeploymentNumber(callFrame.codeDeploymentNumber()) .pContextByteCodeDeploymentStatus(callFrame.isDeployment() ? 1 : 0) - .pContextByteCodeCodeFragmentIndex(cfi) + .pContextByteCodeCodeFragmentIndex(callFrame.getCodeFragmentIndex(hub)) .pContextCallerAddressHi(highPart(callerAddress)) .pContextCallerAddressLo(lowPart(callerAddress)) .pContextCallValue(callFrame.value()) @@ -154,10 +165,10 @@ public Trace trace(Trace trace) { .pContextReturnAtOffset(callFrame.requestedReturnDataTarget().offset()) .pContextReturnAtCapacity(callFrame.requestedReturnDataTarget().length()) .pContextUpdate(updateReturnData) - .pContextReturnDataContextNumber( - callFrame.id() == 0 - ? callFrame.universalParentReturnDataContextNumber - : callFrame.lastCallee().map(c -> callStack.getById(c).contextNumber()).orElse(0)) + .pContextReturnDataContextNumber(returnDataContextNumber) +// callFrame.id() == 0 +// ? callFrame.universalParentReturnDataContextNumber +// : callFrame.lastCallee().map(c -> callStack.getById(c).contextNumber()).orElse(0)) .pContextReturnDataOffset(returnDataSegment.offset()) .pContextReturnDataSize(returnDataSegment.length()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index e261319719..2e9458f557 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -175,8 +175,7 @@ public void feedHashedValue(MessageFrame frame) { private boolean traceLog() { return this.opCode.isLog() && this.exceptions - .none() // TODO: should be redundant (exceptions trigger reverts) --- this could be - // asserted + .none() // TODO: should be redundant (exceptions trigger reverts) --- this could be asserted && !this.willRevert; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index c62383c82c..035db0ca9c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -198,7 +198,7 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 11))); } - r.add(ContextFragment.providesReturnData(hub)); + r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_ADD -> { @@ -220,7 +220,7 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcAdd(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub)); + r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_MUL -> { @@ -242,7 +242,7 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcMul(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub)); + r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_PAIRING -> { @@ -267,7 +267,7 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcPairing(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub)); + r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case BLAKE2F -> { @@ -296,7 +296,7 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add( p.success() - ? ContextFragment.providesReturnData(hub) + ? ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber()) : ContextFragment.nonExecutionEmptyReturnData(hub)); return r; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 307f6df964..f4fd4b00d8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -31,21 +31,6 @@ public class SstoreSection extends TraceSection { final EWord valueCurrent; final EWord valueNext; - public static void appendTo(Hub hub) { - - if (hub.pch().exceptions().staticException()) { - // static exception SSTORE section - } else if (hub.pch().exceptions().sstoreException()) { - // SSTORE specific exception (avaible gas <= G_callstipend = 2300) - } else if (hub.pch().exceptions().outOfGasException()) { - // out of gas exception SSTORE section - } else if (hub.callStack().current().willRevert()) { - // reverted SSTORE section - } else { - // reverted SSTORE section - } - } - private SstoreSection(Hub hub) { this.hub = hub; Address address = hub.currentFrame().accountAddress(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index 87369d0d5f..bdb7a8f8e1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -84,8 +84,10 @@ public static StopSection deploymentStopSection(Hub hub) { beforeEmptyDeployment, DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1)), executionProvidesEmptyReturnData(hub)); + } else { stopWhileDeploying.addFragmentsWithoutStack(hub, executionProvidesEmptyReturnData(hub)); + } return stopWhileDeploying; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index f4907c335e..869ba3476a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -38,6 +38,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; @Accessors(fluent = true) public class CallFrame { @@ -88,6 +89,16 @@ public boolean isMessageCall() { /** the CFI of this frame bytecode if applicable */ @Getter private int codeFragmentIndex = -1; + public int getCodeFragmentIndex(Hub hub) { + return + this == CallFrame.EMPTY || this.type() == CallFrameType.MANTLE + ? 0 + : hub.getCfiByMetaData( + Words.toAddress(this.codeAddressAsEWord()), + this.codeDeploymentNumber(), + this.isDeployment()); + } + @Getter @Setter private int pc; @Getter @Setter private OpCode opCode = OpCode.STOP; @Getter @Setter private OpCodeData opCodeData = OpCodes.of(OpCode.STOP); @@ -114,7 +125,7 @@ public boolean isMessageCall() { @Getter private MemorySpan requestedReturnDataTarget = MemorySpan.empty(); /** the latest child context to have been called from this frame */ - @Getter @Setter private int returnDataContextNumber = -1; + @Getter @Setter private int returnDataContextNumber = 0; @Getter @Setter private int selfRevertsAt = 0; @Getter @Setter private int getsRevertedAt = 0; 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 81f704ef15..14c4e95a66 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 @@ -17,11 +17,14 @@ import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.frame.MessageFrame; +import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; + public class Stack { public static final int MAX_STACK_SIZE = 1024; @@ -47,13 +50,17 @@ public Stack snapshot() { return r; } + private int stackStampWithOffset(int offset) { + return this.stamp + offset; + } + private Bytes getStack(MessageFrame frame, int i) { return frame.getStackItem(i); } private void oneZero(MessageFrame frame, StackContext pending) { Bytes val = getStack(frame, 0); - pending.addLine(new IndexedStackOperation(1, StackOperation.pop(this.height, val, this.stamp))); + pending.addLine(new IndexedStackOperation(1, StackOperation.pop(this.height, val, stackStampWithOffset(0)))); } private void twoZero(MessageFrame frame, StackContext pending) { @@ -61,21 +68,21 @@ private void twoZero(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, 1); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height, val2, this.stamp))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation(2, StackOperation.pop(this.height, val2, stackStampWithOffset(1)))); } private void zeroOne(MessageFrame ignoredFrame, StackContext pending) { pending.addArmingLine( - new IndexedStackOperation(4, StackOperation.push(this.height + 1, this.stamp))); + new IndexedStackOperation(4, StackOperation.push(this.height + 1, stackStampWithOffset(0)))); } private void oneOne(MessageFrame frame, StackContext pending) { Bytes val = getStack(frame, 0); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val, this.stamp)), - new IndexedStackOperation(4, StackOperation.push(this.height, this.stamp + 1))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val, stackStampWithOffset(0))), + new IndexedStackOperation(4, StackOperation.push(this.height, stackStampWithOffset(1)))); } private void twoOne(MessageFrame frame, StackContext pending) { @@ -83,9 +90,9 @@ private void twoOne(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, 1); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, this.stamp + 1)), - new IndexedStackOperation(4, StackOperation.push(this.height - 1, this.stamp + 2))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation(4, StackOperation.push(this.height - 1, stackStampWithOffset(2)))); } private void threeOne(MessageFrame frame, StackContext pending) { @@ -94,27 +101,26 @@ private void threeOne(MessageFrame frame, StackContext pending) { Bytes val3 = getStack(frame, 2); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, this.stamp + 1)), - new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val3, this.stamp + 2)), - new IndexedStackOperation(4, StackOperation.push(this.height - 2, this.stamp + 3))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(2))), + new IndexedStackOperation(4, StackOperation.push(this.height - 2, stackStampWithOffset(3)))); } private void loadStore(MessageFrame frame, StackContext pending) { - if (this.currentOpcodeData.stackSettings().flag3() - || this.currentOpcodeData.stackSettings().flag4()) { + if (this.currentOpcodeData.mnemonic().isAnyOf(OpCode.MSTORE, OpCode.MSTORE8, OpCode.SSTORE)) { Bytes val1 = getStack(frame, 0); Bytes val2 = getStack(frame, 1); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), - new IndexedStackOperation(4, StackOperation.pop(this.height - 1, val2, this.stamp + 1))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation(4, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1)))); } else { Bytes val = getStack(frame, 0); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val, this.stamp)), - new IndexedStackOperation(4, StackOperation.push(this.height, this.stamp + 1))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val, stackStampWithOffset(0))), + new IndexedStackOperation(4, StackOperation.push(this.height, stackStampWithOffset(1)))); } } @@ -123,11 +129,9 @@ private void dup(MessageFrame frame, StackContext pending) { Bytes val = getStack(frame, depth); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - depth, val, this.stamp)), - new IndexedStackOperation( - 2, StackOperation.pushImmediate(this.height - depth, val, this.stamp + 1)), - new IndexedStackOperation( - 4, StackOperation.pushImmediate(this.height + 1, val, this.stamp + 2))); + new IndexedStackOperation(1, StackOperation.pop(this.height - depth, val, stackStampWithOffset(0))), + new IndexedStackOperation( 2, StackOperation.pushImmediate(this.height - depth, val, stackStampWithOffset(1))), + new IndexedStackOperation( 4, StackOperation.pushImmediate(this.height + 1, val, stackStampWithOffset(2)))); } private void swap(MessageFrame frame, StackContext pending) { @@ -136,12 +140,10 @@ private void swap(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, depth); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - depth, val1, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height, val2, this.stamp + 1)), - new IndexedStackOperation( - 3, StackOperation.pushImmediate(this.height - depth, val2, this.stamp + 2)), - new IndexedStackOperation( - 4, StackOperation.pushImmediate(this.height, val1, this.stamp + 3))); + new IndexedStackOperation(1, StackOperation.pop(this.height - depth, val1, stackStampWithOffset(0))), + new IndexedStackOperation(2, StackOperation.pop(this.height, val2, stackStampWithOffset(1))), + new IndexedStackOperation( 3, StackOperation.pushImmediate(this.height - depth, val2, stackStampWithOffset(2))), + new IndexedStackOperation( 4, StackOperation.pushImmediate(this.height, val1, stackStampWithOffset(3)))); } private void log(MessageFrame frame, StackContext pending) { @@ -150,8 +152,8 @@ private void log(MessageFrame frame, StackContext pending) { // Stack line 1 pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, offset, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, size, this.stamp + 1))); + new IndexedStackOperation(1, StackOperation.pop(this.height, offset, stackStampWithOffset(0))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 1, size, stackStampWithOffset(1)))); // Stack line 2 IndexedStackOperation[] line2 = new IndexedStackOperation[] {}; @@ -161,9 +163,7 @@ private void log(MessageFrame frame, StackContext pending) { Bytes topic1 = getStack(frame, 2); line2 = - new IndexedStackOperation[] { - new IndexedStackOperation( - 1, StackOperation.pop(this.height - 2, topic1, this.stamp + 2)), + new IndexedStackOperation[] { new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(0))), }; } case LOG2 -> { @@ -172,10 +172,8 @@ private void log(MessageFrame frame, StackContext pending) { line2 = new IndexedStackOperation[] { - new IndexedStackOperation( - 1, StackOperation.pop(this.height - 2, topic1, this.stamp + 2)), - new IndexedStackOperation( - 2, StackOperation.pop(this.height - 3, topic2, this.stamp + 3)), + new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), + new IndexedStackOperation( 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), }; } case LOG3 -> { @@ -185,12 +183,9 @@ private void log(MessageFrame frame, StackContext pending) { line2 = new IndexedStackOperation[] { - new IndexedStackOperation( - 1, StackOperation.pop(this.height - 2, topic1, this.stamp + 2)), - new IndexedStackOperation( - 2, StackOperation.pop(this.height - 3, topic2, this.stamp + 3)), - new IndexedStackOperation( - 3, StackOperation.pop(this.height - 4, topic3, this.stamp + 4)), + new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), + new IndexedStackOperation( 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), + new IndexedStackOperation( 3, StackOperation.pop(this.height - 4, topic3, stackStampWithOffset(4))), }; } case LOG4 -> { @@ -201,14 +196,10 @@ private void log(MessageFrame frame, StackContext pending) { line2 = new IndexedStackOperation[] { - new IndexedStackOperation( - 1, StackOperation.pop(this.height - 2, topic1, this.stamp + 2)), - new IndexedStackOperation( - 2, StackOperation.pop(this.height - 3, topic2, this.stamp + 3)), - new IndexedStackOperation( - 3, StackOperation.pop(this.height - 4, topic3, this.stamp + 4)), - new IndexedStackOperation( - 4, StackOperation.pop(this.height - 5, topic4, this.stamp + 5)), + new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), + new IndexedStackOperation( 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), + new IndexedStackOperation( 3, StackOperation.pop(this.height - 4, topic3, stackStampWithOffset(4))), + new IndexedStackOperation( 4, StackOperation.pop(this.height - 5, topic4, stackStampWithOffset(5))), }; } default -> throw new RuntimeException("not a LOGx"); @@ -224,9 +215,9 @@ private void copy(MessageFrame frame, StackContext pending) { Bytes val3 = getStack(frame, 3); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 1, val1, this.stamp + 1)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val3, this.stamp + 2)), - new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val2, this.stamp + 3)), + new IndexedStackOperation(1, StackOperation.pop(this.height - 1, val1, stackStampWithOffset(1))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val3, stackStampWithOffset(2))), + new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(3))), new IndexedStackOperation(4, StackOperation.pop(this.height, val0, this.stamp))); } else { Bytes val1 = getStack(frame, 0); @@ -234,9 +225,9 @@ private void copy(MessageFrame frame, StackContext pending) { Bytes val3 = getStack(frame, 1); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp + 1)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 2, val2, this.stamp + 2)), - new IndexedStackOperation(3, StackOperation.pop(this.height - 1, val3, this.stamp + 3))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(1))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(2))), + new IndexedStackOperation(3, StackOperation.pop(this.height - 1, val3, stackStampWithOffset(3)))); } } @@ -255,27 +246,27 @@ private void call(MessageFrame frame, StackContext pending) { Bytes val7 = getStack(frame, 6); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 3, val4, this.stamp + 3)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 4, val5, this.stamp + 4)), - new IndexedStackOperation(3, StackOperation.pop(this.height - 5, val6, this.stamp + 5)), - new IndexedStackOperation(4, StackOperation.pop(this.height - 6, val7, this.stamp + 6))); + new IndexedStackOperation(1, StackOperation.pop(this.height - 3, val4, stackStampWithOffset(3))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 4, val5, stackStampWithOffset(4))), + new IndexedStackOperation(3, StackOperation.pop(this.height - 5, val6, stackStampWithOffset(5))), + new IndexedStackOperation(4, StackOperation.pop(this.height - 6, val7, stackStampWithOffset(6)))); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, this.stamp + 1)), - new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val3, this.stamp + 2)), - new IndexedStackOperation(4, StackOperation.push(this.height - 6, this.stamp + 6))); + new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(2))), + new IndexedStackOperation(4, StackOperation.push(this.height - 6, stackStampWithOffset(6)))); } else { pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 2, val3, this.stamp + 3)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val4, this.stamp + 4)), - new IndexedStackOperation(3, StackOperation.pop(this.height - 4, val5, this.stamp + 5)), - new IndexedStackOperation(4, StackOperation.pop(this.height - 5, val6, this.stamp + 6))); + new IndexedStackOperation(1, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(3))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val4, stackStampWithOffset(4))), + new IndexedStackOperation(3, StackOperation.pop(this.height - 4, val5, stackStampWithOffset(5))), + new IndexedStackOperation(4, StackOperation.pop(this.height - 5, val6, stackStampWithOffset(6)))); pending.addArmingLine( new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, this.stamp + 1)), - new IndexedStackOperation(4, StackOperation.push(this.height - 5, this.stamp + 7))); + new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation(4, StackOperation.push(this.height - 5, stackStampWithOffset(7)))); } } @@ -284,22 +275,22 @@ private void create(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, 2); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 1, val1, this.stamp + 1)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 2, val2, this.stamp + 2))); + new IndexedStackOperation(1, StackOperation.pop(this.height - 1, val1, stackStampWithOffset(1))), + new IndexedStackOperation(2, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(2)))); if (this.currentOpcodeData.stackSettings().flag1()) { Bytes val3 = getStack(frame, 3); Bytes val4 = getStack(frame, 0); pending.addArmingLine( - new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val3, this.stamp + 3)), - new IndexedStackOperation(3, StackOperation.pop(this.height, val4, this.stamp)), - new IndexedStackOperation(4, StackOperation.push(this.height - 3, this.stamp + 4))); + new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val3, stackStampWithOffset(3))), + new IndexedStackOperation(3, StackOperation.pop(this.height, val4, stackStampWithOffset(0))), + new IndexedStackOperation(4, StackOperation.push(this.height - 3, stackStampWithOffset(4)))); } else { Bytes val4 = getStack(frame, 0); pending.addArmingLine( - new IndexedStackOperation(3, StackOperation.pop(this.height, val4, this.stamp)), - new IndexedStackOperation(4, StackOperation.push(this.height - 2, this.stamp + 4))); + new IndexedStackOperation(3, StackOperation.pop(this.height, val4, stackStampWithOffset(0))), + new IndexedStackOperation(4, StackOperation.push(this.height - 2, stackStampWithOffset(4)))); } } diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml index 5a6796c75e..8e7f701f67 100644 --- a/arithmetization/src/main/resources/opcodes.yml +++ b/arithmetization/src/main/resources/opcodes.yml @@ -617,7 +617,7 @@ opcodes: value: 0x54 instructionFamily: STORAGE stackSettings: - pattern: ONE_ONE + pattern: LOAD_STORE alpha: 1 delta: 1 nbAdded: 1 @@ -627,7 +627,7 @@ opcodes: value: 0x55 instructionFamily: STORAGE stackSettings: - pattern: TWO_ZERO + pattern: LOAD_STORE alpha: 0 delta: 2 nbAdded: 0 diff --git a/zkevm-constraints b/zkevm-constraints index 3999fb7ed0..5bf311b57d 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 3999fb7ed0491ad4e474cd773030d421485c3061 +Subproject commit 5bf311b57d2bec3ff596bd0137ef33235ee555da From e63d204159162395bc3d37a9ef08e911bf0b0c03 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 11 Jun 2024 12:00:45 +0530 Subject: [PATCH 088/461] fix: rewrite txndata + fix lookup hub into txndata --- .../linea/zktracer/module/Module.java | 2 + .../zktracer/module/blockdata/Blockdata.java | 2 +- .../linea/zktracer/module/hub/Hub.java | 18 +- .../hub/fragment/TransactionFragment.java | 2 + .../zktracer/module/rlptxrcpt/RlpTxrcpt.java | 19 +- .../module/rlptxrcpt/RlpTxrcptChunk.java | 2 +- .../linea/zktracer/module/romlex/RomLex.java | 3 +- .../module/txndata/BlockSnapshot.java | 53 +- .../module/txndata/TransactionSnapshot.java | 485 ------------------ .../zktracer/module/txndata/TxnData.java | 200 +------- .../module/txndata/TxndataOperation.java | 371 ++++++++++++++ .../types/TransactionProcessingMetadata.java | 14 + zkevm-constraints | 2 +- 13 files changed, 431 insertions(+), 742 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java index 126c3cb43b..bdfa1bdda2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java @@ -52,6 +52,8 @@ default void traceEndTx( List logs, long gasUsed) {} + default void traceEndTx(TransactionProcessingMetadata tx, List logs) {} + default void traceContextEnter(MessageFrame frame) {} default void traceContextExit(MessageFrame frame) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java index 7d953927c7..9ddd7a95af 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java @@ -68,7 +68,7 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo currentTimestamp, blockHeader.getNumber(), blockHeader.getDifficulty().getAsBigInteger(), - this.txnData.currentBlock().getTxs().size())); + this.txnData.currentBlock().getNbOfTxsInBlock())); this.batchUnderConstruction = false; this.wcp.callGT(currentTimestamp, previousTimestamp); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 5de8bf2937..4acf14e78b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -245,7 +245,7 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.rom = new Rom(this.romLex); this.rlpTxn = new RlpTxn(this.romLex); this.euc = new Euc(this.wcp); - this.txnData = new TxnData(this, this.romLex, this.wcp, this.euc); + this.txnData = new TxnData(this.wcp, this.euc); this.blockdata = new Blockdata(this.wcp, this.txnData, this.rlpTxn); this.rlpTxrcpt = new RlpTxrcpt(txnData); this.logData = new LogData(rlpTxrcpt); @@ -293,7 +293,6 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.add, this.bin, this.blake2fModexpData, - this.blockdata, this.blockhash, this.ecData, this.euc, @@ -317,6 +316,7 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.trm, this.wcp, /* WARN: must be called BEFORE txnData */ this.txnData, + this.blockdata, /* WARN: must be called AFTER txnData */ this.rlpTxrcpt /* WARN: must be called AFTER txnData */), this.precompileLimitModules.stream()) .toList(); @@ -770,7 +770,9 @@ public void traceEndTx( this.defers.runPostTx(this, world, tx, isSuccessful); for (Module m : this.modules) { + // TODO shift all module to the method with TxMetaData m.traceEndTx(world, tx, isSuccessful, output, logs, gasUsed); + m.traceEndTx(txStack.current(), logs); } } @@ -1059,21 +1061,15 @@ public void traceStartConflation(long blockCount) { @Override public void traceEndConflation(final WorldView world) { - this.romLex.traceEndConflation(world); - + this.romLex.determineCodeFragmentIndex(); + this.txStack.setCodeFragmentIndex(this); this.defers.runPostConflation(this, world); for (Module m : this.modules) { - if (!m.equals(this.romLex)) { - m.traceEndConflation(world); - } + m.traceEndConflation(world); } } - public long accruedRefunds() { - return this.state.currentTxTrace().refundCounter(); - } - // TODO: how do these implementations of remainingGas() // and expectedGas() behave with respect to resuming // execution after a CALL / CREATE ? One of them is diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index a3e9969953..4a44df5b4a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -71,6 +71,8 @@ public Trace trace(Trace trace) { Bytes.minimalBytes(transactionProcessingMetadata.getInitiallyAvailableGas())) .pTransactionGasPrice( Bytes.minimalBytes(transactionProcessingMetadata.getEffectiveGasPrice())) + .pTransactionPriorityFeePerGas( + Bytes.minimalBytes(transactionProcessingMetadata.weiPerGasForMiner())) .pTransactionBasefee(Bytes.minimalBytes(transactionProcessingMetadata.getBaseFee())) .pTransactionCallDataSize(tx.getData().map(Bytes::size).orElse(0)) .pTransactionInitCodeSize(tx.getInit().map(Bytes::size).orElse(0)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java index 76c0c58c4e..1a4ad6d396 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java @@ -39,13 +39,12 @@ import net.consensys.linea.zktracer.module.rlputils.ByteCountAndPowerOutput; import net.consensys.linea.zktracer.module.txndata.TxnData; import net.consensys.linea.zktracer.types.BitDecOutput; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.log.LogsBloomFilter; -import org.hyperledger.besu.evm.worldstate.WorldView; public class RlpTxrcpt implements Module { private final TxnData txnData; @@ -75,18 +74,12 @@ public void popTransaction() { } @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logList, - long gasUsed) { + public void traceEndTx(TransactionProcessingMetadata txMetaData, List logList) { RlpTxrcptChunk chunk = new RlpTxrcptChunk( - tx.getType(), - isSuccessful, - this.txnData.cumulatedGasUsed.getFirst().longValue(), + txMetaData.getBesuTransaction().getType(), + txMetaData.statusCode(), + txMetaData.getAccumulatedGasUsedInBlock(), logList); this.chunkList.add(chunk); } @@ -104,7 +97,7 @@ public void traceChunk(final RlpTxrcptChunk chunk, int absTxNum, int absLogNumMa phase2(traceValue, chunk.status(), trace); // PHASE 3: Cumulative gas Ru. - phase3(traceValue, chunk.gasUsed(), trace); + phase3(traceValue, (long) chunk.gasUsed(), trace); // PHASE 4: Bloom Filter Rb. phase4(traceValue, chunk.logs(), trace); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcptChunk.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcptChunk.java index f3db168bbb..bbe60e59a7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcptChunk.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcptChunk.java @@ -30,7 +30,7 @@ public final class RlpTxrcptChunk extends ModuleOperation { private final TransactionType txType; private final Boolean status; - private final Long gasUsed; + private final int gasUsed; private final List logs; @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index a15340e22c..5dac38cd19 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -278,8 +278,7 @@ private void traceChunk( .validateRow(); } - @Override - public void traceEndConflation(final WorldView state) { + public void determineCodeFragmentIndex() { this.sortedChunks.addAll(this.chunks); this.sortedChunks.sort(ROM_CHUNK_COMPARATOR); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java index 6ed6458a8d..f2350a78e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java @@ -18,14 +18,10 @@ import java.util.Optional; import lombok.Getter; -import net.consensys.linea.zktracer.container.stacked.list.StackedList; -import net.consensys.linea.zktracer.module.euc.Euc; -import net.consensys.linea.zktracer.module.wcp.Wcp; +import lombok.Setter; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.worldstate.WorldView; import org.hyperledger.besu.plugin.data.ProcessableBlockHeader; /** @@ -33,60 +29,17 @@ */ @Getter public class BlockSnapshot { - /** Sequential ID of this block within a conflation */ - int id; - /** A list of {@link TransactionSnapshot} contained in this block */ - private final StackedList txs = new StackedList<>(); /** The base fee of this block */ private final Optional baseFee; /** The coinbase of this block */ private final Address coinbaseAddress; private final Bytes blockGasLimit; + @Setter private int nbOfTxsInBlock; - BlockSnapshot(int id, ProcessableBlockHeader header) { - this.id = id; + BlockSnapshot(ProcessableBlockHeader header) { this.baseFee = header.getBaseFee().map(x -> (Wei) x); this.coinbaseAddress = header.getCoinbase(); this.blockGasLimit = Bytes.minimalBytes(header.getGasLimit()); } - - /** - * Returns the latest transaction snapshotted in this block. - * - * @return the latest {@link TransactionSnapshot} - */ - TransactionSnapshot currentTx() { - return this.txs.getLast(); - } - - /** - * Start capturing a transaction in this block. - * - * @param worldView a view on the state - * @param tx the {@link Transaction} - */ - void captureTx(Wcp wcp, Euc euc, WorldView worldView, Transaction tx) { - final TransactionSnapshot snapshot = - TransactionSnapshot.fromTransaction( - wcp, euc, tx, worldView, this.baseFee, this.blockGasLimit); - this.txs.add(snapshot); - } - - /** - * Finishes capturing a transaction in this block. - * - * @param leftoverGas - * @param refundCounter - * @param status true if the transaction was successful - */ - void endTx(final long leftoverGas, final long refundCounter, final boolean status) { - final TransactionSnapshot currentTx = this.currentTx(); - - currentTx.status(status); - currentTx.refundCounter(refundCounter); - currentTx.leftoverGas(leftoverGas); - - currentTx.setCallsToEucAndWcp(); - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java deleted file mode 100644 index 661e8048f1..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java +++ /dev/null @@ -1,485 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.txndata; - -import static net.consensys.linea.zktracer.module.Util.getTxTypeAsInt; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_0; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_1; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_2; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_3; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_4; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_5; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_ACCESS_LIST_ADRESS; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_ACCESS_LIST_STORAGE; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TRANSACTION; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TX_CREATE; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TX_DATA_NONZERO; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TX_DATA_ZERO; -import static net.consensys.linea.zktracer.module.txndata.Trace.LLARGE; -import static net.consensys.linea.zktracer.module.txndata.Trace.MAX_REFUND_QUOTIENT; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_0; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_1; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_2; -import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_CUMUL_GAS; -import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_STATUS_CODE; -import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_TYPE; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_0_RLP_TXN_PHASE_NUMBER_6; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_1_RLP_TXN_PHASE_NUMBER_6; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_1_RLP_TXN_PHASE_NUMBER_7; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_2_RLP_TXN_PHASE_NUMBER_6; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_2_RLP_TXN_PHASE_NUMBER_7; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.euc.Euc; -import net.consensys.linea.zktracer.module.wcp.Wcp; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Quantity; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.feemarket.TransactionPriceCalculator; -import org.hyperledger.besu.evm.account.AccountState; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** Gathers all the information required to trace a {@link Transaction} in {@link TxnData}. */ -@Accessors(fluent = true) -@Getter -public final class TransactionSnapshot extends ModuleOperation { - - private final Wcp wcp; - private final Euc euc; - - private final Optional baseFee; - private final Bytes blockGasLimit; - - /** Value moved by the transaction */ - private final BigInteger value; - /** Sender address */ - private final Address from; - /** Receiver or contract deployment address */ - private final Address to; - /** Sender nonce */ - private final long nonce; - /** Number of addresses to pre-warm */ - private final int prewarmedAddressesCount; - /** Number of storage slots to pre-warm */ - private final int prewarmedStorageKeysCount; - /** Whether this transaction is a smart contract deployment */ - private final boolean isDeployment; - /** Whether this transaction triggers the EVM */ - private final boolean requiresEvmExecution; - /** The transaction {@link TransactionType} */ - private final TransactionType type; - /** The sender balance when it sent the transaction */ - private final BigInteger initialSenderBalance; - /** 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; - private final Optional maxPriorityFeePerGas; - @Setter private boolean status; - @Setter private long refundCounter; - @Setter private long leftoverGas; - @Setter private long effectiveGasRefund; - @Setter private long cumulativeGasConsumption; - - @Setter private boolean getFullTip; - - private final List callsToEucAndWcp; - private final List valuesToRlptxn; - private final List valuesToRlpTxrcpt; - - // plus one because the last tx of the block has one more row - private final int MAX_NB_ROWS = - Math.max(Math.max(NB_ROWS_TYPE_1, NB_ROWS_TYPE_2), NB_ROWS_TYPE_0) + 1; - - public TransactionSnapshot( - Wcp wcp, - Euc euc, - BigInteger value, - Address from, - Address to, - long nonce, - int prewarmedAddressesCount, - int prewarmedStorageKeysCount, - boolean isDeployment, - boolean requiresEvmExecution, - TransactionType type, - BigInteger initialSenderBalance, - Bytes payload, - long gasLimit, - BigInteger effectiveGasPrice, - Optional maxFeePerGas, - Optional maxPriorityFeePerGas, - Bytes blockGasLimit, - Optional baseFee) { - - this.wcp = wcp; - this.euc = euc; - - this.value = value; - this.from = from; - this.to = to; - this.nonce = nonce; - this.prewarmedAddressesCount = prewarmedAddressesCount; - this.prewarmedStorageKeysCount = prewarmedStorageKeysCount; - this.isDeployment = isDeployment; - this.requiresEvmExecution = requiresEvmExecution; - this.type = type; - this.initialSenderBalance = initialSenderBalance; - this.payload = payload; - this.gasLimit = gasLimit; - this.effectiveGasPrice = effectiveGasPrice; - this.maxFeePerGas = maxFeePerGas; - this.maxPriorityFeePerGas = maxPriorityFeePerGas; - this.callDataSize = this.isDeployment ? 0 : this.payload.size(); - this.callsToEucAndWcp = new ArrayList<>(); - this.valuesToRlptxn = new ArrayList<>(); - this.valuesToRlpTxrcpt = new ArrayList<>(); - this.blockGasLimit = blockGasLimit; - this.baseFee = baseFee; - } - - public static TransactionSnapshot fromTransaction( - Wcp wcp, - Euc euc, - Transaction tx, - WorldView world, - Optional baseFee, - Bytes blockGasLimit) { - - return new TransactionSnapshot( - wcp, - euc, - tx.getValue().getAsBigInteger(), - tx.getSender(), - tx.getTo() - .map(x -> (Address) x) - .orElse(Address.contractAddress(tx.getSender(), tx.getNonce())), - tx.getNonce(), - tx.getAccessList().map(List::size).orElse(0), - tx.getAccessList() - .map( - accessSet -> - accessSet.stream() - .mapToInt(accessSetItem -> accessSetItem.storageKeys().size()) - .sum()) - .orElse(0), - tx.getTo().isEmpty(), - tx.getTo().map(world::get).map(AccountState::hasCode).orElse(!tx.getPayload().isEmpty()), - tx.getType(), - Optional.ofNullable(tx.getSender()) - .map(world::get) - .map(x -> x.getBalance().getAsBigInteger()) - .orElse(BigInteger.ZERO), - tx.getPayload().copy(), - tx.getGasLimit(), - computeEffectiveGasPrice(baseFee, tx), - tx.getMaxFeePerGas(), - tx.getMaxPriorityFeePerGas(), - blockGasLimit, - baseFee); - } - - // dataCost returns the gas cost of the call data / init code - public long dataCost() { - Bytes payload = this.payload(); - long dataCost = 0; - for (int i = 0; i < payload.size(); i++) { - dataCost += payload.get(i) == 0 ? GAS_CONST_G_TX_DATA_ZERO : GAS_CONST_G_TX_DATA_NONZERO; - } - return dataCost; - } - - private static BigInteger computeEffectiveGasPrice(Optional baseFee, Transaction tx) { - return switch (tx.getType()) { - case FRONTIER, ACCESS_LIST -> tx.getGasPrice().get().getAsBigInteger(); - case EIP1559 -> TransactionPriceCalculator.eip1559() - .price((org.hyperledger.besu.ethereum.core.Transaction) tx, baseFee) - .getAsBigInteger(); - default -> throw new RuntimeException("transaction type not supported"); - }; - } - - // getData should return either: - // - call data (message call) - // - init code (contract creation) - int maxCounter() { - return switch (this.type()) { - case FRONTIER -> NB_ROWS_TYPE_0 - 1; - case ACCESS_LIST -> NB_ROWS_TYPE_1 - 1; - case EIP1559 -> NB_ROWS_TYPE_2 - 1; - default -> throw new RuntimeException("transaction type not supported"); - }; - } - - long getUpfrontGasCost() { - long initialCost = this.dataCost(); - - if (this.isDeployment()) { - initialCost += GAS_CONST_G_TX_CREATE; - } - - initialCost += GAS_CONST_G_TRANSACTION; - - if (this.type() != TransactionType.FRONTIER) { - initialCost += (long) this.prewarmedAddressesCount() * GAS_CONST_G_ACCESS_LIST_ADRESS; - initialCost += (long) this.prewarmedStorageKeysCount() * GAS_CONST_G_ACCESS_LIST_STORAGE; - } - - return initialCost; - } - - public void setRlptxnValues() { - // i+0 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_0, - Bytes.EMPTY, - Bytes.ofUnsignedInt(getTxTypeAsInt(this.type)))); - // i+1 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_1, - isDeployment ? Bytes.EMPTY : this.to.slice(0, 4), - isDeployment ? Bytes.EMPTY : this.to.slice(4, LLARGE))); - - // i+2 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_2, Bytes.EMPTY, Bytes.ofUnsignedLong(this.nonce))); - - // i+3 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_3, - isDeployment ? Bytes.of(1) : Bytes.EMPTY, - bigIntegerToBytes(this.value))); - - // i+4 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_4, - Bytes.ofUnsignedLong(this.dataCost()), - Bytes.ofUnsignedLong(this.payload.size()))); - - // i+5 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_5, - Bytes.EMPTY, - Bytes.ofUnsignedLong(this.gasLimit))); - - switch (this.type) { - case FRONTIER -> { - // i+6 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_0_RLP_TXN_PHASE_NUMBER_6, - Bytes.EMPTY, - bigIntegerToBytes(this.effectiveGasPrice))); - for (int i = 7; i < NB_ROWS_TYPE_0 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); - } - } - case ACCESS_LIST -> { - // i+6 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_1_RLP_TXN_PHASE_NUMBER_6, - Bytes.EMPTY, - bigIntegerToBytes(this.effectiveGasPrice))); - - // i+7 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_1_RLP_TXN_PHASE_NUMBER_7, - Bytes.ofUnsignedInt(this.prewarmedStorageKeysCount), - Bytes.ofUnsignedInt(this.prewarmedAddressesCount))); - - for (int i = 8; i < NB_ROWS_TYPE_1 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); - } - } - - case EIP1559 -> { - // i+6 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_2_RLP_TXN_PHASE_NUMBER_6, - bigIntegerToBytes(this.maxPriorityFeePerGas.get().getAsBigInteger()), - bigIntegerToBytes(this.maxFeePerGas.get().getAsBigInteger()))); - - // i+7 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_2_RLP_TXN_PHASE_NUMBER_7, - Bytes.ofUnsignedInt(this.prewarmedStorageKeysCount), - Bytes.ofUnsignedInt(this.prewarmedAddressesCount))); - - for (int i = 8; i < NB_ROWS_TYPE_2 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); - } - } - } - } - - public void setRlptxrcptValues() { - // i+0 - this.valuesToRlpTxrcpt.add( - RlptxrcptOutgoing.set((short) RLP_RCPT_SUBPHASE_ID_TYPE, getTxTypeAsInt(this.type()))); - // i+1 - this.valuesToRlpTxrcpt.add( - RlptxrcptOutgoing.set((short) RLP_RCPT_SUBPHASE_ID_STATUS_CODE, booleanToInt(this.status))); - // i+2 - this.valuesToRlpTxrcpt.add( - RlptxrcptOutgoing.set( - (short) RLP_RCPT_SUBPHASE_ID_CUMUL_GAS, this.cumulativeGasConsumption)); - // i+3 to i+MAX_NB_ROWS - for (int ct = 3; ct < MAX_NB_ROWS; ct++) { - this.valuesToRlpTxrcpt.add(RlptxrcptOutgoing.emptyValue()); - } - } - - public void setCallsToEucAndWcp() { - // i+0 - final Bytes row0arg1 = bigIntegerToBytes(this.initialSenderBalance); - final BigInteger value = this.value; - final BigInteger maxFeeShortHand = setOutgoingLoRowPlus6(); - final BigInteger gasLimit = BigInteger.valueOf(this.gasLimit); - final Bytes row0arg2 = bigIntegerToBytes(value.add(maxFeeShortHand.multiply(gasLimit))); - wcp.callLT(row0arg1, row0arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row0arg1, row0arg2, false)); - - // i+1 - final Bytes row1arg1 = Bytes.minimalBytes(this.gasLimit); - final Bytes row1arg2 = Bytes.minimalBytes(this.getUpfrontGasCost()); - wcp.callLT(row1arg1, row1arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row1arg1, row1arg2, false)); - - // i+2 - final Bytes row2arg1 = Bytes.minimalBytes(this.gasLimit - this.leftoverGas); - final Bytes row2arg2 = Bytes.of(MAX_REFUND_QUOTIENT); - final Bytes refundLimit = euc.callEUC(row2arg1, row2arg2).quotient(); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToEuc(row2arg1, row2arg2, refundLimit)); - - // i+3 - final Bytes refundCounterMax = Bytes.minimalBytes(this.refundCounter); - final boolean getFullRefund = wcp.callLT(refundCounterMax, refundLimit); - this.callsToEucAndWcp.add( - TxnDataComparisonRecord.callToLt(refundCounterMax, refundLimit, getFullRefund)); - - this.effectiveGasRefund( - getFullRefund ? leftoverGas + this.refundCounter : leftoverGas + refundLimit.toInt()); - - // i+4 - final Bytes row4arg1 = Bytes.minimalBytes(this.payload.size()); - final boolean nonZeroDataSize = wcp.callISZERO(row4arg1); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToIsZero(row4arg1, nonZeroDataSize)); - - switch (this.type) { - case FRONTIER -> { - for (int i = 5; i < NB_ROWS_TYPE_0; i++) { - this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); - } - } - case ACCESS_LIST -> { - for (int i = 5; i < NB_ROWS_TYPE_1; i++) { - this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); - } - } - case EIP1559 -> { - // i+5 - final Bytes maxFee = bigIntegerToBytes(this.maxFeePerGas.get().getAsBigInteger()); - final Bytes row5arg2 = Bytes.minimalBytes(this.baseFee.get().intValue()); - wcp.callLT(maxFee, row5arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row5arg2, false)); - - // i+6 - final Bytes row6arg2 = bigIntegerToBytes(this.maxPriorityFeePerGas.get().getAsBigInteger()); - wcp.callLT(maxFee, row6arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row6arg2, false)); - - // i+7 - final Bytes row7arg2 = - bigIntegerToBytes( - this.maxPriorityFeePerGas - .get() - .getAsBigInteger() - .add(this.baseFee.get().getAsBigInteger())); - final boolean result = wcp.callLT(maxFee, row7arg2); - getFullTip = !result; - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row7arg2, result)); - } - } - } - - public void setCallWcpLastTxOfBlock(final Bytes blockGasLimit) { - final Bytes arg1 = Bytes.minimalBytes(this.cumulativeGasConsumption); - this.wcp.callLEQ(arg1, blockGasLimit); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLeq(arg1, blockGasLimit, true)); - } - - public Bytes computeGasPriceColumn() { - switch (this.type) { - case FRONTIER, ACCESS_LIST -> { - return bigIntegerToBytes(effectiveGasPrice); - } - case EIP1559 -> { - return getFullTip - ? bigIntegerToBytes( - this.baseFee - .get() - .getAsBigInteger() - .add(this.maxPriorityFeePerGas.get().getAsBigInteger())) - : bigIntegerToBytes(this.maxFeePerGas.get().getAsBigInteger()); - } - default -> throw new IllegalArgumentException("Transaction type not supported"); - } - } - - private BigInteger setOutgoingLoRowPlus6() { - switch (this.type) { - case FRONTIER, ACCESS_LIST -> { - return this.effectiveGasPrice; - } - case EIP1559 -> { - return this.maxFeePerGas.get().getAsBigInteger(); - } - default -> throw new IllegalArgumentException("Transaction type not supported"); - } - } - - @Override - protected int computeLineCount() { - throw new IllegalStateException("should never be called"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java index 1da2524a67..8aa72c3c8e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java @@ -15,32 +15,18 @@ package net.consensys.linea.zktracer.module.txndata; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_0; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_1; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_2; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; - import java.nio.MappedByteBuffer; -import java.util.ArrayDeque; import java.util.ArrayList; -import java.util.Deque; import java.util.List; import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.container.stacked.list.StackedList; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.euc.Euc; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.romlex.ContractMetadata; -import net.consensys.linea.zktracer.module.romlex.RomLex; import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.TransactionType; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.evm.log.Log; -import org.hyperledger.besu.evm.worldstate.WorldView; import org.hyperledger.besu.plugin.data.BlockBody; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.ProcessableBlockHeader; @@ -48,32 +34,25 @@ @RequiredArgsConstructor public class TxnData implements Module { - private static final int N_ROWS_TX_MAX = - Math.max(Math.max(NB_ROWS_TYPE_0, NB_ROWS_TYPE_1), NB_ROWS_TYPE_2); - - private final Hub hub; - private final RomLex romLex; private final Wcp wcp; private final Euc euc; + private final List blocks = new ArrayList<>(); + private final StackedList txs = new StackedList<>(); + @Override public String moduleKey() { return "TXN_DATA"; } - public final List blocks = new ArrayList<>(); - /** accumulate the gas used since the beginning of the current block */ - public final Deque cumulatedGasUsed = new ArrayDeque<>(); - @Override public void enterTransaction() { - this.currentBlock().getTxs().enter(); + this.txs.enter(); } @Override public void popTransaction() { - this.currentBlock().getTxs().pop(); - this.cumulatedGasUsed.pop(); + this.txs.pop(); } @Override @@ -82,156 +61,34 @@ public void traceStartConflation(final long blockCount) { this.wcp.additionalRows.pop() + 4); /* 4 = byte length of LINEA_BLOCK_GAS_LIMIT */ } - public BlockSnapshot currentBlock() { - return this.blocks.get(this.blocks.size() - 1); - } - @Override public final void traceStartBlock(final ProcessableBlockHeader blockHeader) { - this.blocks.add(new BlockSnapshot(this.blocks.size() + 1, blockHeader)); - this.cumulatedGasUsed.push(0); - } - - @Override - public void traceStartTx(WorldView worldView, Transaction tx) { - this.currentBlock().captureTx(wcp, euc, worldView, tx); + this.blocks.add(new BlockSnapshot(blockHeader)); } @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) { - final long leftoverGas = tx.getGasLimit() - gasUsed; - final long refundCounter = hub.accruedRefunds(); - this.currentBlock().endTx(leftoverGas, refundCounter, isSuccessful); - - final TransactionSnapshot currentTx = this.currentBlock().currentTx(); - - final int gasUsedMinusRefunded = (int) (currentTx.gasLimit() - currentTx.effectiveGasRefund()); - this.cumulatedGasUsed.push((this.cumulatedGasUsed.getFirst() + gasUsedMinusRefunded)); - this.currentBlock().currentTx().cumulativeGasConsumption(this.cumulatedGasUsed.getFirst()); + public void traceEndTx(TransactionProcessingMetadata tx, List logs) { + this.txs.add(new TxndataOperation(wcp, euc, tx)); } @Override public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { - this.currentBlock().currentTx().setCallWcpLastTxOfBlock(this.currentBlock().getBlockGasLimit()); + this.currentBlock().setNbOfTxsInBlock(this.currentTx().tx.getRelativeTransactionNumber()); + this.currentTx().setCallWcpLastTxOfBlock(this.currentBlock().getBlockGasLimit()); } @Override public int lineCount() { // The last tx of each block has one more rows - int traceSize = this.blocks.size(); - - // Count the number of rows of each tx, only depending on the type of the transaction - for (BlockSnapshot block : this.blocks) { - for (TransactionSnapshot tx : block.getTxs()) { - switch (tx.type()) { - case FRONTIER -> traceSize += NB_ROWS_TYPE_0; - case ACCESS_LIST -> traceSize += NB_ROWS_TYPE_1; - case EIP1559 -> traceSize += NB_ROWS_TYPE_2; - default -> throw new RuntimeException("Transaction type not supported:" + tx.type()); - } - } - } - return traceSize; + return this.txs.lineCount() + this.blocks.size(); } - private void traceTx( - Trace trace, - BlockSnapshot block, - TransactionSnapshot tx, - int absTxNumMax, - int absTxNum, - int blockNum, - int relTxNumMax, - int relTxNum) { - - tx.setRlptxnValues(); - tx.setRlptxrcptValues(); - - final EWord from = EWord.of(tx.from()); - final EWord to = EWord.of(tx.to()); - final long toHi = to.hi().slice(12, 4).toLong(); - final EWord coinbase = EWord.of(block.getCoinbaseAddress()); - final long coinbaseLo = coinbase.hi().trimLeadingZeros().toLong(); - final int codeFragmentIndex = - tx.isDeployment() && tx.requiresEvmExecution() - ? this.romLex.getCodeFragmentIndexByMetadata( - ContractMetadata.underDeployment(tx.to(), 1)) - : 0; - final boolean copyTxCd = tx.requiresEvmExecution() && tx.callDataSize() != 0; - final long fromHi = from.hi().slice(12, 4).toLong(); - final Bytes gasPrice = tx.computeGasPriceColumn(); - final Bytes priorityFeePerGas = - tx.type() == TransactionType.EIP1559 - ? bigIntegerToBytes( - tx.maxFeePerGas() - .get() - .getAsBigInteger() - .subtract(tx.baseFee().get().getAsBigInteger())) - : gasPrice; - final Bytes nonce = Bytes.ofUnsignedLong(tx.nonce()); - final Bytes initialBalance = bigIntegerToBytes(tx.initialSenderBalance()); - final Bytes value = bigIntegerToBytes(tx.value()); - - final boolean isLastTxOfTheBlock = relTxNum == relTxNumMax; - final int ctMax = isLastTxOfTheBlock ? tx.maxCounter() + 1 : tx.maxCounter(); + public BlockSnapshot currentBlock() { + return this.blocks.get(this.blocks.size() - 1); + } - for (int ct = 0; ct <= ctMax; ct++) { - trace - .absTxNumMax(absTxNumMax) - .absTxNum(absTxNum) - .relBlock(blockNum) - .relTxNumMax(relTxNumMax) - .relTxNum(relTxNum) - .isLastTxOfBlock(isLastTxOfTheBlock) - .ct(UnsignedByte.of(ct)) - .fromHi(fromHi) - .fromLo(from.lo()) - .nonce(nonce) - .initialBalance(initialBalance) - .value(value) - .toHi(toHi) - .toLo(to.lo()) - .isDep(tx.isDeployment()) - .gasLimit(Bytes.ofUnsignedLong(tx.gasLimit())) - .gasInitiallyAvailable(Bytes.ofUnsignedLong(tx.gasLimit() - tx.getUpfrontGasCost())) - .gasPrice(gasPrice) - .priorityFeePerGas(priorityFeePerGas) - .basefee(block.getBaseFee().orElseThrow()) - .coinbaseHi(coinbaseLo) - .coinbaseLo(coinbase.lo()) - .blockGasLimit(block.getBlockGasLimit()) - .callDataSize(tx.callDataSize()) - .initCodeSize(tx.isDeployment() ? tx.payload().size() : 0) - .type0(tx.type() == TransactionType.FRONTIER) - .type1(tx.type() == TransactionType.ACCESS_LIST) - .type2(tx.type() == TransactionType.EIP1559) - .requiresEvmExecution(tx.requiresEvmExecution()) - .copyTxcd(copyTxCd) - .gasLeftover(Bytes.ofUnsignedLong(tx.leftoverGas())) - .refundCounter(Bytes.ofUnsignedLong(tx.refundCounter())) - .refundEffective(Bytes.ofUnsignedLong(tx.effectiveGasRefund())) - .gasCumulative(Bytes.ofUnsignedLong(tx.cumulativeGasConsumption())) - .statusCode(tx.status()) - .codeFragmentIndex(codeFragmentIndex) - .phaseRlpTxn(UnsignedByte.of(tx.valuesToRlptxn().get(ct).phase())) - .outgoingHi(tx.valuesToRlptxn().get(ct).outGoingHi()) - .outgoingLo(tx.valuesToRlptxn().get(ct).outGoingLo()) - .eucFlag(tx.callsToEucAndWcp().get(ct).eucFlag()) - .wcpFlag(tx.callsToEucAndWcp().get(ct).wcpFlag()) - .inst(UnsignedByte.of(tx.callsToEucAndWcp().get(ct).instruction())) - .argOneLo(tx.callsToEucAndWcp().get(ct).arg1()) - .argTwoLo(tx.callsToEucAndWcp().get(ct).arg2()) - .res(tx.callsToEucAndWcp().get(ct).result()) - .phaseRlpTxnrcpt(UnsignedByte.of(tx.valuesToRlpTxrcpt().get(ct).phase())) - .outgoingRlpTxnrcpt(Bytes.ofUnsignedLong(tx.valuesToRlpTxrcpt().get(ct).outgoing())) - .validateRow(); - } + private TxndataOperation currentTx() { + return this.txs.getLast(); } @Override @@ -243,23 +100,10 @@ public List columnsHeaders() { public void commit(List buffers) { final Trace trace = new Trace(buffers); - int absTxNumMax = 0; - int absTxNum = 0; - int blockNum = 0; - for (BlockSnapshot block : this.blocks) { - absTxNumMax += block.getTxs().size(); - } - for (BlockSnapshot block : this.blocks) { - final int relTxNumMax = block.getTxs().size(); - if (relTxNumMax != 0) { - blockNum++; - int relTxNum = 0; - for (TransactionSnapshot tx : block.getTxs()) { - absTxNum++; - relTxNum++; - this.traceTx(trace, block, tx, absTxNumMax, absTxNum, blockNum, relTxNumMax, relTxNum); - } - } + final int absTxNumMax = this.txs.size(); + + for (TxndataOperation tx : this.txs) { + tx.traceTx(trace, this.blocks.get(tx.getTx().getRelativeBlockNumber() - 1), absTxNumMax); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java new file mode 100644 index 0000000000..863b9da2d4 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java @@ -0,0 +1,371 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.txndata; + +import static net.consensys.linea.zktracer.module.Util.getTxTypeAsInt; +import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_0; +import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_1; +import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_2; +import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_3; +import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_4; +import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_5; +import static net.consensys.linea.zktracer.module.txndata.Trace.MAX_REFUND_QUOTIENT; +import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_0; +import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_1; +import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_2; +import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_CUMUL_GAS; +import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_STATUS_CODE; +import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_TYPE; +import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_0_RLP_TXN_PHASE_NUMBER_6; +import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_1_RLP_TXN_PHASE_NUMBER_6; +import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_1_RLP_TXN_PHASE_NUMBER_7; +import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_2_RLP_TXN_PHASE_NUMBER_6; +import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_2_RLP_TXN_PHASE_NUMBER_7; +import static net.consensys.linea.zktracer.types.AddressUtils.highPart; +import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; +import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; +import net.consensys.linea.zktracer.container.ModuleOperation; +import net.consensys.linea.zktracer.module.euc.Euc; +import net.consensys.linea.zktracer.module.wcp.Wcp; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import net.consensys.linea.zktracer.types.UnsignedByte; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.TransactionType; + +public class TxndataOperation extends ModuleOperation { + private final Wcp wcp; + private final Euc euc; + @Getter public final TransactionProcessingMetadata tx; + + private static final int N_ROWS_TX_MAX = + Math.max(Math.max(NB_ROWS_TYPE_0, NB_ROWS_TYPE_1), NB_ROWS_TYPE_2); + private final List callsToEucAndWcp = new ArrayList<>(N_ROWS_TX_MAX); + private final ArrayList valuesToRlptxn = new ArrayList<>(N_ROWS_TX_MAX); + private final ArrayList valuesToRlpTxrcpt = new ArrayList<>(N_ROWS_TX_MAX); + + public TxndataOperation(Wcp wcp, Euc euc, TransactionProcessingMetadata tx) { + this.wcp = wcp; + this.euc = euc; + this.tx = tx; + + this.setCallsToEucAndWcp(); + } + + private void setCallsToEucAndWcp() { + // i+0 + final Bytes row0arg1 = bigIntegerToBytes(tx.getInitialBalance()); + final BigInteger value = tx.getBesuTransaction().getValue().getAsBigInteger(); + final Bytes row0arg2 = + bigIntegerToBytes( + value.add( + BigInteger.valueOf(tx.getEffectiveGasPrice()) + .multiply(BigInteger.valueOf(tx.getBesuTransaction().getGasLimit())))); + wcp.callLT(row0arg1, row0arg2); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row0arg1, row0arg2, false)); + + // i+1 + final Bytes row1arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getGasLimit()); + final Bytes row1arg2 = Bytes.minimalBytes(tx.getUpfrontGasCost()); + wcp.callLT(row1arg1, row1arg2); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row1arg1, row1arg2, false)); + + // i+2 + final Bytes row2arg1 = + Bytes.minimalBytes(tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas()); + final Bytes row2arg2 = Bytes.of(MAX_REFUND_QUOTIENT); + final Bytes refundLimit = euc.callEUC(row2arg1, row2arg2).quotient(); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToEuc(row2arg1, row2arg2, refundLimit)); + + // i+3 + final Bytes refundCounterMax = Bytes.minimalBytes(tx.getRefundCounterMax()); + final boolean getFullRefund = wcp.callLT(refundCounterMax, refundLimit); + this.callsToEucAndWcp.add( + TxnDataComparisonRecord.callToLt(refundCounterMax, refundLimit, getFullRefund)); + + // i+4 + final Bytes row4arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getPayload().size()); + final boolean nonZeroDataSize = wcp.callISZERO(row4arg1); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToIsZero(row4arg1, nonZeroDataSize)); + + switch (tx.getBesuTransaction().getType()) { + case FRONTIER -> { + for (int i = 5; i < NB_ROWS_TYPE_0; i++) { + this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); + } + } + case ACCESS_LIST -> { + for (int i = 5; i < NB_ROWS_TYPE_1; i++) { + this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); + } + } + case EIP1559 -> { + // i+5 + final Bytes maxFee = + bigIntegerToBytes(tx.getBesuTransaction().getMaxFeePerGas().get().getAsBigInteger()); + final Bytes row5arg2 = Bytes.minimalBytes(tx.getBaseFee()); + wcp.callLT(maxFee, row5arg2); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row5arg2, false)); + + // i+6 + final Bytes row6arg2 = + bigIntegerToBytes( + tx.getBesuTransaction().getMaxPriorityFeePerGas().get().getAsBigInteger()); + wcp.callLT(maxFee, row6arg2); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row6arg2, false)); + + // i+7 + final Bytes row7arg2 = + bigIntegerToBytes( + tx.getBesuTransaction() + .getMaxPriorityFeePerGas() + .get() + .getAsBigInteger() + .add(BigInteger.valueOf(tx.getBaseFee()))); + final boolean result = wcp.callLT(maxFee, row7arg2); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row7arg2, result)); + } + } + } + + @Override + protected int computeLineCount() { + // Count the number of rows of each tx, only depending on the type of the transaction + return switch (tx.getBesuTransaction().getType()) { + case FRONTIER -> NB_ROWS_TYPE_0; + case ACCESS_LIST -> NB_ROWS_TYPE_1; + case EIP1559 -> NB_ROWS_TYPE_2; + default -> throw new RuntimeException( + "Transaction type not supported:" + tx.getBesuTransaction().getType()); + }; + } + + private void setRlptxnValues() { + // i+0 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) COMMON_RLP_TXN_PHASE_NUMBER_0, + Bytes.EMPTY, + Bytes.ofUnsignedInt(getTxTypeAsInt(tx.getBesuTransaction().getType())))); + // i+1 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) COMMON_RLP_TXN_PHASE_NUMBER_1, + tx.isDeployment() ? Bytes.EMPTY : tx.getEffectiveTo().slice(0, 4), + tx.isDeployment() ? Bytes.EMPTY : lowPart(tx.getEffectiveTo()))); + + // i+2 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) COMMON_RLP_TXN_PHASE_NUMBER_2, + Bytes.EMPTY, + Bytes.ofUnsignedLong(tx.getBesuTransaction().getNonce()))); + + // i+3 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) COMMON_RLP_TXN_PHASE_NUMBER_3, + tx.isDeployment() ? Bytes.of(1) : Bytes.EMPTY, + bigIntegerToBytes(tx.getBesuTransaction().getValue().getAsBigInteger()))); + + // i+4 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) COMMON_RLP_TXN_PHASE_NUMBER_4, + Bytes.ofUnsignedLong(tx.getDataCost()), + Bytes.ofUnsignedLong(tx.getBesuTransaction().getPayload().size()))); + + // i+5 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) COMMON_RLP_TXN_PHASE_NUMBER_5, + Bytes.EMPTY, + Bytes.ofUnsignedLong(tx.getBesuTransaction().getGasLimit()))); + + switch (tx.getBesuTransaction().getType()) { + case FRONTIER -> { + // i+6 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) TYPE_0_RLP_TXN_PHASE_NUMBER_6, + Bytes.EMPTY, + Bytes.minimalBytes(tx.getEffectiveGasPrice()))); + for (int i = 7; i < NB_ROWS_TYPE_0 + 1; i++) { + this.valuesToRlptxn.add(RlptxnOutgoing.empty()); + } + } + case ACCESS_LIST -> { + // i+6 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) TYPE_1_RLP_TXN_PHASE_NUMBER_6, + Bytes.EMPTY, + Bytes.minimalBytes(tx.getEffectiveGasPrice()))); + + // i+7 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) TYPE_1_RLP_TXN_PHASE_NUMBER_7, + Bytes.ofUnsignedInt(tx.numberWarmedKey()), + Bytes.ofUnsignedInt(tx.numberWarmedAddress()))); + + for (int i = 8; i < NB_ROWS_TYPE_1 + 1; i++) { + this.valuesToRlptxn.add(RlptxnOutgoing.empty()); + } + } + + case EIP1559 -> { + // i+6 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) TYPE_2_RLP_TXN_PHASE_NUMBER_6, + bigIntegerToBytes( + tx.getBesuTransaction().getMaxPriorityFeePerGas().get().getAsBigInteger()), + bigIntegerToBytes( + tx.getBesuTransaction().getMaxFeePerGas().get().getAsBigInteger()))); + + // i+7 + this.valuesToRlptxn.add( + RlptxnOutgoing.set( + (short) TYPE_2_RLP_TXN_PHASE_NUMBER_7, + Bytes.ofUnsignedInt(tx.numberWarmedKey()), + Bytes.ofUnsignedInt(tx.numberWarmedAddress()))); + + for (int i = 8; i < NB_ROWS_TYPE_2 + 1; i++) { + this.valuesToRlptxn.add(RlptxnOutgoing.empty()); + } + } + } + } + + public void setRlptxrcptValues() { + // i+0 + this.valuesToRlpTxrcpt.add( + RlptxrcptOutgoing.set( + (short) RLP_RCPT_SUBPHASE_ID_TYPE, getTxTypeAsInt(tx.getBesuTransaction().getType()))); + // i+1 + this.valuesToRlpTxrcpt.add( + RlptxrcptOutgoing.set( + (short) RLP_RCPT_SUBPHASE_ID_STATUS_CODE, booleanToInt(tx.statusCode()))); + // i+2 + this.valuesToRlpTxrcpt.add( + RlptxrcptOutgoing.set( + (short) RLP_RCPT_SUBPHASE_ID_CUMUL_GAS, tx.getAccumulatedGasUsedInBlock())); + // i+3 to i+MAX_NB_ROWS + for (int ct = 3; ct < N_ROWS_TX_MAX; ct++) { + this.valuesToRlpTxrcpt.add(RlptxrcptOutgoing.emptyValue()); + } + } + + public void setCallWcpLastTxOfBlock(final Bytes blockGasLimit) { + final Bytes arg1 = Bytes.minimalBytes(tx.getAccumulatedGasUsedInBlock()); + this.wcp.callLEQ(arg1, blockGasLimit); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLeq(arg1, blockGasLimit, true)); + } + + public void traceTx(Trace trace, BlockSnapshot block, int absTxNumMax) { + + this.setRlptxnValues(); + this.setRlptxrcptValues(); + + final boolean isLastTxOfTheBlock = tx.getRelativeBlockNumber() == block.getNbOfTxsInBlock(); + if (isLastTxOfTheBlock) { + this.valuesToRlptxn.add(RlptxnOutgoing.empty()); + this.valuesToRlpTxrcpt.add(RlptxrcptOutgoing.emptyValue()); + } + + final long fromHi = highPart(tx.getSender()); + final Bytes fromLo = lowPart(tx.getSender()); + final Bytes nonce = Bytes.ofUnsignedLong(tx.getBesuTransaction().getNonce()); + final Bytes initialBalance = bigIntegerToBytes(tx.getInitialBalance()); + final Bytes value = bigIntegerToBytes(tx.getBesuTransaction().getValue().getAsBigInteger()); + final long toHi = highPart(tx.getEffectiveTo()); + final Bytes toLo = lowPart(tx.getEffectiveTo()); + final Bytes gasLimit = Bytes.minimalBytes(tx.getBesuTransaction().getGasLimit()); + final Bytes gasInitiallyAvailable = Bytes.minimalBytes(tx.getInitiallyAvailableGas()); + final Bytes gasPrice = Bytes.minimalBytes(tx.getEffectiveGasPrice()); + final Bytes priorityFeePerGas = Bytes.minimalBytes(tx.weiPerGasForMiner()); + final Bytes baseFee = block.getBaseFee().get().toMinimalBytes(); + final long coinbaseHi = highPart(block.getCoinbaseAddress()); + final Bytes coinbaseLo = lowPart(block.getCoinbaseAddress()); + final int callDataSize = tx.isDeployment() ? tx.getBesuTransaction().getPayload().size() : 0; + final int initCodeSize = tx.isDeployment() ? 0 : tx.getBesuTransaction().getPayload().size(); + final Bytes gasLeftOver = Bytes.minimalBytes(tx.getLeftoverGas()); + final Bytes refundCounter = Bytes.minimalBytes(tx.getRefundCounterMax()); + final Bytes refundEffective = Bytes.minimalBytes(tx.getGasRefunded()); + final Bytes cumulativeGas = Bytes.minimalBytes(tx.getAccumulatedGasUsedInBlock()); + + final int nbLInes = isLastTxOfTheBlock ? this.lineCount() + 1 : this.lineCount(); + + for (int ct = 0; ct < nbLInes; ct++) { + trace + .absTxNumMax(absTxNumMax) + .absTxNum(tx.getAbsoluteTransactionNumber()) + .relBlock(tx.getRelativeBlockNumber()) + .relTxNumMax(block.getNbOfTxsInBlock()) + .relTxNum(tx.getRelativeTransactionNumber()) + .isLastTxOfBlock(isLastTxOfTheBlock) + .ct(UnsignedByte.of(ct)) + .fromHi(fromHi) + .fromLo(fromLo) + .nonce(nonce) + .initialBalance(initialBalance) + .value(value) + .toHi(toHi) + .toLo(toLo) + .isDep(tx.isDeployment()) + .gasLimit(gasLimit) + .gasInitiallyAvailable(gasInitiallyAvailable) + .gasPrice(gasPrice) + .priorityFeePerGas(priorityFeePerGas) + .basefee(baseFee) + .coinbaseHi(coinbaseHi) + .coinbaseLo(coinbaseLo) + .blockGasLimit(block.getBlockGasLimit()) + .callDataSize(callDataSize) + .initCodeSize(initCodeSize) + .type0(tx.getBesuTransaction().getType() == TransactionType.FRONTIER) + .type1(tx.getBesuTransaction().getType() == TransactionType.ACCESS_LIST) + .type2(tx.getBesuTransaction().getType() == TransactionType.EIP1559) + .requiresEvmExecution(tx.requiresEvmExecution()) + .copyTxcd(tx.copyTransactionCallData()) + .gasLeftover(gasLeftOver) + .refundCounter(refundCounter) + .refundEffective(refundEffective) + .gasCumulative(cumulativeGas) + .statusCode(tx.statusCode()) + .codeFragmentIndex(tx.getCodeFragmentIndex()) + .phaseRlpTxn(UnsignedByte.of(this.valuesToRlptxn.get(ct).phase())) + .outgoingHi(this.valuesToRlptxn.get(ct).outGoingHi()) + .outgoingLo(this.valuesToRlptxn.get(ct).outGoingLo()) + .eucFlag(this.callsToEucAndWcp.get(ct).eucFlag()) + .wcpFlag(this.callsToEucAndWcp.get(ct).wcpFlag()) + .inst(UnsignedByte.of(this.callsToEucAndWcp.get(ct).instruction())) + .argOneLo(this.callsToEucAndWcp.get(ct).arg1()) + .argTwoLo(this.callsToEucAndWcp.get(ct).arg2()) + .res(this.callsToEucAndWcp.get(ct).result()) + .phaseRlpTxnrcpt(UnsignedByte.of(this.valuesToRlpTxrcpt.get(ct).phase())) + .outgoingRlpTxnrcpt(Bytes.ofUnsignedLong(this.valuesToRlpTxrcpt.get(ct).outgoing())) + .validateRow(); + } + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 9daa2e7d37..423eb9351e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -262,4 +262,18 @@ public Wei getMinerReward() { public Wei getGasRefundInWei() { return Wei.of(BigInteger.valueOf(gasRefunded).multiply(BigInteger.valueOf(effectiveGasPrice))); } + + public int numberWarmedAddress() { + return this.besuTransaction.getAccessList().isPresent() + ? this.besuTransaction.getAccessList().get().size() + : 0; + } + + public int numberWarmedKey() { + return this.besuTransaction.getAccessList().isPresent() + ? this.besuTransaction.getAccessList().get().stream() + .mapToInt(accessListEntry -> accessListEntry.storageKeys().size()) + .sum() + : 0; + } } diff --git a/zkevm-constraints b/zkevm-constraints index 3999fb7ed0..5bf311b57d 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 3999fb7ed0491ad4e474cd773030d421485c3061 +Subproject commit 5bf311b57d2bec3ff596bd0137ef33235ee555da From 442d3cd05a750e12efae5be27406a3c98cc49924 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 11 Jun 2024 14:14:45 +0530 Subject: [PATCH 089/461] fix(txndata): typo + spotless --- .../linea/zktracer/module/hub/Hub.java | 8 +- .../module/hub/fragment/ContextFragment.java | 43 ++-- .../module/hub/fragment/StackFragment.java | 3 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 3 +- .../precompiles/PrecompileLinesGenerator.java | 19 +- .../module/hub/section/StopSection.java | 1 - .../module/txndata/TxndataOperation.java | 3 +- .../zktracer/runtime/callstack/CallFrame.java | 16 +- .../linea/zktracer/runtime/stack/Stack.java | 184 ++++++++++++------ 9 files changed, 175 insertions(+), 105 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 4587b283f2..6645df8c06 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1286,8 +1286,12 @@ void traceOperation(MessageFrame frame) { } case STORAGE -> { switch (this.currentFrame().opCode()) { - case SSTORE -> { SstoreSection.appendSection(this); } - case SLOAD -> { SloadSection.appendSection(this); } + case SSTORE -> { + SstoreSection.appendSection(this); + } + case SLOAD -> { + SloadSection.appendSection(this); + } default -> throw new IllegalStateException("invalid operation in family STORAGE"); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 7f41b70f05..9c1a41dfe4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -21,13 +21,11 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.types.Either; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.internal.Words; public record ContextFragment( Hub hub, @@ -72,7 +70,8 @@ public static ContextFragment initializeExecutionContext(final Hub hub) { hub.callStack(), Either.right(hub.stamp() + 1), 0, - MemorySpan.fromStartEnd(0, hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)), + MemorySpan.fromStartEnd( + 0, hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)), false); } @@ -80,22 +79,22 @@ public static ContextFragment executionProvidesEmptyReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, - callStack, - Either.left(callStack.parent().id()), - hub.callStack().current().contextNumber(), - MemorySpan.empty(), - true); + callStack, + Either.left(callStack.parent().id()), + hub.callStack().current().contextNumber(), + MemorySpan.empty(), + true); } public static ContextFragment nonExecutionEmptyReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, - callStack, - Either.left(callStack.current().id()), - hub.newChildContextNumber(), - MemorySpan.empty(), - true); + callStack, + Either.left(callStack.current().id()), + hub.newChildContextNumber(), + MemorySpan.empty(), + true); } public static ContextFragment executionReturnData(final Hub hub) { @@ -112,15 +111,11 @@ public static ContextFragment executionReturnData(final Hub hub) { public static ContextFragment enterContext(final Hub hub, final CallFrame calledCallFrame) { CallStack callStack = hub.callStack(); return new ContextFragment( - hub, - callStack, - Either.left(calledCallFrame.id()), - 0, - MemorySpan.empty(), - false); + hub, callStack, Either.left(calledCallFrame.id()), 0, MemorySpan.empty(), false); } - public static ContextFragment providesReturnData(final Hub hub, int receiverContextNumber, int providerContextNumber) { + public static ContextFragment providesReturnData( + final Hub hub, int receiverContextNumber, int providerContextNumber) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, @@ -141,7 +136,6 @@ public Trace trace(Trace trace) { final Address codeAddress = callFrame.byteCodeAddress(); final Address callerAddress = callFrame.callerAddress(); - return trace .peekAtContext(true) .pContextContextNumber(callFrame.contextNumber()) @@ -166,9 +160,10 @@ public Trace trace(Trace trace) { .pContextReturnAtCapacity(callFrame.requestedReturnDataTarget().length()) .pContextUpdate(updateReturnData) .pContextReturnDataContextNumber(returnDataContextNumber) -// callFrame.id() == 0 -// ? callFrame.universalParentReturnDataContextNumber -// : callFrame.lastCallee().map(c -> callStack.getById(c).contextNumber()).orElse(0)) + // callFrame.id() == 0 + // ? callFrame.universalParentReturnDataContextNumber + // : callFrame.lastCallee().map(c -> + // callStack.getById(c).contextNumber()).orElse(0)) .pContextReturnDataOffset(returnDataSegment.offset()) .pContextReturnDataSize(returnDataSegment.length()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 2e9458f557..e261319719 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -175,7 +175,8 @@ public void feedHashedValue(MessageFrame frame) { private boolean traceLog() { return this.opCode.isLog() && this.exceptions - .none() // TODO: should be redundant (exceptions trigger reverts) --- this could be asserted + .none() // TODO: should be redundant (exceptions trigger reverts) --- this could be + // asserted && !this.willRevert; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 1b02fbd36e..fb2ec57b85 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -230,7 +230,8 @@ public static MmuCall extCodeCopy(final Hub hub) { public static MmuCall returnDataCopy(final Hub hub) { final MemorySpan returnDataSegment = hub.currentFrame().latestReturnDataSource(); return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) - .sourceId(hub.callStack().getById(hub.currentFrame().returnDataContextNumber()).contextNumber()) + .sourceId( + hub.callStack().getById(hub.currentFrame().returnDataContextNumber()).contextNumber()) .targetId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .targetOffset(EWord.of(hub.messageFrame().getStackItem(0))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index 035db0ca9c..3cb52bfe4a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -198,7 +198,9 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 11))); } - r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); + r.add( + ContextFragment.providesReturnData( + hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_ADD -> { @@ -220,7 +222,9 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcAdd(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); + r.add( + ContextFragment.providesReturnData( + hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_MUL -> { @@ -242,7 +246,9 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcMul(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); + r.add( + ContextFragment.providesReturnData( + hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_PAIRING -> { @@ -267,7 +273,9 @@ public static List generateFor(final Hub hub, final PrecompileInv p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcPairing(hub, p, 2))); - r.add(ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); + r.add( + ContextFragment.providesReturnData( + hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case BLAKE2F -> { @@ -296,7 +304,8 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add( p.success() - ? ContextFragment.providesReturnData(hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber()) + ? ContextFragment.providesReturnData( + hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber()) : ContextFragment.nonExecutionEmptyReturnData(hub)); return r; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index bdb7a8f8e1..630325fc85 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -87,7 +87,6 @@ public static StopSection deploymentStopSection(Hub hub) { } else { stopWhileDeploying.addFragmentsWithoutStack(hub, executionProvidesEmptyReturnData(hub)); - } return stopWhileDeploying; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java index 863b9da2d4..df52b7bee1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java @@ -287,7 +287,8 @@ public void traceTx(Trace trace, BlockSnapshot block, int absTxNumMax) { this.setRlptxnValues(); this.setRlptxrcptValues(); - final boolean isLastTxOfTheBlock = tx.getRelativeBlockNumber() == block.getNbOfTxsInBlock(); + final boolean isLastTxOfTheBlock = + tx.getRelativeTransactionNumber() == block.getNbOfTxsInBlock(); if (isLastTxOfTheBlock) { this.valuesToRlptxn.add(RlptxnOutgoing.empty()); this.valuesToRlpTxrcpt.add(RlptxrcptOutgoing.emptyValue()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 869ba3476a..fb89934982 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -90,13 +90,12 @@ public boolean isMessageCall() { @Getter private int codeFragmentIndex = -1; public int getCodeFragmentIndex(Hub hub) { - return - this == CallFrame.EMPTY || this.type() == CallFrameType.MANTLE - ? 0 - : hub.getCfiByMetaData( - Words.toAddress(this.codeAddressAsEWord()), - this.codeDeploymentNumber(), - this.isDeployment()); + return this == CallFrame.EMPTY || this.type() == CallFrameType.MANTLE + ? 0 + : hub.getCfiByMetaData( + Words.toAddress(this.codeAddressAsEWord()), + this.codeDeploymentNumber(), + this.isDeployment()); } @Getter @Setter private int pc; @@ -139,7 +138,8 @@ public static void provideParentContextWithEmptyReturnData(Hub hub) { updateParentContextReturnData(hub, Bytes.EMPTY, MemorySpan.empty()); } - public static void updateParentContextReturnData(Hub hub, Bytes returnData, MemorySpan returnDataSource) { + public static void updateParentContextReturnData( + Hub hub, Bytes returnData, MemorySpan returnDataSource) { CallFrame parent = hub.callStack().parent(); parent.returnDataContextNumber = hub.currentFrame().contextNumber; parent.latestReturnData = returnData; 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 14c4e95a66..1cf5137b22 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 @@ -23,8 +23,6 @@ import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.frame.MessageFrame; -import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; - public class Stack { public static final int MAX_STACK_SIZE = 1024; @@ -60,7 +58,9 @@ private Bytes getStack(MessageFrame frame, int i) { private void oneZero(MessageFrame frame, StackContext pending) { Bytes val = getStack(frame, 0); - pending.addLine(new IndexedStackOperation(1, StackOperation.pop(this.height, val, stackStampWithOffset(0)))); + pending.addLine( + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val, stackStampWithOffset(0)))); } private void twoZero(MessageFrame frame, StackContext pending) { @@ -68,13 +68,16 @@ private void twoZero(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, 1); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), - new IndexedStackOperation(2, StackOperation.pop(this.height, val2, stackStampWithOffset(1)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height, val2, stackStampWithOffset(1)))); } private void zeroOne(MessageFrame ignoredFrame, StackContext pending) { pending.addArmingLine( - new IndexedStackOperation(4, StackOperation.push(this.height + 1, stackStampWithOffset(0)))); + new IndexedStackOperation( + 4, StackOperation.push(this.height + 1, stackStampWithOffset(0)))); } private void oneOne(MessageFrame frame, StackContext pending) { @@ -90,9 +93,12 @@ private void twoOne(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, 1); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), - new IndexedStackOperation(4, StackOperation.push(this.height - 1, stackStampWithOffset(2)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation( + 4, StackOperation.push(this.height - 1, stackStampWithOffset(2)))); } private void threeOne(MessageFrame frame, StackContext pending) { @@ -101,10 +107,14 @@ private void threeOne(MessageFrame frame, StackContext pending) { Bytes val3 = getStack(frame, 2); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), - new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(2))), - new IndexedStackOperation(4, StackOperation.push(this.height - 2, stackStampWithOffset(3)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(2))), + new IndexedStackOperation( + 4, StackOperation.push(this.height - 2, stackStampWithOffset(3)))); } private void loadStore(MessageFrame frame, StackContext pending) { @@ -113,13 +123,16 @@ private void loadStore(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, 1); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), - new IndexedStackOperation(4, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation( + 4, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1)))); } else { Bytes val = getStack(frame, 0); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val, stackStampWithOffset(0))), + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val, stackStampWithOffset(0))), new IndexedStackOperation(4, StackOperation.push(this.height, stackStampWithOffset(1)))); } } @@ -129,9 +142,12 @@ private void dup(MessageFrame frame, StackContext pending) { Bytes val = getStack(frame, depth); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - depth, val, stackStampWithOffset(0))), - new IndexedStackOperation( 2, StackOperation.pushImmediate(this.height - depth, val, stackStampWithOffset(1))), - new IndexedStackOperation( 4, StackOperation.pushImmediate(this.height + 1, val, stackStampWithOffset(2)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height - depth, val, stackStampWithOffset(0))), + new IndexedStackOperation( + 2, StackOperation.pushImmediate(this.height - depth, val, stackStampWithOffset(1))), + new IndexedStackOperation( + 4, StackOperation.pushImmediate(this.height + 1, val, stackStampWithOffset(2)))); } private void swap(MessageFrame frame, StackContext pending) { @@ -140,10 +156,14 @@ private void swap(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, depth); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - depth, val1, stackStampWithOffset(0))), - new IndexedStackOperation(2, StackOperation.pop(this.height, val2, stackStampWithOffset(1))), - new IndexedStackOperation( 3, StackOperation.pushImmediate(this.height - depth, val2, stackStampWithOffset(2))), - new IndexedStackOperation( 4, StackOperation.pushImmediate(this.height, val1, stackStampWithOffset(3)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height - depth, val1, stackStampWithOffset(0))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height, val2, stackStampWithOffset(1))), + new IndexedStackOperation( + 3, StackOperation.pushImmediate(this.height - depth, val2, stackStampWithOffset(2))), + new IndexedStackOperation( + 4, StackOperation.pushImmediate(this.height, val1, stackStampWithOffset(3)))); } private void log(MessageFrame frame, StackContext pending) { @@ -152,8 +172,10 @@ private void log(MessageFrame frame, StackContext pending) { // Stack line 1 pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, offset, stackStampWithOffset(0))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, size, stackStampWithOffset(1)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height, offset, stackStampWithOffset(0))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 1, size, stackStampWithOffset(1)))); // Stack line 2 IndexedStackOperation[] line2 = new IndexedStackOperation[] {}; @@ -163,7 +185,9 @@ private void log(MessageFrame frame, StackContext pending) { Bytes topic1 = getStack(frame, 2); line2 = - new IndexedStackOperation[] { new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(0))), + new IndexedStackOperation[] { + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(0))), }; } case LOG2 -> { @@ -172,8 +196,10 @@ private void log(MessageFrame frame, StackContext pending) { line2 = new IndexedStackOperation[] { - new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), - new IndexedStackOperation( 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), }; } case LOG3 -> { @@ -183,9 +209,12 @@ private void log(MessageFrame frame, StackContext pending) { line2 = new IndexedStackOperation[] { - new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), - new IndexedStackOperation( 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), - new IndexedStackOperation( 3, StackOperation.pop(this.height - 4, topic3, stackStampWithOffset(4))), + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 4, topic3, stackStampWithOffset(4))), }; } case LOG4 -> { @@ -196,10 +225,14 @@ private void log(MessageFrame frame, StackContext pending) { line2 = new IndexedStackOperation[] { - new IndexedStackOperation( 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), - new IndexedStackOperation( 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), - new IndexedStackOperation( 3, StackOperation.pop(this.height - 4, topic3, stackStampWithOffset(4))), - new IndexedStackOperation( 4, StackOperation.pop(this.height - 5, topic4, stackStampWithOffset(5))), + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 2, topic1, stackStampWithOffset(2))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 3, topic2, stackStampWithOffset(3))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 4, topic3, stackStampWithOffset(4))), + new IndexedStackOperation( + 4, StackOperation.pop(this.height - 5, topic4, stackStampWithOffset(5))), }; } default -> throw new RuntimeException("not a LOGx"); @@ -215,9 +248,12 @@ private void copy(MessageFrame frame, StackContext pending) { Bytes val3 = getStack(frame, 3); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 1, val1, stackStampWithOffset(1))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val3, stackStampWithOffset(2))), - new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(3))), + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 1, val1, stackStampWithOffset(1))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 3, val3, stackStampWithOffset(2))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(3))), new IndexedStackOperation(4, StackOperation.pop(this.height, val0, this.stamp))); } else { Bytes val1 = getStack(frame, 0); @@ -225,9 +261,12 @@ private void copy(MessageFrame frame, StackContext pending) { Bytes val3 = getStack(frame, 1); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(1))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(2))), - new IndexedStackOperation(3, StackOperation.pop(this.height - 1, val3, stackStampWithOffset(3)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val1, stackStampWithOffset(1))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(2))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 1, val3, stackStampWithOffset(3)))); } } @@ -246,27 +285,41 @@ private void call(MessageFrame frame, StackContext pending) { Bytes val7 = getStack(frame, 6); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 3, val4, stackStampWithOffset(3))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 4, val5, stackStampWithOffset(4))), - new IndexedStackOperation(3, StackOperation.pop(this.height - 5, val6, stackStampWithOffset(5))), - new IndexedStackOperation(4, StackOperation.pop(this.height - 6, val7, stackStampWithOffset(6)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 3, val4, stackStampWithOffset(3))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 4, val5, stackStampWithOffset(4))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 5, val6, stackStampWithOffset(5))), + new IndexedStackOperation( + 4, StackOperation.pop(this.height - 6, val7, stackStampWithOffset(6)))); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), - new IndexedStackOperation(3, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(2))), - new IndexedStackOperation(4, StackOperation.push(this.height - 6, stackStampWithOffset(6)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(2))), + new IndexedStackOperation( + 4, StackOperation.push(this.height - 6, stackStampWithOffset(6)))); } else { pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(3))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val4, stackStampWithOffset(4))), - new IndexedStackOperation(3, StackOperation.pop(this.height - 4, val5, stackStampWithOffset(5))), - new IndexedStackOperation(4, StackOperation.pop(this.height - 5, val6, stackStampWithOffset(6)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(3))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 3, val4, stackStampWithOffset(4))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height - 4, val5, stackStampWithOffset(5))), + new IndexedStackOperation( + 4, StackOperation.pop(this.height - 5, val6, stackStampWithOffset(6)))); pending.addArmingLine( new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), - new IndexedStackOperation(2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), - new IndexedStackOperation(4, StackOperation.push(this.height - 5, stackStampWithOffset(7)))); + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), + new IndexedStackOperation( + 4, StackOperation.push(this.height - 5, stackStampWithOffset(7)))); } } @@ -275,22 +328,29 @@ private void create(MessageFrame frame, StackContext pending) { Bytes val2 = getStack(frame, 2); pending.addLine( - new IndexedStackOperation(1, StackOperation.pop(this.height - 1, val1, stackStampWithOffset(1))), - new IndexedStackOperation(2, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(2)))); + new IndexedStackOperation( + 1, StackOperation.pop(this.height - 1, val1, stackStampWithOffset(1))), + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(2)))); if (this.currentOpcodeData.stackSettings().flag1()) { Bytes val3 = getStack(frame, 3); Bytes val4 = getStack(frame, 0); pending.addArmingLine( - new IndexedStackOperation(2, StackOperation.pop(this.height - 3, val3, stackStampWithOffset(3))), - new IndexedStackOperation(3, StackOperation.pop(this.height, val4, stackStampWithOffset(0))), - new IndexedStackOperation(4, StackOperation.push(this.height - 3, stackStampWithOffset(4)))); + new IndexedStackOperation( + 2, StackOperation.pop(this.height - 3, val3, stackStampWithOffset(3))), + new IndexedStackOperation( + 3, StackOperation.pop(this.height, val4, stackStampWithOffset(0))), + new IndexedStackOperation( + 4, StackOperation.push(this.height - 3, stackStampWithOffset(4)))); } else { Bytes val4 = getStack(frame, 0); pending.addArmingLine( - new IndexedStackOperation(3, StackOperation.pop(this.height, val4, stackStampWithOffset(0))), - new IndexedStackOperation(4, StackOperation.push(this.height - 2, stackStampWithOffset(4)))); + new IndexedStackOperation( + 3, StackOperation.pop(this.height, val4, stackStampWithOffset(0))), + new IndexedStackOperation( + 4, StackOperation.push(this.height - 2, stackStampWithOffset(4)))); } } From 9d8ce1d5c1a2c7fbcb8d4ecf6d5d08dd987eb385 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 11 Jun 2024 15:08:37 +0530 Subject: [PATCH 090/461] fix: fix rebase --- .../linea/zktracer/module/hub/Hub.java | 675 +++++++++--------- 1 file changed, 339 insertions(+), 336 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 0af23a1bb4..5ab19dc6ce 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -23,6 +23,7 @@ import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; +import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; import java.nio.MappedByteBuffer; import java.util.HashMap; @@ -128,38 +129,28 @@ public class Hub implements Module { public static final GasProjector GAS_PROJECTOR = new GasProjector(); /** accumulate the trace information for the Hub */ - @Getter - public final State state = new State(); + @Getter public final State state = new State(); /** contain the factories for trace segments that need complex initialization */ - @Getter - private final Factories factories; + @Getter private final Factories factories; /** provides phase-related volatile information */ - @Getter - Transients transients; + @Getter Transients transients; /** - * Long-lived states, not used in tracing per se but keeping track of data of - * the associated + * Long-lived states, not used in tracing per se but keeping track of data of the associated * lifetime */ - @Getter - CallStack callStack = new CallStack(); + @Getter CallStack callStack = new CallStack(); - /** - * Stores the transaction Metadata of all the transaction of the conflated block - */ - @Getter - TransactionStack txStack = new TransactionStack(); + /** Stores the transaction Metadata of all the transaction of the conflated block */ + @Getter TransactionStack txStack = new TransactionStack(); /** Stores all the actions that must be deferred to a later time */ - @Getter - private final DeferRegistry defers = new DeferRegistry(); + @Getter private final DeferRegistry defers = new DeferRegistry(); /** stores all data related to failure states & module activation */ - @Getter - private final PlatformController pch; + @Getter private final PlatformController pch; @Override public String moduleKey() { @@ -201,13 +192,11 @@ public void addTraceSection(TraceSection section) { this.state.currentTxTrace().add(section); } - @Getter - private final Wcp wcp = new Wcp(this); + @Getter private final Wcp wcp = new Wcp(this); private final Module add = new Add(this); private final Module bin = new Bin(this); private final Blake2fModexpData blake2fModexpData = new Blake2fModexpData(this.wcp); - @Getter - private final EcData ecData; + @Getter private final EcData ecData; private final Blockdata blockdata; private final Blockhash blockhash = new Blockhash(wcp); private final Euc euc; @@ -219,10 +208,8 @@ public void addTraceSection(TraceSection section) { private final Module mxp; private final Mmio mmio; - @Getter - private final Exp exp; - @Getter - private final Mmu mmu; + @Getter private final Exp exp; + @Getter private final Mmu mmu; private final RlpTxrcpt rlpTxrcpt; private final LogInfo logInfo; private final LogData logData; @@ -230,16 +217,14 @@ public void addTraceSection(TraceSection section) { private final RlpAddr rlpAddr = new RlpAddr(this, trm); private final Rom rom; - @Getter - private final RomLex romLex; + @Getter private final RomLex romLex; private final TxnData txnData; private final ShakiraData shakiraData = new ShakiraData(this.wcp); private final ModexpEffectiveCall modexpEffectiveCall; private final Stp stp = new Stp(this, wcp, mod); private final L2Block l2Block; - @Getter - private final Oob oob; + @Getter private final Oob oob; private final List modules; /* @@ -268,15 +253,16 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.logInfo = new LogInfo(rlpTxrcpt); this.ecData = new EcData(this, this.wcp, this.ext); this.oob = new Oob(this, (Add) this.add, this.mod, this.wcp); - this.mmu = new Mmu( - this.euc, - this.wcp, - this.romLex, - this.rlpTxn, - this.rlpTxrcpt, - this.ecData, - this.blake2fModexpData, - this.callStack); + this.mmu = + new Mmu( + this.euc, + this.wcp, + this.romLex, + this.rlpTxn, + this.rlpTxrcpt, + this.ecData, + this.blake2fModexpData, + this.callStack); this.mmio = new Mmio(this.mmu); final EcRecoverEffectiveCall ecRec = new EcRecoverEffectiveCall(this); @@ -284,55 +270,57 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { final EcPairingCallEffectiveCall ecPairingCall = new EcPairingCallEffectiveCall(this); final L2Block l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic)); - this.precompileLimitModules = List.of( - new Sha256Blocks(this, shakiraData), - ecRec, - new RipeMd160Blocks(this, shakiraData), - this.modexpEffectiveCall, - new EcAddEffectiveCall(this), - new EcMulEffectiveCall(this), - ecPairingCall, - new EcPairingMillerLoop(ecPairingCall), - new Blake2fRounds(this, this.blake2fModexpData), - // Block level limits - l2Block, - new Keccak(this, ecRec, l2Block, shakiraData), - new L2L1Logs(l2Block)); + this.precompileLimitModules = + List.of( + new Sha256Blocks(this, shakiraData), + ecRec, + new RipeMd160Blocks(this, shakiraData), + this.modexpEffectiveCall, + new EcAddEffectiveCall(this), + new EcMulEffectiveCall(this), + ecPairingCall, + new EcPairingMillerLoop(ecPairingCall), + new Blake2fRounds(this, this.blake2fModexpData), + // Block level limits + l2Block, + new Keccak(this, ecRec, l2Block, shakiraData), + new L2L1Logs(l2Block)); this.refTableModules = List.of(new BinRt(), new InstructionDecoder(), new ShfRt()); - this.modules = Stream.concat( - Stream.of( - this.add, - this.bin, - this.blake2fModexpData, - this.blockhash, - this.ecData, - this.euc, - this.ext, - this.logData, - this.logInfo, - this.mmio, - this.mmu, - this.mod, - this.mul, - this.mxp, - this.oob, - this.exp, - this.rlpAddr, - this.rlpTxn, - this.rom, - this.romLex, - this.shakiraData, - this.shf, - this.stp, - this.trm, - this.wcp, /* WARN: must be called BEFORE txnData */ - this.txnData, - this.blockdata, /* WARN: must be called AFTER txnData */ - this.rlpTxrcpt /* WARN: must be called AFTER txnData */), - this.precompileLimitModules.stream()) - .toList(); + this.modules = + Stream.concat( + Stream.of( + this.add, + this.bin, + this.blake2fModexpData, + this.blockhash, + this.ecData, + this.euc, + this.ext, + this.logData, + this.logInfo, + this.mmio, + this.mmu, + this.mod, + this.mul, + this.mxp, + this.oob, + this.exp, + this.rlpAddr, + this.rlpTxn, + this.rom, + this.romLex, + this.shakiraData, + this.shf, + this.stp, + this.trm, + this.wcp, /* WARN: must be called BEFORE txnData */ + this.txnData, + this.blockdata, /* WARN: must be called AFTER txnData */ + this.rlpTxrcpt /* WARN: must be called AFTER txnData */), + this.precompileLimitModules.stream()) + .toList(); } /** @@ -340,79 +328,78 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { */ public List getModulesToTrace() { return Stream.concat( - this.refTableModules.stream(), - // Modules - Stream.of( - this, - this.add, - this.bin, - this.blake2fModexpData, - this.ecData, - this.blockdata, - this.blockhash, - this.ext, - this.euc, - this.exp, - this.logData, - this.logInfo, - this.mmu, // WARN: must be called before the MMIO - this.mmio, - this.mod, - this.mul, - this.mxp, - this.oob, - this.rlpAddr, - this.rlpTxn, - this.rlpTxrcpt, - this.rom, - this.romLex, - this.shakiraData, - this.shf, - this.stp, - this.trm, - this.txnData, - this.wcp)) + this.refTableModules.stream(), + // Modules + Stream.of( + this, + this.add, + this.bin, + this.blake2fModexpData, + this.ecData, + this.blockdata, + this.blockhash, + this.ext, + this.euc, + this.exp, + this.logData, + this.logInfo, + this.mmu, // WARN: must be called before the MMIO + this.mmio, + this.mod, + this.mul, + this.mxp, + this.oob, + this.rlpAddr, + this.rlpTxn, + this.rlpTxrcpt, + this.rom, + this.romLex, + this.shakiraData, + this.shf, + this.stp, + this.trm, + this.txnData, + this.wcp)) .toList(); } /** - * List all the modules for which to generate counters. Intersects with, but is - * not equal to + * List all the modules for which to generate counters. Intersects with, but is not equal to * {@code getModulesToTrace}. * * @return the modules to count */ public List getModulesToCount() { return Stream.concat( - Stream.of( - this, - this.romLex, - this.add, - this.bin, - this.blockdata, - this.blockhash, - this.ext, - this.ecData, - this.euc, - this.mmu, - this.mmio, - this.logData, - this.logInfo, - this.mod, - this.mul, - this.mxp, - this.oob, - this.exp, - this.rlpAddr, - this.rlpTxn, - this.rlpTxrcpt, - this.rom, - this.shf, - this.trm, - this.txnData, - this.wcp, - this.l2Block), - this.precompileLimitModules.stream()) + Stream.of( + this, + this.romLex, + this.add, + this.bin, + this.blockdata, + this.blockhash, + this.ext, + this.ecData, + this.euc, + this.mmu, + this.mmio, + this.logData, + this.logInfo, + this.mod, + this.mul, + this.mxp, + this.oob, + this.exp, + this.rlpAddr, + this.rlpTxn, + this.rlpTxrcpt, + this.rom, + this.shf, + this.trm, + this.txnData, + this.wcp, + this.l2Block), + this.precompileLimitModules.stream()) .toList(); } @@ -438,44 +425,52 @@ void processStateInit(WorldView world) { final Address senderAddress = tx.getSender(); final Account senderAccount = world.get(senderAddress); - final AccountSnapshot senderBeforePayingForTransaction = AccountSnapshot.fromAccount( - senderAccount, - tx.isSenderPreWarmed(), - deploymentInfo.number(senderAddress), - deploymentInfo.isDeploying(senderAddress)); - final DomSubStampsSubFragment senderDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 0); + final AccountSnapshot senderBeforePayingForTransaction = + AccountSnapshot.fromAccount( + senderAccount, + tx.isSenderPreWarmed(), + deploymentInfo.number(senderAddress), + deploymentInfo.isDeploying(senderAddress)); + final DomSubStampsSubFragment senderDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 0); final Wei transactionGasPrice = Wei.of(tx.getEffectiveGasPrice()); final Wei value = (Wei) tx.getBesuTransaction().getValue(); - final AccountSnapshot senderAfterPayingForTransaction = senderBeforePayingForTransaction.debit( - transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value), true); + final AccountSnapshot senderAfterPayingForTransaction = + senderBeforePayingForTransaction.debit( + transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value), true); final boolean isSelfCredit = toAddress.equals(senderAddress); final Account recipientAccount = world.get(toAddress); - final AccountSnapshot recipientBeforeValueTransfer = isSelfCredit - ? senderAfterPayingForTransaction - : AccountSnapshot.fromAccount( - recipientAccount, - tx.isReceiverPreWarmed(), - deploymentInfo.number(toAddress), - deploymentInfo.isDeploying(toAddress)); + final AccountSnapshot recipientBeforeValueTransfer = + isSelfCredit + ? senderAfterPayingForTransaction + : AccountSnapshot.fromAccount( + recipientAccount, + tx.isReceiverPreWarmed(), + deploymentInfo.number(toAddress), + deploymentInfo.isDeploying(toAddress)); if (isDeployment) { deploymentInfo.deploy(toAddress); } - final Bytecode initBytecode = new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); - final AccountSnapshot recipientAfterValueTransfer = isDeployment - ? recipientBeforeValueTransfer.initiateDeployment(value, initBytecode) - : recipientBeforeValueTransfer.credit(value, true); - final DomSubStampsSubFragment recipientDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 1); + final Bytecode initBytecode = + new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); + final AccountSnapshot recipientAfterValueTransfer = + isDeployment + ? recipientBeforeValueTransfer.initiateDeployment(value, initBytecode) + : recipientBeforeValueTransfer.credit(value, true); + final DomSubStampsSubFragment recipientDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 1); final TransactionFragment txFragment = TransactionFragment.prepare(tx); this.defers.postTx(txFragment); - final AccountFragment.AccountFragmentFactory accountFragmentFactory = this.factories.accountFragment(); + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + this.factories.accountFragment(); this.addTraceSection( new TxInitializationSection( @@ -533,7 +528,8 @@ public int contextNumberNew(CallFrame frame) { return currentContextNumber; } - final Address calleeAddress = Words.toAddress(this.currentFrame().frame().getStackItem(1)); + final Address calleeAddress = + Words.toAddress(this.currentFrame().frame().getStackItem(1)); AtomicInteger newContext = new AtomicInteger(currentContextNumber); @@ -723,7 +719,8 @@ public void traceContextExit(MessageFrame frame) { .deploymentInfo() .unmarkDeploying(this.currentFrame().byteCodeAddress()); - DeploymentExceptions contextExceptions = DeploymentExceptions.fromFrame(this.currentFrame(), frame); + DeploymentExceptions contextExceptions = + DeploymentExceptions.fromFrame(this.currentFrame(), frame); this.currentTraceSection().setContextExceptions(contextExceptions); if (contextExceptions.any()) { this.callStack.revert(this.state.stamps().hub()); @@ -829,8 +826,8 @@ public void traceContextEnter(MessageFrame frame) { final Address toAddress = effectiveToAddress(currentTx.getBesuTransaction()); final boolean isDeployment = this.transients.tx().getBesuTransaction().getTo().isEmpty(); - final boolean shouldCopyTxCallData = !isDeployment && !frame.getInputData().isEmpty() - && currentTx.requiresEvmExecution(); + final boolean shouldCopyTxCallData = + !isDeployment && !frame.getInputData().isEmpty() && currentTx.requiresEvmExecution(); // TODO simplify this, the same bedRock context ( = root context ??) seems to be // generated in // both case @@ -879,23 +876,28 @@ public void traceContextEnter(MessageFrame frame) { // ...or CALL final boolean isDeployment = frame.getType() == MessageFrame.Type.CONTRACT_CREATION; final Address codeAddress = frame.getContractAddress(); - final CallFrameType frameType = frame.isStatic() ? CallFrameType.STATIC : CallFrameType.STANDARD; + final CallFrameType frameType = + frame.isStatic() ? CallFrameType.STATIC : CallFrameType.STANDARD; if (isDeployment) { this.transients.conflation().deploymentInfo().markDeploying(codeAddress); } - final int codeDeploymentNumber = this.transients.conflation().deploymentInfo().number(codeAddress); + final int codeDeploymentNumber = + this.transients.conflation().deploymentInfo().number(codeAddress); - final int callDataOffsetStackArgument = callStack.current().opCode().callHasSixArgument() ? 2 : 3; + final int callDataOffsetStackArgument = + callStack.current().opCode().callHasSixArgument() ? 2 : 3; - final long callDataOffset = isDeployment - ? 0 - : Words.clampedToLong( - callStack.current().frame().getStackItem(callDataOffsetStackArgument)); + final long callDataOffset = + isDeployment + ? 0 + : Words.clampedToLong( + callStack.current().frame().getStackItem(callDataOffsetStackArgument)); - final long callDataSize = isDeployment - ? 0 - : Words.clampedToLong( - callStack.current().frame().getStackItem(callDataOffsetStackArgument + 1)); + final long callDataSize = + isDeployment + ? 0 + : Words.clampedToLong( + callStack.current().frame().getStackItem(callDataOffsetStackArgument + 1)); final long callDataContextNumber = this.callStack.current().contextNumber(); @@ -995,23 +997,17 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.wcp.tracePostOpcode(frame); } } - case BIN -> { - } + case BIN -> {} case SHF -> { if (this.pch.exceptions().noStackException()) { this.shf.tracePostOpcode(frame); } } - case KEC -> { - } - case CONTEXT -> { - } - case ACCOUNT -> { - } - case COPY -> { - } - case TRANSACTION -> { - } + case KEC -> {} + case CONTEXT -> {} + case ACCOUNT -> {} + case COPY -> {} + case TRANSACTION -> {} case BATCH -> { if (this.currentFrame().opCode() == OpCode.BLOCKHASH) { this.blockhash.tracePostOpcode(frame); @@ -1022,30 +1018,18 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.mxp.tracePostOpcode(frame); } } - case STORAGE -> { - } - case JUMP -> { - } - case MACHINE_STATE -> { - } - case PUSH_POP -> { - } - case DUP -> { - } - case SWAP -> { - } - case LOG -> { - } - case CREATE -> { - } - case CALL -> { - } - case HALT -> { - } - case INVALID -> { - } - default -> { - } + case STORAGE -> {} + case JUMP -> {} + case MACHINE_STATE -> {} + case PUSH_POP -> {} + case DUP -> {} + case SWAP -> {} + case LOG -> {} + case CREATE -> {} + case CALL -> {} + case HALT -> {} + case INVALID -> {} + default -> {} } } @@ -1184,23 +1168,27 @@ void traceOperation(MessageFrame frame) { this, this.currentFrame(), ContextFragment.readCurrentContextData(this)); } - final Bytes rawTargetAddress = switch (this.currentFrame().opCode()) { - case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); - default -> this.currentFrame().accountAddress(); - }; + final Bytes rawTargetAddress = + switch (this.currentFrame().opCode()) { + case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); + default -> this.currentFrame().accountAddress(); + }; final Address targetAddress = Words.toAddress(rawTargetAddress); final Account targetAccount = frame.getWorldUpdater().get(targetAddress); - final AccountSnapshot accountBefore = AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - final AccountSnapshot accountAfter = AccountSnapshot.fromAccount( - targetAccount, - true, - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 0); + final AccountSnapshot accountBefore = + AccountSnapshot.fromAccount( + targetAccount, + frame.isAddressWarm(targetAddress), + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + final AccountSnapshot accountAfter = + AccountSnapshot.fromAccount( + targetAccount, + true, + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + final DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 0); accountSection.addFragment( this, this.currentFrame(), @@ -1209,8 +1197,8 @@ void traceOperation(MessageFrame frame) { .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps)); if (this.currentFrame().willRevert()) { - final DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment - .revertWithCurrentDomSubStamps(this, 0); + final DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); accountSection.addFragment( this, this.currentFrame(), @@ -1224,30 +1212,34 @@ void traceOperation(MessageFrame frame) { case COPY -> { TraceSection copySection = new CopySection(this); if (!this.opCode().equals(OpCode.RETURNDATACOPY)) { - final Bytes rawTargetAddress = switch (this.currentFrame().opCode()) { - case CODECOPY -> this.currentFrame().byteCodeAddress(); - case EXTCODECOPY -> frame.getStackItem(0); - case CALLDATACOPY -> addressFromBytes( - Bytes.fromHexString("0xdeadbeef")); // TODO: implement me please - default -> throw new IllegalStateException( - String.format("unexpected opcode %s", this.opCode())); - }; + final Bytes rawTargetAddress = + switch (this.currentFrame().opCode()) { + case CODECOPY -> this.currentFrame().byteCodeAddress(); + case EXTCODECOPY -> frame.getStackItem(0); + case CALLDATACOPY -> addressFromBytes( + Bytes.fromHexString("0xdeadbeef")); // TODO: implement me please + default -> throw new IllegalStateException( + String.format("unexpected opcode %s", this.opCode())); + }; final Address targetAddress = Words.toAddress(rawTargetAddress); final Account targetAccount = frame.getWorldUpdater().get(targetAddress); - AccountSnapshot accountBefore = AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - - AccountSnapshot accountAfter = AccountSnapshot.fromAccount( - targetAccount, - true, - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - - DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 0); + AccountSnapshot accountBefore = + AccountSnapshot.fromAccount( + targetAccount, + frame.isAddressWarm(targetAddress), + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + + AccountSnapshot accountAfter = + AccountSnapshot.fromAccount( + targetAccount, + true, + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + + DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 0); copySection.addFragment( this, this.currentFrame(), @@ -1261,8 +1253,8 @@ void traceOperation(MessageFrame frame) { .make(accountBefore, accountAfter, doingDomSubStamps)); if (this.callStack.current().willRevert()) { - DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, - 0); + DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); copySection.addFragment( this, this.currentFrame(), @@ -1303,23 +1295,26 @@ void traceOperation(MessageFrame frame) { } } case CREATE -> { - final Address myAddress = this.currentFrame().address(); + final Address myAddress = this.currentFrame().accountAddress(); final Account myAccount = frame.getWorldUpdater().get(myAddress); - AccountSnapshot myAccountSnapshot = AccountSnapshot.fromAccount( - myAccount, - frame.isAddressWarm(myAddress), - this.transients.conflation().deploymentInfo().number(myAddress), - this.transients.conflation().deploymentInfo().isDeploying(myAddress)); - - final Address createdAddress = AddressUtils.getCreateAddress(frame); + AccountSnapshot myAccountSnapshot = + AccountSnapshot.fromAccount( + myAccount, + frame.isAddressWarm(myAddress), + this.transients.conflation().deploymentInfo().number(myAddress), + this.transients.conflation().deploymentInfo().isDeploying(myAddress)); + + final Address createdAddress = getCreateAddress(frame); final Account createdAccount = frame.getWorldUpdater().get(createdAddress); - AccountSnapshot createdAccountSnapshot = AccountSnapshot.fromAccount( - createdAccount, - frame.isAddressWarm(createdAddress), - this.transients.conflation().deploymentInfo().number(createdAddress), - this.transients.conflation().deploymentInfo().isDeploying(createdAddress)); - - CreateSection createSection = new CreateSection(this, myAccountSnapshot, createdAccountSnapshot); + AccountSnapshot createdAccountSnapshot = + AccountSnapshot.fromAccount( + createdAccount, + frame.isAddressWarm(createdAddress), + this.transients.conflation().deploymentInfo().number(createdAddress), + this.transients.conflation().deploymentInfo().isDeploying(createdAddress)); + + CreateSection createSection = + new CreateSection(this, myAccountSnapshot, createdAccountSnapshot); this.addTraceSection(createSection); this.currentFrame().needsUnlatchingAtReEntry(createSection); } @@ -1327,22 +1322,25 @@ void traceOperation(MessageFrame frame) { case CALL -> { final Address myAddress = this.currentFrame().accountAddress(); final Account myAccount = frame.getWorldUpdater().get(myAddress); - final AccountSnapshot myAccountSnapshot = AccountSnapshot.fromAccount( - myAccount, - frame.isAddressWarm(myAddress), - this.transients.conflation().deploymentInfo().number(myAddress), - this.transients.conflation().deploymentInfo().isDeploying(myAddress)); + final AccountSnapshot myAccountSnapshot = + AccountSnapshot.fromAccount( + myAccount, + frame.isAddressWarm(myAddress), + this.transients.conflation().deploymentInfo().number(myAddress), + this.transients.conflation().deploymentInfo().isDeploying(myAddress)); final Bytes rawCalledAddress = frame.getStackItem(1); final Address calledAddress = Words.toAddress(rawCalledAddress); - final Optional calledAccount = Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)); + final Optional calledAccount = + Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)); final boolean hasCode = calledAccount.map(AccountState::hasCode).orElse(false); - final AccountSnapshot calledAccountSnapshot = AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(myAddress), - this.transients.conflation().deploymentInfo().number(myAddress), - this.transients.conflation().deploymentInfo().isDeploying(myAddress)); + final AccountSnapshot calledAccountSnapshot = + AccountSnapshot.fromAccount( + calledAccount, + frame.isAddressWarm(myAddress), + this.transients.conflation().deploymentInfo().number(myAddress), + this.transients.conflation().deploymentInfo().isDeploying(myAddress)); Optional targetPrecompile = Precompile.maybeOf(calledAddress); @@ -1381,32 +1379,34 @@ void traceOperation(MessageFrame frame) { // // THERE IS AN ABORT // - TraceSection abortedSection = new FailedCallSection( - this, - ScenarioFragment.forCall(this, hasCode), - ImcFragment.forCall(this, myAccount, calledAccount), - ContextFragment.readCurrentContextData(this), - this.factories - .accountFragment() - .make( - myAccountSnapshot, - myAccountSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this, 0)), - this.factories - .accountFragment() - .makeWithTrm( - calledAccountSnapshot, - calledAccountSnapshot, - rawCalledAddress, - DomSubStampsSubFragment.standardDomSubStamps(this, 1)), - ContextFragment.nonExecutionEmptyReturnData(this)); + TraceSection abortedSection = + new FailedCallSection( + this, + ScenarioFragment.forCall(this, hasCode), + ImcFragment.forCall(this, myAccount, calledAccount), + ContextFragment.readCurrentContextData(this), + this.factories + .accountFragment() + .make( + myAccountSnapshot, + myAccountSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this, 0)), + this.factories + .accountFragment() + .makeWithTrm( + calledAccountSnapshot, + calledAccountSnapshot, + rawCalledAddress, + DomSubStampsSubFragment.standardDomSubStamps(this, 1)), + ContextFragment.nonExecutionEmptyReturnData(this)); this.addTraceSection(abortedSection); } else { final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); if (hasCode) { - final SmartContractCallSection section = new SmartContractCallSection( - this, myAccountSnapshot, calledAccountSnapshot, rawCalledAddress, imcFragment); + final SmartContractCallSection section = + new SmartContractCallSection( + this, myAccountSnapshot, calledAccountSnapshot, rawCalledAddress, imcFragment); this.addTraceSection(section); this.currentFrame().needsUnlatchingAtReEntry(section); } else { @@ -1417,8 +1417,8 @@ void traceOperation(MessageFrame frame) { // TODO: fill the callee & requested return data for the current call frame // TODO: i.e. ensure that the precompile frame behaves as expected - Optional precompileInvocation = targetPrecompile - .map(p -> PrecompileInvocation.of(this, p)); + Optional precompileInvocation = + targetPrecompile.map(p -> PrecompileInvocation.of(this, p)); // TODO: this is ugly, and surely not at the right place. It should provide the // precompile result (from the precompile module) @@ -1428,13 +1428,14 @@ void traceOperation(MessageFrame frame) { this.stamp(), Bytes.EMPTY, 0, targetPrecompile.get().address); } - final NoCodeCallSection section = new NoCodeCallSection( - this, - precompileInvocation, - myAccountSnapshot, - calledAccountSnapshot, - rawCalledAddress, - imcFragment); + final NoCodeCallSection section = + new NoCodeCallSection( + this, + precompileInvocation, + myAccountSnapshot, + calledAccountSnapshot, + rawCalledAddress, + imcFragment); this.addTraceSection(section); this.currentFrame().needsUnlatchingAtReEntry(section); } @@ -1442,25 +1443,27 @@ void traceOperation(MessageFrame frame) { } case JUMP -> { - AccountSnapshot codeAccountSnapshot = AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(this.currentFrame().byteCodeAddress()), - true, - this.transients - .conflation() - .deploymentInfo() - .number(this.currentFrame().byteCodeAddress()), - this.currentFrame().isDeployment()); - - JumpSection jumpSection = new JumpSection( - this, - ContextFragment.readCurrentContextData(this), - this.factories - .accountFragment() - .make( - codeAccountSnapshot, - codeAccountSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this, 0)), - ImcFragment.forOpcode(this, frame)); + AccountSnapshot codeAccountSnapshot = + AccountSnapshot.fromAccount( + frame.getWorldUpdater().get(this.currentFrame().byteCodeAddress()), + true, + this.transients + .conflation() + .deploymentInfo() + .number(this.currentFrame().byteCodeAddress()), + this.currentFrame().isDeployment()); + + JumpSection jumpSection = + new JumpSection( + this, + ContextFragment.readCurrentContextData(this), + this.factories + .accountFragment() + .make( + codeAccountSnapshot, + codeAccountSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this, 0)), + ImcFragment.forOpcode(this, frame)); this.addTraceSection(jumpSection); } From 95c7094f67098f3218672a8d7e7a46bee5a293d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 11 Jun 2024 19:05:10 +0200 Subject: [PATCH 091/461] solved some SSTORE/SLOAD stuff also Besu provides already the original values ... :) --- .../linea/zktracer/module/hub/Hub.java | 4 +- .../hub/fragment/storage/StorageFragment.java | 30 ++++----- .../module/hub/section/SloadSection.java | 61 ++++++++++--------- .../module/hub/section/SstoreSection.java | 50 +++++++-------- 4 files changed, 74 insertions(+), 71 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 5ab19dc6ce..2e5b242e82 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1286,10 +1286,10 @@ void traceOperation(MessageFrame frame) { case STORAGE -> { switch (this.currentFrame().opCode()) { case SSTORE -> { - SstoreSection.appendSection(this); + SstoreSection.appendSection(this, frame.getWorldUpdater()); } case SLOAD -> { - SloadSection.appendSection(this); + SloadSection.appendSection(this, frame.getWorldUpdater()); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 7d2cc751b2..e6f0ee5b7a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -36,9 +36,9 @@ public final class StorageFragment implements TraceFragment { private final State hubState; @Setter private StorageFragmentType type; private final State.StorageSlotIdentifier storageSlotIdentifier; - private final EWord valOrig; - private final EWord valCurr; - private final EWord valNext; + private final EWord valueOriginal; + private final EWord valueCurrent; + private final EWord valueNext; private final boolean oldWarmth; private final boolean newWarmth; private final DomSubStampsSubFragment domSubStampsSubFragment; @@ -65,20 +65,20 @@ public Trace trace(Trace trace) { .pStorageDeploymentNumber(storageSlotIdentifier.getDeploymentNumber()) .pStorageStorageKeyHi(EWord.of(storageSlotIdentifier.getStorageKey()).hi()) .pStorageStorageKeyLo(EWord.of(storageSlotIdentifier.getStorageKey()).lo()) - .pStorageValueOrigHi(valOrig.hi()) - .pStorageValueOrigLo(valOrig.lo()) - .pStorageValueCurrHi(valCurr.hi()) - .pStorageValueCurrLo(valCurr.lo()) - .pStorageValueNextHi(valNext.hi()) - .pStorageValueNextLo(valNext.lo()) + .pStorageValueOrigHi(valueOriginal.hi()) + .pStorageValueOrigLo(valueOriginal.lo()) + .pStorageValueCurrHi(valueCurrent.hi()) + .pStorageValueCurrLo(valueCurrent.lo()) + .pStorageValueNextHi(valueNext.hi()) + .pStorageValueNextLo(valueNext.lo()) .pStorageWarmth(oldWarmth) .pStorageWarmthNew(newWarmth) - .pStorageValueOrigIsZero(valOrig.isZero()) - .pStorageValueCurrIsOrig(valCurr.equals(valOrig)) - .pStorageValueCurrIsZero(valCurr.isZero()) - .pStorageValueNextIsCurr(valNext.equals(valCurr)) - .pStorageValueNextIsZero(valNext.isZero()) - .pStorageValueNextIsOrig(valNext.equals(valOrig)) + .pStorageValueOrigIsZero(valueOriginal.isZero()) + .pStorageValueCurrIsOrig(valueCurrent.equals(valueOriginal)) + .pStorageValueCurrIsZero(valueCurrent.isZero()) + .pStorageValueNextIsCurr(valueNext.equals(valueCurrent)) + .pStorageValueNextIsZero(valueNext.isZero()) + .pStorageValueNextIsOrig(valueNext.equals(valueOriginal)) .pStorageUnconstrainedFirst(isFirstOccurrence) .pStorageUnconstrainedFinal(isFinalOccurrence); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 849f20c53a..7f20cc191f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -14,7 +14,7 @@ */ package net.consensys.linea.zktracer.module.hub.section; -import lombok.RequiredArgsConstructor; +import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; @@ -22,39 +22,38 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.EWord; +import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.worldstate.WorldView; -@RequiredArgsConstructor +@Getter public class SloadSection extends TraceSection { final Hub hub; - final State.StorageSlotIdentifier storageSlotIdentifier; - final EWord valueCurrent; + final WorldView world; - private SloadSection(Hub hub) { + private SloadSection(Hub hub, WorldView world) { this.hub = hub; - Address address = hub.currentFrame().accountAddress(); - EWord key = EWord.of(hub.messageFrame().getStackItem(0)); - this.storageSlotIdentifier = - new State.StorageSlotIdentifier(address, hub.currentFrame().accountDeploymentNumber(), key); - this.valueCurrent = EWord.of(hub.messageFrame().getTransientStorageValue(address, key)); + this.world = world; } - public static void appendSection(Hub hub) { + public static void appendSection(Hub hub, WorldView world) { - final SloadSection sloadSection = new SloadSection(hub); + final SloadSection sloadSection = new SloadSection(hub, world); hub.addTraceSection(sloadSection); - final State.StorageSlotIdentifier storageSlotIdentifier = sloadSection.storageSlotIdentifier; - final Address address = storageSlotIdentifier.getAddress(); - final EWord storageKey = storageSlotIdentifier.getStorageKey(); + final Address address = hub.currentFrame().accountAddress(); + final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); + final EWord storageKey = EWord.of(hub.messageFrame().getStackItem(0)); final EWord valueOriginal = - hub.txStack().current().getStorage().getOriginalValueOrUpdate(address, storageKey); - final EWord valueCurrent = sloadSection.valueCurrent; + EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); + final EWord valueCurrent = + EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); ImcFragment miscFragmentForSload = ImcFragment.empty(hub); - StorageFragment doingSload = doingSload(hub, address, storageKey, valueOriginal, valueCurrent); + StorageFragment doingSload = + doingSload(hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent); sloadSection.addFragmentsAndStack( hub, hub.currentFrame(), readCurrentContext, miscFragmentForSload, doingSload); @@ -65,24 +64,24 @@ public static void appendSection(Hub hub) { if (outOfGasException || contextWillRevert) { final StorageFragment undoingSload = - undoingSload(hub, address, storageKey, valueOriginal, valueCurrent); + undoingSload(hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent); // TODO: make sure we trace a context when there is an exception sloadSection.addFragment(hub, hub.currentFrame(), undoingSload); - hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, undoingSload); - return; } - - hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingSload); } private static StorageFragment doingSload( - Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent) { + Hub hub, + Address address, + int deploymentNumber, + EWord storageKey, + EWord valueOriginal, + EWord valueCurrent) { return new StorageFragment( hub.state, - new State.StorageSlotIdentifier( - address, hub.currentFrame().accountDeploymentNumber(), storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), valueOriginal, valueCurrent, valueCurrent, @@ -93,12 +92,16 @@ private static StorageFragment doingSload( } private static StorageFragment undoingSload( - Hub hub, Address address, EWord storageKey, EWord valueOriginal, EWord valueCurrent) { + Hub hub, + Address address, + int deploymentNumber, + EWord storageKey, + EWord valueOriginal, + EWord valueCurrent) { return new StorageFragment( hub.state, - new State.StorageSlotIdentifier( - address, hub.currentFrame().accountDeploymentNumber(), storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), valueOriginal, valueCurrent, valueCurrent, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index f4fd4b00d8..542ab157e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section; +import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; @@ -22,37 +23,34 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.EWord; +import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.worldstate.WorldView; +@Getter public class SstoreSection extends TraceSection { final Hub hub; - final State.StorageSlotIdentifier storageSlotIdentifier; - final EWord valueCurrent; - final EWord valueNext; + final WorldView world; - private SstoreSection(Hub hub) { + private SstoreSection(Hub hub, WorldView world) { this.hub = hub; - Address address = hub.currentFrame().accountAddress(); - EWord key = EWord.of(hub.messageFrame().getStackItem(0)); - this.storageSlotIdentifier = - new State.StorageSlotIdentifier(address, hub.currentFrame().accountDeploymentNumber(), key); - this.valueCurrent = EWord.of(hub.messageFrame().getTransientStorageValue(address, key)); - this.valueNext = EWord.of(hub.messageFrame().getStackItem(1)); + this.world = world; } - public static void appendSection(Hub hub) { + public static void appendSection(Hub hub, WorldView world) { - final SstoreSection sstoreSection = new SstoreSection(hub); + final SstoreSection sstoreSection = new SstoreSection(hub, world); hub.addTraceSection(sstoreSection); - final State.StorageSlotIdentifier storageSlotIdentifier = sstoreSection.storageSlotIdentifier; - final Address address = storageSlotIdentifier.getAddress(); - final EWord storageKey = storageSlotIdentifier.getStorageKey(); + final Address address = hub.currentFrame().accountAddress(); + final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); + final EWord storageKey = EWord.of(hub.messageFrame().getStackItem(0)); final EWord valueOriginal = - hub.txStack().current().getStorage().getOriginalValueOrUpdate(address, storageKey); - final EWord valueCurrent = sstoreSection.valueCurrent; - final EWord valueNext = sstoreSection.valueNext; + EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); + final EWord valueCurrent = + EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); + final EWord valueNext = EWord.of(hub.messageFrame().getStackItem(1)); final boolean staticContextException = hub.pch().exceptions().staticException(); final boolean sstoreException = hub.pch().exceptions().sstoreException(); @@ -76,14 +74,16 @@ public static void appendSection(Hub hub) { } StorageFragment doingSstore = - doingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); - StorageFragment undoingSstore = - undoingSstore(hub, address, storageKey, valueOriginal, valueCurrent, valueNext); + doingSstore( + hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); sstoreSection.addFragment(hub, hub.currentFrame(), doingSstore); // TODO: make sure we trace a context when there is an exception (oogx case) if (outOfGasException || contextWillRevert) { + StorageFragment undoingSstore = + undoingSstore( + hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); sstoreSection.addFragment(hub, hub.currentFrame(), undoingSstore); } } @@ -91,6 +91,7 @@ public static void appendSection(Hub hub) { private static StorageFragment doingSstore( Hub hub, Address address, + int deploymentNumber, EWord storageKey, EWord valueOriginal, EWord valueCurrent, @@ -98,8 +99,7 @@ private static StorageFragment doingSstore( return new StorageFragment( hub.state, - new State.StorageSlotIdentifier( - address, hub.currentFrame().accountDeploymentNumber(), storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), valueOriginal, valueCurrent, valueNext, @@ -112,6 +112,7 @@ private static StorageFragment doingSstore( private static StorageFragment undoingSstore( Hub hub, Address address, + int deploymentNumber, EWord storageKey, EWord valueOriginal, EWord valueCurrent, @@ -119,8 +120,7 @@ private static StorageFragment undoingSstore( return new StorageFragment( hub.state, - new State.StorageSlotIdentifier( - address, hub.currentFrame().accountDeploymentNumber(), storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), valueOriginal, valueNext, valueCurrent, From 83a078b604a6dc4d5f0f62d9f6c6ee9dee8a4875 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 12 Jun 2024 12:20:27 +0530 Subject: [PATCH 092/461] fix(txndata): spec issue + typo --- .../module/txndata/TxndataOperation.java | 18 +++++++++++++----- zkevm-constraints | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java index df52b7bee1..6586c69f53 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java @@ -78,7 +78,7 @@ private void setCallsToEucAndWcp() { final Bytes row0arg2 = bigIntegerToBytes( value.add( - BigInteger.valueOf(tx.getEffectiveGasPrice()) + outgoingLowRow6() .multiply(BigInteger.valueOf(tx.getBesuTransaction().getGasLimit())))); wcp.callLT(row0arg1, row0arg2); this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row0arg1, row0arg2, false)); @@ -240,8 +240,7 @@ private void setRlptxnValues() { (short) TYPE_2_RLP_TXN_PHASE_NUMBER_6, bigIntegerToBytes( tx.getBesuTransaction().getMaxPriorityFeePerGas().get().getAsBigInteger()), - bigIntegerToBytes( - tx.getBesuTransaction().getMaxFeePerGas().get().getAsBigInteger()))); + bigIntegerToBytes(outgoingLowRow6()))); // i+7 this.valuesToRlptxn.add( @@ -282,6 +281,15 @@ public void setCallWcpLastTxOfBlock(final Bytes blockGasLimit) { this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLeq(arg1, blockGasLimit, true)); } + private BigInteger outgoingLowRow6() { + return switch (tx.getBesuTransaction().getType()) { + case FRONTIER, ACCESS_LIST -> tx.getBesuTransaction().getGasPrice().get().getAsBigInteger(); + case EIP1559 -> tx.getBesuTransaction().getMaxFeePerGas().get().getAsBigInteger(); + default -> throw new RuntimeException( + "Transaction type not supported:" + tx.getBesuTransaction().getType()); + }; + } + public void traceTx(Trace trace, BlockSnapshot block, int absTxNumMax) { this.setRlptxnValues(); @@ -308,8 +316,8 @@ public void traceTx(Trace trace, BlockSnapshot block, int absTxNumMax) { final Bytes baseFee = block.getBaseFee().get().toMinimalBytes(); final long coinbaseHi = highPart(block.getCoinbaseAddress()); final Bytes coinbaseLo = lowPart(block.getCoinbaseAddress()); - final int callDataSize = tx.isDeployment() ? tx.getBesuTransaction().getPayload().size() : 0; - final int initCodeSize = tx.isDeployment() ? 0 : tx.getBesuTransaction().getPayload().size(); + final int callDataSize = tx.isDeployment() ? 0 : tx.getBesuTransaction().getPayload().size(); + final int initCodeSize = tx.isDeployment() ? tx.getBesuTransaction().getPayload().size() : 0; final Bytes gasLeftOver = Bytes.minimalBytes(tx.getLeftoverGas()); final Bytes refundCounter = Bytes.minimalBytes(tx.getRefundCounterMax()); final Bytes refundEffective = Bytes.minimalBytes(tx.getGasRefunded()); diff --git a/zkevm-constraints b/zkevm-constraints index 5bf311b57d..4711f947a7 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 5bf311b57d2bec3ff596bd0137ef33235ee555da +Subproject commit 4711f947a74df96179ea817d7edd71b1a0d80064 From 24bb20cd050f516dd5c84e9cd10ace1fbda3de0d Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 12 Jun 2024 17:05:37 +0530 Subject: [PATCH 093/461] test(bin): add ref tests --- .../linea/zktracer/module/bin/BinTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java index fd457edb20..7632ab4d28 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java @@ -49,4 +49,20 @@ void testSignedSignextend() { .compile()) .run(); } + + @Test + void testSignextendRef() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push(0xFF) + .push(0) + .op(OpCode.SIGNEXTEND) + .op(OpCode.POP) + .push(0x7F) + .push(0) + .op(OpCode.SIGNEXTEND) + .op(OpCode.POP) + .compile()) + .run(); + } } From eb9cb2fb0f51ad18a5e7d852aa0f1bebd8e4bbdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 13 Jun 2024 00:39:11 +0200 Subject: [PATCH 094/461] GAS_COST now filled during tracePostExecution --- .../linea/zktracer/module/hub/Hub.java | 28 +++- .../module/hub/fragment/CommonFragment.java | 154 +++++++++++++++--- .../module/hub/fragment/StackFragment.java | 2 +- .../module/hub/fragment/imc/call/MxpCall.java | 148 ++++++++++++++--- .../hub/fragment/storage/StorageFragment.java | 8 +- .../module/hub/section/CreateSection.java | 2 +- .../module/hub/section/SloadSection.java | 22 ++- .../module/hub/section/SstoreSection.java | 18 +- .../module/hub/signals/Exceptions.java | 24 +-- .../zktracer/module/hub/signals/Signals.java | 12 +- 10 files changed, 328 insertions(+), 90 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 2e5b242e82..2ed744deca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -37,6 +37,7 @@ import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.bin.Bin; @@ -60,6 +61,7 @@ import net.consensys.linea.zktracer.module.hub.section.txFinalization.TxFinalizationPostTxDefer; import net.consensys.linea.zktracer.module.hub.section.txPreWarming.PreWarmingMacroSection; import net.consensys.linea.zktracer.module.hub.section.txSkipippedSection.SkippedPostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -960,6 +962,30 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.state().processingPhase != TX_SKIP, "There can't be any execution if the HUB is in the a skip phase"); + long gasCost = operationResult.getGasCost(); + TraceSection currentSection = this.state.currentTxTrace().currentSection(); + + Exceptions exceptions = this.pch().exceptions(); + boolean memoryExpansionException = exceptions.memoryExpansionException(); + boolean outOfGasException = exceptions.outOfGasException(); + boolean unexceptional = exceptions.none(); + + // Setting gas cost IN MOST CASES + // TODO: + // * complete this for CREATE's and CALL's + // * make sure this aligns with exception handling of the zkevm + if ((!memoryExpansionException & outOfGasException) || unexceptional) { + for (TraceSection.TraceLine line : currentSection.lines()) { + line.common().gasCost(gasCost); + line.common().gasNext(line.common().gasActual() - gasCost); + } + } else { + for (TraceSection.TraceLine line : currentSection.lines()) { + line.common().gasCost(0xdeadbeefL); // TODO: fill with correct values --- likely 0 + line.common().gasNext(0xdeadbeefL); + } + } + if (this.currentFrame().opCode().isCreate() && operationResult.getHaltReason() == null) { this.handleCreate(Words.toAddress(frame.getStackItem(0))); } @@ -1355,7 +1381,7 @@ void traceOperation(MessageFrame frame) { ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount), ContextFragment.readCurrentContextData(this))); - } else if (this.pch().exceptions().outOfMemoryExpansion()) { + } else if (this.pch().exceptions().memoryExpansionException()) { this.addTraceSection( new FailedCallSection( this, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index e9a803808f..1bb71c9d1f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -15,12 +15,16 @@ package net.consensys.linea.zktracer.module.hub.fragment; +import static net.consensys.linea.zktracer.opcode.OpCode.SSTORE; + import java.math.BigInteger; +import java.util.function.Supplier; import lombok.Builder; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.State; @@ -31,12 +35,27 @@ import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.units.bigints.UInt256; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.EvmSpecVersion; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.fluent.EVMExecutor; +import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.evm.operation.Operation; +import org.hyperledger.besu.evm.operation.OperationRegistry; +import org.hyperledger.besu.evm.operation.SelfDestructOperation; +import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true, chain = false) @Builder public final class CommonFragment implements TraceFragment { + private final Hub hub; private final int absoluteTransactionNumber; private final int relativeBlockNumber; @@ -57,10 +76,10 @@ public final class CommonFragment implements TraceFragment { @Setter private int pcNew; private int codeDeploymentNumber; private final boolean codeDeploymentStatus; - private final long gasExpected; - private final long gasActual; - private final long gasCost; - private final long gasNext; + @Setter long gasExpected; + @Getter long gasActual; + @Setter long gasCost; + @Setter long gasNext; @Getter private final long refundDelta; @Setter private long gasRefund; @Getter @Setter private boolean twoLineInstruction; @@ -70,25 +89,33 @@ public final class CommonFragment implements TraceFragment { public static CommonFragment fromHub( final Hub hub, - final CallFrame frame, + final CallFrame callFrame, boolean counterTli, int counterNsr, int numberOfNonStackRows) { final boolean noStackException = hub.pch().exceptions().noStackException(); final long refundDelta = - noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).refund() : 0; + noStackException ? Hub.GAS_PROJECTOR.of(callFrame.frame(), hub.opCode()).refund() : 0; // TODO: partial solution, will not work in general final long gasExpected = hub.expectedGas(); final long gasActual = hub.remainingGas(); - final long gasCost = - noStackException ? Hub.GAS_PROJECTOR.of(frame.frame(), hub.opCode()).staticGas() : 0; - final long gasNext = - hub.pch().exceptions().any() - ? 0 - : Math.max( - gasActual - gasCost, 0); // TODO: ugly, to fix just to not trace negative value + +// final boolean gasCostComputationIsRequired = +// (hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC) +// & noStackException +// & (hub.pch().exceptions().outOfGasException() || hub.pch().exceptions().none()); +// final long gasCost = +// gasCostComputationIsRequired +// ? CommonFragment.computeGasCost(hub, callFrame.frame().getWorldUpdater()) +// : 0; +// +// final long gasNext = +// hub.pch().exceptions().any() +// ? 0 +// : Math.max( +// gasActual - gasCost, 0); // TODO: ugly, to fix just to not trace negative value final int height = hub.currentFrame().stack().getHeight(); final int heightNew = @@ -98,7 +125,7 @@ public static CommonFragment fromHub( + hub.opCode().getData().stackSettings().alpha() : 0); final boolean hubInExecPhase = hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC; - final int pc = hubInExecPhase ? frame.pc() : 0; + final int pc = hubInExecPhase ? callFrame.pc() : 0; final int pcNew = computePcNew(hub, pc, noStackException, hubInExecPhase); return CommonFragment.builder() @@ -111,20 +138,20 @@ public static CommonFragment fromHub( .exceptions(hub.pch().exceptions().snapshot()) .abortingConditions(hub.pch().abortingConditions().snapshot()) .failureConditions(hub.pch().failureConditions().snapshot()) - .callFrameId(frame.id()) - .contextNumber(hubInExecPhase ? frame.contextNumber() : 0) - .contextNumberNew(hub.contextNumberNew(frame)) + .callFrameId(callFrame.id()) + .contextNumber(hubInExecPhase ? callFrame.contextNumber() : 0) + .contextNumberNew(hub.contextNumberNew(callFrame)) .pc(pc) .pcNew(pcNew) .height((short) height) .heightNew((short) heightNew) - .codeDeploymentNumber(frame.codeDeploymentNumber()) - .codeDeploymentStatus(frame.isDeployment()) + .codeDeploymentNumber(callFrame.codeDeploymentNumber()) + .codeDeploymentStatus(callFrame.isDeployment()) .gasExpected(gasExpected) .gasActual(gasActual) - .gasCost(gasCost) - .gasNext(gasNext) - .callerContextNumber(hub.callStack().getParentOf(frame.id()).contextNumber()) +// .gasCost(gasCost) +// .gasNext(gasNext) + .callerContextNumber(hub.callStack().getParentOf(callFrame.id()).contextNumber()) .refundDelta(refundDelta) .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) .twoLineInstructionCounter(counterTli) @@ -239,4 +266,87 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .nonStackRows((short) numberOfNonStackRows) .counterNsr((short) nonStackRowsCounter); } + + static long computeGasCost(Hub hub, WorldView world) { + + switch (hub.opCodeData().instructionFamily()) { + case ADD, MOD, SHF, BIN, WCP, EXT, BATCH, MACHINE_STATE, PUSH_POP, DUP, SWAP, INVALID -> { + if (hub.pch().exceptions().outOfGasException() || hub.pch().exceptions().none()) { + return hub.opCode().getData().stackSettings().staticGas().cost(); + } + return 0; + } + case STORAGE -> { + switch (hub.opCode()) { + case SSTORE -> { + return gasCostSstore(hub, world); + } + case SLOAD -> { + return gasCostSload(hub, world); + } + default -> throw new RuntimeException( + "Gas cost not covered for " + hub.opCode().toString()); + } + } + case HALT -> { + switch (hub.opCode()) { + case STOP -> { return 0; } + case RETURN, REVERT -> { + Bytes offset = hub.messageFrame().getStackItem(0); + Bytes size = hub.messageFrame().getStackItem(0); + return hub.pch().exceptions().memoryExpansionException() + ? 0 + : ZkTracer.gasCalculator.memoryExpansionGasCost(hub.messageFrame(), offset.toLong(), size.toLong()); + } + case SELFDESTRUCT -> { + SelfDestructOperation op = new SelfDestructOperation(ZkTracer.gasCalculator); + Operation.OperationResult operationResult = op.execute(hub.messageFrame(), new EVM(new OperationRegistry(), ZkTracer.gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.LONDON)); + long gasCost = operationResult.getGasCost(); + Address recipient = Address.extract((Bytes32) hub.messageFrame().getStackItem(0)); + Wei inheritance = world.get(hub.messageFrame().getRecipientAddress()).getBalance(); + return ZkTracer.gasCalculator.selfDestructOperationGasCost(world.get(recipient), inheritance); + } + } + return 0;} + default -> { + throw new RuntimeException("Gas cost not covered for " + hub.opCode().toString()); + } + } + } + + static long gasCostSstore(Hub hub, WorldView world) { + + final Address address = hub.currentFrame().accountAddress(); + final EWord storageKey = EWord.of(hub.messageFrame().getStackItem(0)); + + final UInt256 storageKeyUint256 = UInt256.fromBytes(hub.messageFrame().getStackItem(0)); + final UInt256 valueNextUint256 = UInt256.fromBytes(hub.messageFrame().getStackItem(1)); + + final Supplier valueCurrentSupplier = + () -> world.get(address).getStorageValue(storageKeyUint256); + final Supplier valueOriginalSupplier = + () -> world.get(address).getOriginalStorageValue(storageKeyUint256); + + final long storageCost = + ZkTracer.gasCalculator.calculateStorageCost( + valueNextUint256, valueCurrentSupplier, valueOriginalSupplier); + final boolean storageSlotWarmth = hub.currentFrame().frame().isStorageWarm(address, storageKey); + + return storageCost + (storageSlotWarmth ? 0L : ZkTracer.gasCalculator.getColdSloadCost()); + } + + static long gasCostSload(Hub hub, WorldView world) { + final Address address = hub.currentFrame().accountAddress(); + final EWord storageKey = EWord.of(hub.messageFrame().getStackItem(0)); + final boolean storageSlotWarmth = hub.currentFrame().frame().isStorageWarm(address, storageKey); + + return ZkTracer.gasCalculator.getSloadOperationGasCost() + + (storageSlotWarmth + ? ZkTracer.gasCalculator.getWarmStorageReadCost() + : ZkTracer.gasCalculator.getColdSloadCost()); + } + + static long Bull() { + return 0x1337; + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index e261319719..b5f7f0a272 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -290,7 +290,7 @@ public Trace trace(Trace trace) { .pStackOpcx(exceptions.invalidOpcode()) .pStackSux(exceptions.stackUnderflow()) .pStackSox(exceptions.stackOverflow()) - .pStackMxpx(exceptions.outOfMemoryExpansion()) + .pStackMxpx(exceptions.memoryExpansionException()) .pStackOogx(exceptions.outOfGasException()) .pStackRdcx(exceptions.returnDataCopyFault()) .pStackJumpx(exceptions.jumpFault()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index 6f0522edfa..d19ab78f8e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call; +import com.google.common.base.Preconditions; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; @@ -22,57 +24,149 @@ import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; -public record MxpCall( - boolean mxpException, - int opCode, - boolean deploys, - int memorySize, - long gasMxp, - EWord offset1, - EWord offset2, - EWord size1, - EWord size2) - implements TraceSubFragment { +@RequiredArgsConstructor +public class MxpCall implements TraceSubFragment { + + final Hub hub; + final OpCode opCode; + final boolean deploys; + final EWord offset1; + final EWord size1; + final EWord offset2; + final EWord size2; + final boolean memoryExpansionException; + final long memorySizeInWords; + final long gasMxp; + public static MxpCall build(Hub hub) { - final OpCode opCode = hub.currentFrame().opCode(); // TODO: call the MXP here // TODO: get from Mxp all the following // TODO: check hub mxpx == mxp mxpx - long gasMxp = 0; EWord offset1 = EWord.ZERO; EWord offset2 = EWord.ZERO; EWord size1 = EWord.ZERO; EWord size2 = EWord.ZERO; + long gasMxp = 0; + return new MxpCall( - hub.pch().exceptions().outOfMemoryExpansion(), - hub.currentFrame().opCodeData().value(), - opCode == OpCode.RETURN && hub.currentFrame().isDeployment(), - hub.currentFrame().frame().memoryWordSize(), - gasMxp, + hub, + hub.opCode(), + getDeploys(hub), offset1, - offset2, size1, - size2); + offset2, + size2, + getMemoryExpansionException(hub), + gasMxp, + hub.messageFrame().memoryWordSize()); + } + + public MxpCall mxpCallType1(Hub hub) { + Preconditions.checkArgument(hub.opCode().equals(OpCode.MSIZE)); + return new MxpCall( + hub, + getOpcode(hub), + getDeploys(hub), + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + getMemoryExpansionException(hub), + hub.messageFrame().memoryWordSize(), + 0); + } + + public MxpCall mxpCallType2(Hub hub, EWord offset1) { + return new MxpCall( + hub, + getOpcode(hub), + getDeploys(hub), + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + getMemoryExpansionException(hub), + hub.messageFrame().memoryWordSize(), + 0); + } + + public MxpCall mxpCallType3(Hub hub) { + return new MxpCall( + hub, + getOpcode(hub), + getDeploys(hub), + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + getMemoryExpansionException(hub), + hub.messageFrame().memoryWordSize(), + 0); + } + + public MxpCall mxpCallType4(Hub hub) { + return new MxpCall( + hub, + getOpcode(hub), + getDeploys(hub), + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + getMemoryExpansionException(hub), + hub.messageFrame().memoryWordSize(), + 0); + } + + public MxpCall mxpCallType5(Hub hub) { + return new MxpCall( + hub, + getOpcode(hub), + getDeploys(hub), + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + EWord.ZERO, + getMemoryExpansionException(hub), + hub.messageFrame().memoryWordSize(), + 0); + } + + static OpCode getOpcode(Hub hub) { + return hub.opCode(); + } + + static boolean getDeploys(Hub hub) { + return getOpcode(hub) == OpCode.RETURN && hub.currentFrame().isDeployment(); + } + + static boolean getMemoryExpansionException(Hub hub) { + return hub.pch().exceptions().memoryExpansionException(); + } + + final boolean type4InstructionMayTriggerNonTrivialOperation(Hub hub) { + return !getMemoryExpansionException(hub) && !this.size1.isZero(); } @Override public Trace trace(Trace trace) { return trace .pMiscMxpFlag(true) - .pMiscMxpMxpx(this.mxpException) - .pMiscMxpInst(this.opCode) + .pMiscMxpInst(this.opCode.byteValue()) .pMiscMxpDeploys(this.deploys) - .pMiscMxpWords(Bytes.ofUnsignedLong(this.memorySize)) - .pMiscMxpGasMxp(Bytes.ofUnsignedLong(this.gasMxp)) .pMiscMxpOffset1Hi(this.offset1.hi()) .pMiscMxpOffset1Lo(this.offset1.lo()) - .pMiscMxpOffset2Hi(this.offset2.hi()) - .pMiscMxpOffset2Lo(this.offset2.lo()) .pMiscMxpSize1Hi(this.size1.hi()) .pMiscMxpSize1Lo(this.size1.lo()) + .pMiscMxpOffset2Hi(this.offset2.hi()) + .pMiscMxpOffset2Lo(this.offset2.lo()) .pMiscMxpSize2Hi(this.size2.hi()) - .pMiscMxpSize2Lo(this.size2.lo()); + .pMiscMxpSize2Lo(this.size2.lo()) + .pMiscMxpMtntop(this.type4InstructionMayTriggerNonTrivialOperation(hub)) + .pMiscMxpMxpx(this.memoryExpansionException) + .pMiscMxpWords(Bytes.ofUnsignedLong(this.memorySizeInWords)) + .pMiscMxpGasMxp(Bytes.ofUnsignedLong(this.gasMxp)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index e6f0ee5b7a..1e9a3ec53f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -39,8 +39,8 @@ public final class StorageFragment implements TraceFragment { private final EWord valueOriginal; private final EWord valueCurrent; private final EWord valueNext; - private final boolean oldWarmth; - private final boolean newWarmth; + private final boolean incomingWarmth; + private final boolean outgoingWarmth; private final DomSubStampsSubFragment domSubStampsSubFragment; private final int blockNumber; @@ -71,8 +71,8 @@ public Trace trace(Trace trace) { .pStorageValueCurrLo(valueCurrent.lo()) .pStorageValueNextHi(valueNext.hi()) .pStorageValueNextLo(valueNext.lo()) - .pStorageWarmth(oldWarmth) - .pStorageWarmthNew(newWarmth) + .pStorageWarmth(incomingWarmth) + .pStorageWarmthNew(outgoingWarmth) .pStorageValueOrigIsZero(valueOriginal.isZero()) .pStorageValueCurrIsOrig(valueCurrent.equals(valueOriginal)) .pStorageValueCurrIsZero(valueCurrent.isZero()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 88d768d5f4..e7d601e675 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -186,7 +186,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces ImcFragment.empty(hub), ContextFragment.readCurrentContextData(hub), ContextFragment.executionProvidesEmptyReturnData(hub)); - } else if (this.exceptions.outOfMemoryExpansion()) { + } else if (this.exceptions.memoryExpansionException()) { this.addFragmentsWithoutStack( hub, ImcFragment.empty(hub).callMxp(MxpCall.build(hub)), diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 7f20cc191f..1df05001c5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -22,6 +22,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.EWord; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -42,9 +44,9 @@ public static void appendSection(Hub hub, WorldView world) { final SloadSection sloadSection = new SloadSection(hub, world); hub.addTraceSection(sloadSection); - final Address address = hub.currentFrame().accountAddress(); + final Address address = hub.messageFrame().getRecipientAddress(); final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); - final EWord storageKey = EWord.of(hub.messageFrame().getStackItem(0)); + final Bytes32 storageKey = (Bytes32) (hub.messageFrame().getStackItem(0)); final EWord valueOriginal = EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); final EWord valueCurrent = @@ -75,17 +77,19 @@ private static StorageFragment doingSload( Hub hub, Address address, int deploymentNumber, - EWord storageKey, + Bytes32 storageKey, EWord valueOriginal, EWord valueCurrent) { + final boolean incomingWarmth = hub.messageFrame().isStorageWarm(address, storageKey); + return new StorageFragment( hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), valueOriginal, valueCurrent, valueCurrent, - hub.currentFrame().frame().isStorageWarm(address, storageKey), + incomingWarmth, true, DomSubStampsSubFragment.standardDomSubStamps(hub, 0), hub.state.firstAndLastStorageSlotOccurrences.size()); @@ -95,18 +99,20 @@ private static StorageFragment undoingSload( Hub hub, Address address, int deploymentNumber, - EWord storageKey, + Bytes32 storageKey, EWord valueOriginal, EWord valueCurrent) { + final boolean initiallyIncomingWarmth = hub.messageFrame().isStorageWarm(address, storageKey); + return new StorageFragment( hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), valueOriginal, valueCurrent, valueCurrent, true, - hub.currentFrame().frame().isStorageWarm(address, storageKey), + initiallyIncomingWarmth, DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), hub.state.firstAndLastStorageSlotOccurrences.size()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 542ab157e4..26f7ad3cc3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -23,6 +23,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.EWord; +import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -43,9 +44,10 @@ public static void appendSection(Hub hub, WorldView world) { final SstoreSection sstoreSection = new SstoreSection(hub, world); hub.addTraceSection(sstoreSection); - final Address address = hub.currentFrame().accountAddress(); + final Address address = hub.messageFrame().getRecipientAddress(); final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); - final EWord storageKey = EWord.of(hub.messageFrame().getStackItem(0)); + final Bytes32 storageKey = (Bytes32) hub.messageFrame().getStackItem(0); + final EWord valueOriginal = EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); final EWord valueCurrent = @@ -92,18 +94,18 @@ private static StorageFragment doingSstore( Hub hub, Address address, int deploymentNumber, - EWord storageKey, + Bytes32 storageKey, EWord valueOriginal, EWord valueCurrent, EWord valueNext) { return new StorageFragment( hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), valueOriginal, valueCurrent, valueNext, - hub.currentFrame().frame().isStorageWarm(address, storageKey), + hub.messageFrame().isStorageWarm(address, storageKey), true, DomSubStampsSubFragment.standardDomSubStamps(hub, 0), hub.state.firstAndLastStorageSlotOccurrences.size()); @@ -113,19 +115,19 @@ private static StorageFragment undoingSstore( Hub hub, Address address, int deploymentNumber, - EWord storageKey, + Bytes32 storageKey, EWord valueOriginal, EWord valueCurrent, EWord valueNext) { return new StorageFragment( hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, storageKey), + new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), valueOriginal, valueNext, valueCurrent, true, - hub.currentFrame().frame().isStorageWarm(address, storageKey), + hub.messageFrame().isStorageWarm(address, storageKey), DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), hub.state.firstAndLastStorageSlotOccurrences.size()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java index 2a01cf19c0..9923371978 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java @@ -41,7 +41,7 @@ public final class Exceptions { private boolean invalidOpcode; private boolean stackUnderflow; private boolean stackOverflow; - private boolean outOfMemoryExpansion; + private boolean memoryExpansionException; private boolean outOfGasException; private boolean returnDataCopyFault; private boolean jumpFault; @@ -54,7 +54,7 @@ public final class Exceptions { * @param invalidOpcode unknown opcode * @param stackUnderflow stack underflow * @param stackOverflow stack overflow - * @param outOfMemoryExpansion tried to use memory too far away + * @param memoryExpansionException tried to use memory too far away * @param outOfGasException not enough gas for instruction * @param returnDataCopyFault trying to read pas the RETURNDATA end * @param jumpFault jumping to an invalid destination @@ -65,7 +65,7 @@ public Exceptions( boolean invalidOpcode, boolean stackUnderflow, boolean stackOverflow, - boolean outOfMemoryExpansion, + boolean memoryExpansionException, boolean outOfGasException, boolean returnDataCopyFault, boolean jumpFault, @@ -77,7 +77,7 @@ public Exceptions( this.invalidOpcode = invalidOpcode; this.stackUnderflow = stackUnderflow; this.stackOverflow = stackOverflow; - this.outOfMemoryExpansion = outOfMemoryExpansion; + this.memoryExpansionException = memoryExpansionException; this.outOfGasException = outOfGasException; this.returnDataCopyFault = returnDataCopyFault; this.jumpFault = jumpFault; @@ -98,7 +98,7 @@ public String toString() { if (this.stackOverflow) { return "Stack overflow"; } - if (this.outOfMemoryExpansion) { + if (this.memoryExpansionException) { return "Out of MXP"; } if (this.outOfGasException) { @@ -129,7 +129,7 @@ public void reset() { this.invalidOpcode = false; this.stackUnderflow = false; this.stackOverflow = false; - this.outOfMemoryExpansion = false; + this.memoryExpansionException = false; this.outOfGasException = false; this.returnDataCopyFault = false; this.jumpFault = false; @@ -159,7 +159,7 @@ public Exceptions snapshot() { invalidOpcode, stackUnderflow, stackOverflow, - outOfMemoryExpansion, + memoryExpansionException, outOfGasException, returnDataCopyFault, jumpFault, @@ -176,7 +176,7 @@ public boolean any() { return this.invalidOpcode || this.stackUnderflow || this.stackOverflow - || this.outOfMemoryExpansion + || this.memoryExpansionException || this.outOfGasException || this.returnDataCopyFault || this.jumpFault @@ -350,8 +350,8 @@ public void prepare(final MessageFrame frame, GasProjector gp) { MLOAD, MSTORE, MSTORE8 -> { - this.outOfMemoryExpansion = isMemoryExpansionFault(frame, opCode, gp); - if (this.outOfMemoryExpansion) { + this.memoryExpansionException = isMemoryExpansionFault(frame, opCode, gp); + if (this.memoryExpansionException) { return; } @@ -366,8 +366,8 @@ public void prepare(final MessageFrame frame, GasProjector gp) { return; } - this.outOfMemoryExpansion = isMemoryExpansionFault(frame, opCode, gp); - if (this.outOfMemoryExpansion) { + this.memoryExpansionException = isMemoryExpansionFault(frame, opCode, gp); + if (this.memoryExpansionException) { return; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index 99da6c2919..bbe93eeb1c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -142,19 +142,19 @@ public void prepare(MessageFrame frame, PlatformController platformController, H switch (opCode) { case CALLDATACOPY, CODECOPY -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); + this.mxp = ex.memoryExpansionException() || ex.outOfGasException() || ex.none(); this.mmu = ex.none() && !frame.getStackItem(2).isZero(); } case RETURNDATACOPY -> { this.oob = ex.none() || ex.returnDataCopyFault(); - this.mxp = ex.none() || ex.outOfMemoryExpansion() || ex.outOfGasException(); + this.mxp = ex.none() || ex.memoryExpansionException() || ex.outOfGasException(); this.mmu = ex.none() && !frame.getStackItem(2).isZero(); } case EXTCODECOPY -> { final boolean nonzeroSize = !frame.getStackItem(3).isZero(); - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); + this.mxp = ex.memoryExpansionException() || ex.outOfGasException() || ex.none(); this.trm = ex.outOfGasException() || ex.none(); this.mmu = ex.none() && nonzeroSize; @@ -168,7 +168,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H } case LOG0, LOG1, LOG2, LOG3, LOG4 -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); + this.mxp = ex.memoryExpansionException() || ex.outOfGasException() || ex.none(); this.mmu = ex.none() && !frame @@ -224,7 +224,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H } case REVERT -> { - this.mxp = ex.outOfMemoryExpansion() || ex.outOfGasException() || ex.none(); + this.mxp = ex.memoryExpansionException() || ex.outOfGasException() || ex.none(); this.mmu = ex.none() && !frame.getStackItem(1).isZero() @@ -237,7 +237,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H // WARN: Static part, other modules may be dynamically requested in the hub this.mxp = - ex.outOfMemoryExpansion() + ex.memoryExpansionException() || ex.outOfGasException() || ex.invalidCodePrefix() || ex.none(); From 709190f5d93a75d2565eee6137581324f43799ca Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 13 Jun 2024 11:53:24 +0530 Subject: [PATCH 095/461] fix(bin): trace full arg and result for trivial BYTE ans SIGNEXTEND + spotless --- .../zktracer/module/bin/BinOperation.java | 12 ++-- .../linea/zktracer/module/hub/Hub.java | 1 - .../module/hub/fragment/CommonFragment.java | 60 +++++++++++-------- .../module/hub/section/SloadSection.java | 1 - zkevm-constraints | 2 +- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/BinOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/BinOperation.java index cfbabe20f4..0be3cca1c6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/BinOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/BinOperation.java @@ -39,8 +39,6 @@ @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) @RequiredArgsConstructor public class BinOperation extends ModuleOperation { - private static final int LIMB_SIZE = 16; - @EqualsAndHashCode.Include private final OpCode opCode; @EqualsAndHashCode.Include private final BaseBytes arg1; @EqualsAndHashCode.Include private final BaseBytes arg2; @@ -79,7 +77,7 @@ private int maxCt() { arg1.getLow().trimLeadingZeros().size(), arg2.getLow().trimLeadingZeros().size())) - 1); - default -> throw new IllegalStateException("Unexpected value: " + opCode); + default -> throw new IllegalStateException("BIN doesn't support OpCode" + opCode); }; } @@ -92,7 +90,7 @@ private int getPivotThreshold() { case AND, OR, XOR, NOT -> 16; case BYTE -> low4; case SIGNEXTEND -> 15 - low4; - default -> throw new IllegalStateException("Bin doesn't support OpCode" + opCode); + default -> throw new IllegalStateException("BIN doesn't support OpCode" + opCode); }; } @@ -194,10 +192,14 @@ private void compute() { this.pivot = getPivot(); } + private boolean isTrivialOperation() { + return (opCode == OpCode.BYTE || opCode == OpCode.SIGNEXTEND) && ctMax == 0; + } + public void traceBinOperation(int stamp, Trace trace) { this.compute(); - final int length = ctMax + 1; + final int length = isTrivialOperation() ? LLARGE : ctMax + 1; final int offset = LLARGE - length; final Bytes arg1Hi = this.arg1.getHigh().slice(offset, length); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 2ed744deca..3b1fe82210 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -37,7 +37,6 @@ import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.bin.Bin; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index 1bb71c9d1f..acfcddb198 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -44,8 +44,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.EvmSpecVersion; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.fluent.EVMExecutor; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.operation.OperationRegistry; @@ -102,20 +100,22 @@ public static CommonFragment fromHub( final long gasExpected = hub.expectedGas(); final long gasActual = hub.remainingGas(); -// final boolean gasCostComputationIsRequired = -// (hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC) -// & noStackException -// & (hub.pch().exceptions().outOfGasException() || hub.pch().exceptions().none()); -// final long gasCost = -// gasCostComputationIsRequired -// ? CommonFragment.computeGasCost(hub, callFrame.frame().getWorldUpdater()) -// : 0; -// -// final long gasNext = -// hub.pch().exceptions().any() -// ? 0 -// : Math.max( -// gasActual - gasCost, 0); // TODO: ugly, to fix just to not trace negative value + // final boolean gasCostComputationIsRequired = + // (hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC) + // & noStackException + // & (hub.pch().exceptions().outOfGasException() || + // hub.pch().exceptions().none()); + // final long gasCost = + // gasCostComputationIsRequired + // ? CommonFragment.computeGasCost(hub, callFrame.frame().getWorldUpdater()) + // : 0; + // + // final long gasNext = + // hub.pch().exceptions().any() + // ? 0 + // : Math.max( + // gasActual - gasCost, 0); // TODO: ugly, to fix just to not trace negative + // value final int height = hub.currentFrame().stack().getHeight(); final int heightNew = @@ -149,8 +149,8 @@ public static CommonFragment fromHub( .codeDeploymentStatus(callFrame.isDeployment()) .gasExpected(gasExpected) .gasActual(gasActual) -// .gasCost(gasCost) -// .gasNext(gasNext) + // .gasCost(gasCost) + // .gasNext(gasNext) .callerContextNumber(hub.callStack().getParentOf(callFrame.id()).contextNumber()) .refundDelta(refundDelta) .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) @@ -290,24 +290,36 @@ static long computeGasCost(Hub hub, WorldView world) { } case HALT -> { switch (hub.opCode()) { - case STOP -> { return 0; } + case STOP -> { + return 0; + } case RETURN, REVERT -> { Bytes offset = hub.messageFrame().getStackItem(0); Bytes size = hub.messageFrame().getStackItem(0); return hub.pch().exceptions().memoryExpansionException() - ? 0 - : ZkTracer.gasCalculator.memoryExpansionGasCost(hub.messageFrame(), offset.toLong(), size.toLong()); + ? 0 + : ZkTracer.gasCalculator.memoryExpansionGasCost( + hub.messageFrame(), offset.toLong(), size.toLong()); } case SELFDESTRUCT -> { SelfDestructOperation op = new SelfDestructOperation(ZkTracer.gasCalculator); - Operation.OperationResult operationResult = op.execute(hub.messageFrame(), new EVM(new OperationRegistry(), ZkTracer.gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.LONDON)); + Operation.OperationResult operationResult = + op.execute( + hub.messageFrame(), + new EVM( + new OperationRegistry(), + ZkTracer.gasCalculator, + EvmConfiguration.DEFAULT, + EvmSpecVersion.LONDON)); long gasCost = operationResult.getGasCost(); Address recipient = Address.extract((Bytes32) hub.messageFrame().getStackItem(0)); Wei inheritance = world.get(hub.messageFrame().getRecipientAddress()).getBalance(); - return ZkTracer.gasCalculator.selfDestructOperationGasCost(world.get(recipient), inheritance); + return ZkTracer.gasCalculator.selfDestructOperationGasCost( + world.get(recipient), inheritance); } } - return 0;} + return 0; + } default -> { throw new RuntimeException("Gas cost not covered for " + hub.opCode().toString()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 1df05001c5..5a3015c160 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -22,7 +22,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; diff --git a/zkevm-constraints b/zkevm-constraints index 4711f947a7..15ac2bd78a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 4711f947a74df96179ea817d7edd71b1a0d80064 +Subproject commit 15ac2bd78a1d8f99b7f0e83aa25f12f92f1a497a From b96724b8e3b078cda085f489017056dc1efb5f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 13 Jun 2024 12:01:55 +0200 Subject: [PATCH 096/461] ras --- .../consensys/linea/zktracer/module/hub/Hub.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 3b1fe82210..302bc1eaa8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -961,18 +961,19 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.state().processingPhase != TX_SKIP, "There can't be any execution if the HUB is in the a skip phase"); - long gasCost = operationResult.getGasCost(); - TraceSection currentSection = this.state.currentTxTrace().currentSection(); + final long gasCost = operationResult.getGasCost(); + final TraceSection currentSection = this.state.currentTxTrace().currentSection(); - Exceptions exceptions = this.pch().exceptions(); - boolean memoryExpansionException = exceptions.memoryExpansionException(); - boolean outOfGasException = exceptions.outOfGasException(); - boolean unexceptional = exceptions.none(); + final Exceptions exceptions = this.pch().exceptions(); + final boolean memoryExpansionException = exceptions.memoryExpansionException(); + final boolean outOfGasException = exceptions.outOfGasException(); + final boolean unexceptional = exceptions.none(); // Setting gas cost IN MOST CASES // TODO: // * complete this for CREATE's and CALL's // * make sure this aligns with exception handling of the zkevm + // * write a method `final boolean requiresGasCostInsertion()` (huge switch case) if ((!memoryExpansionException & outOfGasException) || unexceptional) { for (TraceSection.TraceLine line : currentSection.lines()) { line.common().gasCost(gasCost); From 4fea802ab4e0ac8c8569ad1b32c7ec13b25e2ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 13 Jun 2024 19:15:42 +0200 Subject: [PATCH 097/461] every exception triggers a final context row (previously was only implemneted AFAICT for stack exceptions) --- .../linea/zktracer/module/hub/Hub.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 302bc1eaa8..d9df5c341b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -654,8 +654,6 @@ void processStateExec(MessageFrame frame) { this.traceOperation(frame); } else { this.addTraceSection(new StackOnlySection(this)); - this.currentTraceSection() - .addFragmentsWithoutStack(this, ContextFragment.executionProvidesEmptyReturnData(this)); } } @@ -968,21 +966,35 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope final boolean memoryExpansionException = exceptions.memoryExpansionException(); final boolean outOfGasException = exceptions.outOfGasException(); final boolean unexceptional = exceptions.none(); + final boolean exceptional = exceptions.any(); + // adds the final context row to reset the caller's return data + if (exceptional) { + this.currentTraceSection() + .addFragmentsWithoutStack(this, ContextFragment.executionProvidesEmptyReturnData(this)); + } // Setting gas cost IN MOST CASES // TODO: // * complete this for CREATE's and CALL's + // + are we getting the correct cost (i.e. excluding the 63/64-th's) ? // * make sure this aligns with exception handling of the zkevm - // * write a method `final boolean requiresGasCostInsertion()` (huge switch case) + // * write a method `final boolean requiresGasCost()` (huge switch case) if ((!memoryExpansionException & outOfGasException) || unexceptional) { for (TraceSection.TraceLine line : currentSection.lines()) { line.common().gasCost(gasCost); - line.common().gasNext(line.common().gasActual() - gasCost); + line.common().gasNext(unexceptional ? line.common().gasActual() - gasCost : 0); + } + + // we add a context fragment updating the CALLER CONTEXT's + // return data to be empty + if (exceptions.any()) { + currentSection.addFragment( + this, this.currentFrame(), ContextFragment.executionProvidesEmptyReturnData(this)); } } else { for (TraceSection.TraceLine line : currentSection.lines()) { line.common().gasCost(0xdeadbeefL); // TODO: fill with correct values --- likely 0 - line.common().gasNext(0xdeadbeefL); + line.common().gasNext(0); } } From a5f3c74e5c4433d131bad1a50aa7b8db82e5ce8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 13 Jun 2024 19:16:55 +0200 Subject: [PATCH 098/461] providing the ECDATA module with return data --- .../linea/zktracer/module/ecdata/EcData.java | 6 ++++-- .../module/ecdata/EcDataOperation.java | 4 +++- .../linea/zktracer/module/hub/Hub.java | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index dfdb9a05d4..aac8b2c8a5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -44,6 +44,7 @@ public class EcData implements Module { private final Hub hub; private final Wcp wcp; private final Ext ext; + @Getter private EcDataOperation ecDataOperation; @Override public String moduleKey() { @@ -74,8 +75,9 @@ public void tracePreOpcode(MessageFrame frame) { } final Bytes data = hub.transients().op().callData(); - this.operations.add( - EcDataOperation.of(this.wcp, this.ext, 1 + this.hub.stamp(), target.get(19), data)); + ecDataOperation = + EcDataOperation.of(this.wcp, this.ext, 1 + this.hub.stamp(), target.get(19), data); + this.operations.add(ecDataOperation); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 0b8d17627b..9e33f03ece 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -56,6 +56,7 @@ import com.google.common.base.Preconditions; import lombok.Getter; +import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.ext.Ext; @@ -76,6 +77,8 @@ public class EcDataOperation extends ModuleOperation { public static final EWord SECP256K1N = EWord.of(SECP256K1N_HI, SECP256K1N_LO); public static final int nBYTES_OF_DELTA_BYTES = 4; // TODO: from Corset ? + @Setter private Bytes returnData; + private final Wcp wcp; private final Ext ext; @@ -112,7 +115,6 @@ public class EcDataOperation extends ModuleOperation { private final List extResLo; private final List extInst; - private Bytes returnData; @Getter private boolean successBit; private boolean circuitSelectorEcrecover; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index d9df5c341b..3efef18725 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -235,6 +235,8 @@ public void addTraceSection(TraceSection section) { private final List precompileLimitModules; private final List refTableModules; + private boolean previousOperationWasCallToEcPrecompile; + public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic)); this.transients = new Transients(this); @@ -638,6 +640,12 @@ void triggerModules(MessageFrame frame) { } void processStateExec(MessageFrame frame) { + + if (previousOperationWasCallToEcPrecompile) { + this.ecData.getEcDataOperation().returnData(frame.getReturnData()); + previousOperationWasCallToEcPrecompile = false; + } + this.currentFrame().frame(frame); this.state.stamps().incrementHubStamp(); @@ -646,13 +654,18 @@ void processStateExec(MessageFrame frame) { this.handleStack(frame); this.triggerModules(frame); + if (this.pch().exceptions().any() || this.currentFrame().opCode() == OpCode.REVERT) { this.callStack.revert(this.state.stamps().hub()); } if (this.currentFrame().stack().isOk()) { + if (this.pch.signals().ecData()) { + this.previousOperationWasCallToEcPrecompile = true; + } this.traceOperation(frame); } else { + this.addTraceSection(new StackOnlySection(this)); } } @@ -963,10 +976,12 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope final TraceSection currentSection = this.state.currentTxTrace().currentSection(); final Exceptions exceptions = this.pch().exceptions(); + final boolean memoryExpansionException = exceptions.memoryExpansionException(); final boolean outOfGasException = exceptions.outOfGasException(); final boolean unexceptional = exceptions.none(); final boolean exceptional = exceptions.any(); + // adds the final context row to reset the caller's return data if (exceptional) { this.currentTraceSection() @@ -1005,6 +1020,10 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.defers.runPostExec(this, frame, operationResult); this.romLex.tracePostOpcode(frame); + if (this.previousOperationWasCallToEcPrecompile) { + this.ecData.getEcDataOperation().returnData(frame.getReturnData()); + } + if (this.currentFrame().needsUnlatchingAtReEntry() == null) { this.unlatchStack(frame); } From 3d63df6b37f540a089c2f46f62a41dafb029716d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 14 Jun 2024 01:57:59 +0200 Subject: [PATCH 099/461] KEC first draft (it sucks) --- .../linea/zktracer/module/hub/Hub.java | 34 +++++- .../module/hub/fragment/StackFragment.java | 3 +- .../module/hub/fragment/imc/call/MxpCall.java | 105 ++++++++++++++---- .../module/hub/section/KeccakSection.java | 24 +++- 4 files changed, 135 insertions(+), 31 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 3efef18725..8c763c573a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -109,6 +109,7 @@ import net.consensys.linea.zktracer.runtime.stack.StackLine; import net.consensys.linea.zktracer.types.*; import org.apache.tuweni.bytes.Bytes; +import org.bouncycastle.crypto.digests.KeccakDigest; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; @@ -660,6 +661,14 @@ void processStateExec(MessageFrame frame) { } if (this.currentFrame().stack().isOk()) { + // TODO: this is insufficient because it neglects: + // - exceptions other than stack exceptions e.g. + // * STATICX + // * MXPX + // * OOGX + // - it COULD (unlikely ?) produce issues with ABORTS + // - it COULD interfere with CALL's to precompiles that don't reach EC_DATA e.g. + // * ECRECOVER, ECADD, ECMUL, ECPAIRING with zero call data size parameter if (this.pch.signals().ecData()) { this.previousOperationWasCallToEcPrecompile = true; } @@ -1208,9 +1217,28 @@ void traceOperation(MessageFrame frame) { } } - case KEC -> this.addTraceSection( - new KeccakSection( - this, this.currentFrame(), ImcFragment.forOpcode(this, this.messageFrame()))); + case KEC -> { + final boolean triggerMmu = KeccakSection.appendToTrace(this); + + // we trigger the HASH_INFO flag + TraceSection currentSection = this.state.currentTxTrace().currentSection(); + for (TraceSection.TraceLine line : currentSection.lines()) { + if (line.specific() instanceof StackFragment) { + ((StackFragment) line.specific()).hashInfoFlag = triggerMmu; + + // TODO: this shouldn't be done by us ... + Bytes offset = this.messageFrame().getStackItem(0); + Bytes size = this.messageFrame().getStackItem(1); + Bytes dataToHash = this.messageFrame().shadowReadMemory(offset.toLong(), size.toLong()); + KeccakDigest keccakDigest = new KeccakDigest(256); + keccakDigest.update(dataToHash.toArray(), 0, dataToHash.size()); + byte[] hashOutput = new byte[keccakDigest.getDigestSize()]; + keccakDigest.doFinal(hashOutput, 0); + ((StackFragment) line.specific()).hash = Bytes.of(hashOutput); + } + } + } + case CONTEXT -> this.addTraceSection( new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); case LOG -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index b5f7f0a272..98de9c022a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -52,7 +52,8 @@ public final class StackFragment implements TraceFragment { @Setter private DeploymentExceptions contextExceptions; private final long staticGas; private EWord hashInfoKeccak = EWord.ZERO; - private final boolean hashInfoFlag; + @Setter public boolean hashInfoFlag; + @Setter public Bytes hash; @Getter private final OpCode opCode; private final boolean jumpDestinationVettingRequired; private final boolean willRevert; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index d19ab78f8e..2f8eb4b6a5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call; +import static net.consensys.linea.zktracer.opcode.OpCode.EXTCODECOPY; + import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.Hub; @@ -67,71 +69,128 @@ public MxpCall mxpCallType1(Hub hub) { Preconditions.checkArgument(hub.opCode().equals(OpCode.MSIZE)); return new MxpCall( hub, - getOpcode(hub), - getDeploys(hub), + OpCode.MSIZE, + false, EWord.ZERO, EWord.ZERO, EWord.ZERO, EWord.ZERO, - getMemoryExpansionException(hub), + false, hub.messageFrame().memoryWordSize(), 0); } - public MxpCall mxpCallType2(Hub hub, EWord offset1) { + public MxpCall mxpCallType2(Hub hub) { + + EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); + return new MxpCall( hub, getOpcode(hub), - getDeploys(hub), - EWord.ZERO, + false, + offset, EWord.ZERO, EWord.ZERO, EWord.ZERO, getMemoryExpansionException(hub), hub.messageFrame().memoryWordSize(), - 0); + 0x1337L); // TODO } public MxpCall mxpCallType3(Hub hub) { + + EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); + return new MxpCall( hub, - getOpcode(hub), - getDeploys(hub), - EWord.ZERO, + OpCode.MSTORE8, + false, + offset, EWord.ZERO, EWord.ZERO, EWord.ZERO, getMemoryExpansionException(hub), hub.messageFrame().memoryWordSize(), - 0); + 0x1337L); // TODO } - public MxpCall mxpCallType4(Hub hub) { + public static MxpCall mxpCallType4(Hub hub) { + + final OpCode opCode = getOpcode(hub); + int offsetIndex; + int sizeIndex; + + switch (opCode) { + case SHA3, LOG0, LOG1, LOG2, LOG3, LOG4, RETURN, REVERT -> { + offsetIndex = 0; + sizeIndex = 1; + } + case CALLDATACOPY, CODECOPY, RETURNDATACOPY -> { + offsetIndex = 0; + sizeIndex = 2; + } + case EXTCODECOPY -> { + offsetIndex = 1; + sizeIndex = 3; + } + case CREATE, CREATE2 -> { + offsetIndex = 1; + sizeIndex = 2; + } + default -> { + throw new RuntimeException("MXP Type 4 incompatible opcode"); + } + } + + EWord offset = EWord.of(hub.messageFrame().getStackItem(offsetIndex)); + EWord size = EWord.of(hub.messageFrame().getStackItem(sizeIndex)); + return new MxpCall( hub, - getOpcode(hub), + opCode, getDeploys(hub), - EWord.ZERO, - EWord.ZERO, + offset, + size, EWord.ZERO, EWord.ZERO, getMemoryExpansionException(hub), hub.messageFrame().memoryWordSize(), - 0); + 0x1337L); // TODO } public MxpCall mxpCallType5(Hub hub) { + + final OpCode opCode = getOpcode(hub); + int extra; + + switch (opCode) { + case CALL, CALLCODE -> { + extra = 1; + } + case DELEGATECALL, STATICCALL -> { + extra = 0; + } + default -> { + throw new RuntimeException("MXP Type 5 incompatible opcode"); + } + } + + EWord callDataOffset = EWord.of(hub.messageFrame().getStackItem(2 + extra)); + EWord callDataSize = EWord.of(hub.messageFrame().getStackItem(3 + extra)); + EWord returnAtOffset = EWord.of(hub.messageFrame().getStackItem(4 + extra)); + EWord returnAtCapacity = EWord.of(hub.messageFrame().getStackItem(5 + extra)); + return new MxpCall( hub, getOpcode(hub), - getDeploys(hub), - EWord.ZERO, - EWord.ZERO, - EWord.ZERO, - EWord.ZERO, + false, + callDataOffset, + callDataSize, + returnAtOffset, + returnAtCapacity, getMemoryExpansionException(hub), hub.messageFrame().memoryWordSize(), - 0); + 0x1337L); // TODO } static OpCode getOpcode(Hub hub) { @@ -146,7 +205,7 @@ static boolean getMemoryExpansionException(Hub hub) { return hub.pch().exceptions().memoryExpansionException(); } - final boolean type4InstructionMayTriggerNonTrivialOperation(Hub hub) { + public final boolean type4InstructionMayTriggerNonTrivialOperation(Hub hub) { return !getMemoryExpansionException(hub) && !this.size1.isZero(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 47c626c69a..eb258cdc4e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -16,11 +16,27 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; public class KeccakSection extends TraceSection { - public KeccakSection(Hub hub, CallFrame callFrame, TraceFragment... chunks) { - this.addFragmentsAndStack(hub, callFrame, chunks); + + public static boolean appendToTrace(Hub hub) { + + ImcFragment imcFragment = ImcFragment.empty(hub); + + MxpCall mxpCall = MxpCall.mxpCallType4(hub); + + final boolean mayTriggerNonTrivialOperation = + mxpCall.type4InstructionMayTriggerNonTrivialOperation(hub); + final boolean triggerMmu = mayTriggerNonTrivialOperation & hub.pch().exceptions().none(); + + if (triggerMmu) { + imcFragment.callMmu(MmuCall.sha3(hub)); + // TODO: we must trigger hashInfo iff triggerMmu + } + + return triggerMmu; } } From 458021a5261a597133553033958b6f7435af0f5e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 14 Jun 2024 17:17:38 +0530 Subject: [PATCH 100/461] fix: wip, fix part of the issue arising with besu / java / check / corset updates --- .../linea/zktracer/module/hub/Hub.java | 6 +- .../module/hub/section/TraceSection.java | 72 +-- .../module/txndata/BlockSnapshot.java | 6 +- .../module/txndata/TransactionSnapshot.java | 495 ------------------ .../zktracer/runtime/callstack/CallFrame.java | 148 ++---- .../zktracer/runtime/callstack/CallStack.java | 122 +++-- zkevm-constraints | 2 +- 7 files changed, 142 insertions(+), 709 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a689377a18..a16acd4284 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -763,8 +763,10 @@ public void traceEndTx( Bytes output, List logs, long gasUsed) { - this.txStack.current().completeLineaTransaction(isSuccessful, this.state.stamps().hub(), this.state() - .getProcessingPhase(), logs); + this.txStack + .current() + .completeLineaTransaction( + isSuccessful, this.state.stamps().hub(), this.state().getProcessingPhase(), logs); if (this.state.getProcessingPhase() != TX_SKIP) { this.defers.postTx(new TxFinalizationPostTxDefer(this, world)); } 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 dab742679b..64f2711e8c 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 @@ -37,15 +37,13 @@ /** A TraceSection gather the trace lines linked to a single operation */ public abstract class TraceSection { private WorldView world; - @Getter - private int stackHeight = 0; - @Getter - private int stackHeightNew = 0; + @Getter private int stackHeight = 0; + @Getter private int stackHeightNew = 0; /** * A TraceLine stores the information required to generate a trace line. * - * @param common data required to trace shared columns + * @param common data required to trace shared columns * @param specific data required to trace perspective-specific columns */ public record TraceLine(CommonFragment common, TraceFragment specific) { @@ -67,24 +65,17 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { } /** Count the stack lines */ - @Getter - private int stackRowsCounter; + @Getter private int stackRowsCounter; /** Count the non-stack lines */ public int nonStackRowCounter; public int numberOfNonStackRows; - @Getter - @Setter - private TxTrace parentTrace; + @Getter @Setter private TxTrace parentTrace; - /** - * A list of {@link TraceLine} representing the trace lines associated with this - * section. - */ - @Getter - List lines = new ArrayList<>(32); + /** A list of {@link TraceLine} representing the trace lines associated with this section. */ + @Getter List lines = new ArrayList<>(32); /** * Fill the columns shared by all type of lines. @@ -93,17 +84,16 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { */ private CommonFragment traceCommon(Hub hub, CallFrame frame) { return CommonFragment.fromHub( - hub, frame, this.stackRowCounter == 2, this.nonStackRowCounter, this.numberOfNonStackRows); + hub, frame, this.stackRowsCounter == 2, this.nonStackRowCounter, this.numberOfNonStackRows); } /** Default creator for an empty section. */ - public TraceSection() { - } + public TraceSection() {} /** * Add a fragment to the section while pairing it to its common piece. * - * @param hub the execution context + * @param hub the execution context * @param fragment the fragment to insert */ public final void addFragment(Hub hub, CallFrame callFrame, TraceFragment fragment) { @@ -125,10 +115,9 @@ public final void addStack(Hub hub) { } /** - * Create several {@link TraceLine} within this section for the specified - * fragments. + * Create several {@link TraceLine} within this section for the specified fragments. * - * @param hub the Hub linked to fragments execution + * @param hub the Hub linked to fragments execution * @param fragments the fragments to add to the section */ public final void addFragmentsWithoutStack( @@ -139,10 +128,9 @@ public final void addFragmentsWithoutStack( } /** - * Create several {@link TraceLine} within this section for the specified - * fragments. + * Create several {@link TraceLine} within this section for the specified fragments. * - * @param hub the Hub linked to fragments execution + * @param hub the Hub linked to fragments execution * @param fragments the fragments to add to the section */ public final void addFragmentsWithoutStack(Hub hub, TraceFragment... fragments) { @@ -152,15 +140,12 @@ public final void addFragmentsWithoutStack(Hub hub, TraceFragment... fragments) } /** - * Insert {@link TraceLine} related to the current state of the stack, then - * insert the provided + * Insert {@link TraceLine} related to the current state of the stack, then insert the provided * fragments in a single swoop. * - * @param hub the execution context - * @param callFrame the {@link CallFrame} containing the execution context; - * typically the current - * one in the hub for most instructions, but may be the parent - * one for e.g. CREATE* + * @param hub the execution context + * @param callFrame the {@link CallFrame} containing the execution context; typically the current + * one in the hub for most instructions, but may be the parent one for e.g. CREATE* * @param fragments the fragments to insert */ public final void addFragmentsAndStack(Hub hub, CallFrame callFrame, TraceFragment... fragments) { @@ -169,11 +154,10 @@ public final void addFragmentsAndStack(Hub hub, CallFrame callFrame, TraceFragme } /** - * Insert {@link TraceLine} related to the current state of the stack of the - * current {@link + * Insert {@link TraceLine} related to the current state of the stack of the current {@link * CallFrame}, then insert the provided fragments in a single swoop. * - * @param hub the execution context + * @param hub the execution context * @param fragments the fragments to insert */ public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { @@ -182,13 +166,12 @@ public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { } /** - * This method is called when the TraceSection is finished, to build required - * information + * This method is called when the TraceSection is finished, to build required information * post-hoc. */ public void seal() { - final int numberOfNonStackRows = (int) this.lines.stream().filter(l -> !(l.specific instanceof StackFragment)) - .count(); + final int numberOfNonStackRows = + (int) this.lines.stream().filter(l -> !(l.specific instanceof StackFragment)).count(); int nonStackLineCounter = 0; for (TraceLine line : this.lines) { if (!(line.specific instanceof StackFragment)) { @@ -200,8 +183,7 @@ public void seal() { } /** - * Returns whether the opcode encoded in this section is part of a reverted - * context. As it is + * Returns whether the opcode encoded in this section is part of a reverted context. As it is * section-specific, we simply take the first one. * * @return true if the context reverted @@ -211,8 +193,7 @@ public final boolean hasReverted() { } /** - * Returns the gas refund delta incurred by this operation. As it is - * section-specific, we simply + * Returns the gas refund delta incurred by this operation. As it is section-specific, we simply * take the first one. * * @return the gas delta @@ -222,8 +203,7 @@ public final long refundDelta() { } /** - * Update the stack fragments of the section with the provided - * {@link DeploymentExceptions}. + * Update the stack fragments of the section with the provided {@link DeploymentExceptions}. * * @param contEx the computed exceptions */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java index 6c8e520fec..579563098d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/BlockSnapshot.java @@ -25,8 +25,7 @@ import org.hyperledger.besu.plugin.data.ProcessableBlockHeader; /** - * This class gathers the block-related information required to trace the - * {@link TxnData} module. + * This class gathers the block-related information required to trace the {@link TxnData} module. */ @Getter public class BlockSnapshot { @@ -37,8 +36,7 @@ public class BlockSnapshot { private final Address coinbaseAddress; private final Bytes blockGasLimit; - @Setter - private int nbOfTxsInBlock; + @Setter private int nbOfTxsInBlock; BlockSnapshot(ProcessableBlockHeader header) { this.baseFee = header.getBaseFee().map(x -> (Wei) x); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java deleted file mode 100644 index 6a55a8d66f..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TransactionSnapshot.java +++ /dev/null @@ -1,495 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.txndata; - -import static net.consensys.linea.zktracer.module.Util.getTxTypeAsInt; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_0; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_1; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_2; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_3; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_4; -import static net.consensys.linea.zktracer.module.txndata.Trace.COMMON_RLP_TXN_PHASE_NUMBER_5; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_ACCESS_LIST_ADRESS; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_ACCESS_LIST_STORAGE; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TRANSACTION; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TX_CREATE; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TX_DATA_NONZERO; -import static net.consensys.linea.zktracer.module.txndata.Trace.GAS_CONST_G_TX_DATA_ZERO; -import static net.consensys.linea.zktracer.module.txndata.Trace.LLARGE; -import static net.consensys.linea.zktracer.module.txndata.Trace.MAX_REFUND_QUOTIENT; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_0; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_1; -import static net.consensys.linea.zktracer.module.txndata.Trace.NB_ROWS_TYPE_2; -import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_CUMUL_GAS; -import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_STATUS_CODE; -import static net.consensys.linea.zktracer.module.txndata.Trace.RLP_RCPT_SUBPHASE_ID_TYPE; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_0_RLP_TXN_PHASE_NUMBER_6; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_1_RLP_TXN_PHASE_NUMBER_6; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_1_RLP_TXN_PHASE_NUMBER_7; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_2_RLP_TXN_PHASE_NUMBER_6; -import static net.consensys.linea.zktracer.module.txndata.Trace.TYPE_2_RLP_TXN_PHASE_NUMBER_7; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.euc.Euc; -import net.consensys.linea.zktracer.module.wcp.Wcp; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Quantity; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.feemarket.TransactionPriceCalculator; -import org.hyperledger.besu.evm.account.AccountState; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** Gathers all the information required to trace a {@link Transaction} in {@link TxnData}. */ -@Accessors(fluent = true) -@Getter -public final class TransactionSnapshot extends ModuleOperation { - - private final Wcp wcp; - private final Euc euc; - - private final Optional baseFee; - private final Bytes blockGasLimit; - - /** Value moved by the transaction */ - private final BigInteger value; - - /** Sender address */ - private final Address from; - - /** Receiver or contract deployment address */ - private final Address to; - - /** Sender nonce */ - private final long nonce; - - /** Number of addresses to pre-warm */ - private final int prewarmedAddressesCount; - - /** Number of storage slots to pre-warm */ - private final int prewarmedStorageKeysCount; - - /** Whether this transaction is a smart contract deployment */ - private final boolean isDeployment; - - /** Whether this transaction triggers the EVM */ - private final boolean requiresEvmExecution; - - /** The transaction {@link TransactionType} */ - private final TransactionType type; - - /** The sender balance when it sent the transaction */ - private final BigInteger initialSenderBalance; - - /** 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; - private final Optional maxPriorityFeePerGas; - @Setter private boolean status; - @Setter private long refundCounter; - @Setter private long leftoverGas; - @Setter private long effectiveGasRefund; - @Setter private long cumulativeGasConsumption; - - @Setter private boolean getFullTip; - - private final List callsToEucAndWcp; - private final List valuesToRlptxn; - private final List valuesToRlpTxrcpt; - - // plus one because the last tx of the block has one more row - private final int MAX_NB_ROWS = - Math.max(Math.max(NB_ROWS_TYPE_1, NB_ROWS_TYPE_2), NB_ROWS_TYPE_0) + 1; - - public TransactionSnapshot( - Wcp wcp, - Euc euc, - BigInteger value, - Address from, - Address to, - long nonce, - int prewarmedAddressesCount, - int prewarmedStorageKeysCount, - boolean isDeployment, - boolean requiresEvmExecution, - TransactionType type, - BigInteger initialSenderBalance, - Bytes payload, - long gasLimit, - BigInteger effectiveGasPrice, - Optional maxFeePerGas, - Optional maxPriorityFeePerGas, - Bytes blockGasLimit, - Optional baseFee) { - - this.wcp = wcp; - this.euc = euc; - - this.value = value; - this.from = from; - this.to = to; - this.nonce = nonce; - this.prewarmedAddressesCount = prewarmedAddressesCount; - this.prewarmedStorageKeysCount = prewarmedStorageKeysCount; - this.isDeployment = isDeployment; - this.requiresEvmExecution = requiresEvmExecution; - this.type = type; - this.initialSenderBalance = initialSenderBalance; - this.payload = payload; - this.gasLimit = gasLimit; - this.effectiveGasPrice = effectiveGasPrice; - this.maxFeePerGas = maxFeePerGas; - this.maxPriorityFeePerGas = maxPriorityFeePerGas; - this.callDataSize = this.isDeployment ? 0 : this.payload.size(); - this.callsToEucAndWcp = new ArrayList<>(); - this.valuesToRlptxn = new ArrayList<>(); - this.valuesToRlpTxrcpt = new ArrayList<>(); - this.blockGasLimit = blockGasLimit; - this.baseFee = baseFee; - } - - public static TransactionSnapshot fromTransaction( - Wcp wcp, - Euc euc, - Transaction tx, - WorldView world, - Optional baseFee, - Bytes blockGasLimit) { - - return new TransactionSnapshot( - wcp, - euc, - tx.getValue().getAsBigInteger(), - tx.getSender(), - tx.getTo() - .map(x -> (Address) x) - .orElse(Address.contractAddress(tx.getSender(), tx.getNonce())), - tx.getNonce(), - tx.getAccessList().map(List::size).orElse(0), - tx.getAccessList() - .map( - accessSet -> - accessSet.stream() - .mapToInt(accessSetItem -> accessSetItem.storageKeys().size()) - .sum()) - .orElse(0), - tx.getTo().isEmpty(), - tx.getTo().map(world::get).map(AccountState::hasCode).orElse(!tx.getPayload().isEmpty()), - tx.getType(), - Optional.ofNullable(tx.getSender()) - .map(world::get) - .map(x -> x.getBalance().getAsBigInteger()) - .orElse(BigInteger.ZERO), - tx.getPayload().copy(), - tx.getGasLimit(), - computeEffectiveGasPrice(baseFee, tx), - tx.getMaxFeePerGas(), - tx.getMaxPriorityFeePerGas(), - blockGasLimit, - baseFee); - } - - // dataCost returns the gas cost of the call data / init code - public long dataCost() { - Bytes payload = this.payload(); - long dataCost = 0; - for (int i = 0; i < payload.size(); i++) { - dataCost += payload.get(i) == 0 ? GAS_CONST_G_TX_DATA_ZERO : GAS_CONST_G_TX_DATA_NONZERO; - } - return dataCost; - } - - private static BigInteger computeEffectiveGasPrice(Optional baseFee, Transaction tx) { - return switch (tx.getType()) { - case FRONTIER, ACCESS_LIST -> tx.getGasPrice().get().getAsBigInteger(); - case EIP1559 -> TransactionPriceCalculator.eip1559() - .price((org.hyperledger.besu.ethereum.core.Transaction) tx, baseFee) - .getAsBigInteger(); - default -> throw new RuntimeException("transaction type not supported"); - }; - } - - // getData should return either: - // - call data (message call) - // - init code (contract creation) - int maxCounter() { - return switch (this.type()) { - case FRONTIER -> NB_ROWS_TYPE_0 - 1; - case ACCESS_LIST -> NB_ROWS_TYPE_1 - 1; - case EIP1559 -> NB_ROWS_TYPE_2 - 1; - default -> throw new RuntimeException("transaction type not supported"); - }; - } - - long getUpfrontGasCost() { - long initialCost = this.dataCost(); - - if (this.isDeployment()) { - initialCost += GAS_CONST_G_TX_CREATE; - } - - initialCost += GAS_CONST_G_TRANSACTION; - - if (this.type() != TransactionType.FRONTIER) { - initialCost += (long) this.prewarmedAddressesCount() * GAS_CONST_G_ACCESS_LIST_ADRESS; - initialCost += (long) this.prewarmedStorageKeysCount() * GAS_CONST_G_ACCESS_LIST_STORAGE; - } - - return initialCost; - } - - public void setRlptxnValues() { - // i+0 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_0, - Bytes.EMPTY, - Bytes.ofUnsignedInt(getTxTypeAsInt(this.type)))); - // i+1 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_1, - isDeployment ? Bytes.EMPTY : this.to.slice(0, 4), - isDeployment ? Bytes.EMPTY : this.to.slice(4, LLARGE))); - - // i+2 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_2, Bytes.EMPTY, Bytes.ofUnsignedLong(this.nonce))); - - // i+3 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_3, - isDeployment ? Bytes.of(1) : Bytes.EMPTY, - bigIntegerToBytes(this.value))); - - // i+4 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_4, - Bytes.ofUnsignedLong(this.dataCost()), - Bytes.ofUnsignedLong(this.payload.size()))); - - // i+5 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) COMMON_RLP_TXN_PHASE_NUMBER_5, - Bytes.EMPTY, - Bytes.ofUnsignedLong(this.gasLimit))); - - switch (this.type) { - case FRONTIER -> { - // i+6 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_0_RLP_TXN_PHASE_NUMBER_6, - Bytes.EMPTY, - bigIntegerToBytes(this.effectiveGasPrice))); - for (int i = 7; i < NB_ROWS_TYPE_0 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); - } - } - case ACCESS_LIST -> { - // i+6 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_1_RLP_TXN_PHASE_NUMBER_6, - Bytes.EMPTY, - bigIntegerToBytes(this.effectiveGasPrice))); - - // i+7 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_1_RLP_TXN_PHASE_NUMBER_7, - Bytes.ofUnsignedInt(this.prewarmedStorageKeysCount), - Bytes.ofUnsignedInt(this.prewarmedAddressesCount))); - - for (int i = 8; i < NB_ROWS_TYPE_1 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); - } - } - - case EIP1559 -> { - // i+6 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_2_RLP_TXN_PHASE_NUMBER_6, - bigIntegerToBytes(this.maxPriorityFeePerGas.get().getAsBigInteger()), - bigIntegerToBytes(this.maxFeePerGas.get().getAsBigInteger()))); - - // i+7 - this.valuesToRlptxn.add( - RlptxnOutgoing.set( - (short) TYPE_2_RLP_TXN_PHASE_NUMBER_7, - Bytes.ofUnsignedInt(this.prewarmedStorageKeysCount), - Bytes.ofUnsignedInt(this.prewarmedAddressesCount))); - - for (int i = 8; i < NB_ROWS_TYPE_2 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); - } - } - } - } - - public void setRlptxrcptValues() { - // i+0 - this.valuesToRlpTxrcpt.add( - RlptxrcptOutgoing.set((short) RLP_RCPT_SUBPHASE_ID_TYPE, getTxTypeAsInt(this.type()))); - // i+1 - this.valuesToRlpTxrcpt.add( - RlptxrcptOutgoing.set((short) RLP_RCPT_SUBPHASE_ID_STATUS_CODE, booleanToInt(this.status))); - // i+2 - this.valuesToRlpTxrcpt.add( - RlptxrcptOutgoing.set( - (short) RLP_RCPT_SUBPHASE_ID_CUMUL_GAS, this.cumulativeGasConsumption)); - // i+3 to i+MAX_NB_ROWS - for (int ct = 3; ct < MAX_NB_ROWS; ct++) { - this.valuesToRlpTxrcpt.add(RlptxrcptOutgoing.emptyValue()); - } - } - - public void setCallsToEucAndWcp() { - // i+0 - final Bytes row0arg1 = bigIntegerToBytes(this.initialSenderBalance); - final BigInteger value = this.value; - final BigInteger maxFeeShortHand = setOutgoingLoRowPlus6(); - final BigInteger gasLimit = BigInteger.valueOf(this.gasLimit); - final Bytes row0arg2 = bigIntegerToBytes(value.add(maxFeeShortHand.multiply(gasLimit))); - wcp.callLT(row0arg1, row0arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row0arg1, row0arg2, false)); - - // i+1 - final Bytes row1arg1 = Bytes.minimalBytes(this.gasLimit); - final Bytes row1arg2 = Bytes.minimalBytes(this.getUpfrontGasCost()); - wcp.callLT(row1arg1, row1arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row1arg1, row1arg2, false)); - - // i+2 - final Bytes row2arg1 = Bytes.minimalBytes(this.gasLimit - this.leftoverGas); - final Bytes row2arg2 = Bytes.of(MAX_REFUND_QUOTIENT); - final Bytes refundLimit = euc.callEUC(row2arg1, row2arg2).quotient(); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToEuc(row2arg1, row2arg2, refundLimit)); - - // i+3 - final Bytes refundCounterMax = Bytes.minimalBytes(this.refundCounter); - final boolean getFullRefund = wcp.callLT(refundCounterMax, refundLimit); - this.callsToEucAndWcp.add( - TxnDataComparisonRecord.callToLt(refundCounterMax, refundLimit, getFullRefund)); - - this.effectiveGasRefund( - getFullRefund ? leftoverGas + this.refundCounter : leftoverGas + refundLimit.toInt()); - - // i+4 - final Bytes row4arg1 = Bytes.minimalBytes(this.payload.size()); - final boolean nonZeroDataSize = wcp.callISZERO(row4arg1); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToIsZero(row4arg1, nonZeroDataSize)); - - switch (this.type) { - case FRONTIER -> { - for (int i = 5; i < NB_ROWS_TYPE_0; i++) { - this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); - } - } - case ACCESS_LIST -> { - for (int i = 5; i < NB_ROWS_TYPE_1; i++) { - this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); - } - } - case EIP1559 -> { - // i+5 - final Bytes maxFee = bigIntegerToBytes(this.maxFeePerGas.get().getAsBigInteger()); - final Bytes row5arg2 = Bytes.minimalBytes(this.baseFee.get().intValue()); - wcp.callLT(maxFee, row5arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row5arg2, false)); - - // i+6 - final Bytes row6arg2 = bigIntegerToBytes(this.maxPriorityFeePerGas.get().getAsBigInteger()); - wcp.callLT(maxFee, row6arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row6arg2, false)); - - // i+7 - final Bytes row7arg2 = - bigIntegerToBytes( - this.maxPriorityFeePerGas - .get() - .getAsBigInteger() - .add(this.baseFee.get().getAsBigInteger())); - final boolean result = wcp.callLT(maxFee, row7arg2); - getFullTip = !result; - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row7arg2, result)); - } - } - } - - public void setCallWcpLastTxOfBlock(final Bytes blockGasLimit) { - final Bytes arg1 = Bytes.minimalBytes(this.cumulativeGasConsumption); - this.wcp.callLEQ(arg1, blockGasLimit); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLeq(arg1, blockGasLimit, true)); - } - - public Bytes computeGasPriceColumn() { - switch (this.type) { - case FRONTIER, ACCESS_LIST -> { - return bigIntegerToBytes(effectiveGasPrice); - } - case EIP1559 -> { - return getFullTip - ? bigIntegerToBytes( - this.baseFee - .get() - .getAsBigInteger() - .add(this.maxPriorityFeePerGas.get().getAsBigInteger())) - : bigIntegerToBytes(this.maxFeePerGas.get().getAsBigInteger()); - } - default -> throw new IllegalArgumentException("Transaction type not supported"); - } - } - - private BigInteger setOutgoingLoRowPlus6() { - switch (this.type) { - case FRONTIER, ACCESS_LIST -> { - return this.effectiveGasPrice; - } - case EIP1559 -> { - return this.maxFeePerGas.get().getAsBigInteger(); - } - default -> throw new IllegalArgumentException("Transaction type not supported"); - } - } - - @Override - protected int computeLineCount() { - throw new IllegalStateException("should never be called"); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index a99aee4bf2..8b7780c332 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -44,75 +44,60 @@ public class CallFrame { public static final CallFrame EMPTY = new CallFrame(); - @Setter - public int universalParentReturnDataContextNumber; + @Setter public int universalParentReturnDataContextNumber; /** the position of this {@link CallFrame} in the {@link CallStack}. */ - @Getter - private int id; + @Getter private int id; /** the context number of the frame, i.e. the hub stamp at its creation */ - @Getter - private final int contextNumber; + @Getter private final int contextNumber; /** the depth of this CallFrame within its call hierarchy. */ - @Getter - private int depth; + @Getter private int depth; /** */ - @Getter - private int accountDeploymentNumber; + @Getter private int accountDeploymentNumber; /** */ - @Getter - private int codeDeploymentNumber; + @Getter private int codeDeploymentNumber; /** */ - @Getter - private boolean isDeployment; + @Getter private boolean isDeployment; public boolean isMessageCall() { return !isDeployment; } - @Getter - @Setter - private TraceSection needsUnlatchingAtReEntry = null; + @Getter @Setter private TraceSection needsUnlatchingAtReEntry = null; /** the ID of this {@link CallFrame} parent in the {@link CallStack}. */ - @Getter - private int parentFrame; + @Getter private int parentFrame; /** all the {@link CallFrame} that have been called by this frame. */ - @Getter - private final List childFrames = new ArrayList<>(); + @Getter private final List childFrames = new ArrayList<>(); /** the {@link Address} of the account executing this {@link CallFrame}. */ - @Getter - private final Address accountAddress; + @Getter private final Address accountAddress; + /** A memoized {@link EWord} conversion of `address` */ private EWord eAddress = null; /** the {@link Address} of the code executed in this {@link CallFrame}. */ - @Getter - private Address byteCodeAddress = Address.ZERO; + @Getter private Address byteCodeAddress = Address.ZERO; + + @Getter private Address callerAddress = Address.ZERO; - @Getter - private Address callerAddress = Address.ZERO; /** A memoized {@link EWord} conversion of `codeAddress` */ private EWord eCodeAddress = null; /** the {@link CallFrameType} of this frame. */ - @Getter - private final CallFrameType type; + @Getter private final CallFrameType type; /** the {@link Bytecode} executing within this frame. */ - @Getter - private Bytecode code = Bytecode.EMPTY; + @Getter private Bytecode code = Bytecode.EMPTY; /** the CFI of this frame bytecode if applicable */ - @Getter - private int codeFragmentIndex = -1; + @Getter private int codeFragmentIndex = -1; public int getCodeFragmentIndex(Hub hub) { return this == CallFrame.EMPTY || this.type() == CallFrameType.MANTLE @@ -123,77 +108,46 @@ public int getCodeFragmentIndex(Hub hub) { this.isDeployment()); } - @Getter - @Setter - private int pc; - @Getter - @Setter - private OpCode opCode = OpCode.STOP; - @Getter - @Setter - private OpCodeData opCodeData = OpCodes.of(OpCode.STOP); - @Getter - private MessageFrame frame; + @Getter @Setter private int pc; + @Getter @Setter private OpCode opCode = OpCode.STOP; + @Getter @Setter private OpCodeData opCodeData = OpCodes.of(OpCode.STOP); + @Getter private MessageFrame frame; /** the ether amount given to this frame. */ - @Getter - private Wei value = Wei.fromHexString("0xBadF00d"); // Marker for debugging + @Getter private Wei value = Wei.fromHexString("0xBadF00d"); // Marker for debugging /** the gas given to this frame. */ - @Getter - private long gasEndowment; + @Getter private long gasEndowment; /** the call data given to this frame. */ - @Getter - CallDataInfo callDataInfo; + @Getter CallDataInfo callDataInfo; /** the data returned by the latest callee. */ - @Getter - @Setter - private Bytes latestReturnData = Bytes.EMPTY; + @Getter @Setter private Bytes latestReturnData = Bytes.EMPTY; /** returnData position within the latest callee memory space. */ - @Getter - @Setter - private MemorySpan latestReturnDataSource = new MemorySpan(0, 0); + @Getter @Setter private MemorySpan latestReturnDataSource = new MemorySpan(0, 0); /** the return data provided by this frame */ - @Getter - @Setter - private Bytes returnData = Bytes.EMPTY; + @Getter @Setter private Bytes returnData = Bytes.EMPTY; /** where this frame store its return data in its own RAM */ - @Getter - @Setter - private MemorySpan returnDataSource; + @Getter @Setter private MemorySpan returnDataSource; - /** - * where this frame is expected to write its returnData within its parent's - * memory space. - */ - @Getter - private MemorySpan requestedReturnDataTarget = MemorySpan.empty(); + /** where this frame is expected to write its returnData within its parent's memory space. */ + @Getter private MemorySpan requestedReturnDataTarget = MemorySpan.empty(); /** the latest child context to have been called from this frame */ - @Getter - @Setter - private int returnDataContextNumber = 0; + @Getter @Setter private int returnDataContextNumber = 0; - @Getter - @Setter - private int selfRevertsAt = 0; - @Getter - @Setter - private int getsRevertedAt = 0; + @Getter @Setter private int selfRevertsAt = 0; + @Getter @Setter private int getsRevertedAt = 0; /** this frame {@link Stack}. */ - @Getter - private final Stack stack = new Stack(); + @Getter private final Stack stack = new Stack(); /** the latched context of this callframe stack. */ - @Getter - @Setter - private StackContext pending; + @Getter @Setter private StackContext pending; public static void provideParentContextWithEmptyReturnData(Hub hub) { updateParentContextReturnData(hub, Bytes.EMPTY, MemorySpan.empty()); @@ -244,17 +198,16 @@ public static void updateParentContextReturnData( * Create a normal (non-root) call frame. * * @param accountDeploymentNumber the DN of this frame in the {@link Hub} - * @param codeDeploymentNumber the DN of this frame in the {@link Hub} - * @param isDeployment whether the executing code is initcode - * @param id the ID of this frame in the {@link CallStack} - * @param hubStamp the hub stamp at the frame creation - * @param accountAddress the {@link Address} of this frame executor - * @param type the {@link CallFrameType} of this frame - * @param caller the ID of this frame caller in the - * {@link CallStack} - * @param value how much ether was given to this frame - * @param gas how much gas was given to this frame - * @param callData {@link Bytes} containing this frame call data + * @param codeDeploymentNumber the DN of this frame in the {@link Hub} + * @param isDeployment whether the executing code is initcode + * @param id the ID of this frame in the {@link CallStack} + * @param hubStamp the hub stamp at the frame creation + * @param accountAddress the {@link Address} of this frame executor + * @param type the {@link CallFrameType} of this frame + * @param caller the ID of this frame caller in the {@link CallStack} + * @param value how much ether was given to this frame + * @param gas how much gas was given to this frame + * @param callData {@link Bytes} containing this frame call data */ CallFrame( int accountDeploymentNumber, @@ -288,7 +241,8 @@ public static void updateParentContextReturnData( this.parentFrame = caller; this.value = value; this.gasEndowment = gas; - this.callDataInfo = new CallDataInfo(callData, callDataOffset, callDataSize, callDataContextNumber); + this.callDataInfo = + new CallDataInfo(callData, callDataOffset, callDataSize, callDataContextNumber); this.depth = depth; this.returnDataSource = MemorySpan.empty(); this.latestReturnDataSource = MemorySpan.empty(); @@ -312,8 +266,7 @@ public EWord addressAsEWord() { } /** - * Return the address of the code executed within this callframe as an - * {@link EWord}. + * Return the address of the code executed within this callframe as an {@link EWord}. * * @return the address */ @@ -338,8 +291,7 @@ public Optional lastCallee() { } /** - * Returns a {@link ContractMetadata} instance representing the executed - * contract. + * Returns a {@link ContractMetadata} instance representing the executed contract. * * @return the executed contract metadata */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 1e6ef5ffe5..9f6c74f971 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -32,9 +32,7 @@ /** * This class represents the call hierarchy of a transaction. * - *

- * Although it is accessible in a stack-like manner, it is actually a tree, the - * stack access + *

Although it is accessible in a stack-like manner, it is actually a tree, the stack access * representing the path from the latest leaf to the root context. */ @Accessors(fluent = true) @@ -43,14 +41,15 @@ public final class CallStack { static final int MAX_CALLSTACK_SIZE = 1024; /** a never-pruned-tree of the {@link CallFrame} executed by the {@link Hub} */ - private final List frames = new ArrayList<>(50) { - { - add(CallFrame.EMPTY); - } - }; + private final List frames = + new ArrayList<>(50) { + { + add(CallFrame.EMPTY); + } + }; + /** the current depth of the call stack. */ - @Getter - private int depth; + @Getter private int depth; /** a "pointer" to the current {@link CallFrame} in frames. */ private int current; @@ -61,25 +60,26 @@ public void newPrecompileResult( final int returnDataOffset, final Address precompileAddress) { - final CallFrame newFrame = new CallFrame( - -1, - -1, - false, - this.frames.size(), - hubStamp, - precompileAddress, - precompileAddress, - precompileAddress, - Bytecode.EMPTY, - CallFrameType.PRECOMPILE_RETURN_DATA, - this.current, - Wei.ZERO, - 0, - precompileResult, - returnDataOffset, - precompileResult.size(), - -1, - this.depth); + final CallFrame newFrame = + new CallFrame( + -1, + -1, + false, + this.frames.size(), + hubStamp, + precompileAddress, + precompileAddress, + precompileAddress, + Bytecode.EMPTY, + CallFrameType.PRECOMPILE_RETURN_DATA, + this.current, + Wei.ZERO, + 0, + precompileResult, + returnDataOffset, + precompileResult.size(), + -1, + this.depth); this.frames.add(newFrame); } @@ -117,8 +117,7 @@ public void newBedrock( } /** - * A “mantle” {@link CallFrame} holds the call data for a message call with a - * non-empty call data + * A “mantle” {@link CallFrame} holds the call data for a message call with a non-empty call data * * @param hubStamp * @param from @@ -198,15 +197,13 @@ public Optional maybeCurrent() { /** * Creates a new call frame. * - * @param hubStamp the hub stamp at the time of entry in the new - * frame - * @param accountAddress the {@link Address} of the bytecode being - * executed - * @param code the {@link Code} being executed - * @param type the execution type of call frame - * @param value the value given to this call frame - * @param gas the gas provided to this call frame - * @param input the call data sent to this call frame + * @param hubStamp the hub stamp at the time of entry in the new frame + * @param accountAddress the {@link Address} of the bytecode being executed + * @param code the {@link Code} being executed + * @param type the execution type of call frame + * @param value the value given to this call frame + * @param gas the gas provided to this call frame + * @param input the call data sent to this call frame * @param accountDeploymentNumber * @param codeDeploymentNumber * @param isDeployment @@ -236,25 +233,26 @@ public void enter( callData = input; } - CallFrame newFrame = new CallFrame( - accountDeploymentNumber, - codeDeploymentNumber, - isDeployment, - newTop, - hubStamp, - accountAddress, - callerAddress, - byteCodeAddress, - code, - type, - caller, - value, - gas, - callData, - callDataOffset, - callDataSize, - callDataContextNumber, - this.depth); + CallFrame newFrame = + new CallFrame( + accountDeploymentNumber, + codeDeploymentNumber, + isDeployment, + newTop, + hubStamp, + accountAddress, + callerAddress, + byteCodeAddress, + code, + type, + caller, + value, + gas, + callData, + callDataOffset, + callDataSize, + callDataContextNumber, + this.depth); this.frames.add(newFrame); this.current = newTop; @@ -265,8 +263,7 @@ public void enter( } /** - * Exit the current context, sets it return data for the caller to read, and - * marks its last + * Exit the current context, sets it return data for the caller to read, and marks its last * position in the hub traces. */ public void exit() { @@ -283,8 +280,7 @@ public boolean isOverflow() { } /** - * @return whether the call stack is at its maximum capacity and a new frame - * would overflow it + * @return whether the call stack is at its maximum capacity and a new frame would overflow it */ public boolean wouldOverflow() { return this.depth >= MAX_CALLSTACK_SIZE; diff --git a/zkevm-constraints b/zkevm-constraints index 15ac2bd78a..4e868acfa4 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 15ac2bd78a1d8f99b7f0e83aa25f12f92f1a497a +Subproject commit 4e868acfa46282f86db85910500821fbe293e284 From cf11489978a3dd826e4c8d86d196829e7da33452 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 17 Jun 2024 16:40:55 +0530 Subject: [PATCH 101/461] fix: some nothing smart --- .../linea/zktracer/module/Module.java | 2 +- .../linea/zktracer/module/hub/Hub.java | 21 ++++++++++++++++++- .../zktracer/module/rlptxrcpt/RlpTxrcpt.java | 4 ++-- .../zktracer/module/txndata/TxnData.java | 3 +-- gradle/corset.gradle | 4 ++-- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java index bdfa1bdda2..421afe5774 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java @@ -52,7 +52,7 @@ default void traceEndTx( List logs, long gasUsed) {} - default void traceEndTx(TransactionProcessingMetadata tx, List logs) {} + default void traceEndTx(TransactionProcessingMetadata tx) {} default void traceContextEnter(MessageFrame frame) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a16acd4284..c3432a3168 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -753,6 +753,25 @@ public void traceContextExit(MessageFrame frame) { m.traceContextExit(frame); } } + + // We take a snapshot before exiting the transaction + if (frame.getDepth() == 0) { + final long leftOverGas = frame.getRemainingGas(); + final long gasRefund = frame.getGasRefund(); + final boolean minerIsWarm = frame.isAddressWarm(txStack.current().getCoinbase()); + + txStack + .current() + .setPreFinalisationValues( + leftOverGas, + gasRefund, + minerIsWarm, + this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); + + if (this.state.getProcessingPhase() != TX_SKIP) { + this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); + } + } } @Override @@ -776,7 +795,7 @@ public void traceEndTx( for (Module m : this.modules) { // TODO shift all module to the method with TxMetaData m.traceEndTx(world, tx, isSuccessful, output, logs, gasUsed); - m.traceEndTx(txStack.current(), logs); + m.traceEndTx(txStack.current()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java index 1a4ad6d396..f7b02f1faf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxrcpt/RlpTxrcpt.java @@ -74,13 +74,13 @@ public void popTransaction() { } @Override - public void traceEndTx(TransactionProcessingMetadata txMetaData, List logList) { + public void traceEndTx(TransactionProcessingMetadata txMetaData) { RlpTxrcptChunk chunk = new RlpTxrcptChunk( txMetaData.getBesuTransaction().getType(), txMetaData.statusCode(), txMetaData.getAccumulatedGasUsedInBlock(), - logList); + txMetaData.getLogs()); this.chunkList.add(chunk); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java index 8aa72c3c8e..32e699e19c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxnData.java @@ -26,7 +26,6 @@ import net.consensys.linea.zktracer.module.euc.Euc; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.plugin.data.BlockBody; import org.hyperledger.besu.plugin.data.BlockHeader; import org.hyperledger.besu.plugin.data.ProcessableBlockHeader; @@ -67,7 +66,7 @@ public final void traceStartBlock(final ProcessableBlockHeader blockHeader) { } @Override - public void traceEndTx(TransactionProcessingMetadata tx, List logs) { + public void traceEndTx(TransactionProcessingMetadata tx) { this.txs.add(new TxndataOperation(wcp, euc, tx)); } diff --git a/gradle/corset.gradle b/gradle/corset.gradle index 04d6ae39fc..02b335b843 100644 --- a/gradle/corset.gradle +++ b/gradle/corset.gradle @@ -16,7 +16,7 @@ tasks.register('corsetExists') { doLast { def result = exec{ ignoreExitValue = true - commandLine "corset", "-V" + commandLine "corset -V" } if (result.getExitValue() != 0){ throw new GradleException('Corset not found, skipping corsetTests') @@ -25,7 +25,7 @@ tasks.register('corsetExists') { } tasks.register('buildZkevmBin', Exec) { - dependsOn corsetExists + // dependsOn corsetExists workingDir "${project.rootDir}/zkevm-constraints/" commandLine 'make', 'zkevm.bin' From 99d41a72985c85ab9b8dd8ff493361d1421e2e25 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 17 Jun 2024 17:12:24 +0530 Subject: [PATCH 102/461] fix: some more stupid fix --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c3432a3168..2c347f8d48 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -767,10 +767,6 @@ public void traceContextExit(MessageFrame frame) { gasRefund, minerIsWarm, this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); - - if (this.state.getProcessingPhase() != TX_SKIP) { - this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); - } } } @@ -787,6 +783,8 @@ public void traceEndTx( .completeLineaTransaction( isSuccessful, this.state.stamps().hub(), this.state().getProcessingPhase(), logs); if (this.state.getProcessingPhase() != TX_SKIP) { + this.state.setProcessingPhase(TX_FINAL); + this.state.stamps().incrementHubStamp(); this.defers.postTx(new TxFinalizationPostTxDefer(this, world)); } From 1c7b4a3b5b6a1ed2967b755dd615200abf31e808 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 17 Jun 2024 17:21:30 +0530 Subject: [PATCH 103/461] fix: remaining stupid fix --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 2c347f8d48..17af6f2a7c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -767,6 +767,10 @@ public void traceContextExit(MessageFrame frame) { gasRefund, minerIsWarm, this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); + if (this.state.getProcessingPhase() != TX_SKIP) { + this.state.setProcessingPhase(TX_FINAL); + this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); + } } } @@ -782,10 +786,9 @@ public void traceEndTx( .current() .completeLineaTransaction( isSuccessful, this.state.stamps().hub(), this.state().getProcessingPhase(), logs); - if (this.state.getProcessingPhase() != TX_SKIP) { - this.state.setProcessingPhase(TX_FINAL); + + if (!(this.state.getProcessingPhase() == TX_SKIP)) { this.state.stamps().incrementHubStamp(); - this.defers.postTx(new TxFinalizationPostTxDefer(this, world)); } this.defers.runPostTx(this, world, tx, isSuccessful); From b24342ee9465751f965095b1826502da650a8bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 17 Jun 2024 22:10:06 +0200 Subject: [PATCH 104/461] MxpCall object --- .../linea/zktracer/module/hub/Hub.java | 44 +-- .../module/hub/fragment/StackFragment.java | 2 +- .../module/hub/fragment/imc/ImcFragment.java | 3 + .../module/hub/fragment/imc/call/MxpCall.java | 325 ++++++++---------- .../module/hub/section/KeccakSection.java | 8 +- .../module/hub/section/SloadSection.java | 2 +- .../module/hub/section/SstoreSection.java | 25 +- .../zktracer/module/hub/section/StackRam.java | 44 +++ .../linea/zktracer/module/mxp/Mxp.java | 18 +- .../zktracer/module/mxp/MxpOperation.java | 225 ++++++------ .../linea/zktracer/module/mxp/Trace.java | 1 + .../linea/zktracer/module/mxp/MxpTest.java | 24 ++ .../zktracer/module/mxp/SeveralKeccaks.java | 49 +++ zkevm-constraints | 2 +- 14 files changed, 451 insertions(+), 321 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 17af6f2a7c..699336ca71 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -15,11 +15,7 @@ package net.consensys.linea.zktracer.module.hub; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.*; import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; @@ -207,11 +203,15 @@ public void addTraceSection(TraceSection section) { private final Mod mod = new Mod(); private final Module shf = new Shf(); private final RlpTxn rlpTxn; - private final Module mxp; private final Mmio mmio; + // sub-fragments of the MISCELLANEOUS / IMC perspective @Getter private final Exp exp; @Getter private final Mmu mmu; + @Getter private final Mxp mxp; + @Getter private final Oob oob; + @Getter private final Stp stp = new Stp(this, wcp, mod); + private final RlpTxrcpt rlpTxrcpt; private final LogInfo logInfo; private final LogData logData; @@ -223,11 +223,8 @@ public void addTraceSection(TraceSection section) { private final TxnData txnData; private final ShakiraData shakiraData = new ShakiraData(this.wcp); private final ModexpEffectiveCall modexpEffectiveCall; - private final Stp stp = new Stp(this, wcp, mod); private final L2Block l2Block; - @Getter private final Oob oob; - private final List modules; /* * Those modules are not traced, we just compute the number of calls to those @@ -1226,15 +1223,18 @@ void traceOperation(MessageFrame frame) { if (line.specific() instanceof StackFragment) { ((StackFragment) line.specific()).hashInfoFlag = triggerMmu; - // TODO: this shouldn't be done by us ... - Bytes offset = this.messageFrame().getStackItem(0); - Bytes size = this.messageFrame().getStackItem(1); - Bytes dataToHash = this.messageFrame().shadowReadMemory(offset.toLong(), size.toLong()); - KeccakDigest keccakDigest = new KeccakDigest(256); - keccakDigest.update(dataToHash.toArray(), 0, dataToHash.size()); - byte[] hashOutput = new byte[keccakDigest.getDigestSize()]; - keccakDigest.doFinal(hashOutput, 0); - ((StackFragment) line.specific()).hash = Bytes.of(hashOutput); + if (triggerMmu) { + // TODO: this shouldn't be done by us ... + Bytes offset = this.messageFrame().getStackItem(0); + Bytes size = this.messageFrame().getStackItem(1); + Bytes dataToHash = + this.messageFrame().shadowReadMemory(offset.toLong(), size.toLong()); + KeccakDigest keccakDigest = new KeccakDigest(256); + keccakDigest.update(dataToHash.toArray(), 0, dataToHash.size()); + byte[] hashOutput = new byte[keccakDigest.getDigestSize()]; + keccakDigest.doFinal(hashOutput, 0); + ((StackFragment) line.specific()).hash = Bytes.of(hashOutput); + } } } } @@ -1371,10 +1371,10 @@ void traceOperation(MessageFrame frame) { case STORAGE -> { switch (this.currentFrame().opCode()) { case SSTORE -> { - SstoreSection.appendSection(this, frame.getWorldUpdater()); + SstoreSection.appendSectionTo(this, frame.getWorldUpdater()); } case SLOAD -> { - SloadSection.appendSection(this, frame.getWorldUpdater()); + SloadSection.appendSectionTo(this, frame.getWorldUpdater()); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); } @@ -1561,4 +1561,8 @@ void traceOperation(MessageFrame frame) { this, this.currentFrame(), ContextFragment.executionProvidesEmptyReturnData(this)); } } + + public TraceSection getCurrentSection() { + return this.state.currentTxTrace().currentSection(); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 98de9c022a..49811cf2fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -152,7 +152,7 @@ public static StackFragment prepare( public void feedHashedValue(MessageFrame frame) { if (hashInfoFlag) { - switch (this.opCode) { + switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { case SHA3 -> this.hashInfoKeccak = EWord.of(frame.getStackItem(0)); case CREATE2 -> { Address newAddress = EWord.of(frame.getStackItem(0)).toAddress(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index fca3654423..3c293f2195 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -252,6 +252,7 @@ public ImcFragment callOob(OobCall f) { } else { oobIsSet = true; } + // TODO: this.hub.oob().call(f, this.hub); this.moduleCalls.add(f); return this; } @@ -298,6 +299,7 @@ public ImcFragment callMxp(MxpCall f) { } else { mxpIsSet = true; } + this.hub.mxp().call(f); this.moduleCalls.add(f); return this; } @@ -308,6 +310,7 @@ public ImcFragment callStp(StpCall f) { } else { stpIsSet = true; } + // TODO: this.hub.stp().call(f, this.hub); this.moduleCalls.add(f); return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index 2f8eb4b6a5..e39aee30d9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -15,191 +15,167 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call; -import static net.consensys.linea.zktracer.opcode.OpCode.EXTCODECOPY; - -import com.google.common.base.Preconditions; +import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; -import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.opcode.OpCodeData; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; @RequiredArgsConstructor public class MxpCall implements TraceSubFragment { - final Hub hub; - final OpCode opCode; - final boolean deploys; - final EWord offset1; - final EWord size1; - final EWord offset2; - final EWord size2; - final boolean memoryExpansionException; - final long memorySizeInWords; - final long gasMxp; - - public static MxpCall build(Hub hub) { - - // TODO: call the MXP here - // TODO: get from Mxp all the following - // TODO: check hub mxpx == mxp mxpx - EWord offset1 = EWord.ZERO; - EWord offset2 = EWord.ZERO; - EWord size1 = EWord.ZERO; - EWord size2 = EWord.ZERO; - - long gasMxp = 0; - - return new MxpCall( - hub, - hub.opCode(), - getDeploys(hub), - offset1, - size1, - offset2, - size2, - getMemoryExpansionException(hub), - gasMxp, - hub.messageFrame().memoryWordSize()); - } - - public MxpCall mxpCallType1(Hub hub) { - Preconditions.checkArgument(hub.opCode().equals(OpCode.MSIZE)); - return new MxpCall( - hub, - OpCode.MSIZE, - false, - EWord.ZERO, - EWord.ZERO, - EWord.ZERO, - EWord.ZERO, - false, - hub.messageFrame().memoryWordSize(), - 0); - } - - public MxpCall mxpCallType2(Hub hub) { - - EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); - - return new MxpCall( - hub, - getOpcode(hub), - false, - offset, - EWord.ZERO, - EWord.ZERO, - EWord.ZERO, - getMemoryExpansionException(hub), - hub.messageFrame().memoryWordSize(), - 0x1337L); // TODO - } - - public MxpCall mxpCallType3(Hub hub) { - - EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); + public final Hub hub; - return new MxpCall( - hub, - OpCode.MSTORE8, - false, - offset, - EWord.ZERO, - EWord.ZERO, - EWord.ZERO, - getMemoryExpansionException(hub), - hub.messageFrame().memoryWordSize(), - 0x1337L); // TODO - } - - public static MxpCall mxpCallType4(Hub hub) { - - final OpCode opCode = getOpcode(hub); - int offsetIndex; - int sizeIndex; - - switch (opCode) { - case SHA3, LOG0, LOG1, LOG2, LOG3, LOG4, RETURN, REVERT -> { - offsetIndex = 0; - sizeIndex = 1; - } - case CALLDATACOPY, CODECOPY, RETURNDATACOPY -> { - offsetIndex = 0; - sizeIndex = 2; - } - case EXTCODECOPY -> { - offsetIndex = 1; - sizeIndex = 3; - } - case CREATE, CREATE2 -> { - offsetIndex = 1; - sizeIndex = 2; - } - default -> { - throw new RuntimeException("MXP Type 4 incompatible opcode"); - } - } - - EWord offset = EWord.of(hub.messageFrame().getStackItem(offsetIndex)); - EWord size = EWord.of(hub.messageFrame().getStackItem(sizeIndex)); - - return new MxpCall( - hub, - opCode, - getDeploys(hub), - offset, - size, - EWord.ZERO, - EWord.ZERO, - getMemoryExpansionException(hub), - hub.messageFrame().memoryWordSize(), - 0x1337L); // TODO - } - - public MxpCall mxpCallType5(Hub hub) { + // filled in by MXP module + @Getter @Setter public OpCodeData opCodeData; + @Getter @Setter public boolean deploys; + @Getter @Setter public EWord offset1 = EWord.ZERO; + @Getter @Setter public EWord size1 = EWord.ZERO; + @Getter @Setter public EWord offset2 = EWord.ZERO; + @Getter @Setter public EWord size2 = EWord.ZERO; + @Getter @Setter public boolean mayTriggerNonTrivialMmuOperation; + @Getter @Setter public boolean mxpx; + @Getter @Setter public long memorySizeInWords; + @Getter @Setter public long gasMxp; - final OpCode opCode = getOpcode(hub); - int extra; - - switch (opCode) { - case CALL, CALLCODE -> { - extra = 1; - } - case DELEGATECALL, STATICCALL -> { - extra = 0; - } - default -> { - throw new RuntimeException("MXP Type 5 incompatible opcode"); - } - } - - EWord callDataOffset = EWord.of(hub.messageFrame().getStackItem(2 + extra)); - EWord callDataSize = EWord.of(hub.messageFrame().getStackItem(3 + extra)); - EWord returnAtOffset = EWord.of(hub.messageFrame().getStackItem(4 + extra)); - EWord returnAtCapacity = EWord.of(hub.messageFrame().getStackItem(5 + extra)); - - return new MxpCall( - hub, - getOpcode(hub), - false, - callDataOffset, - callDataSize, - returnAtOffset, - returnAtCapacity, - getMemoryExpansionException(hub), - hub.messageFrame().memoryWordSize(), - 0x1337L); // TODO - } - - static OpCode getOpcode(Hub hub) { - return hub.opCode(); + public static MxpCall build(Hub hub) { + return new MxpCall(hub); } - static boolean getDeploys(Hub hub) { - return getOpcode(hub) == OpCode.RETURN && hub.currentFrame().isDeployment(); - } + // public MxpCall mxpCallType1(Hub hub) { + // Preconditions.checkArgument(hub.opCode().equals(OpCode.MSIZE)); + // return new MxpCall( + // hub, + // OpCode.MSIZE, + // false, + // EWord.ZERO, + // EWord.ZERO, + // EWord.ZERO, + // EWord.ZERO, + // false, + // hub.messageFrame().memoryWordSize()); + // } + // + // public MxpCall mxpCallType2(Hub hub) { + // + // EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); + // + // return new MxpCall( + // hub, + // getOpcode(hub), + // false, + // offset, + // EWord.ZERO, + // EWord.ZERO, + // EWord.ZERO, + // getMemoryExpansionException(hub), + // hub.messageFrame().memoryWordSize()); // TODO + // } + // + // public MxpCall mxpCallType3(Hub hub) { + // + // EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); + // + // return new MxpCall( + // hub, + // OpCode.MSTORE8, + // false, + // offset, + // EWord.ZERO, + // EWord.ZERO, + // EWord.ZERO, + // getMemoryExpansionException(hub), + // hub.messageFrame().memoryWordSize()); // TODO + // } + // + // public static MxpCall mxpCallType4(Hub hub) { + // + // final OpCode opCode = getOpcode(hub); + // int offsetIndex; + // int sizeIndex; + // + // switch (opCode) { + // case SHA3, LOG0, LOG1, LOG2, LOG3, LOG4, RETURN, REVERT -> { + // offsetIndex = 0; + // sizeIndex = 1; + // } + // case CALLDATACOPY, CODECOPY, RETURNDATACOPY -> { + // offsetIndex = 0; + // sizeIndex = 2; + // } + // case EXTCODECOPY -> { + // offsetIndex = 1; + // sizeIndex = 3; + // } + // case CREATE, CREATE2 -> { + // offsetIndex = 1; + // sizeIndex = 2; + // } + // default -> { + // throw new RuntimeException("MXP Type 4 incompatible opcode"); + // } + // } + // + // EWord offset = EWord.of(hub.messageFrame().getStackItem(offsetIndex)); + // EWord size = EWord.of(hub.messageFrame().getStackItem(sizeIndex)); + // + // return new MxpCall( + // hub, + // opCode, + // getDeploys(hub), + // offset, + // size, + // EWord.ZERO, + // EWord.ZERO, + // getMemoryExpansionException(hub), + // hub.messageFrame().memoryWordSize()); // TODO + // } + // + // public MxpCall mxpCallType5(Hub hub) { + // + // final OpCode opCode = getOpcode(hub); + // int extra; + // + // switch (opCode) { + // case CALL, CALLCODE -> { + // extra = 1; + // } + // case DELEGATECALL, STATICCALL -> { + // extra = 0; + // } + // default -> { + // throw new RuntimeException("MXP Type 5 incompatible opcode"); + // } + // } + // + // EWord callDataOffset = EWord.of(hub.messageFrame().getStackItem(2 + extra)); + // EWord callDataSize = EWord.of(hub.messageFrame().getStackItem(3 + extra)); + // EWord returnAtOffset = EWord.of(hub.messageFrame().getStackItem(4 + extra)); + // EWord returnAtCapacity = EWord.of(hub.messageFrame().getStackItem(5 + extra)); + // + // return new MxpCall( + // hub, + // getOpcode(hub), + // false, + // callDataOffset, + // callDataSize, + // returnAtOffset, + // returnAtCapacity, + // getMemoryExpansionException(hub), + // hub.messageFrame().memoryWordSize()); // TODO + // } + + // static OpCode getOpcode(Hub hub) { + // return hub.opCode(); + // } + + // static boolean getDeploys(Hub hub) { + // return getOpcode(hub) == OpCode.RETURN && hub.currentFrame().isDeployment(); + // } static boolean getMemoryExpansionException(Hub hub) { return hub.pch().exceptions().memoryExpansionException(); @@ -209,11 +185,10 @@ public final boolean type4InstructionMayTriggerNonTrivialOperation(Hub hub) { return !getMemoryExpansionException(hub) && !this.size1.isZero(); } - @Override public Trace trace(Trace trace) { return trace .pMiscMxpFlag(true) - .pMiscMxpInst(this.opCode.byteValue()) + .pMiscMxpInst(this.opCodeData.mnemonic().byteValue()) .pMiscMxpDeploys(this.deploys) .pMiscMxpOffset1Hi(this.offset1.hi()) .pMiscMxpOffset1Lo(this.offset1.lo()) @@ -223,8 +198,8 @@ public Trace trace(Trace trace) { .pMiscMxpOffset2Lo(this.offset2.lo()) .pMiscMxpSize2Hi(this.size2.hi()) .pMiscMxpSize2Lo(this.size2.lo()) - .pMiscMxpMtntop(this.type4InstructionMayTriggerNonTrivialOperation(hub)) - .pMiscMxpMxpx(this.memoryExpansionException) + .pMiscMxpMtntop(this.mayTriggerNonTrivialMmuOperation) + .pMiscMxpMxpx(this.mxpx) .pMiscMxpWords(Bytes.ofUnsignedLong(this.memorySizeInWords)) .pMiscMxpGasMxp(Bytes.ofUnsignedLong(this.gasMxp)); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index eb258cdc4e..cf88f8dc65 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -26,15 +26,15 @@ public static boolean appendToTrace(Hub hub) { ImcFragment imcFragment = ImcFragment.empty(hub); - MxpCall mxpCall = MxpCall.mxpCallType4(hub); + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); - final boolean mayTriggerNonTrivialOperation = - mxpCall.type4InstructionMayTriggerNonTrivialOperation(hub); + final boolean mayTriggerNonTrivialOperation = mxpCall.isMayTriggerNonTrivialMmuOperation(); final boolean triggerMmu = mayTriggerNonTrivialOperation & hub.pch().exceptions().none(); if (triggerMmu) { imcFragment.callMmu(MmuCall.sha3(hub)); - // TODO: we must trigger hashInfo iff triggerMmu + // TODO: trigger hashInfo (iff triggerMmu) } return triggerMmu; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 5a3015c160..50b9c74003 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -38,7 +38,7 @@ private SloadSection(Hub hub, WorldView world) { this.world = world; } - public static void appendSection(Hub hub, WorldView world) { + public static void appendSectionTo(Hub hub, WorldView world) { final SloadSection sloadSection = new SloadSection(hub, world); hub.addTraceSection(sloadSection); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 26f7ad3cc3..cb774bf006 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -39,19 +39,14 @@ private SstoreSection(Hub hub, WorldView world) { this.world = world; } - public static void appendSection(Hub hub, WorldView world) { - - final SstoreSection sstoreSection = new SstoreSection(hub, world); - hub.addTraceSection(sstoreSection); + public static void appendSectionTo(Hub hub, WorldView world) { final Address address = hub.messageFrame().getRecipientAddress(); final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); final Bytes32 storageKey = (Bytes32) hub.messageFrame().getStackItem(0); - final EWord valueOriginal = - EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); - final EWord valueCurrent = - EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); + final EWord valueOriginal = EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); + final EWord valueCurrent = EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); final EWord valueNext = EWord.of(hub.messageFrame().getStackItem(1)); final boolean staticContextException = hub.pch().exceptions().staticException(); @@ -59,18 +54,19 @@ public static void appendSection(Hub hub, WorldView world) { final boolean outOfGasException = hub.pch().exceptions().outOfGasException(); final boolean contextWillRevert = hub.callStack().current().willRevert(); + final SstoreSection currentSection = new SstoreSection(hub, world); + hub.addTraceSection(currentSection); + ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); - sstoreSection.addFragmentsAndStack(hub, hub.currentFrame(), readCurrentContext); + currentSection.addFragmentsAndStack(hub, hub.currentFrame(), readCurrentContext); - // TODO: make sure we trace a context when there is an exception if (staticContextException) { return; } ImcFragment miscForSstore = ImcFragment.forOpcode(hub, hub.messageFrame()); - sstoreSection.addFragment(hub, hub.currentFrame(), miscForSstore); + currentSection.addFragment(hub, hub.currentFrame(), miscForSstore); - // TODO: make sure we trace a context when there is an exception if (sstoreException) { return; } @@ -79,14 +75,13 @@ public static void appendSection(Hub hub, WorldView world) { doingSstore( hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); - sstoreSection.addFragment(hub, hub.currentFrame(), doingSstore); + currentSection.addFragment(hub, hub.currentFrame(), doingSstore); - // TODO: make sure we trace a context when there is an exception (oogx case) if (outOfGasException || contextWillRevert) { StorageFragment undoingSstore = undoingSstore( hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); - sstoreSection.addFragment(hub, hub.currentFrame(), undoingSstore); + currentSection.addFragment(hub, hub.currentFrame(), undoingSstore); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java index 4a0afc2e71..9dc2959604 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java @@ -17,8 +17,52 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoad; public class StackRam extends TraceSection { + + public static void appendToTrace(Hub hub) { + + ImcFragment imcFragment = ImcFragment.empty(hub); + + switch (hub.opCode()) { + case MSTORE, MSTORE8, MLOAD -> { + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + } + case CALLDATALOAD -> { + OobCall oobCall = CallDataLoad.build(hub, hub.messageFrame()); + imcFragment.callOob(oobCall); + } + } + + boolean triggerMmu = hub.pch().exceptions().none(); + + if (triggerMmu) { + switch (hub.opCode()) { + case MSTORE -> { + imcFragment.callMmu(MmuCall.mstore(hub)); + } + case MSTORE8 -> { + imcFragment.callMmu(MmuCall.mstore8(hub)); + } + case MLOAD -> { + imcFragment.callMmu(MmuCall.mload(hub)); + } + case CALLDATALOAD -> { + imcFragment.callMmu(MmuCall.callDataLoad(hub)); + } + default -> { + throw new RuntimeException("Opcode not part of the stack ram family"); + } + } + } + } + public StackRam(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java index 85bd7ffab5..e8e49a7f41 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java @@ -22,12 +22,13 @@ import net.consensys.linea.zktracer.container.stacked.list.StackedList; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import org.hyperledger.besu.evm.frame.MessageFrame; /** Implementation of a {@link Module} for memory expansion. */ public class Mxp implements Module { /** A list of the operations to trace */ - private final StackedList chunks = new StackedList<>(); + private final StackedList mxpOperations = new StackedList<>(); private Hub hub; @@ -45,22 +46,21 @@ public Mxp() {} @Override public void tracePreOpcode(MessageFrame frame) { // This will be renamed to tracePreOp - this.chunks.add(new MxpOperation(frame, hub)); } @Override public void enterTransaction() { - this.chunks.enter(); + this.mxpOperations.enter(); } @Override public void popTransaction() { - this.chunks.pop(); + this.mxpOperations.pop(); } @Override public int lineCount() { - return this.chunks.lineCount(); + return this.mxpOperations.lineCount(); } @Override @@ -71,8 +71,12 @@ public List columnsHeaders() { @Override public void commit(List buffers) { final Trace trace = new Trace(buffers); - for (int i = 0; i < this.chunks.size(); i++) { - this.chunks.get(i).trace(i + 1, trace); + for (int i = 0; i < this.mxpOperations.size(); i++) { + this.mxpOperations.get(i).trace(i + 1, trace); } } + + public void call(MxpCall mxpCall) { + this.mxpOperations.add(new MxpOperation(mxpCall)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java index 40b498a0dd..0c23488400 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java @@ -30,6 +30,7 @@ import lombok.Getter; import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.transients.OperationAncillaries; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; @@ -50,20 +51,17 @@ public class MxpOperation extends ModuleOperation { public static final BigInteger TWO_POW_128 = BigInteger.ONE.shiftLeft(128); public static final BigInteger TWO_POW_32 = BigInteger.ONE.shiftLeft(32); - private final OpCodeData opCodeData; + final MxpCall mxpCall; private final int contextNumber; - private EWord offset1 = EWord.ZERO; - private EWord offset2 = EWord.ZERO; - private EWord size1 = EWord.ZERO; - private EWord size2 = EWord.ZERO; + private BigInteger maxOffset1 = BigInteger.ZERO; private BigInteger maxOffset2 = BigInteger.ZERO; private BigInteger maxOffset = BigInteger.ZERO; - private boolean mxpx; + private boolean roob; private boolean noOperation; - private boolean mtntop; private boolean comp; + private BigInteger acc1 = BigInteger.ZERO; private BigInteger acc2 = BigInteger.ZERO; private BigInteger acc3 = BigInteger.ZERO; @@ -71,6 +69,7 @@ public class MxpOperation extends ModuleOperation { private BigInteger accA = BigInteger.ZERO; private BigInteger accW = BigInteger.ZERO; private BigInteger accQ = BigInteger.ZERO; + private UnsignedByte[] byte1; private UnsignedByte[] byte2; private UnsignedByte[] byte3; @@ -80,28 +79,34 @@ public class MxpOperation extends ModuleOperation { private UnsignedByte[] byteQ; private UnsignedByte[] byteQQ; private UnsignedByte[] byteR; + private boolean expands; private final MxpType typeMxp; - private final long words; private long wordsNew; private final long cMem; private long cMemNew; private long quadCost = 0; private long linCost = 0; - private final boolean deploys; - public MxpOperation(final MessageFrame frame, final Hub hub) { - this.opCodeData = hub.opCodeData(); - this.contextNumber = hub.currentFrame().contextNumber(); - this.typeMxp = opCodeData.billing().type(); + public MxpOperation(final MxpCall mxpCall) { + this.mxpCall = mxpCall; + + final Hub hub = mxpCall.hub; - this.words = frame.memoryWordSize(); - this.wordsNew = frame.memoryWordSize(); + final MessageFrame frame = hub.messageFrame(); + + this.mxpCall.setOpCodeData(hub.opCodeData()); + this.mxpCall.setDeploys( + mxpCall.getOpCodeData().mnemonic() == OpCode.RETURN & hub.currentFrame().isDeployment()); + this.mxpCall.setMemorySizeInWords(frame.memoryWordSize()); + + this.wordsNew = frame.memoryWordSize(); // will (may) be updated later this.cMem = memoryCost(frame.memoryWordSize()); - this.cMemNew = memoryCost(frame.memoryWordSize()); - this.deploys = hub.currentFrame().isDeployment(); + this.cMemNew = memoryCost(frame.memoryWordSize()); // will (may) be updated later + this.contextNumber = hub.currentFrame().contextNumber(); + this.typeMxp = mxpCall.opCodeData.billing().type(); - setOffsetsAndSizes(frame); + setOffsetsAndSizes(); setRoob(); setNoOperation(); setMaxOffset1and2(); @@ -111,6 +116,9 @@ public MxpOperation(final MessageFrame frame, final Hub hub) { setExpands(); setWordsNew(frame); setMtntop(); + + // "tracing" the remaining fields of the MxpCall + mxpCall.setGasMxp(getGasMxp()); } @Override @@ -152,37 +160,39 @@ private void setInitializeByteArrays() { Arrays.fill(byteR, UnsignedByte.of(0)); } - private void setOffsetsAndSizes(final MessageFrame frame) { + private void setOffsetsAndSizes() { + final MessageFrame frame = this.mxpCall.hub.messageFrame(); final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); switch (opCode) { case SHA3, LOG0, LOG1, LOG2, LOG3, LOG4, RETURN, REVERT -> { - offset1 = EWord.of(frame.getStackItem(0)); - size1 = EWord.of(frame.getStackItem(1)); + mxpCall.setOffset1(EWord.of(frame.getStackItem(0))); + mxpCall.setSize1(EWord.of(frame.getStackItem(1))); } case MSIZE -> {} case CALLDATACOPY, CODECOPY, RETURNDATACOPY -> { - offset1 = EWord.of(frame.getStackItem(0)); - size1 = EWord.of(frame.getStackItem(2)); + mxpCall.setOffset1(EWord.of(frame.getStackItem(0))); + mxpCall.setSize1(EWord.of(frame.getStackItem(2))); } case EXTCODECOPY -> { - offset1 = EWord.of(frame.getStackItem(1)); - size1 = EWord.of(frame.getStackItem(3)); + mxpCall.setOffset1(EWord.of(frame.getStackItem(1))); + mxpCall.setSize1(EWord.of(frame.getStackItem(3))); } - case MLOAD, MSTORE, MSTORE8 -> offset1 = EWord.of(frame.getStackItem(0)); + case MLOAD, MSTORE, MSTORE8 -> mxpCall.setOffset1(EWord.of(frame.getStackItem(0))); case CREATE, CREATE2 -> { - offset1 = EWord.of(frame.getStackItem(1)); - size1 = EWord.of(frame.getStackItem(2)); + mxpCall.setOffset1(EWord.of(frame.getStackItem(1))); + mxpCall.setSize1(EWord.of(frame.getStackItem(2))); } case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { final MemorySpan callDataSegment = OperationAncillaries.callDataSegment(frame); - final MemorySpan returnDataSegment = OperationAncillaries.returnDataRequestedSegment(frame); + final MemorySpan returnDataRecipientSegment = + OperationAncillaries.returnDataRequestedSegment(frame); - offset1 = EWord.of(callDataSegment.offset()); - size1 = EWord.of(callDataSegment.length()); + mxpCall.setOffset1(EWord.of(callDataSegment.offset())); + mxpCall.setSize1(EWord.of(callDataSegment.length())); - offset2 = EWord.of(returnDataSegment.offset()); - size2 = EWord.of(returnDataSegment.length()); + mxpCall.setOffset2(EWord.of(returnDataRecipientSegment.offset())); + mxpCall.setSize2(EWord.of(returnDataRecipientSegment.length())); } default -> throw new IllegalStateException("Unexpected value: " + opCode); } @@ -192,16 +202,17 @@ private void setOffsetsAndSizes(final MessageFrame frame) { protected void setRoob() { roob = switch (typeMxp) { - case TYPE_2, TYPE_3 -> offset1.toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0; - case TYPE_4 -> size1.toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 - || (offset1.toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 - && !size1.toUnsignedBigInteger().equals(BigInteger.ZERO)); - case TYPE_5 -> size1.toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 - || (offset1.toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 - && !size1.toUnsignedBigInteger().equals(BigInteger.ZERO)) - || (size2.toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 - || (offset2.toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 - && !size2.toUnsignedBigInteger().equals(BigInteger.ZERO))); + case TYPE_2, TYPE_3 -> mxpCall.getOffset1().toUnsignedBigInteger().compareTo(TWO_POW_128) + >= 0; + case TYPE_4 -> mxpCall.getSize1().toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 + || (mxpCall.getOffset1().toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 + && !mxpCall.getSize1().toUnsignedBigInteger().equals(BigInteger.ZERO)); + case TYPE_5 -> mxpCall.getSize1().toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 + || (mxpCall.getOffset1().toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 + && !mxpCall.getSize1().toUnsignedBigInteger().equals(BigInteger.ZERO)) + || (mxpCall.getSize2().toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 + || (mxpCall.getOffset2().toUnsignedBigInteger().compareTo(TWO_POW_128) >= 0 + && !mxpCall.getSize2().toUnsignedBigInteger().equals(BigInteger.ZERO))); default -> false; }; } @@ -214,44 +225,50 @@ protected void setNoOperation() { noOperation = switch (typeMxp) { case TYPE_1 -> true; - case TYPE_4 -> size1.isZero(); - case TYPE_5 -> size1.isZero() && size2.isZero(); + case TYPE_4 -> mxpCall.getSize1().isZero(); + case TYPE_5 -> mxpCall.getSize1().isZero() && mxpCall.getSize2().isZero(); default -> false; }; } private void setMtntop() { - mtntop = typeMxp == MxpType.TYPE_4 && !mxpx && size1.loBigInt().signum() != 0; + final boolean mxpx = mxpCall.isMxpx(); + mxpCall.setMayTriggerNonTrivialMmuOperation( + typeMxp == MxpType.TYPE_4 && !mxpx && mxpCall.getSize1().loBigInt().signum() != 0); } /** set max offsets 1 and 2. */ protected void setMaxOffset1and2() { if (getMxpExecutionPath() != mxpExecutionPath.TRIVIAL) { switch (typeMxp) { - case TYPE_2 -> maxOffset1 = offset1.toUnsignedBigInteger().add(BigInteger.valueOf(31)); - case TYPE_3 -> maxOffset1 = offset1.toUnsignedBigInteger(); + case TYPE_2 -> maxOffset1 = + mxpCall.getOffset1().toUnsignedBigInteger().add(BigInteger.valueOf(31)); + case TYPE_3 -> maxOffset1 = mxpCall.getOffset1().toUnsignedBigInteger(); case TYPE_4 -> { - if (!size1.toUnsignedBigInteger().equals(BigInteger.ZERO)) { + if (!mxpCall.getSize1().toUnsignedBigInteger().equals(BigInteger.ZERO)) { maxOffset1 = - offset1 + mxpCall + .getOffset1() .toUnsignedBigInteger() - .add(size1.toUnsignedBigInteger()) + .add(mxpCall.getSize1().toUnsignedBigInteger()) .subtract(BigInteger.ONE); } } case TYPE_5 -> { - if (!size1.toUnsignedBigInteger().equals(BigInteger.ZERO)) { + if (!mxpCall.getSize1().toUnsignedBigInteger().equals(BigInteger.ZERO)) { maxOffset1 = - offset1 + mxpCall + .getOffset1() .toUnsignedBigInteger() - .add(size1.toUnsignedBigInteger()) + .add(mxpCall.getSize1().toUnsignedBigInteger()) .subtract(BigInteger.ONE); } - if (!size2.toUnsignedBigInteger().equals(BigInteger.ZERO)) { + if (!mxpCall.getSize2().toUnsignedBigInteger().equals(BigInteger.ZERO)) { maxOffset2 = - offset2 + mxpCall + .getOffset2() .toUnsignedBigInteger() - .add(size2.toUnsignedBigInteger()) + .add(mxpCall.getSize2().toUnsignedBigInteger()) .subtract(BigInteger.ONE); } } @@ -262,17 +279,17 @@ protected void setMaxOffset1and2() { /** set max offset and mxpx. */ protected void setMaxOffsetAndMxpx() { if (roob || noOperation) { - mxpx = roob; + mxpCall.setMxpx(roob); } else { // choose the max value maxOffset = max(maxOffset1, maxOffset2); - mxpx = maxOffset.compareTo(TWO_POW_32) >= 0; + mxpCall.setMxpx(maxOffset.compareTo(TWO_POW_32) >= 0); } } public void setExpands() { - if (!roob && !noOperation && !mxpx) { - expands = accA.compareTo(BigInteger.valueOf(words)) > 0; + if (!roob && !noOperation && !mxpCall.isMxpx()) { + expands = accA.compareTo(BigInteger.valueOf(mxpCall.getMemorySizeInWords())) > 0; } } @@ -327,7 +344,7 @@ protected void setAcc1and2() { if (roob) { return; } - if (mxpx) { + if (mxpCall.isMxpx()) { if (maxOffset1.compareTo(TWO_POW_32) >= 0) { acc1 = maxOffset1.subtract(TWO_POW_32); } else { @@ -352,9 +369,9 @@ protected void setAcc3() { protected void setAcc4() { if (this.getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { if (expands) { - acc4 = accA.subtract(BigInteger.valueOf(words + 1)); + acc4 = accA.subtract(BigInteger.valueOf(mxpCall.getMemorySizeInWords() + 1)); } else { - acc4 = BigInteger.valueOf(words).subtract(accA); + acc4 = BigInteger.valueOf(mxpCall.getMemorySizeInWords()).subtract(accA); } } } @@ -367,9 +384,14 @@ protected void setAccWAndLastTwoBytesOfByteR() { } accW = - size1.toUnsignedBigInteger().add(BigInteger.valueOf(31)).divide(BigInteger.valueOf(32)); + mxpCall + .getSize1() + .toUnsignedBigInteger() + .add(BigInteger.valueOf(31)) + .divide(BigInteger.valueOf(32)); - BigInteger r = accW.multiply(BigInteger.valueOf(32)).subtract(size1.toUnsignedBigInteger()); + BigInteger r = + accW.multiply(BigInteger.valueOf(32)).subtract(mxpCall.getSize1().toUnsignedBigInteger()); // r in [0,31] UnsignedByte rByte = UnsignedByte.of(r.toByteArray()[r.toByteArray().length - 1]); @@ -389,7 +411,7 @@ private mxpExecutionPath getMxpExecutionPath() { if (this.isRoob() || this.isNoOperation()) { return mxpExecutionPath.TRIVIAL; } - if (this.isMxpx()) { + if (mxpCall.mxpx) { return mxpExecutionPath.NON_TRIVIAL_BUT_MXPX; } return mxpExecutionPath.NON_TRIVIAL; @@ -454,19 +476,24 @@ protected void setBytes() { private void setWordsNew(final MessageFrame frame) { if (getMxpExecutionPath() == MxpOperation.mxpExecutionPath.NON_TRIVIAL && expands) { switch (getTypeMxp()) { - case TYPE_1 -> wordsNew = frame.calculateMemoryExpansion(Words.clampedToLong(offset1), 0); - case TYPE_2 -> wordsNew = frame.calculateMemoryExpansion(Words.clampedToLong(offset1), 32); - case TYPE_3 -> wordsNew = frame.calculateMemoryExpansion(Words.clampedToLong(offset1), 1); + case TYPE_1 -> wordsNew = + frame.calculateMemoryExpansion(Words.clampedToLong(mxpCall.getOffset1()), 0); + case TYPE_2 -> wordsNew = + frame.calculateMemoryExpansion(Words.clampedToLong(mxpCall.getOffset1()), 32); + case TYPE_3 -> wordsNew = + frame.calculateMemoryExpansion(Words.clampedToLong(mxpCall.getOffset1()), 1); case TYPE_4 -> wordsNew = frame.calculateMemoryExpansion( - Words.clampedToLong(offset1), Words.clampedToLong(size1)); + Words.clampedToLong(mxpCall.getOffset1()), Words.clampedToLong(mxpCall.getSize1())); case TYPE_5 -> { long wordsNew1 = frame.calculateMemoryExpansion( - Words.clampedToLong(offset1), Words.clampedToLong(size1)); + Words.clampedToLong(mxpCall.getOffset1()), + Words.clampedToLong(mxpCall.getSize1())); long wordsNew2 = frame.calculateMemoryExpansion( - Words.clampedToLong(offset2), Words.clampedToLong(size2)); + Words.clampedToLong(mxpCall.getOffset2()), + Words.clampedToLong(mxpCall.getSize2())); wordsNew = Math.max(wordsNew1, wordsNew2); } } @@ -482,22 +509,26 @@ private void setCMemNew() { private void setCosts() { if (getMxpExecutionPath() == mxpExecutionPath.NON_TRIVIAL) { quadCost = cMemNew - cMem; - linCost = getLinCost(opCodeData, Words.clampedToLong(size1)); + linCost = getLinCost(mxpCall.getOpCodeData(), Words.clampedToLong(mxpCall.getSize1())); } } long getEffectiveLinCost() { - if (opCodeData.mnemonic() != OpCode.RETURN) { - return getLinCost(opCodeData, Words.clampedToLong(size1)); + if (mxpCall.getOpCodeData().mnemonic() != OpCode.RETURN) { + return getLinCost(mxpCall.getOpCodeData(), Words.clampedToLong(mxpCall.getSize1())); } else { - if (deploys) { - return getLinCost(opCodeData, Words.clampedToLong(size1)); + if (mxpCall.isDeploys()) { + return getLinCost(mxpCall.getOpCodeData(), Words.clampedToLong(mxpCall.getSize1())); } else { return 0; } } } + long getGasMxp() { + return getQuadCost() + getEffectiveLinCost(); + } + final void trace(int stamp, Trace trace) { this.compute(); @@ -508,10 +539,10 @@ final void trace(int stamp, Trace trace) { Bytes32 accABytes32 = Bytes32.leftPad(bigIntegerToBytes(this.getAccA())); Bytes32 accWBytes32 = Bytes32.leftPad(bigIntegerToBytes(this.getAccW())); Bytes32 accQBytes32 = Bytes32.leftPad(bigIntegerToBytes(this.getAccQ())); - final EWord eOffset1 = EWord.of(this.offset1); - final EWord eOffset2 = EWord.of(this.offset2); - final EWord eSize1 = EWord.of(this.size1); - final EWord eSize2 = EWord.of(this.size2); + final EWord eOffset1 = EWord.of(this.mxpCall.getOffset1()); + final EWord eOffset2 = EWord.of(this.mxpCall.getOffset2()); + final EWord eSize1 = EWord.of(this.mxpCall.getSize1()); + final EWord eSize2 = EWord.of(this.mxpCall.getSize2()); final int nRows = this.nRows(); final int nRowsComplement = 32 - nRows; @@ -523,24 +554,24 @@ final void trace(int stamp, Trace trace) { .ct((short) i) .roob(this.isRoob()) .noop(this.isNoOperation()) - .mxpx(this.isMxpx()) - .inst(UnsignedByte.of(this.getOpCodeData().value())) - .mxpType1(this.getOpCodeData().billing().type() == MxpType.TYPE_1) - .mxpType2(this.getOpCodeData().billing().type() == MxpType.TYPE_2) - .mxpType3(this.getOpCodeData().billing().type() == MxpType.TYPE_3) - .mxpType4(this.getOpCodeData().billing().type() == MxpType.TYPE_4) - .mxpType5(this.getOpCodeData().billing().type() == MxpType.TYPE_5) + .mxpx(this.mxpCall.isMxpx()) + .inst(UnsignedByte.of(this.mxpCall.getOpCodeData().value())) + .mxpType1(this.mxpCall.getOpCodeData().billing().type() == MxpType.TYPE_1) + .mxpType2(this.mxpCall.getOpCodeData().billing().type() == MxpType.TYPE_2) + .mxpType3(this.mxpCall.getOpCodeData().billing().type() == MxpType.TYPE_3) + .mxpType4(this.mxpCall.getOpCodeData().billing().type() == MxpType.TYPE_4) + .mxpType5(this.mxpCall.getOpCodeData().billing().type() == MxpType.TYPE_5) .gword( Bytes.ofUnsignedLong( - this.getOpCodeData().billing().billingRate() == BillingRate.BY_WORD - ? this.getOpCodeData().billing().perUnit().cost() + this.mxpCall.getOpCodeData().billing().billingRate() == BillingRate.BY_WORD + ? this.mxpCall.getOpCodeData().billing().perUnit().cost() : 0)) .gbyte( Bytes.ofUnsignedLong( - this.getOpCodeData().billing().billingRate() == BillingRate.BY_BYTE - ? this.getOpCodeData().billing().perUnit().cost() + this.mxpCall.getOpCodeData().billing().billingRate() == BillingRate.BY_BYTE + ? this.mxpCall.getOpCodeData().billing().perUnit().cost() : 0)) - .deploys(this.isDeploys()) + .deploys(mxpCall.isDeploys()) .offset1Hi(eOffset1.hi()) .offset1Lo(eOffset1.lo()) .offset2Hi(eOffset2.hi()) @@ -569,7 +600,7 @@ final void trace(int stamp, Trace trace) { .byteQ(UnsignedByte.of(accQBytes32.get(nRowsComplement + i))) .byteQq(UnsignedByte.of(this.getByteQQ()[i].toInteger())) .byteR(UnsignedByte.of(this.getByteR()[i].toInteger())) - .words(Bytes.ofUnsignedLong(this.getWords())) + .words(Bytes.ofUnsignedLong(this.mxpCall.getMemorySizeInWords())) .wordsNew( Bytes.ofUnsignedLong( this.getWordsNew())) // TODO: Could (should?) be set in tracePostOp? @@ -577,9 +608,9 @@ final void trace(int stamp, Trace trace) { .cMemNew(Bytes.ofUnsignedLong(this.getCMemNew())) .quadCost(Bytes.ofUnsignedLong(this.getQuadCost())) .linCost(Bytes.ofUnsignedLong(this.getLinCost())) - .gasMxp(Bytes.ofUnsignedLong(this.getQuadCost() + this.getEffectiveLinCost())) + .gasMxp(Bytes.ofUnsignedLong(this.mxpCall.getGasMxp())) .expands(this.isExpands()) - .mtntop(this.isMtntop()) + .mtntop(this.mxpCall.isMayTriggerNonTrivialMmuOperation()) .validateRow(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java index 6400b46c42..4ea2a7cd9f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java @@ -23,6 +23,7 @@ import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; + /** * WARNING: This code is generated automatically. * diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index 9a8f51c0cc..25f6721367 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -74,6 +74,30 @@ public class MxpTest { final OpCode[] opCodesHalting = new OpCode[] {OpCode.RETURN, OpCode.REVERT}; + @Test + void testSeveralKeccaks() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(64) + .push(13) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(11) + .push(75) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(32) + .push(32) + .op(OpCode.SHA3) + .op(OpCode.POP) + .compile()) + .run(); + } + @Test void testMxpMinimalNonEmptyReturn() { BytecodeRunner.of(Bytes.fromHexString("6101006000f3")).run(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java new file mode 100644 index 0000000000..b1e9b057b7 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java @@ -0,0 +1,49 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.mxp; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import net.consensys.linea.zktracer.testing.EvmExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class SeveralKeccaks { + @Test + void testSeveralKeccaks() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(64) + .push(13) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(11) + .push(75) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(32) + .push(32) + .op(OpCode.SHA3) + .op(OpCode.POP) + .compile()) + .run(); + } +} diff --git a/zkevm-constraints b/zkevm-constraints index 4e868acfa4..15ac2bd78a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 4e868acfa46282f86db85910500821fbe293e284 +Subproject commit 15ac2bd78a1d8f99b7f0e83aa25f12f92f1a497a From 4956db5732e9ca7708bc25b090bbc765e66c6983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 01:33:11 +0200 Subject: [PATCH 105/461] KeccakSection clean up + bugfix --- .../linea/zktracer/module/hub/Hub.java | 25 ++------------- .../module/hub/fragment/imc/ImcFragment.java | 2 +- .../module/hub/section/KeccakSection.java | 27 ++++++++++++++-- .../module/hub/section/SstoreSection.java | 4 +++ .../module/hub/section/StopSection.java | 32 ++++--------------- .../module/hub/section/TraceSection.java | 11 +++++++ .../linea/zktracer/module/oob/Oob.java | 5 +++ 7 files changed, 54 insertions(+), 52 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 699336ca71..f4aef98da3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1215,29 +1215,8 @@ void traceOperation(MessageFrame frame) { } case KEC -> { - final boolean triggerMmu = KeccakSection.appendToTrace(this); - - // we trigger the HASH_INFO flag - TraceSection currentSection = this.state.currentTxTrace().currentSection(); - for (TraceSection.TraceLine line : currentSection.lines()) { - if (line.specific() instanceof StackFragment) { - ((StackFragment) line.specific()).hashInfoFlag = triggerMmu; - - if (triggerMmu) { - // TODO: this shouldn't be done by us ... - Bytes offset = this.messageFrame().getStackItem(0); - Bytes size = this.messageFrame().getStackItem(1); - Bytes dataToHash = - this.messageFrame().shadowReadMemory(offset.toLong(), size.toLong()); - KeccakDigest keccakDigest = new KeccakDigest(256); - keccakDigest.update(dataToHash.toArray(), 0, dataToHash.size()); - byte[] hashOutput = new byte[keccakDigest.getDigestSize()]; - keccakDigest.doFinal(hashOutput, 0); - ((StackFragment) line.specific()).hash = Bytes.of(hashOutput); - } - } - } - } + KeccakSection.appendToTrace(this); + } case CONTEXT -> this.addTraceSection( new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 3c293f2195..7a27e03a52 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -252,7 +252,7 @@ public ImcFragment callOob(OobCall f) { } else { oobIsSet = true; } - // TODO: this.hub.oob().call(f, this.hub); + this.hub.oob().call(f, this.hub); this.moduleCalls.add(f); return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index cf88f8dc65..0d1ed07152 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -19,12 +19,19 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import org.apache.tuweni.bytes.Bytes; +import org.bouncycastle.crypto.digests.KeccakDigest; public class KeccakSection extends TraceSection { - public static boolean appendToTrace(Hub hub) { + public static void appendToTrace(Hub hub) { + + + final KeccakSection currentSection = new KeccakSection(); + hub.addTraceSection(currentSection); ImcFragment imcFragment = ImcFragment.empty(hub); + currentSection.addFragmentsAndStack(hub, hub.currentFrame(), imcFragment); MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); @@ -34,9 +41,23 @@ public static boolean appendToTrace(Hub hub) { if (triggerMmu) { imcFragment.callMmu(MmuCall.sha3(hub)); - // TODO: trigger hashInfo (iff triggerMmu) + + // TODO: computing the hash shouldn't be done here + Bytes offset = hub.messageFrame().getStackItem(0); + Bytes size = hub.messageFrame().getStackItem(1); + Bytes dataToHash = hub.messageFrame().shadowReadMemory(offset.toLong(), size.toLong()); + KeccakDigest keccakDigest = new KeccakDigest(256); + keccakDigest.update(dataToHash.toArray(), 0, dataToHash.size()); + byte[] hashOutput = new byte[keccakDigest.getDigestSize()]; + keccakDigest.doFinal(hashOutput, 0); + + // retroactively set HASH_INFO_FLAG and HASH_INFO_KECCAK_HI, HASH_INFO_KECCAK_LO + currentSection.triggerHashInfo(Bytes.of(hashOutput)); } - return triggerMmu; + } + + + private KeccakSection() { } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index cb774bf006..4c00fa6605 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -57,6 +57,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { final SstoreSection currentSection = new SstoreSection(hub, world); hub.addTraceSection(currentSection); + // CONTEXT fragment ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); currentSection.addFragmentsAndStack(hub, hub.currentFrame(), readCurrentContext); @@ -64,6 +65,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { return; } + // MISC fragment ImcFragment miscForSstore = ImcFragment.forOpcode(hub, hub.messageFrame()); currentSection.addFragment(hub, hub.currentFrame(), miscForSstore); @@ -71,12 +73,14 @@ public static void appendSectionTo(Hub hub, WorldView world) { return; } + // STORAGE fragment (for doing) StorageFragment doingSstore = doingSstore( hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); currentSection.addFragment(hub, hub.currentFrame(), doingSstore); + // STORAGE fragment (for undoing) if (outOfGasException || contextWillRevert) { StorageFragment undoingSstore = undoingSstore( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index 630325fc85..369496aa62 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -33,21 +33,23 @@ public static void appendTo(Hub hub) { CallFrame.provideParentContextWithEmptyReturnData(hub); if (hub.currentFrame().isMessageCall()) { - hub.addTraceSection(messageCallStopSection(hub)); + StopSection messageCallStopSection = messageCallStopSection(hub); + hub.addTraceSection(messageCallStopSection); return; } - hub.addTraceSection(deploymentStopSection(hub)); + StopSection deploymentStopSection = deploymentStopSection(hub); + hub.addTraceSection(deploymentStopSection); } - public StopSection(Hub hub, TraceFragment... fragments) { + private StopSection(Hub hub, TraceFragment... fragments) { this.addFragmentsAndStack(hub, fragments); } public static StopSection messageCallStopSection(Hub hub) { - StopSection messageCallStopSetion = + StopSection messageCallStopSection = new StopSection(hub, readCurrentContextData(hub), executionProvidesEmptyReturnData(hub)); - return messageCallStopSetion; + return messageCallStopSection; } public static StopSection deploymentStopSection(Hub hub) { @@ -91,24 +93,4 @@ public static StopSection deploymentStopSection(Hub hub) { return stopWhileDeploying; } - - public static StopSection unrevertedDeploymentStopSection(Hub hub) { - - AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - final Address address = hub.currentFrame().accountAddress(); - final int deploymentNumber = hub.transients().conflation().deploymentInfo().number(address); - final boolean deploymentStatus = - hub.transients().conflation().deploymentInfo().isDeploying(address); - - // we should be deploying - Preconditions.checkArgument(deploymentStatus); - - return new StopSection( - hub, - readCurrentContextData(hub), - // current (under deployment => deployed with empty byte code) - executionProvidesEmptyReturnData(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 64f2711e8c..5ebf025b6c 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 @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.stack.StackLine; +import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true) @@ -246,4 +247,14 @@ private List makeStackFragments(final Hub hub, CallFrame f) { } return r; } + + public void triggerHashInfo(Bytes hash) { + + for (TraceSection.TraceLine line : this.lines()) { + if (line.specific() instanceof StackFragment) { + ((StackFragment) line.specific()).hashInfoFlag = true; + ((StackFragment) line.specific()).hash = hash; + } + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index ab1bb2ac99..3b22e866c5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -28,6 +28,7 @@ import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; @@ -140,6 +141,10 @@ final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { } } + public void call(OobCall oobCall, Hub hub) { + // TODO!!! + } + @Override public void enterTransaction() { this.chunks.enter(); From 2dbaf983facf4680d89ede1fbb4b3ea9e9b182a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 01:33:54 +0200 Subject: [PATCH 106/461] spotless --- .../linea/zktracer/module/hub/Hub.java | 3 +- .../module/hub/section/KeccakSection.java | 6 +-- .../module/hub/section/SstoreSection.java | 6 ++- .../linea/zktracer/module/mxp/Trace.java | 1 - .../zktracer/module/mxp/SeveralKeccaks.java | 46 +++++++++---------- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f4aef98da3..ad03f246fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -105,7 +105,6 @@ import net.consensys.linea.zktracer.runtime.stack.StackLine; import net.consensys.linea.zktracer.types.*; import org.apache.tuweni.bytes.Bytes; -import org.bouncycastle.crypto.digests.KeccakDigest; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; @@ -1216,7 +1215,7 @@ void traceOperation(MessageFrame frame) { case KEC -> { KeccakSection.appendToTrace(this); - } + } case CONTEXT -> this.addTraceSection( new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 0d1ed07152..9bd4d9afa3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -26,7 +26,6 @@ public class KeccakSection extends TraceSection { public static void appendToTrace(Hub hub) { - final KeccakSection currentSection = new KeccakSection(); hub.addTraceSection(currentSection); @@ -54,10 +53,7 @@ public static void appendToTrace(Hub hub) { // retroactively set HASH_INFO_FLAG and HASH_INFO_KECCAK_HI, HASH_INFO_KECCAK_LO currentSection.triggerHashInfo(Bytes.of(hashOutput)); } - } - - private KeccakSection() { - } + private KeccakSection() {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 4c00fa6605..bb3b234b6d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -45,8 +45,10 @@ public static void appendSectionTo(Hub hub, WorldView world) { final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); final Bytes32 storageKey = (Bytes32) hub.messageFrame().getStackItem(0); - final EWord valueOriginal = EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); - final EWord valueCurrent = EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); + final EWord valueOriginal = + EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); + final EWord valueCurrent = + EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); final EWord valueNext = EWord.of(hub.messageFrame().getStackItem(1)); final boolean staticContextException = hub.pch().exceptions().staticException(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java index 4ea2a7cd9f..6400b46c42 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Trace.java @@ -23,7 +23,6 @@ import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; - /** * WARNING: This code is generated automatically. * diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java index b1e9b057b7..8dc909131e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java @@ -23,27 +23,27 @@ @ExtendWith(EvmExtension.class) public class SeveralKeccaks { - @Test - void testSeveralKeccaks() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(0) - .push(0) - .op(OpCode.SHA3) - .op(OpCode.POP) - .push(64) - .push(13) - .op(OpCode.SHA3) - .op(OpCode.POP) - .push(11) - .push(75) - .op(OpCode.SHA3) - .op(OpCode.POP) - .push(32) - .push(32) - .op(OpCode.SHA3) - .op(OpCode.POP) - .compile()) - .run(); - } + @Test + void testSeveralKeccaks() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(64) + .push(13) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(11) + .push(75) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(32) + .push(32) + .op(OpCode.SHA3) + .op(OpCode.POP) + .compile()) + .run(); + } } From 8b9cd8bea92515297937a13d09157012a9fa5578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 02:34:30 +0200 Subject: [PATCH 107/461] fixes - MXP: several computations were relegated to trace production time but required by the MxpCall - SHA3 opcode: had the wrong static gas --- .../net/consensys/linea/zktracer/module/mxp/MxpOperation.java | 4 ++-- arithmetization/src/main/resources/opcodes.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java index 0c23488400..ee80186b2b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java @@ -115,6 +115,8 @@ public MxpOperation(final MxpCall mxpCall) { setAccAAndFirstTwoBytesOfByteR(); setExpands(); setWordsNew(frame); + setCMemNew(); + setCosts(); setMtntop(); // "tracing" the remaining fields of the MxpCall @@ -127,7 +129,6 @@ protected int computeLineCount() { } void compute() { - setCMemNew(); setComp(); setAcc1and2(); setAcc3(); @@ -135,7 +136,6 @@ void compute() { setAccWAndLastTwoBytesOfByteR(); setAccQAndByteQQ(); setBytes(); - setCosts(); } private void setInitializeByteArrays() { diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml index 8e7f701f67..68b659078c 100644 --- a/arithmetization/src/main/resources/opcodes.yml +++ b/arithmetization/src/main/resources/opcodes.yml @@ -275,7 +275,7 @@ opcodes: delta: 2 nbAdded: 1 nbRemoved: 2 - staticGas: S_MXP + staticGas: G_KECCAK_256 billing: byWord: type: TYPE_4 From 99227ee6cdcc22f6bd0a0829bdb69f0fdfcb1049 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 18 Jun 2024 11:48:39 +0530 Subject: [PATCH 108/461] move txInit out of the hub + cleaning: only one start/endTx for modules, add snapshot of selfdestructed acc, and ras --- .../consensys/linea/zktracer/ZkTracer.java | 4 +- .../linea/zktracer/module/Module.java | 16 +- .../blake2fmodexpdata/Blake2fModexpData.java | 14 +- .../zktracer/module/hub/AccountSnapshot.java | 49 +- .../linea/zktracer/module/hub/Hub.java | 982 ++++++++---------- .../TxFinalizationPostTxDefer.java | 9 +- .../hub/section/TxInitializationSection.java | 106 +- ...ion.java => TxPreWarmingMacroSection.java} | 13 +- ...Defer.java => TxSkippedSectionDefers.java} | 13 +- .../txFinalization/TxFinalizationSection.java | 26 - .../txPreWarming/TxPrewarmingSection.java | 33 - .../txSkipippedSection/TxSkippedSection.java | 26 - .../linea/zktracer/module/limits/L2Block.java | 17 +- .../zktracer/module/rlpaddr/RlpAddr.java | 3 +- .../linea/zktracer/module/rlptxn/RlpTxn.java | 4 +- .../linea/zktracer/module/romlex/RomLex.java | 4 +- .../module/shakiradata/ShakiraData.java | 14 +- .../linea/zktracer/module/trm/Trm.java | 3 +- .../types/TransactionProcessingMetadata.java | 11 +- zkevm-constraints | 2 +- 20 files changed, 618 insertions(+), 731 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{txFinalization => }/TxFinalizationPostTxDefer.java (96%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{txPreWarming/PreWarmingMacroSection.java => TxPreWarmingMacroSection.java} (93%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{txSkipippedSection/SkippedPostTransactionDefer.java => TxSkippedSectionDefers.java} (92%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/TxPrewarmingSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/TxSkippedSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index a1f159e296..c5360b26c5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -225,7 +225,7 @@ public void tracePrepareTransaction(WorldView worldView, Transaction transaction try { hashOfLastTransactionTraced = transaction.getHash(); this.pin55.ifPresent(x -> x.tracePrepareTx(worldView, transaction)); - this.hub.traceStartTx(worldView, transaction); + this.hub.traceStartTransaction(worldView, transaction); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -243,7 +243,7 @@ public void traceEndTransaction( long timeNs) { try { this.pin55.ifPresent(x -> x.traceEndTx(worldView, tx, status, output, logs, gasUsed)); - this.hub.traceEndTx(worldView, tx, status, output, logs, gasUsed); + this.hub.traceEndTransaction(worldView, tx, status, logs, selfDestructs); } catch (final Exception e) { this.tracingExceptions.add(e); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java index 421afe5774..cffaec3742 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Module.java @@ -20,10 +20,7 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.worldstate.WorldView; import org.hyperledger.besu.plugin.data.BlockBody; import org.hyperledger.besu.plugin.data.BlockHeader; @@ -40,17 +37,8 @@ default void traceStartBlock(final ProcessableBlockHeader processableBlockHeader default void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) {} - default void traceStartTx(WorldView worldView, Transaction tx) {} - - default void traceStartTx(TransactionProcessingMetadata transactionProcessingMetadata) {} - - default void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) {} + default void traceStartTx( + WorldView worldView, TransactionProcessingMetadata transactionProcessingMetadata) {} default void traceEndTx(TransactionProcessingMetadata tx) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/Blake2fModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/Blake2fModexpData.java index 9fe18deeff..4e76ce7ca9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/Blake2fModexpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/Blake2fModexpData.java @@ -32,9 +32,8 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.wcp.Wcp; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor @@ -55,13 +54,7 @@ public void enterTransaction() { } @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) { + public void traceEndTx(TransactionProcessingMetadata tx) { final List newOperations = new ArrayList<>(this.operations.sets.getLast()) .stream().sorted(Comparator.comparingLong(Blake2fModexpDataOperation::id)).toList(); @@ -75,7 +68,8 @@ public void traceEndTx( } @Override - public void traceStartTx(WorldView worldView, Transaction tx) { + public void traceStartTx( + WorldView world, TransactionProcessingMetadata transactionProcessingMetadata) { this.numberOfOperationsAtStartTx = operations.size(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 59fa034a0c..97f59a5d61 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.worldstate.WorldView; @AllArgsConstructor @Getter @@ -54,18 +55,9 @@ public AccountSnapshot incrementBalance(Wei quantity) { return this; } - public AccountSnapshot incrementNonce() { - this.nonce++; - return this; - } - - // TODO: Warning, does it really creates a copy or a pointer ?? - public static AccountSnapshot deepCopy(final AccountSnapshot accountSnapshot) { - return AccountSnapshot.fromAccount( - (Account) accountSnapshot, - accountSnapshot.isWarm(), - accountSnapshot.deploymentNumber(), - accountSnapshot.deploymentStatus()); + public static AccountSnapshot fromWorld(WorldView world, Address address) { + final Account account = world.get(address); + return fromAccount(account, true, 0, false); // TODO: implement warm, depNumber and Status } public static AccountSnapshot fromAccount( @@ -102,17 +94,6 @@ public static AccountSnapshot fromAccount( .orElseGet(() -> AccountSnapshot.empty(isWarm, deploymentNumber, deploymentStatus)); } - public AccountSnapshot debit(Wei quantity) { - return new AccountSnapshot( - this.address, - this.nonce + 1, - this.balance.subtract(quantity), - this.isWarm, - this.code, - this.deploymentNumber, - this.deploymentStatus); - } - public AccountSnapshot debit(Wei quantity, boolean isWarm) { return new AccountSnapshot( this.address, @@ -124,17 +105,6 @@ public AccountSnapshot debit(Wei quantity, boolean isWarm) { this.deploymentStatus); } - public AccountSnapshot initiateDeployment(Wei value) { - return new AccountSnapshot( - this.address, - this.nonce + 1, - this.balance.add(value), - this.isWarm, - this.code, - this.deploymentNumber + 1, - this.deploymentStatus); - } - // TODO: does this update the deployment number in the deploymentInfo object ? public AccountSnapshot initiateDeployment(Wei value, Bytecode code) { Preconditions.checkState( @@ -158,17 +128,6 @@ public AccountSnapshot deployByteCode(Bytecode code) { this.address, this.nonce, this.balance, true, code, this.deploymentNumber, false); } - public AccountSnapshot credit(Wei value) { - return new AccountSnapshot( - this.address, - this.nonce, - this.balance.add(value), - true, - this.code, - this.deploymentNumber, - this.deploymentStatus); - } - public AccountSnapshot credit(Wei value, boolean isWarm) { return new AccountSnapshot( this.address, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index ad03f246fc..6278a2c972 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; @@ -45,20 +46,18 @@ import net.consensys.linea.zktracer.module.ext.Ext; import net.consensys.linea.zktracer.module.hub.defer.*; import net.consensys.linea.zktracer.module.hub.fragment.*; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.section.*; +import net.consensys.linea.zktracer.module.hub.section.TxFinalizationPostTxDefer; +import net.consensys.linea.zktracer.module.hub.section.TxPreWarmingMacroSection; +import net.consensys.linea.zktracer.module.hub.section.TxSkippedSectionDefers; import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; -import net.consensys.linea.zktracer.module.hub.section.txFinalization.TxFinalizationPostTxDefer; -import net.consensys.linea.zktracer.module.hub.section.txPreWarming.PreWarmingMacroSection; -import net.consensys.linea.zktracer.module.hub.section.txSkipippedSection.SkippedPostTransactionDefer; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; -import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.module.hub.transients.Transients; import net.consensys.linea.zktracer.module.limits.Keccak; import net.consensys.linea.zktracer.module.limits.L2Block; @@ -149,6 +148,8 @@ public class Hub implements Module { /** stores all data related to failure states & module activation */ @Getter private final PlatformController pch; + private boolean previousOperationWasCallToEcPrecompile; + @Override public String moduleKey() { return "HUB"; @@ -165,74 +166,140 @@ public void commit(List buffers) { this.state.commit(trace); } - public int stamp() { - return this.state.stamps().hub(); - } - - public OpCodeData opCodeData() { - return this.currentFrame().opCodeData(); - } - - public OpCode opCode() { - return this.currentFrame().opCode(); - } - - TraceSection currentTraceSection() { - return this.state.currentTxTrace().currentSection(); - } - - public void addFragmentsAndStack(TraceFragment... fragments) { - currentTraceSection().addFragmentsAndStack(this, fragments); - } - - public void addTraceSection(TraceSection section) { - this.state.currentTxTrace().add(section); + @Override + public int lineCount() { + return this.state.lineCount(); } + /** List of all modules of the ZK-evm */ + // stateless modules @Getter private final Wcp wcp = new Wcp(this); + private final Module add = new Add(this); private final Module bin = new Bin(this); - private final Blake2fModexpData blake2fModexpData = new Blake2fModexpData(this.wcp); - @Getter private final EcData ecData; private final Blockdata blockdata; private final Blockhash blockhash = new Blockhash(wcp); private final Euc euc; private final Ext ext = new Ext(this); - private final Module mul = new Mul(this); private final Mod mod = new Mod(); + private final Module mul = new Mul(this); private final Module shf = new Shf(); + private final Trm trm = new Trm(); + + // other private final RlpTxn rlpTxn; + private final Rom rom; + @Getter private final RomLex romLex; + private final RlpTxrcpt rlpTxrcpt; + private final LogInfo logInfo; + private final LogData logData; private final Mmio mmio; + private final RlpAddr rlpAddr = new RlpAddr(this, trm); + private final TxnData txnData; - // sub-fragments of the MISCELLANEOUS / IMC perspective + // modules triggered by sub-fragments of the MISCELLANEOUS / IMC perspective + @Getter private final Stp stp = new Stp(this, wcp, mod); @Getter private final Exp exp; @Getter private final Mmu mmu; @Getter private final Mxp mxp; @Getter private final Oob oob; - @Getter private final Stp stp = new Stp(this, wcp, mod); - - private final RlpTxrcpt rlpTxrcpt; - private final LogInfo logInfo; - private final LogData logData; - private final Trm trm = new Trm(); - private final RlpAddr rlpAddr = new RlpAddr(this, trm); - private final Rom rom; - @Getter private final RomLex romLex; - private final TxnData txnData; - private final ShakiraData shakiraData = new ShakiraData(this.wcp); + // precompile-linked modules + private final Blake2fModexpData blake2fModexpData = new Blake2fModexpData(this.wcp); + @Getter private final EcData ecData; private final ModexpEffectiveCall modexpEffectiveCall; - private final L2Block l2Block; - - private final List modules; + private final ShakiraData shakiraData = new ShakiraData(this.wcp); /* * Those modules are not traced, we just compute the number of calls to those * precompile to meet the prover limits */ private final List precompileLimitModules; + private final L2Block l2Block; + + private final List modules; + + // reference table modules private final List refTableModules; - private boolean previousOperationWasCallToEcPrecompile; + /** + * @return a list of all modules for which to generate traces + */ + public List getModulesToTrace() { + return Stream.concat( + this.refTableModules.stream(), + // Modules + Stream.of( + this, + this.add, + this.bin, + this.blake2fModexpData, + this.ecData, + this.blockdata, + this.blockhash, + this.ext, + this.euc, + this.exp, + this.logData, + this.logInfo, + this.mmu, // WARN: must be called before the MMIO + this.mmio, + this.mod, + this.mul, + this.mxp, + this.oob, + this.rlpAddr, + this.rlpTxn, + this.rlpTxrcpt, + this.rom, + this.romLex, + this.shakiraData, + this.shf, + this.stp, + this.trm, + this.txnData, + this.wcp)) + .toList(); + } + + /** + * List all the modules for which to generate counters. Intersects with, but is not equal to + * {@code getModulesToTrace}. + * + * @return the modules to count + */ + public List getModulesToCount() { + return Stream.concat( + Stream.of( + this, + this.romLex, + this.add, + this.bin, + this.blockdata, + this.blockhash, + this.ext, + this.ecData, + this.euc, + this.mmu, + this.mmio, + this.logData, + this.logInfo, + this.mod, + this.mul, + this.mxp, + this.oob, + this.exp, + this.rlpAddr, + this.rlpTxn, + this.rlpTxrcpt, + this.rom, + this.shf, + this.trm, + this.txnData, + this.wcp, + this.l2Block), + this.precompileLimitModules.stream()) + .toList(); + } public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic)); @@ -323,367 +390,60 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { .toList(); } - /** - * @return a list of all modules for which to generate traces - */ - public List getModulesToTrace() { - return Stream.concat( - this.refTableModules.stream(), - // Modules - Stream.of( - this, - this.add, - this.bin, - this.blake2fModexpData, - this.ecData, - this.blockdata, - this.blockhash, - this.ext, - this.euc, - this.exp, - this.logData, - this.logInfo, - this.mmu, // WARN: must be called before the MMIO - this.mmio, - this.mod, - this.mul, - this.mxp, - this.oob, - this.rlpAddr, - this.rlpTxn, - this.rlpTxrcpt, - this.rom, - this.romLex, - this.shakiraData, - this.shf, - this.stp, - this.trm, - this.txnData, - this.wcp)) - .toList(); + @Override + public void enterTransaction() { + for (Module m : this.modules) { + m.enterTransaction(); + } } - /** - * List all the modules for which to generate counters. Intersects with, but is not equal to - * {@code getModulesToTrace}. - * - * @return the modules to count - */ - public List getModulesToCount() { - return Stream.concat( - Stream.of( - this, - this.romLex, - this.add, - this.bin, - this.blockdata, - this.blockhash, - this.ext, - this.ecData, - this.euc, - this.mmu, - this.mmio, - this.logData, - this.logInfo, - this.mod, - this.mul, - this.mxp, - this.oob, - this.exp, - this.rlpAddr, - this.rlpTxn, - this.rlpTxrcpt, - this.rom, - this.shf, - this.trm, - this.txnData, - this.wcp, - this.l2Block), - this.precompileLimitModules.stream()) - .toList(); + @Override + public void popTransaction() { + this.txStack.pop(); + this.state.pop(); + for (Module m : this.modules) { + m.popTransaction(); + } } - public int getCfiByMetaData( - final Address address, final int deploymentNumber, final boolean deploymentStatus) { - return this.romLex() - .getCodeFragmentIndexByMetadata( - ContractMetadata.make(address, deploymentNumber, deploymentStatus)); + /** Tracing Operation, triggered by Besu hook */ + @Override + public void traceStartConflation(long blockCount) { + this.transients.conflation().update(); + for (Module m : this.modules) { + m.traceStartConflation(blockCount); + } } - /** - * Trace the preamble of a transaction - * - * @param world a view onto the state - */ - void processStateInit(WorldView world) { - this.state.setProcessingPhase(TX_INIT); - this.state.stamps().incrementHubStamp(); - TransactionProcessingMetadata tx = this.txStack.current(); - final boolean isDeployment = tx.isDeployment(); - final Address toAddress = tx.getEffectiveTo(); - final DeploymentInfo deploymentInfo = this.transients.conflation().deploymentInfo(); - - final Address senderAddress = tx.getSender(); - final Account senderAccount = world.get(senderAddress); - final AccountSnapshot senderBeforePayingForTransaction = - AccountSnapshot.fromAccount( - senderAccount, - tx.isSenderPreWarmed(), - deploymentInfo.number(senderAddress), - deploymentInfo.isDeploying(senderAddress)); - final DomSubStampsSubFragment senderDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this, 0); - - final Wei transactionGasPrice = Wei.of(tx.getEffectiveGasPrice()); - final Wei value = (Wei) tx.getBesuTransaction().getValue(); - final AccountSnapshot senderAfterPayingForTransaction = - senderBeforePayingForTransaction.debit( - transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value), true); - - final boolean isSelfCredit = toAddress.equals(senderAddress); - - final Account recipientAccount = world.get(toAddress); - - final AccountSnapshot recipientBeforeValueTransfer = - isSelfCredit - ? senderAfterPayingForTransaction - : AccountSnapshot.fromAccount( - recipientAccount, - tx.isReceiverPreWarmed(), - deploymentInfo.number(toAddress), - deploymentInfo.isDeploying(toAddress)); - - if (isDeployment) { - deploymentInfo.deploy(toAddress); - } + @Override + public void traceEndConflation(final WorldView world) { + this.romLex.determineCodeFragmentIndex(); + this.txStack.setCodeFragmentIndex(this); + this.defers.runPostConflation(this, world); - final Bytecode initBytecode = - new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); - final AccountSnapshot recipientAfterValueTransfer = - isDeployment - ? recipientBeforeValueTransfer.initiateDeployment(value, initBytecode) - : recipientBeforeValueTransfer.credit(value, true); - final DomSubStampsSubFragment recipientDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this, 1); + for (Module m : this.modules) { + m.traceEndConflation(world); + } + } - final TransactionFragment txFragment = TransactionFragment.prepare(tx); - this.defers.postTx(txFragment); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - this.factories.accountFragment(); - - this.addTraceSection( - new TxInitializationSection( - this, - accountFragmentFactory.make( - senderBeforePayingForTransaction, - senderAfterPayingForTransaction, - senderDomSubStamps), - accountFragmentFactory - .makeWithTrm( - recipientBeforeValueTransfer, - recipientAfterValueTransfer, - toAddress, - recipientDomSubStamps) - .requiresRomlex(true), - ImcFragment.forTxInit(this), - ContextFragment.initializeExecutionContext(this), - txFragment)); - - this.state.setProcessingPhase(TX_EXEC); - } - - public int newChildContextNumber() { - return 1 + this.stamp(); - } - - public CallFrame currentFrame() { - if (this.callStack().isEmpty()) { - return CallFrame.EMPTY; - } - return this.callStack.current(); - } - - public int contextNumberNew(CallFrame frame) { - switch (this.state.getProcessingPhase()) { - case TX_SKIP, TX_WARM, TX_FINAL -> { - return 0; - } - case TX_INIT -> { - return newChildContextNumber(); - } - case TX_EXEC -> { - final OpCode opCode = this.opCode(); - - if (pch.exceptions().any() - || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) - || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { - return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); - } - - final int currentContextNumber = this.callStack().current().contextNumber(); - - if (opCode.isCall()) { - if (pch().abortingConditions().any()) { - return currentContextNumber; - } - - final Address calleeAddress = - Words.toAddress(this.currentFrame().frame().getStackItem(1)); - - AtomicInteger newContext = new AtomicInteger(currentContextNumber); - - Optional.ofNullable(frame.frame().getWorldUpdater().get(calleeAddress)) - .map(AccountState::getCode) - .ifPresent( - byteCode -> { - if (!byteCode.isEmpty()) { - newContext.set(newChildContextNumber()); - } - }); - return newContext.get(); - } - - if (opCode.isCreate()) { - if (pch().abortingConditions().any() || pch().failureConditions().any()) { - return currentContextNumber; - } - final int initCodeSize = this.currentFrame().frame().getStackItem(2).toInt(); - if (initCodeSize != 0) { - return newChildContextNumber(); - } - } - - return currentContextNumber; - } - default -> { - { - throw new IllegalStateException( - String.format("Hub can't be in the state %s", this.state.getProcessingPhase())); - } - } - } - } - - public MessageFrame messageFrame() { - MessageFrame frame = this.callStack.current().frame(); - return frame; - } - - private void handleStack(MessageFrame frame) { - this.currentFrame() - .stack() - .processInstruction(this, frame, MULTIPLIER___STACK_HEIGHT * this.state.stamps().hub()); - } - - void triggerModules(MessageFrame frame) { - if (this.pch.exceptions().none() && this.pch.abortingConditions().none()) { - for (Module precompileLimit : this.precompileLimitModules) { - precompileLimit.tracePreOpcode(frame); - } - } - - if (this.pch.signals().romLex()) { - this.romLex.tracePreOpcode(frame); - } - if (this.pch.signals().add()) { - this.add.tracePreOpcode(frame); - } - if (this.pch.signals().bin()) { - this.bin.tracePreOpcode(frame); - } - if (this.pch.signals().rlpAddr()) { - this.rlpAddr.tracePreOpcode(frame); - } - if (this.pch.signals().mul()) { - this.mul.tracePreOpcode(frame); - } - if (this.pch.signals().ext()) { - this.ext.tracePreOpcode(frame); - } - if (this.pch.signals().mod()) { - this.mod.tracePreOpcode(frame); - } - if (this.pch.signals().wcp()) { - this.wcp.tracePreOpcode(frame); - } - if (this.pch.signals().shf()) { - this.shf.tracePreOpcode(frame); - } - if (this.pch.signals().mxp()) { - this.mxp.tracePreOpcode(frame); - } - if (this.pch.signals().oob()) { - this.oob.tracePreOpcode(frame); - } - if (this.pch.signals().stp()) { - this.stp.tracePreOpcode(frame); - } - if (this.pch.signals().exp()) { - this.exp.tracePreOpcode(frame); - } - if (this.pch.signals().trm()) { - this.trm.tracePreOpcode(frame); - } - if (this.pch.signals().hashInfo()) { - // TODO: this.hashInfo.tracePreOpcode(frame); - } - if (this.pch.signals().ecData()) { - this.ecData.tracePreOpcode(frame); - } - if (this.pch.signals().blockhash()) { - this.blockhash.tracePreOpcode(frame); - } - } - - void processStateExec(MessageFrame frame) { - - if (previousOperationWasCallToEcPrecompile) { - this.ecData.getEcDataOperation().returnData(frame.getReturnData()); - previousOperationWasCallToEcPrecompile = false; - } - - this.currentFrame().frame(frame); - this.state.stamps().incrementHubStamp(); - - this.pch.setup(frame); - this.state.stamps().stampSubmodules(this.pch()); - - this.handleStack(frame); - this.triggerModules(frame); - - if (this.pch().exceptions().any() || this.currentFrame().opCode() == OpCode.REVERT) { - this.callStack.revert(this.state.stamps().hub()); - } - - if (this.currentFrame().stack().isOk()) { - // TODO: this is insufficient because it neglects: - // - exceptions other than stack exceptions e.g. - // * STATICX - // * MXPX - // * OOGX - // - it COULD (unlikely ?) produce issues with ABORTS - // - it COULD interfere with CALL's to precompiles that don't reach EC_DATA e.g. - // * ECRECOVER, ECADD, ECMUL, ECPAIRING with zero call data size parameter - if (this.pch.signals().ecData()) { - this.previousOperationWasCallToEcPrecompile = true; - } - this.traceOperation(frame); - } else { - - this.addTraceSection(new StackOnlySection(this)); + @Override + public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { + this.state.firstAndLastStorageSlotOccurrences.add(new HashMap<>()); + this.transients.block().blockUpdate(processableBlockHeader); + this.txStack.resetBlock(); + for (Module m : this.modules) { + m.traceStartBlock(processableBlockHeader); } } @Override - public void enterTransaction() { + public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { for (Module m : this.modules) { - m.enterTransaction(); + m.traceEndBlock(blockHeader, blockBody); } } - @Override - public void traceStartTx(final WorldView world, final Transaction tx) { + public void traceStartTransaction(final WorldView world, final Transaction tx) { this.pch.reset(); this.state.enter(); this.txStack.enterTransaction(world, tx, transients.block()); @@ -695,13 +455,14 @@ public void traceStartTx(final WorldView world, final Transaction tx) { this.state.setProcessingPhase(TX_SKIP); this.state.stamps().incrementHubStamp(); this.defers.postTx( - new SkippedPostTransactionDefer(world, this.txStack.current(), this.transients)); + new TxSkippedSectionDefers(world, this.txStack.current(), this.transients)); } else { if (this.txStack.current().requiresPrewarming()) { this.state.setProcessingPhase(TX_WARM); - new PreWarmingMacroSection(world, this); + new TxPreWarmingMacroSection(world, this); } - this.processStateInit(world); + + new TxInitializationSection(this, world); } /* @@ -713,75 +474,25 @@ public void traceStartTx(final WorldView world, final Transaction tx) { this.callStack.getById(0).universalParentReturnDataContextNumber(this.stamp() + 1); for (Module m : this.modules) { - // TODO: should use only a LineaTransaction as its argument - m.traceStartTx(world, tx); - m.traceStartTx(this.txStack().current()); - } - } - - @Override - public void popTransaction() { - this.txStack.pop(); - this.state.pop(); - for (Module m : this.modules) { - m.popTransaction(); - } - } - - @Override - public void traceContextExit(MessageFrame frame) { - if (frame.getDepth() > 0) { - this.transients - .conflation() - .deploymentInfo() - .unmarkDeploying(this.currentFrame().byteCodeAddress()); - - DeploymentExceptions contextExceptions = - DeploymentExceptions.fromFrame(this.currentFrame(), frame); - this.currentTraceSection().setContextExceptions(contextExceptions); - if (contextExceptions.any()) { - this.callStack.revert(this.state.stamps().hub()); - } - - this.callStack.exit(); - - for (Module m : this.modules) { - m.traceContextExit(frame); - } - } - - // We take a snapshot before exiting the transaction - if (frame.getDepth() == 0) { - final long leftOverGas = frame.getRemainingGas(); - final long gasRefund = frame.getGasRefund(); - final boolean minerIsWarm = frame.isAddressWarm(txStack.current().getCoinbase()); - - txStack - .current() - .setPreFinalisationValues( - leftOverGas, - gasRefund, - minerIsWarm, - this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); - if (this.state.getProcessingPhase() != TX_SKIP) { - this.state.setProcessingPhase(TX_FINAL); - this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); - } + m.traceStartTx(world, this.txStack().current()); } } - @Override - public void traceEndTx( + public void traceEndTransaction( WorldView world, Transaction tx, boolean isSuccessful, - Bytes output, List logs, - long gasUsed) { + Set

selfDestructs) { this.txStack .current() .completeLineaTransaction( - isSuccessful, this.state.stamps().hub(), this.state().getProcessingPhase(), logs); + world, + isSuccessful, + this.state.stamps().hub(), + this.state().getProcessingPhase(), + logs, + selfDestructs); if (!(this.state.getProcessingPhase() == TX_SKIP)) { this.state.stamps().incrementHubStamp(); @@ -790,52 +501,13 @@ public void traceEndTx( this.defers.runPostTx(this, world, tx, isSuccessful); for (Module m : this.modules) { - // TODO shift all module to the method with TxMetaData - m.traceEndTx(world, tx, isSuccessful, output, logs, gasUsed); m.traceEndTx(txStack.current()); } } - private void unlatchStack(MessageFrame frame) { - this.unlatchStack(frame, this.currentTraceSection()); - } - - public void unlatchStack(MessageFrame frame, TraceSection section) { - if (this.currentFrame().pending() == null) { - return; - } - - StackContext pending = this.currentFrame().pending(); - for (int i = 0; i < pending.lines().size(); i++) { - StackLine line = pending.lines().get(i); - - if (line.needsResult()) { - Bytes result = Bytes.EMPTY; - // Only pop from the stack if no exceptions have been encountered - if (this.pch.exceptions().none()) { - result = frame.getStackItem(0).copy(); - } - - // This works because we are certain that the stack chunks are the first. - ((StackFragment) section.lines().get(i).specific()) - .stackOps() - .get(line.resultColumn() - 1) - .value(result); - } - } - - if (this.pch.exceptions().none()) { - for (TraceSection.TraceLine line : section.lines()) { - if (line.specific() instanceof StackFragment stackFragment) { - stackFragment.feedHashedValue(frame); - } - } - } - } - - @Override - public void traceContextEnter(MessageFrame frame) { - this.pch.reset(); + @Override + public void traceContextEnter(MessageFrame frame) { + this.pch.reset(); if (frame.getDepth() == 0) { // Bedrock... @@ -943,18 +615,6 @@ public void traceContextEnter(MessageFrame frame) { } } - private boolean requiresEvmExecution(final WorldView worldView, final Transaction tx) { - Optional receiver = tx.getTo(); - - if (receiver.isPresent()) { - Optional receiverInWorld = Optional.ofNullable(worldView.get(receiver.get())); - - return receiverInWorld.map(AccountState::hasCode).orElse(false); - } - - return !tx.getInit().get().isEmpty(); - } - public void traceContextReEnter(MessageFrame frame) { this.defers.runReEntry(this, frame); if (this.currentFrame().needsUnlatchingAtReEntry() != null) { @@ -963,6 +623,48 @@ public void traceContextReEnter(MessageFrame frame) { } } + @Override + public void traceContextExit(MessageFrame frame) { + if (frame.getDepth() > 0) { + this.transients + .conflation() + .deploymentInfo() + .unmarkDeploying(this.currentFrame().byteCodeAddress()); + + DeploymentExceptions contextExceptions = + DeploymentExceptions.fromFrame(this.currentFrame(), frame); + this.currentTraceSection().setContextExceptions(contextExceptions); + if (contextExceptions.any()) { + this.callStack.revert(this.state.stamps().hub()); + } + + this.callStack.exit(); + + for (Module m : this.modules) { + m.traceContextExit(frame); + } + } + + // We take a snapshot before exiting the transaction + if (frame.getDepth() == 0) { + final long leftOverGas = frame.getRemainingGas(); + final long gasRefund = frame.getGasRefund(); + final boolean minerIsWarm = frame.isAddressWarm(txStack.current().getCoinbase()); + + txStack + .current() + .setPreFinalisationValues( + leftOverGas, + gasRefund, + minerIsWarm, + this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); + if (this.state.getProcessingPhase() != TX_SKIP) { + this.state.setProcessingPhase(TX_FINAL); + this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); + } + } + } + @Override public void tracePreOpcode(final MessageFrame frame) { Preconditions.checkArgument( @@ -1094,44 +796,259 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope default -> {} } } + private void handleCreate(Address target) { this.transients.conflation().deploymentInfo().deploy(target); } - @Override - public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { - this.state.firstAndLastStorageSlotOccurrences.add(new HashMap<>()); - this.transients.block().blockUpdate(processableBlockHeader); - this.txStack.resetBlock(); - for (Module m : this.modules) { - m.traceStartBlock(processableBlockHeader); + public int getCfiByMetaData( + final Address address, final int deploymentNumber, final boolean deploymentStatus) { + return this.romLex() + .getCodeFragmentIndexByMetadata( + ContractMetadata.make(address, deploymentNumber, deploymentStatus)); + } + + public int newChildContextNumber() { + return 1 + this.stamp(); + } + + public CallFrame currentFrame() { + if (this.callStack().isEmpty()) { + return CallFrame.EMPTY; } + return this.callStack.current(); } - @Override - public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { - for (Module m : this.modules) { - m.traceEndBlock(blockHeader, blockBody); + public int contextNumberNew(CallFrame frame) { + switch (this.state.getProcessingPhase()) { + case TX_SKIP, TX_WARM, TX_FINAL -> { + return 0; + } + case TX_INIT -> { + return newChildContextNumber(); + } + case TX_EXEC -> { + final OpCode opCode = this.opCode(); + + if (pch.exceptions().any() + || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) + || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { + return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); + } + + final int currentContextNumber = this.callStack().current().contextNumber(); + + if (opCode.isCall()) { + if (pch().abortingConditions().any()) { + return currentContextNumber; + } + + final Address calleeAddress = + Words.toAddress(this.currentFrame().frame().getStackItem(1)); + + AtomicInteger newContext = new AtomicInteger(currentContextNumber); + + Optional.ofNullable(frame.frame().getWorldUpdater().get(calleeAddress)) + .map(AccountState::getCode) + .ifPresent( + byteCode -> { + if (!byteCode.isEmpty()) { + newContext.set(newChildContextNumber()); + } + }); + return newContext.get(); + } + + if (opCode.isCreate()) { + if (pch().abortingConditions().any() || pch().failureConditions().any()) { + return currentContextNumber; + } + final int initCodeSize = this.currentFrame().frame().getStackItem(2).toInt(); + if (initCodeSize != 0) { + return newChildContextNumber(); + } + } + + return currentContextNumber; + } + default -> { + { + throw new IllegalStateException( + String.format("Hub can't be in the state %s", this.state.getProcessingPhase())); + } + } } } - @Override - public void traceStartConflation(long blockCount) { - this.transients.conflation().update(); - for (Module m : this.modules) { - m.traceStartConflation(blockCount); + public MessageFrame messageFrame() { + MessageFrame frame = this.callStack.current().frame(); + return frame; + } + + private void handleStack(MessageFrame frame) { + this.currentFrame() + .stack() + .processInstruction(this, frame, MULTIPLIER___STACK_HEIGHT * this.state.stamps().hub()); + } + + void triggerModules(MessageFrame frame) { + if (this.pch.exceptions().none() && this.pch.abortingConditions().none()) { + for (Module precompileLimit : this.precompileLimitModules) { + precompileLimit.tracePreOpcode(frame); + } + } + + if (this.pch.signals().romLex()) { + this.romLex.tracePreOpcode(frame); + } + if (this.pch.signals().add()) { + this.add.tracePreOpcode(frame); + } + if (this.pch.signals().bin()) { + this.bin.tracePreOpcode(frame); + } + if (this.pch.signals().rlpAddr()) { + this.rlpAddr.tracePreOpcode(frame); + } + if (this.pch.signals().mul()) { + this.mul.tracePreOpcode(frame); + } + if (this.pch.signals().ext()) { + this.ext.tracePreOpcode(frame); + } + if (this.pch.signals().mod()) { + this.mod.tracePreOpcode(frame); + } + if (this.pch.signals().wcp()) { + this.wcp.tracePreOpcode(frame); + } + if (this.pch.signals().shf()) { + this.shf.tracePreOpcode(frame); + } + if (this.pch.signals().mxp()) { + this.mxp.tracePreOpcode(frame); + } + if (this.pch.signals().oob()) { + this.oob.tracePreOpcode(frame); + } + if (this.pch.signals().stp()) { + this.stp.tracePreOpcode(frame); + } + if (this.pch.signals().exp()) { + this.exp.tracePreOpcode(frame); + } + if (this.pch.signals().trm()) { + this.trm.tracePreOpcode(frame); + } + if (this.pch.signals().hashInfo()) { + // TODO: this.hashInfo.tracePreOpcode(frame); + } + if (this.pch.signals().ecData()) { + this.ecData.tracePreOpcode(frame); + } + if (this.pch.signals().blockhash()) { + this.blockhash.tracePreOpcode(frame); } } - @Override - public void traceEndConflation(final WorldView world) { - this.romLex.determineCodeFragmentIndex(); - this.txStack.setCodeFragmentIndex(this); - this.defers.runPostConflation(this, world); + public int stamp() { + return this.state.stamps().hub(); + } - for (Module m : this.modules) { - m.traceEndConflation(world); + public OpCodeData opCodeData() { + return this.currentFrame().opCodeData(); + } + + public OpCode opCode() { + return this.currentFrame().opCode(); + } + + TraceSection currentTraceSection() { + return this.state.currentTxTrace().currentSection(); + } + + public void addFragmentsAndStack(TraceFragment... fragments) { + currentTraceSection().addFragmentsAndStack(this, fragments); + } + + public void addTraceSection(TraceSection section) { + this.state.currentTxTrace().add(section); + } + + private void unlatchStack(MessageFrame frame) { + this.unlatchStack(frame, this.currentTraceSection()); + } + + public void unlatchStack(MessageFrame frame, TraceSection section) { + if (this.currentFrame().pending() == null) { + return; + } + + StackContext pending = this.currentFrame().pending(); + for (int i = 0; i < pending.lines().size(); i++) { + StackLine line = pending.lines().get(i); + + if (line.needsResult()) { + Bytes result = Bytes.EMPTY; + // Only pop from the stack if no exceptions have been encountered + if (this.pch.exceptions().none()) { + result = frame.getStackItem(0).copy(); + } + + // This works because we are certain that the stack chunks are the first. + ((StackFragment) section.lines().get(i).specific()) + .stackOps() + .get(line.resultColumn() - 1) + .value(result); + } + } + + if (this.pch.exceptions().none()) { + for (TraceSection.TraceLine line : section.lines()) { + if (line.specific() instanceof StackFragment stackFragment) { + stackFragment.feedHashedValue(frame); + } + } + } + } + + void processStateExec(MessageFrame frame) { + + if (previousOperationWasCallToEcPrecompile) { + this.ecData.getEcDataOperation().returnData(frame.getReturnData()); + previousOperationWasCallToEcPrecompile = false; + } + + this.currentFrame().frame(frame); + this.state.stamps().incrementHubStamp(); + + this.pch.setup(frame); + this.state.stamps().stampSubmodules(this.pch()); + + this.handleStack(frame); + this.triggerModules(frame); + + if (this.pch().exceptions().any() || this.currentFrame().opCode() == OpCode.REVERT) { + this.callStack.revert(this.state.stamps().hub()); + } + + if (this.currentFrame().stack().isOk()) { + // TODO: this is insufficient because it neglects: + // - exceptions other than stack exceptions e.g. + // * STATICX + // * MXPX + // * OOGX + // - it COULD (unlikely ?) produce issues with ABORTS + // - it COULD interfere with CALL's to precompiles that don't reach EC_DATA e.g. + // * ECRECOVER, ECADD, ECMUL, ECPAIRING with zero call data size parameter + if (this.pch.signals().ecData()) { + this.previousOperationWasCallToEcPrecompile = true; + } + this.traceOperation(frame); + } else { + + this.addTraceSection(new StackOnlySection(this)); } } @@ -1151,11 +1068,6 @@ public long expectedGas() { : 0; } - @Override - public int lineCount() { - return this.state.lineCount(); - } - public int cumulatedTxCount() { return this.state.txCount(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationPostTxDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationPostTxDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java index 9c31de98a1..9fb4e3126b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationPostTxDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java @@ -13,13 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section.txFinalization; +package net.consensys.linea.zktracer.module.hub.section; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -222,4 +223,10 @@ private boolean toIsMiner() { private boolean noAccountCollision() { return !senderIsMiner() && !senderIsTo() && !toIsMiner(); } + + public class TxFinalizationSection extends TraceSection { + public TxFinalizationSection(Hub hub, TraceFragment... fragments) { + this.addFragmentsWithoutStack(hub, fragments); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 9514ceb36d..9510c90c44 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -1,7 +1,7 @@ /* * Copyright Consensys Software Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use hub file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 @@ -15,11 +15,109 @@ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; +import net.consensys.linea.zktracer.types.Bytecode; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class TxInitializationSection { + public TxInitializationSection(Hub hub, WorldView world) { + + hub.state.setProcessingPhase(TX_INIT); + hub.state.stamps().incrementHubStamp(); + TransactionProcessingMetadata tx = hub.txStack().current(); + final boolean isDeployment = tx.isDeployment(); + final Address toAddress = tx.getEffectiveTo(); + final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); + + final Address senderAddress = tx.getSender(); + final Account senderAccount = world.get(senderAddress); + final AccountSnapshot senderBeforePayingForTransaction = + AccountSnapshot.fromAccount( + senderAccount, + tx.isSenderPreWarmed(), + deploymentInfo.number(senderAddress), + deploymentInfo.isDeploying(senderAddress)); + final DomSubStampsSubFragment senderDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + + final Wei transactionGasPrice = Wei.of(tx.getEffectiveGasPrice()); + final Wei value = (Wei) tx.getBesuTransaction().getValue(); + final AccountSnapshot senderAfterPayingForTransaction = + senderBeforePayingForTransaction.debit( + transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value), true); + + final boolean isSelfCredit = toAddress.equals(senderAddress); + + final Account recipientAccount = world.get(toAddress); + + final AccountSnapshot recipientBeforeValueTransfer = + isSelfCredit + ? senderAfterPayingForTransaction + : AccountSnapshot.fromAccount( + recipientAccount, + tx.isReceiverPreWarmed(), + deploymentInfo.number(toAddress), + deploymentInfo.isDeploying(toAddress)); + + if (isDeployment) { + deploymentInfo.deploy(toAddress); + } + + final Bytecode initBytecode = + new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); + final AccountSnapshot recipientAfterValueTransfer = + isDeployment + ? recipientBeforeValueTransfer.initiateDeployment(value, initBytecode) + : recipientBeforeValueTransfer.credit(value, true); + final DomSubStampsSubFragment recipientDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(hub, 1); + + final TransactionFragment txFragment = TransactionFragment.prepare(tx); + hub.defers().postTx(txFragment); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + hub.addTraceSection( + new InitializationSection( + hub, + accountFragmentFactory.make( + senderBeforePayingForTransaction, + senderAfterPayingForTransaction, + senderDomSubStamps), + accountFragmentFactory + .makeWithTrm( + recipientBeforeValueTransfer, + recipientAfterValueTransfer, + toAddress, + recipientDomSubStamps) + .requiresRomlex(true), + ImcFragment.forTxInit(hub), + ContextFragment.initializeExecutionContext(hub), + txFragment)); + + hub.state.setProcessingPhase(TX_EXEC); + } -public class TxInitializationSection extends TraceSection { - public TxInitializationSection(Hub hub, TraceFragment... chunks) { - this.addFragmentsWithoutStack(hub, chunks); + public class InitializationSection extends TraceSection { + public InitializationSection(Hub hub, TraceFragment... fragments) { + this.addFragmentsWithoutStack(hub, fragments); + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 57d33c7bb1..3830d481d1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/PreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section.txPreWarming; +package net.consensys.linea.zktracer.module.hub.section; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.precompileAddress; @@ -29,6 +29,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.types.EWord; @@ -41,8 +42,8 @@ import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; -public class PreWarmingMacroSection { - public PreWarmingMacroSection(WorldView world, Hub hub) { +public class TxPreWarmingMacroSection { + public TxPreWarmingMacroSection(WorldView world, Hub hub) { final TransactionProcessingMetadata currentTxMetadata = hub.txStack().current(); @@ -137,4 +138,10 @@ public PreWarmingMacroSection(WorldView world, Hub hub) { } }); } + + public class TxPrewarmingSection extends TraceSection { + public TxPrewarmingSection(Hub hub, TraceFragment fragment) { + this.addFragmentsWithoutStack(hub, fragment); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/SkippedPostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java similarity index 92% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/SkippedPostTransactionDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java index 7696638498..79e055fd7d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/SkippedPostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section.txSkipippedSection; +package net.consensys.linea.zktracer.module.hub.section; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; @@ -21,6 +21,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.transients.Transients; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -33,13 +34,13 @@ * later, through a {@link PostTransactionDefer}, to generate the trace chunks required for the * proving of a pure transaction. */ -public class SkippedPostTransactionDefer implements PostTransactionDefer { +public class TxSkippedSectionDefers implements PostTransactionDefer { final TransactionProcessingMetadata txMetadata; final AccountSnapshot oldFromAccount; final AccountSnapshot oldToAccount; final AccountSnapshot oldMinerAccount; - public SkippedPostTransactionDefer( + public TxSkippedSectionDefers( WorldView world, TransactionProcessingMetadata txMetadata, Transients transients) { this.txMetadata = txMetadata; @@ -132,4 +133,10 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces // 1 line -- transaction data TransactionFragment.prepare(hub.txStack().current()))); } + + public class TxSkippedSection extends TraceSection { + public TxSkippedSection(Hub hub, TraceFragment... fragments) { + this.addFragmentsWithoutStack(hub, fragments); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java deleted file mode 100644 index a482a7edc7..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txFinalization/TxFinalizationSection.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.txFinalization; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class TxFinalizationSection extends TraceSection { - public TxFinalizationSection(Hub hub, TraceFragment... chunks) { - this.addFragmentsWithoutStack(hub, chunks); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/TxPrewarmingSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/TxPrewarmingSection.java deleted file mode 100644 index 69d0d5ef05..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txPreWarming/TxPrewarmingSection.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.txPreWarming; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -/** - * A warmup section is generated if a transaction features pre-warmed addresses and/or keys. It - * contains a succession of {@link AccountFragment } and {@link StorageFragment} representing the - * pre-warmed addresses and eventual keys. - */ -public class TxPrewarmingSection extends TraceSection { - public TxPrewarmingSection(Hub hub, TraceFragment fragment) { - this.addFragmentsWithoutStack(hub, fragment); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/TxSkippedSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/TxSkippedSection.java deleted file mode 100644 index 96c500c41c..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/txSkipippedSection/TxSkippedSection.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.txSkipippedSection; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class TxSkippedSection extends TraceSection { - public TxSkippedSection(Hub hub, TraceFragment... chunks) { - this.addFragmentsWithoutStack(hub, chunks); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2Block.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2Block.java index 32f0112f04..0554964b19 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2Block.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/L2Block.java @@ -25,12 +25,10 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.module.Module; -import org.apache.tuweni.bytes.Bytes; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.log.LogTopic; -import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true) @RequiredArgsConstructor @@ -129,20 +127,15 @@ public List columnsHeaders() { } @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) { - for (Log log : logs) { + public void traceEndTx(TransactionProcessingMetadata tx) { + for (Log log : tx.getLogs()) { if (log.getLogger().equals(l2l1Address) && log.getTopics().contains(l2l1Topic)) { this.l2l1LogSizes.peek().add(log.getData().size()); } } - this.sizesRlpEncodedTxs.push(this.sizesRlpEncodedTxs.pop() + tx.encoded().size()); + this.sizesRlpEncodedTxs.push( + this.sizesRlpEncodedTxs.pop() + tx.getBesuTransaction().encoded().size()); } public int l2l1LogsCount() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java index cf189b3707..0533b48c28 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java @@ -54,6 +54,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor public class RlpAddr implements Module { @@ -81,7 +82,7 @@ public void popTransaction() { } @Override - public void traceStartTx(TransactionProcessingMetadata txMetaData) { + public void traceStartTx(WorldView world, TransactionProcessingMetadata txMetaData) { final Transaction tx = txMetaData.getBesuTransaction(); if (tx.getTo().isEmpty()) { final Address senderAddress = tx.getSender(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxn/RlpTxn.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxn/RlpTxn.java index 06dda2ec42..d17c268b8a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxn/RlpTxn.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlptxn/RlpTxn.java @@ -64,6 +64,7 @@ import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.module.romlex.RomLex; import net.consensys.linea.zktracer.types.BitDecOutput; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; @@ -112,7 +113,8 @@ public void popTransaction() { } @Override - public void traceStartTx(WorldView worldView, Transaction tx) { + public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMetaData) { + final Transaction tx = txMetaData.getBesuTransaction(); // Contract Creation if (tx.getTo().isEmpty() && !tx.getInit().get().isEmpty()) { this.chunkList.add(new RlpTxnChunk(tx, true)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 5dac38cd19..b532e2440e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -32,6 +32,7 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; @@ -107,7 +108,8 @@ public Optional getChunkByMetadata(final ContractMetadata metadata) { } @Override - public void traceStartTx(WorldView worldView, Transaction tx) { + public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMetaData) { + final Transaction tx = txMetaData.getBesuTransaction(); // Contract creation with InitCode if (tx.getInit().isPresent() && !tx.getInit().get().isEmpty()) { final Address calledAddress = Address.contractAddress(tx.getSender(), tx.getNonce()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java index 03f62ce17a..26eb8465c0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java @@ -26,9 +26,7 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.wcp.Wcp; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.log.Log; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor @@ -73,18 +71,12 @@ public void call(final ShakiraDataOperation operation) { } @Override - public void traceStartTx(WorldView worldView, Transaction tx) { + public void traceStartTx(WorldView worldView, TransactionProcessingMetadata tx) { this.numberOfOperationsAtStartTx = operations.size(); } @Override - public void traceEndTx( - WorldView worldView, - Transaction tx, - boolean isSuccessful, - Bytes output, - List logs, - long gasUsed) { + public void traceEndTx(TransactionProcessingMetadata tx) { final List newOperations = new ArrayList<>(this.operations.sets.getLast()); newOperations.sort(comparator); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java index 57af31effe..a4ffca4139 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.worldstate.WorldView; public class Trm implements Module { static final int MAX_CT = LLARGE; @@ -73,7 +74,7 @@ public Address callTrimming(Bytes32 rawHash) { } @Override - public void traceStartTx(TransactionProcessingMetadata txMetaData) { + public void traceStartTx(WorldView world, TransactionProcessingMetadata txMetaData) { // Add effective receiver Address this.trimmings.add(new TrmOperation(EWord.of(txMetaData.getEffectiveTo()))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 423eb9351e..b4da6f30b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -22,11 +22,13 @@ import java.math.BigInteger; import java.util.List; import java.util.Optional; +import java.util.Set; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; @@ -106,6 +108,8 @@ public class TransactionProcessingMetadata { @Setter int codeFragmentIndex = -1; + @Setter Set destructedAccountsSnapshot; + public TransactionProcessingMetadata( final WorldView world, final Transaction transaction, @@ -156,14 +160,19 @@ public void setPreFinalisationValues( } public void completeLineaTransaction( + WorldView world, final boolean statusCode, final int hubStampTransactionEnd, final HubProcessingPhase hubPhase, - List logs) { + final List logs, + final Set
selfDestructs) { this.statusCode = statusCode; this.hubStampTransactionEnd = (hubPhase == TX_SKIP) ? hubStampTransactionEnd : hubStampTransactionEnd + 1; this.logs = logs; + for (Address address : selfDestructs) { + this.destructedAccountsSnapshot.add(AccountSnapshot.fromWorld(world, address)); + } } private boolean computeCopyCallData() { diff --git a/zkevm-constraints b/zkevm-constraints index 15ac2bd78a..4e868acfa4 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 15ac2bd78a1d8f99b7f0e83aa25f12f92f1a497a +Subproject commit 4e868acfa46282f86db85910500821fbe293e284 From 2702929cce21031a7c370a097c6598fcc5fa18fe Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 18 Jun 2024 13:13:30 +0530 Subject: [PATCH 109/461] fixing some java issue + spotless --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 1 - .../linea/zktracer/module/hub/section/SloadSection.java | 2 +- .../linea/zktracer/module/hub/section/SstoreSection.java | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6278a2c972..2d5c480e8e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -796,7 +796,6 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope default -> {} } } - private void handleCreate(Address target) { this.transients.conflation().deploymentInfo().deploy(target); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 50b9c74003..c08b9d578e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -45,7 +45,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { final Address address = hub.messageFrame().getRecipientAddress(); final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); - final Bytes32 storageKey = (Bytes32) (hub.messageFrame().getStackItem(0)); + final Bytes32 storageKey = Bytes32.leftPad(hub.messageFrame().getStackItem(0)); final EWord valueOriginal = EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); final EWord valueCurrent = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index bb3b234b6d..b46373548f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -43,7 +43,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { final Address address = hub.messageFrame().getRecipientAddress(); final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); - final Bytes32 storageKey = (Bytes32) hub.messageFrame().getStackItem(0); + final Bytes32 storageKey = Bytes32.leftPad(hub.messageFrame().getStackItem(0)); final EWord valueOriginal = EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); From c95eaca3d9900af2f5296bdd4cc79ab5b1e012a8 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 18 Jun 2024 13:18:48 +0530 Subject: [PATCH 110/461] fix stackArg to long --- .../linea/zktracer/module/hub/section/KeccakSection.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 9bd4d9afa3..324d074acd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.section; +import static org.hyperledger.besu.evm.internal.Words.clampedToLong; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -42,9 +44,9 @@ public static void appendToTrace(Hub hub) { imcFragment.callMmu(MmuCall.sha3(hub)); // TODO: computing the hash shouldn't be done here - Bytes offset = hub.messageFrame().getStackItem(0); - Bytes size = hub.messageFrame().getStackItem(1); - Bytes dataToHash = hub.messageFrame().shadowReadMemory(offset.toLong(), size.toLong()); + final long offset = clampedToLong(hub.messageFrame().getStackItem(0)); + final long size = clampedToLong(hub.messageFrame().getStackItem(1)); + Bytes dataToHash = hub.messageFrame().shadowReadMemory(offset, size); KeccakDigest keccakDigest = new KeccakDigest(256); keccakDigest.update(dataToHash.toArray(), 0, dataToHash.size()); byte[] hashOutput = new byte[keccakDigest.getDigestSize()]; From ea3aab21c1e807cb43e516c41951f6702b15a374 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 18 Jun 2024 13:28:32 +0200 Subject: [PATCH 111/461] feat(oob): partially implemented new approach for OobCall --- .../module/hub/fragment/imc/ImcFragment.java | 41 ++++---------- .../hub/fragment/imc/call/oob/OobCall.java | 44 ++++++++------- .../fragment/imc/call/oob/opcodes/Call.java | 21 +------ .../imc/call/oob/opcodes/CallDataLoad.java | 23 +------- .../fragment/imc/call/oob/opcodes/Create.java | 27 +-------- .../call/oob/opcodes/DeploymentReturn.java | 16 +----- .../imc/call/oob/opcodes/ExceptionalCall.java | 16 +----- .../fragment/imc/call/oob/opcodes/Jump.java | 56 +------------------ .../fragment/imc/call/oob/opcodes/Jumpi.java} | 33 ++++------- .../imc/call/oob/opcodes/ReturnDataCopy.java | 22 +------- .../fragment/imc/call/oob/opcodes/SStore.java | 14 +---- .../oob/precompiles/Blake2FPrecompile1.java | 18 ++---- .../oob/precompiles/Blake2FPrecompile2.java | 23 ++------ .../imc/call/oob/precompiles/EcAdd.java | 21 ++----- .../imc/call/oob/precompiles/EcMul.java | 21 ++----- .../imc/call/oob/precompiles/EcPairing.java | 21 ++----- .../imc/call/oob/precompiles/EcRecover.java | 21 ++----- .../imc/call/oob/precompiles/Identity.java | 21 ++----- .../imc/call/oob/precompiles/ModexpCds.java | 19 ++----- .../call/oob/precompiles/ModexpExtract.java | 23 ++------ .../imc/call/oob/precompiles/ModexpLead.java | 24 ++------ .../call/oob/precompiles/ModexpPricing.java | 22 ++------ .../imc/call/oob/precompiles/ModexpXbs.java | 22 ++------ .../imc/call/oob/precompiles/RipeMd160.java | 21 ++----- .../imc/call/oob/precompiles/Sha2.java | 21 ++----- .../oob/precompiles/SimplePrecompileCall.java | 31 ++-------- .../precompiles/PrecompileLinesGenerator.java | 29 +++------- .../module/hub/section/CreateSection.java | 10 +--- .../zktracer/module/hub/section/StackRam.java | 2 +- .../linea/zktracer/module/oob/Oob.java | 7 ++- 30 files changed, 135 insertions(+), 555 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/OobDataChannel.java => hub/fragment/imc/call/oob/opcodes/Jumpi.java} (52%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 7a27e03a52..bc389c0a3e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -36,15 +36,14 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentReturn; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ExceptionalCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.Jump; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.Jumpi; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SStore; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -122,14 +121,9 @@ public static ImcFragment forCall( switch (hub.opCode()) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { if (hub.opCode().equals(OpCode.CALL) && hub.pch().exceptions().any()) { - r.callOob(new ExceptionalCall(EWord.of(hub.messageFrame().getStackItem(2)))); + r.callOob(new ExceptionalCall()); } else { - r.callOob( - new Call( - EWord.of(hub.messageFrame().getStackItem(2)), - EWord.of(callerAccount.getBalance()), - hub.callStack().depth(), - hub.pch().abortingConditions().any())); + r.callOob(new Call()); } } default -> throw new IllegalArgumentException("unexpected opcode for IMC/CALL"); @@ -208,34 +202,19 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { if (hub.pch().signals().oob()) { switch (hub.opCode()) { - case JUMP, JUMPI -> r.callOob(new Jump(hub, frame)); - case CALLDATALOAD -> r.callOob(CallDataLoad.build(hub, frame)); - case SSTORE -> r.callOob(new SStore(frame.getRemainingGas())); + case JUMP -> r.callOob(new Jump()); + case JUMPI -> r.callOob(new Jumpi()); + case CALLDATALOAD -> r.callOob(new CallDataLoad()); + case SSTORE -> r.callOob(new SStore()); case CALL, CALLCODE -> { - r.callOob( - new Call( - EWord.of(frame.getStackItem(2)), - EWord.of( - Optional.ofNullable(frame.getWorldUpdater().get(frame.getRecipientAddress())) - .map(AccountState::getBalance) - .orElse(Wei.ZERO)), - hub.callStack().depth(), - hub.pch().abortingConditions().any())); + r.callOob(new Call()); } case DELEGATECALL, STATICCALL -> { - r.callOob( - new Call( - EWord.ZERO, - EWord.of( - Optional.ofNullable(frame.getWorldUpdater().get(frame.getRecipientAddress())) - .map(AccountState::getBalance) - .orElse(Wei.ZERO)), - hub.callStack().depth(), - hub.pch().abortingConditions().any())); + r.callOob(new Call()); } case RETURN -> { if (hub.currentFrame().isDeployment()) { - r.callOob(new DeploymentReturn(EWord.of(frame.getStackItem(1)))); + r.callOob(new DeploymentReturn()); } } default -> throw new IllegalArgumentException( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java index 8ed218377a..eeaa8403b4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java @@ -15,37 +15,41 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob; +import lombok.Setter; +import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; import org.apache.tuweni.bytes.Bytes; /** This interface defines the API required to execute a call to the OOB module. */ -public interface OobCall extends TraceSubFragment { - /** - * Given a data channel number, returns the data that should be sent to the OOB through this - * channel. - * - * @param i the channel number - * @return the data to send to the OOB through the channel DATA_i - */ - Bytes data(OobDataChannel i); +@Accessors(fluent = true) +@Setter +public abstract class OobCall implements TraceSubFragment { + // TODO: check if we need 0 instead of EMPTY + Bytes data1 = Bytes.EMPTY; + Bytes data2 = Bytes.EMPTY; + Bytes data3 = Bytes.EMPTY; + Bytes data4 = Bytes.EMPTY; + Bytes data5 = Bytes.EMPTY; + Bytes data6 = Bytes.EMPTY; + Bytes data7 = Bytes.EMPTY; + Bytes data8 = Bytes.EMPTY; /** The instruction to trigger in the OOB for this call. */ - int oobInstruction(); + public abstract int oobInstruction(); @Override - default Trace trace(Trace trace) { + public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobData1(this.data(OobDataChannel.of(0))) - .pMiscOobData2(this.data(OobDataChannel.of(1))) - .pMiscOobData3(this.data(OobDataChannel.of(2))) - .pMiscOobData4(this.data(OobDataChannel.of(3))) - .pMiscOobData5(this.data(OobDataChannel.of(4))) - .pMiscOobData6(this.data(OobDataChannel.of(5))) - .pMiscOobData7(this.data(OobDataChannel.of(6))) - .pMiscOobData8(this.data(OobDataChannel.of(7))) + .pMiscOobData1(data1) + .pMiscOobData2(data2) + .pMiscOobData3(data3) + .pMiscOobData4(data4) + .pMiscOobData5(data5) + .pMiscOobData6(data6) + .pMiscOobData7(data7) + .pMiscOobData8(data8) .pMiscOobInst(this.oobInstruction()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java index 6bf78809b0..728fb9194f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java @@ -16,27 +16,12 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CALL; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; -public record Call(EWord value, EWord balance, int callStackDepth, boolean hasAbort) - implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> value.hi(); - case DATA_2 -> value.lo(); - case DATA_3 -> balance.lo(); - case DATA_6 -> Bytes.ofUnsignedLong(callStackDepth); - case DATA_7 -> booleanToBytes(!value.isZero()); - case DATA_8 -> booleanToBytes(hasAbort); - default -> Bytes.EMPTY; - }; - } +// TODO: rename all these classes to XxxOobCall and follow the classes that have been create in oob +// for OobParameters +public class Call extends OobCall { @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java index ab667ad2de..4235d85bfb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java @@ -16,31 +16,10 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CDL; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; -public record CallDataLoad(EWord readOffset, EWord callDataSize) implements OobCall { - public static CallDataLoad build(Hub hub, MessageFrame frame) { - return new CallDataLoad( - EWord.of(frame.getStackItem(0)), EWord.of(hub.currentFrame().callDataInfo().data().size())); - } - - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> this.readOffset.hi(); - case DATA_2 -> this.readOffset.lo(); - case DATA_5 -> this.callDataSize; - case DATA_7 -> booleanToBytes(this.readOffset.greaterOrEqualThan(this.callDataSize)); - default -> Bytes.EMPTY; - }; - } +public class CallDataLoad extends OobCall { @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java index 976febda7a..0a1f0bef3e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java @@ -16,35 +16,10 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; -public record Create( - boolean hasAbort, - boolean hasFailure, - EWord value, - EWord creatorBalance, - long createdNonce, - boolean createdHasCode, - int callStackDepth) - implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> value.hi(); - case DATA_2 -> value.lo(); - case DATA_3 -> creatorBalance.lo(); - case DATA_4 -> Bytes.ofUnsignedLong(createdNonce); - case DATA_5 -> booleanToBytes(createdHasCode); - case DATA_6 -> Bytes.ofUnsignedLong(callStackDepth); - case DATA_7 -> booleanToBytes(hasAbort); - case DATA_8 -> booleanToBytes(hasFailure); - }; - } +public class Create extends OobCall { @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java index dad8cedc2c..af35eebca2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java @@ -16,24 +16,10 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_DEPLOYMENT; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; -public record DeploymentReturn(EWord size) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> size.hi(); - case DATA_2 -> size.lo(); - case DATA_7 -> booleanToBytes(size.greaterThan(EWord.of(Exceptions.MAX_CODE_SIZE))); - default -> Bytes.EMPTY; - }; - } +public class DeploymentReturn extends OobCall { @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java index 55557edf0e..57990e9425 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java @@ -16,24 +16,10 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_XCALL; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; -public record ExceptionalCall(EWord value) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> value.hi(); - case DATA_2 -> value.lo(); - case DATA_7 -> booleanToBytes(value.isZero()); - case DATA_8 -> booleanToBytes(!value.isZero()); - default -> Bytes.EMPTY; - }; - } +public class ExceptionalCall extends OobCall { @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java index 1a9860c26d..aaf791a264 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java @@ -16,65 +16,13 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMP; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMPI; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; -public final class Jump implements OobCall { - private final EWord targetPc; - private final EWord jumpCondition; - private final int codeSize; - private final int oobInst; - private final boolean event1; - private final boolean event2; - - public Jump(Hub hub, MessageFrame frame) { - long targetPc = Words.clampedToLong(frame.getStackItem(0)); - final boolean invalidDestination = frame.getCode().isJumpDestInvalid((int) targetPc); - - long jumpCondition = 0; - switch (hub.currentFrame().opCode()) { - case JUMP -> { - this.oobInst = OOB_INST_JUMP; - this.event1 = invalidDestination; - } - case JUMPI -> { - this.oobInst = OOB_INST_JUMPI; - jumpCondition = Words.clampedToLong(frame.getStackItem(1)); - this.event1 = (jumpCondition != 0) && invalidDestination; - } - default -> throw new IllegalArgumentException("Unexpected opcode"); - } - - this.targetPc = EWord.of(targetPc); - this.jumpCondition = EWord.of(jumpCondition); - this.codeSize = - frame.getWorldUpdater().get(hub.currentFrame().byteCodeAddress()).getCode().size(); - this.event2 = jumpCondition > 0; - } +public class Jump extends OobCall { @Override public int oobInstruction() { - return this.oobInst; - } - - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> this.targetPc.hi(); - case DATA_2 -> this.targetPc.lo(); - case DATA_3 -> this.jumpCondition.hi(); - case DATA_4 -> this.jumpCondition.lo(); - case DATA_5 -> Bytes.ofUnsignedInt(this.codeSize); - case DATA_7 -> this.event1 ? Bytes.of(1) : Bytes.EMPTY; - case DATA_8 -> this.event2 ? Bytes.of(1) : Bytes.EMPTY; - default -> Bytes.EMPTY; - }; + return OOB_INST_JUMP; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobDataChannel.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jumpi.java similarity index 52% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobDataChannel.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jumpi.java index 41146c7c33..67c4a10c02 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobDataChannel.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jumpi.java @@ -1,5 +1,5 @@ /* - * Copyright ConsenSys AG. + * Copyright Consensys Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -13,29 +13,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; -public enum OobDataChannel { - DATA_1, - DATA_2, - DATA_3, - DATA_4, - DATA_5, - DATA_6, - DATA_7, - DATA_8; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMPI; - public static OobDataChannel of(int i) { - return switch (i) { - case 0 -> DATA_1; - case 1 -> DATA_2; - case 2 -> DATA_3; - case 3 -> DATA_4; - case 4 -> DATA_5; - case 5 -> DATA_6; - case 6 -> DATA_7; - case 7 -> DATA_8; - default -> throw new IllegalArgumentException("unknown OOB data channel: %d".formatted(i)); - }; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; + +public class Jumpi extends OobCall { + + @Override + public int oobInstruction() { + return OOB_INST_JUMPI; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java index e1be80b5e4..a6a5f9de01 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java @@ -16,30 +16,10 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RDC; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; -public record ReturnDataCopy(EWord offset, EWord size, long returnDataSize) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> offset.hi(); - case DATA_2 -> offset.lo(); - case DATA_3 -> size.hi(); - case DATA_4 -> size.lo(); - case DATA_5 -> Bytes.ofUnsignedLong(returnDataSize); - case DATA_7 -> booleanToBytes( - !(offset.hi().isZero() - && size.hi().isZero() - && offset.add(size).lessOrEqualThan(EWord.of(returnDataSize))) - || size.isZero() && offset.greaterOrEqualThan(EWord.of(returnDataSize))); - default -> Bytes.EMPTY; - }; - } +public class ReturnDataCopy extends OobCall { @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java index 5e47d70f62..ee8276e3d6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java @@ -15,23 +15,11 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.GAS_CONST_G_CALL_STIPEND; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SSTORE; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record SStore(long gas) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_5 -> Bytes.ofUnsignedLong(gas); - case DATA_7 -> booleanToBytes(gas <= GAS_CONST_G_CALL_STIPEND); - default -> Bytes.EMPTY; - }; - } +public class SStore extends OobCall { @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java index d7b55efc7c..fe1de4c6f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java @@ -16,24 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record Blake2FPrecompile1(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - default -> Bytes.EMPTY; - }; - } +@RequiredArgsConstructor +public class Blake2FPrecompile1 extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java index e3d51ee61d..038228efcd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java @@ -16,29 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record Blake2FPrecompile2(PrecompileInvocation p) implements OobCall { - - @Override - public Bytes data(OobDataChannel i) { - final Blake2fMetadata metadata = (Blake2fMetadata) p.metadata(); - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAtCall()); - case DATA_4 -> booleanToBytes(p.ramSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.ramSuccess() ? p.precompilePrice() - p.gasAtCall() : 0); - case DATA_6 -> Bytes.ofUnsignedLong(metadata.r()); - case DATA_7 -> Bytes.ofUnsignedLong(metadata.f()); - - default -> Bytes.EMPTY; - }; - } +@RequiredArgsConstructor +public class Blake2FPrecompile2 extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java index 030754d511..a1f75e97b0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECADD; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record EcAdd(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAllowance()); - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.returnGas()); - case DATA_6 -> booleanToBytes(p.hubSuccess() && !p.callDataSource().isEmpty()); - case DATA_7 -> booleanToBytes(p.hubSuccess() && p.callDataSource().isEmpty()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - }; - } +@RequiredArgsConstructor +public class EcAdd extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java index 82f143ec4e..d9e74db858 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECMUL; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record EcMul(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAllowance()); - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.returnGas()); - case DATA_6 -> booleanToBytes(p.hubSuccess() && !p.callDataSource().isEmpty()); - case DATA_7 -> booleanToBytes(p.hubSuccess() && p.callDataSource().isEmpty()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - }; - } +@RequiredArgsConstructor +public class EcMul extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java index 77ef6aea27..7f1737928b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECPAIRING; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record EcPairing(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAllowance()); - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.returnGas()); - case DATA_6 -> booleanToBytes(p.hubSuccess() && !p.callDataSource().isEmpty()); - case DATA_7 -> booleanToBytes(p.hubSuccess() && p.callDataSource().isEmpty()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - }; - } +@RequiredArgsConstructor +public class EcPairing extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java index 5cbd708381..bc62fc02b1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECRECOVER; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record EcRecover(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAllowance()); - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.returnGas()); - case DATA_6 -> booleanToBytes(p.hubSuccess() && !p.callDataSource().isEmpty()); - case DATA_7 -> booleanToBytes(p.hubSuccess() && p.callDataSource().isEmpty()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - }; - } +@RequiredArgsConstructor +public class EcRecover extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java index 945b13361a..570787dac3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record Identity(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAllowance()); - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.returnGas()); - case DATA_6 -> booleanToBytes(p.hubSuccess() && !p.callDataSource().isEmpty()); - case DATA_7 -> booleanToBytes(p.hubSuccess() && p.callDataSource().isEmpty()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - }; - } +@RequiredArgsConstructor +public class Identity extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java index e7eed679cb..1b01f69478 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java @@ -16,23 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -public record ModexpCds(long callDataSize) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_2 -> Bytes.ofUnsignedLong(callDataSize); - case DATA_3 -> booleanToBytes(callDataSize > 0); - case DATA_4 -> booleanToBytes(callDataSize > 32); - case DATA_5 -> booleanToBytes(callDataSize > 64); - default -> Bytes.EMPTY; - }; - } +@RequiredArgsConstructor +public class ModexpCds extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java index f9cd20ae72..b25fc73f15 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -public record ModexpExtract(long callDataSize, int bbsLo, int ebsLo, int mbsLo) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - final boolean modulusExtraction = callDataSize > 96 + bbsLo + ebsLo && mbsLo > 0; - return switch (i) { - case DATA_2 -> Bytes.ofUnsignedLong(callDataSize); - case DATA_3 -> Bytes.ofUnsignedLong(bbsLo); - case DATA_4 -> Bytes.ofUnsignedLong(ebsLo); - case DATA_5 -> Bytes.ofUnsignedLong(mbsLo); - case DATA_6 -> booleanToBytes(modulusExtraction && bbsLo > 0); - case DATA_7 -> booleanToBytes(modulusExtraction && ebsLo > 0); - case DATA_8 -> booleanToBytes(modulusExtraction); - default -> Bytes.EMPTY; - }; - } +@RequiredArgsConstructor +public class ModexpExtract extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java index d092e0779a..e5b01b70de 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java @@ -16,28 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -public record ModexpLead(int bbsLo, long callDataSize, int ebsLo) implements OobCall { - - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(bbsLo); - case DATA_2 -> Bytes.ofUnsignedLong(callDataSize); - case DATA_3 -> Bytes.ofUnsignedLong(ebsLo); - case DATA_4 -> booleanToBytes(callDataSize > 96 + bbsLo && ebsLo > 0); - case DATA_6 -> Bytes.ofUnsignedInt( - callDataSize > 96 + bbsLo ? Math.min(callDataSize - 96 - bbsLo, 32) : 0); - case DATA_7 -> Bytes.ofUnsignedLong(Math.min(ebsLo, 32)); - case DATA_8 -> Bytes.ofUnsignedLong(ebsLo < 32 ? 0 : ebsLo - 32); - default -> Bytes.EMPTY; - }; - } +@RequiredArgsConstructor +public class ModexpLead extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java index 178ad4964d..55e3a42b6c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java @@ -16,28 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record ModexpPricing(PrecompileInvocation p, int exponentLog, int maxMbsBbs) - implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAtCall()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.success()); - case DATA_5 -> Bytes.ofUnsignedLong(p.success() ? p.gasAtCall() - p.precompilePrice() : 0); - case DATA_6 -> Bytes.ofUnsignedLong(exponentLog); - case DATA_7 -> Bytes.ofUnsignedLong(maxMbsBbs); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - default -> Bytes.EMPTY; - }; - } +@RequiredArgsConstructor +public class ModexpPricing extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java index b9d9f04ddf..d10734169f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java @@ -16,26 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.EWord; -import org.apache.tuweni.bytes.Bytes; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -public record ModexpXbs(EWord xbs, EWord ybs, boolean compute) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> xbs.hi(); - case DATA_2 -> xbs.lo(); - case DATA_3 -> ybs.lo(); - case DATA_4 -> booleanToBytes(compute); - case DATA_7 -> compute ? (xbs.greaterOrEqualThan(ybs) ? xbs : ybs) : Bytes.EMPTY; - case DATA_8 -> compute ? booleanToBytes(!xbs.isZero()) : Bytes.EMPTY; - default -> Bytes.EMPTY; - }; - } +@RequiredArgsConstructor +public class ModexpXbs extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java index 30061bcf55..1f2fc6edd0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record RipeMd160(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAllowance()); - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.returnGas()); - case DATA_6 -> booleanToBytes(p.hubSuccess() && !p.callDataSource().isEmpty()); - case DATA_7 -> booleanToBytes(p.hubSuccess() && p.callDataSource().isEmpty()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - }; - } +@RequiredArgsConstructor +public class RipeMd160 extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java index feb1b33c1a..f4d7eafaae 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java @@ -16,27 +16,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import org.apache.tuweni.bytes.Bytes; -public record Sha2(PrecompileInvocation p) implements OobCall { - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(p.gasAllowance()); - case DATA_2 -> Bytes.ofUnsignedLong(p.callDataSource().length()); - case DATA_3 -> Bytes.ofUnsignedLong(p.requestedReturnDataTarget().length()); - case DATA_4 -> booleanToBytes(p.hubSuccess()); - case DATA_5 -> Bytes.ofUnsignedLong(p.returnGas()); - case DATA_6 -> booleanToBytes(p.hubSuccess() && !p.callDataSource().isEmpty()); - case DATA_7 -> booleanToBytes(p.hubSuccess() && p.callDataSource().isEmpty()); - case DATA_8 -> booleanToBytes(!p.requestedReturnDataTarget().isEmpty()); - }; - } +@RequiredArgsConstructor +public class Sha2 extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java index 6c345f0236..0ae2677690 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java @@ -22,39 +22,18 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.OobDataChannel; -import net.consensys.linea.zktracer.types.Precompile; -import org.apache.tuweni.bytes.Bytes; -public record SimplePrecompileCall( - PrecompileInvocation scenario, long callGas, long callDataSize, long returnDataRequestedSize) - implements OobCall { - - @Override - public Bytes data(OobDataChannel i) { - return switch (i) { - case DATA_1 -> Bytes.ofUnsignedLong(callGas); - case DATA_2 -> Bytes.ofUnsignedLong(callDataSize); - case DATA_3 -> Bytes.ofUnsignedLong(returnDataRequestedSize); - case DATA_4 -> scenario.hubFailure() ? Bytes.EMPTY : Bytes.of(1); - case DATA_5 -> scenario.hubSuccess() - ? Bytes.ofUnsignedLong(callGas - scenario.precompilePrice()) - : Bytes.EMPTY; - case DATA_6 -> scenario.precompile().equals(Precompile.EC_PAIRING) - ? booleanToBytes(scenario.hubSuccess() && callDataSize > 0 && callDataSize % 192 == 0) - : booleanToBytes(scenario.hubSuccess() && callDataSize > 0); - case DATA_7 -> booleanToBytes(scenario.hubSuccess() && callDataSize == 0); - case DATA_8 -> booleanToBytes(returnDataRequestedSize > 0); - }; - } +@RequiredArgsConstructor +public class SimplePrecompileCall extends OobCall { + final PrecompileInvocation p; @Override public int oobInstruction() { - return switch (scenario.precompile()) { + return switch (p.precompile()) { case EC_RECOVER -> OOB_INST_ECRECOVER; case SHA2_256 -> OOB_INST_SHA2; case RIPEMD_160 -> OOB_INST_RIPEMD; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index 3cb52bfe4a..bf5bc32fb2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -19,7 +19,6 @@ import java.util.List; import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.exp.ModexpLogOperation; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; @@ -40,7 +39,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbs; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.RipeMd160; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Sha2; -import net.consensys.linea.zktracer.types.EWord; @RequiredArgsConstructor public class PrecompileLinesGenerator { @@ -136,23 +134,22 @@ public static List generateFor(final Hub hub, final PrecompileInv final int ebsInt = m.ebs().toUnsignedBigInteger().intValueExact(); final int mbsInt = m.mbs().toUnsignedBigInteger().intValueExact(); - r.add( - ImcFragment.empty(hub).callOob(new ModexpCds(p.requestedReturnDataTarget().length()))); + r.add(ImcFragment.empty(hub).callOob(new ModexpCds(p))); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbs(m.bbs(), EWord.ZERO, false)) + .callOob(new ModexpXbs(p)) .callMmu(m.extractBbs() ? MmuCall.forModExp(hub, p, 2) : MmuCall.nop())); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbs(m.ebs(), EWord.ZERO, false)) + .callOob(new ModexpXbs(p)) .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 3) : MmuCall.nop())); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbs(m.mbs(), m.bbs(), true)) + .callOob(new ModexpXbs(p)) .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 4) : MmuCall.nop())); final ImcFragment line5 = ImcFragment.empty(hub) - .callOob(new ModexpLead(bbsInt, p.callDataSource().length(), ebsInt)) + .callOob(new ModexpLead(p)) .callMmu(m.loadRawLeadingWord() ? MmuCall.forModExp(hub, p, 5) : MmuCall.nop()); if (m.loadRawLeadingWord()) { line5.callExp( @@ -162,26 +159,14 @@ public static List generateFor(final Hub hub, final PrecompileInv Math.min(ebsInt, 32))); } r.add(line5); - r.add( - ImcFragment.empty(hub) - .callOob( - new ModexpPricing( - p, - m.loadRawLeadingWord() - ? ModexpLogOperation.LeadLogTrimLead.fromArgs( - m.rawLeadingWord(), - Math.min((int) (p.callDataSource().length() - 96 - bbsInt), 32), - Math.min(ebsInt, 32)) - .leadLog() - : 0, - Math.max(mbsInt, bbsInt)))); + r.add(ImcFragment.empty(hub).callOob(new ModexpPricing(p))); if (p.ramFailure()) { r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) - .callOob(new ModexpExtract(p.callDataSource().length(), bbsInt, ebsInt, mbsInt)) + .callOob(new ModexpExtract(p)) .callMmu(m.extractModulus() ? MmuCall.forModExp(hub, p, 7) : MmuCall.nop())); if (m.extractModulus()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index e7d601e675..72e1e35f01 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -156,15 +156,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces final ImcFragment commonImcFragment = ImcFragment.empty(hub) - .callOob( - new Create( - hub.pch().abortingConditions().any(), - hub.pch().failureConditions().any(), - EWord.of(hub.messageFrame().getStackItem(0)), - EWord.of(oldCreatedSnapshot.balance()), - oldCreatedSnapshot.nonce(), - !oldCreatedSnapshot.code().isEmpty(), - hub.callStack().depth())) + .callOob(new Create()) .callMxp(MxpCall.build(hub)) .callStp( new StpCall( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java index 9dc2959604..b436ec2819 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java @@ -35,7 +35,7 @@ public static void appendToTrace(Hub hub) { imcFragment.callMxp(mxpCall); } case CALLDATALOAD -> { - OobCall oobCall = CallDataLoad.build(hub, hub.messageFrame()); + OobCall oobCall = new CallDataLoad(); imcFragment.callOob(oobCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 3b22e866c5..154763b279 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.oob; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import java.math.BigInteger; @@ -142,7 +143,11 @@ final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { } public void call(OobCall oobCall, Hub hub) { - // TODO!!! + // TODO: send the oobCall to OobOperation and fill it with the data + switch (oobCall.oobInstruction()) { + case OOB_INST_CREATE: + oobCall.data1(bigIntegerToBytes(BigInteger.ONE)).data2(bigIntegerToBytes(BigInteger.ONE)); + } } @Override From 4e126c54d62f9f5973456e78ba5f281aed2aadff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 17:04:32 +0200 Subject: [PATCH 112/461] opcodes.yml many fixes How did things run ok with wrong data ? In particular how did CREAT function when it didn't bill the word ... ? --- .../src/main/resources/opcodes.yml | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml index 68b659078c..775a222c63 100644 --- a/arithmetization/src/main/resources/opcodes.yml +++ b/arithmetization/src/main/resources/opcodes.yml @@ -90,7 +90,7 @@ opcodes: delta: 3 nbAdded: 1 nbRemoved: 3 - staticGas: G_LOW + staticGas: G_MID - mnemonic: MULMOD value: 0x9 instructionFamily: EXT @@ -100,7 +100,7 @@ opcodes: delta: 3 nbAdded: 1 nbRemoved: 3 - staticGas: G_LOW + staticGas: G_MID - mnemonic: EXP value: 0xa instructionFamily: MUL @@ -121,7 +121,7 @@ opcodes: delta: 2 nbAdded: 1 nbRemoved: 2 - staticGas: G_VERY_LOW + staticGas: G_LOW # assigned LEQ opcode for WCP module with value 0x0E. Change this value if Linéa/EVM uses this opcode. # assigned GEQ opcode for WCP module with value 0x0F. Change this value if Linéa/EVM uses this opcode. - mnemonic: LT @@ -365,7 +365,7 @@ opcodes: delta: 3 nbAdded: 0 nbRemoved: 3 - staticGas: S_MXP + staticGas: G_VERY_LOW flag1: true billing: byWord: @@ -391,7 +391,7 @@ opcodes: delta: 3 nbAdded: 0 nbRemoved: 3 - staticGas: S_MXP + staticGas: G_VERY_LOW flag3: true billing: byWord: @@ -428,7 +428,7 @@ opcodes: delta: 4 nbAdded: 0 nbRemoved: 4 - staticGas: S_MXP + staticGas: G_VERY_LOW flag4: true billing: byWord: @@ -453,7 +453,7 @@ opcodes: delta: 3 nbAdded: 0 nbRemoved: 3 - staticGas: S_MXP + staticGas: G_VERY_LOW flag2: true billing: byWord: @@ -490,7 +490,7 @@ opcodes: delta: 0 nbAdded: 1 nbRemoved: 0 - staticGas: G_BLOCK_HASH + staticGas: G_BASE - mnemonic: TIMESTAMP value: 0x42 instructionFamily: BATCH @@ -500,7 +500,7 @@ opcodes: delta: 0 nbAdded: 1 nbRemoved: 0 - staticGas: G_BLOCK_HASH + staticGas: G_BASE - mnemonic: NUMBER value: 0x43 instructionFamily: BATCH @@ -510,7 +510,7 @@ opcodes: delta: 0 nbAdded: 1 nbRemoved: 0 - staticGas: G_BLOCK_HASH + staticGas: G_BASE - mnemonic: DIFFICULTY value: 0x44 instructionFamily: BATCH @@ -520,7 +520,7 @@ opcodes: delta: 0 nbAdded: 1 nbRemoved: 0 - staticGas: G_BLOCK_HASH + staticGas: G_BASE - mnemonic: GASLIMIT value: 0x45 instructionFamily: BATCH @@ -530,7 +530,7 @@ opcodes: delta: 0 nbAdded: 1 nbRemoved: 0 - staticGas: G_BLOCK_HASH + staticGas: G_BASE - mnemonic: CHAINID value: 0x46 instructionFamily: BATCH @@ -540,7 +540,7 @@ opcodes: delta: 0 nbAdded: 1 nbRemoved: 0 - staticGas: G_BLOCK_HASH + staticGas: G_BASE - mnemonic: SELFBALANCE value: 0x47 instructionFamily: ACCOUNT @@ -560,7 +560,7 @@ opcodes: delta: 0 nbAdded: 1 nbRemoved: 0 - staticGas: G_BLOCK_HASH + staticGas: G_BASE - mnemonic: POP value: 0x50 instructionFamily: PUSH_POP @@ -655,7 +655,7 @@ opcodes: delta: 2 nbAdded: 0 nbRemoved: 2 - staticGas: G_MID + staticGas: G_HIGH flag2: true - mnemonic: PC value: 0x58 @@ -1509,6 +1509,7 @@ opcodes: billing: byMxp: type: TYPE_4 + wordPrice: G_KECCAK_256_WORD - mnemonic: CALL value: 0xf1 instructionFamily: CALL @@ -1611,7 +1612,7 @@ opcodes: delta: 2 nbAdded: 0 nbRemoved: 2 - staticGas: S_MXP + staticGas: G_ZERO flag2: true billing: byMxp: From e5b3ccbf2baaa64798dde42ff2a8312b540cc181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 17:05:52 +0200 Subject: [PATCH 113/461] JUMP/JUMPI work in progress - JumpSection (wip) - (stack) jumpDestinationVettingRequired --- .../module/hub/fragment/StackFragment.java | 3 +- .../module/hub/fragment/imc/call/MxpCall.java | 131 ------------------ .../module/hub/section/JumpSection.java | 91 ++++++++++++ .../module/hub/section/TraceSection.java | 14 ++ 4 files changed, 107 insertions(+), 132 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 49811cf2fc..7b85663513 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -55,7 +55,8 @@ public final class StackFragment implements TraceFragment { @Setter public boolean hashInfoFlag; @Setter public Bytes hash; @Getter private final OpCode opCode; - private final boolean jumpDestinationVettingRequired; + @Setter private boolean jumpDestinationVettingRequired; + @Setter private boolean validJumpDestination; private final boolean willRevert; private StackFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index e39aee30d9..1f4e45fb4a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -46,137 +46,6 @@ public static MxpCall build(Hub hub) { return new MxpCall(hub); } - // public MxpCall mxpCallType1(Hub hub) { - // Preconditions.checkArgument(hub.opCode().equals(OpCode.MSIZE)); - // return new MxpCall( - // hub, - // OpCode.MSIZE, - // false, - // EWord.ZERO, - // EWord.ZERO, - // EWord.ZERO, - // EWord.ZERO, - // false, - // hub.messageFrame().memoryWordSize()); - // } - // - // public MxpCall mxpCallType2(Hub hub) { - // - // EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); - // - // return new MxpCall( - // hub, - // getOpcode(hub), - // false, - // offset, - // EWord.ZERO, - // EWord.ZERO, - // EWord.ZERO, - // getMemoryExpansionException(hub), - // hub.messageFrame().memoryWordSize()); // TODO - // } - // - // public MxpCall mxpCallType3(Hub hub) { - // - // EWord offset = EWord.of(hub.messageFrame().getStackItem(0)); - // - // return new MxpCall( - // hub, - // OpCode.MSTORE8, - // false, - // offset, - // EWord.ZERO, - // EWord.ZERO, - // EWord.ZERO, - // getMemoryExpansionException(hub), - // hub.messageFrame().memoryWordSize()); // TODO - // } - // - // public static MxpCall mxpCallType4(Hub hub) { - // - // final OpCode opCode = getOpcode(hub); - // int offsetIndex; - // int sizeIndex; - // - // switch (opCode) { - // case SHA3, LOG0, LOG1, LOG2, LOG3, LOG4, RETURN, REVERT -> { - // offsetIndex = 0; - // sizeIndex = 1; - // } - // case CALLDATACOPY, CODECOPY, RETURNDATACOPY -> { - // offsetIndex = 0; - // sizeIndex = 2; - // } - // case EXTCODECOPY -> { - // offsetIndex = 1; - // sizeIndex = 3; - // } - // case CREATE, CREATE2 -> { - // offsetIndex = 1; - // sizeIndex = 2; - // } - // default -> { - // throw new RuntimeException("MXP Type 4 incompatible opcode"); - // } - // } - // - // EWord offset = EWord.of(hub.messageFrame().getStackItem(offsetIndex)); - // EWord size = EWord.of(hub.messageFrame().getStackItem(sizeIndex)); - // - // return new MxpCall( - // hub, - // opCode, - // getDeploys(hub), - // offset, - // size, - // EWord.ZERO, - // EWord.ZERO, - // getMemoryExpansionException(hub), - // hub.messageFrame().memoryWordSize()); // TODO - // } - // - // public MxpCall mxpCallType5(Hub hub) { - // - // final OpCode opCode = getOpcode(hub); - // int extra; - // - // switch (opCode) { - // case CALL, CALLCODE -> { - // extra = 1; - // } - // case DELEGATECALL, STATICCALL -> { - // extra = 0; - // } - // default -> { - // throw new RuntimeException("MXP Type 5 incompatible opcode"); - // } - // } - // - // EWord callDataOffset = EWord.of(hub.messageFrame().getStackItem(2 + extra)); - // EWord callDataSize = EWord.of(hub.messageFrame().getStackItem(3 + extra)); - // EWord returnAtOffset = EWord.of(hub.messageFrame().getStackItem(4 + extra)); - // EWord returnAtCapacity = EWord.of(hub.messageFrame().getStackItem(5 + extra)); - // - // return new MxpCall( - // hub, - // getOpcode(hub), - // false, - // callDataOffset, - // callDataSize, - // returnAtOffset, - // returnAtCapacity, - // getMemoryExpansionException(hub), - // hub.messageFrame().memoryWordSize()); // TODO - // } - - // static OpCode getOpcode(Hub hub) { - // return hub.opCode(); - // } - - // static boolean getDeploys(Hub hub) { - // return getOpcode(hub) == OpCode.RETURN && hub.currentFrame().isDeployment(); - // } - static boolean getMemoryExpansionException(Hub hub) { return hub.pch().exceptions().memoryExpansionException(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index fc4c2a6d63..80667b67e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -15,10 +15,101 @@ package net.consensys.linea.zktracer.module.hub.section; +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; +import net.consensys.linea.zktracer.opcode.OpCode; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.worldstate.WorldView; + +import static net.consensys.linea.zktracer.module.hub.AccountSnapshot.fromAddress; public class JumpSection extends TraceSection { + + public static void appendToTrace(Hub hub, WorldView worldView) { + final JumpSection currentSection = new JumpSection(); + currentSection.addFragmentsAndStack(hub); + + if (hub.pch().exceptions().outOfGasException()) { + return; + } + + hub.addTraceSection(currentSection); + + // CONTEXT fragment + /////////////////// + ContextFragment contextRowCurrentContext = ContextFragment.readCurrentContextData(hub); + + // ACCOUNT fragment + /////////////////// + Address codeAddress = hub.messageFrame().getContractAddress(); + AccountFragment.AccountFragmentFactory accountFragmentFactory = new AccountFragment.AccountFragmentFactory(hub.defers()); + + DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); + final int deploymentNumber = deploymentInfo.number(codeAddress); + final boolean deploymentStatus = deploymentInfo.isDeploying(codeAddress); + + final boolean warmth = hub.messageFrame().isAddressWarm(codeAddress); + Preconditions.checkArgument(warmth); + + AccountSnapshot codeAccount = fromAddress( + codeAddress, + warmth, + deploymentNumber, + deploymentStatus + ); + + AccountFragment accountRowCodeAccount = accountFragmentFactory.make(codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + + + // MISCELLANEOUS fragment + ///////////////////////// + ImcFragment miscRow = ImcFragment.empty(hub); + OobCall oobCall; + boolean mustAttemptJump = false; + switch (hub.opCode()) { + case OpCode.JUMP -> { + JumpOobCall jumpOobCall = new JumpOobCall(hub); + miscRow.callOob(jumpOobCall); + mustAttemptJump = jumpOobCall.getJumpMustBeAttempted(); + oobCall = jumpOobCall; + } + case OpCode.JUMPI -> { + JumpiOobCall jumpiOobCall = new JumpiOobCall(hub); + miscRow.callOob(jumpiOobCall); + mustAttemptJump = jumpiOobCall.getJumpMustBeAttempted(); + oobCall = jumpiOobCall; + } + default -> throw new RuntimeException(hub.opCode().name() + " not part of the JUMP instruction family"); + } + + miscRow.callOob(oobCall); + + + // CONTEXT, ACCOUNT, MISCELLANEOUS + ////////////////////////////////// + currentSection.addFragmentsWithoutStack(hub, + contextRowCurrentContext, + accountRowCodeAccount, + miscRow + ); + + // jump destination vetting + /////////////////////////// + if (mustAttemptJump) { + currentSection.triggerJumpDestinationVetting(hub); + } + } + + private JumpSection() {} + public JumpSection(Hub hub, TraceFragment... chunks) { this.addFragmentsAndStack(hub, chunks); } 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 5ebf025b6c..e2cfaca676 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 @@ -257,4 +257,18 @@ public void triggerHashInfo(Bytes hash) { } } } + + public void triggerJumpDestinationVetting(Hub hub) { + + int pcNew = hub.messageFrame().getStackItem(0).toInt(); + + boolean invalidJumpDestination = hub.messageFrame().getCode().isJumpDestInvalid(pcNew); + + for (TraceSection.TraceLine line : this.lines()) { + if (line.specific() instanceof StackFragment) { + ((StackFragment) line.specific()).jumpDestinationVettingRequired(true); + ((StackFragment) line.specific()).validJumpDestination(invalidJumpDestination); + } + } + } } From f5d5b0ba5a1a5aadfe5f1a35d414d90d81a1a83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 17:10:13 +0200 Subject: [PATCH 114/461] spotless --- .../module/hub/section/JumpSection.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index 80667b67e4..702f5130e5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.module.hub.AccountSnapshot.fromAddress; + import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -29,8 +31,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.worldstate.WorldView; -import static net.consensys.linea.zktracer.module.hub.AccountSnapshot.fromAddress; - public class JumpSection extends TraceSection { public static void appendToTrace(Hub hub, WorldView worldView) { @@ -50,7 +50,8 @@ public static void appendToTrace(Hub hub, WorldView worldView) { // ACCOUNT fragment /////////////////// Address codeAddress = hub.messageFrame().getContractAddress(); - AccountFragment.AccountFragmentFactory accountFragmentFactory = new AccountFragment.AccountFragmentFactory(hub.defers()); + AccountFragment.AccountFragmentFactory accountFragmentFactory = + new AccountFragment.AccountFragmentFactory(hub.defers()); DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); final int deploymentNumber = deploymentInfo.number(codeAddress); @@ -59,15 +60,12 @@ public static void appendToTrace(Hub hub, WorldView worldView) { final boolean warmth = hub.messageFrame().isAddressWarm(codeAddress); Preconditions.checkArgument(warmth); - AccountSnapshot codeAccount = fromAddress( - codeAddress, - warmth, - deploymentNumber, - deploymentStatus - ); - - AccountFragment accountRowCodeAccount = accountFragmentFactory.make(codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + AccountSnapshot codeAccount = + fromAddress(codeAddress, warmth, deploymentNumber, deploymentStatus); + AccountFragment accountRowCodeAccount = + accountFragmentFactory.make( + codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); // MISCELLANEOUS fragment ///////////////////////// @@ -87,19 +85,16 @@ public static void appendToTrace(Hub hub, WorldView worldView) { mustAttemptJump = jumpiOobCall.getJumpMustBeAttempted(); oobCall = jumpiOobCall; } - default -> throw new RuntimeException(hub.opCode().name() + " not part of the JUMP instruction family"); + default -> throw new RuntimeException( + hub.opCode().name() + " not part of the JUMP instruction family"); } miscRow.callOob(oobCall); - // CONTEXT, ACCOUNT, MISCELLANEOUS ////////////////////////////////// - currentSection.addFragmentsWithoutStack(hub, - contextRowCurrentContext, - accountRowCodeAccount, - miscRow - ); + currentSection.addFragmentsWithoutStack( + hub, contextRowCurrentContext, accountRowCodeAccount, miscRow); // jump destination vetting /////////////////////////// From bfa918fd9ba7fa629f98416bd888866c00616cf5 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 18 Jun 2024 17:14:15 +0200 Subject: [PATCH 115/461] feat(oob): wip OobCall update --- .../module/hub/fragment/imc/ImcFragment.java | 10 +-- .../hub/fragment/imc/call/oob/OobCall.java | 38 ++------ .../fragment/imc/call/oob/opcodes/Call.java | 30 ------- .../imc/call/oob/opcodes/CallDataLoad.java | 28 ------ .../oob/opcodes/CallDataLoadOobCall.java} | 25 ++++-- .../imc/call/oob/opcodes/CallOobCall.java} | 29 ++++-- .../fragment/imc/call/oob/opcodes/Create.java | 28 ------ .../imc/call/oob/opcodes/CreateOobCall.java} | 33 ++++--- .../call/oob/opcodes/DeploymentOobCall.java} | 23 +++-- .../call/oob/opcodes/DeploymentReturn.java | 28 ------ .../imc/call/oob/opcodes/ExceptionalCall.java | 28 ------ .../fragment/imc/call/oob/opcodes/Jump.java | 28 ------ .../imc/call/oob/opcodes/JumpOobCall.java} | 42 ++++++--- .../fragment/imc/call/oob/opcodes/Jumpi.java | 28 ------ .../call/oob/opcodes}/JumpiOobParameters.java | 2 +- .../imc/call/oob/opcodes/ReturnDataCopy.java | 28 ------ .../opcodes}/ReturnDataCopyOobParameters.java | 2 +- .../fragment/imc/call/oob/opcodes/SStore.java | 28 ------ .../oob/opcodes}/SstoreOobParameters.java | 2 +- .../call/oob/opcodes}/XCallOobParameters.java | 2 +- .../oob/precompiles/Blake2FPrecompile1.java | 32 ------- .../oob/precompiles/Blake2FPrecompile2.java | 32 ------- .../Blake2fCallDataSizeParameters.java | 2 +- .../precompiles}/Blake2fParamsParameters.java | 2 +- .../imc/call/oob/precompiles/EcAdd.java | 32 ------- .../imc/call/oob/precompiles/EcMul.java | 32 ------- .../imc/call/oob/precompiles/EcPairing.java | 32 ------- .../imc/call/oob/precompiles/EcRecover.java | 32 ------- .../imc/call/oob/precompiles/Identity.java | 32 ------- .../ModexpCallDataSizeParameters.java | 2 +- .../imc/call/oob/precompiles/ModexpCds.java | 32 ------- .../call/oob/precompiles/ModexpExtract.java | 32 ------- .../precompiles}/ModexpExtractParameters.java | 2 +- .../imc/call/oob/precompiles/ModexpLead.java | 32 ------- .../precompiles}/ModexpLeadParameters.java | 2 +- .../call/oob/precompiles/ModexpPricing.java | 32 ------- .../precompiles}/ModexpPricingParameters.java | 2 +- .../imc/call/oob/precompiles/ModexpXbs.java | 32 ------- .../oob/precompiles}/ModexpXbsParameters.java | 2 +- .../PrecompileCommonOobParameters.java | 2 +- .../imc/call/oob/precompiles/RipeMd160.java | 32 ------- .../imc/call/oob/precompiles/Sha2.java | 32 ------- .../oob/precompiles/SimplePrecompileCall.java | 47 ---------- .../precompiles/PrecompileLinesGenerator.java | 14 --- .../module/hub/section/CreateSection.java | 1 - .../zktracer/module/hub/section/StackRam.java | 1 - .../linea/zktracer/module/oob/Oob.java | 31 ++++--- .../zktracer/module/oob/OobOperation.java | 90 ++++++++++--------- .../module/oob/parameters/OobParameters.java | 26 ------ 49 files changed, 194 insertions(+), 942 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters/CallDataLoadOobParameters.java => hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java} (74%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters/CallOobParameters.java => hub/fragment/imc/call/oob/opcodes/CallOobCall.java} (73%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters/CreateOobParameters.java => hub/fragment/imc/call/oob/opcodes/CreateOobCall.java} (72%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters/DeploymentOobParameters.java => hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java} (74%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters/JumpOobParameters.java => hub/fragment/imc/call/oob/opcodes/JumpOobCall.java} (55%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jumpi.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/opcodes}/JumpiOobParameters.java (96%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/opcodes}/ReturnDataCopyOobParameters.java (95%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/opcodes}/SstoreOobParameters.java (94%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/opcodes}/XCallOobParameters.java (95%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/Blake2fCallDataSizeParameters.java (95%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/Blake2fParamsParameters.java (95%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/ModexpCallDataSizeParameters.java (94%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/ModexpExtractParameters.java (95%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/ModexpLeadParameters.java (95%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/ModexpPricingParameters.java (95%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/ModexpXbsParameters.java (95%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{oob/parameters => hub/fragment/imc/call/oob/precompiles}/PrecompileCommonOobParameters.java (96%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/OobParameters.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index bc389c0a3e..d52dc7dea3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -31,13 +31,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.Call; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoad; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentReturn; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ExceptionalCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.Jump; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.Jumpi; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SStore; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; @@ -202,7 +196,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { if (hub.pch().signals().oob()) { switch (hub.opCode()) { - case JUMP -> r.callOob(new Jump()); + case JUMP -> r.callOob(new JumpOobCall()); case JUMPI -> r.callOob(new Jumpi()); case CALLDATALOAD -> r.callOob(new CallDataLoad()); case SSTORE -> r.callOob(new SStore()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java index eeaa8403b4..16bc237353 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java @@ -15,41 +15,17 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import org.apache.tuweni.bytes.Bytes; /** This interface defines the API required to execute a call to the OOB module. */ -@Accessors(fluent = true) -@Setter -public abstract class OobCall implements TraceSubFragment { - // TODO: check if we need 0 instead of EMPTY - Bytes data1 = Bytes.EMPTY; - Bytes data2 = Bytes.EMPTY; - Bytes data3 = Bytes.EMPTY; - Bytes data4 = Bytes.EMPTY; - Bytes data5 = Bytes.EMPTY; - Bytes data6 = Bytes.EMPTY; - Bytes data7 = Bytes.EMPTY; - Bytes data8 = Bytes.EMPTY; +public interface OobCall extends TraceSubFragment { + // TODO: move these constants somewhere else + Bytes ZERO = Bytes.EMPTY; + Bytes ONE = Bytes.of(1); - /** The instruction to trigger in the OOB for this call. */ - public abstract int oobInstruction(); + public int oobInstruction(); - @Override - public Trace trace(Trace trace) { - return trace - .pMiscOobFlag(true) - .pMiscOobData1(data1) - .pMiscOobData2(data2) - .pMiscOobData3(data3) - .pMiscOobData4(data4) - .pMiscOobData5(data5) - .pMiscOobData6(data6) - .pMiscOobData7(data7) - .pMiscOobData8(data8) - .pMiscOobInst(this.oobInstruction()); - } + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java deleted file mode 100644 index 728fb9194f..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Call.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CALL; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -// TODO: rename all these classes to XxxOobCall and follow the classes that have been create in oob -// for OobParameters -public class Call extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_CALL; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java deleted file mode 100644 index 4235d85bfb..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoad.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CDL; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class CallDataLoad extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_CDL; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CallDataLoadOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java similarity index 74% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CallDataLoadOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java index 16fff69463..8fdf55dc6c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CallDataLoadOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -21,17 +21,17 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class CallDataLoadOobParameters implements OobParameters { - private final EWord offset; - private final BigInteger cds; - @Setter boolean cdlOutOfBounds; +@Setter +public class CallDataLoadOobCall implements OobCall { + EWord offset; + BigInteger cds; + boolean cdlOutOfBounds; public BigInteger offsetHi() { return offset.hiBigInt(); @@ -41,6 +41,17 @@ public BigInteger offsetLo() { return offset.loBigInt(); } + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + @Override public Trace trace(Trace trace) { return trace diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CallOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java similarity index 73% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CallOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java index 0951606053..d33eba265e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CallOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -21,19 +21,19 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class CallOobParameters implements OobParameters { - private final EWord value; - private final BigInteger balance; - private final BigInteger callStackDepth; - @Setter boolean valueIsNonzero; - @Setter boolean abortingCondition; +@Setter +public class CallOobCall implements OobCall { + EWord value; + BigInteger balance; + BigInteger callStackDepth; + boolean valueIsNonzero; + boolean abortingCondition; public BigInteger valueHi() { return value.hiBigInt(); @@ -43,6 +43,17 @@ public BigInteger valueLo() { return value.loBigInt(); } + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + @Override public Trace trace(Trace trace) { return trace diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java deleted file mode 100644 index 0a1f0bef3e..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Create.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class Create extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_CREATE; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CreateOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java similarity index 72% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CreateOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java index 7f5e62fa62..b90b2bdacb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/CreateOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -21,21 +21,21 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class CreateOobParameters implements OobParameters { - private final EWord value; - private final BigInteger balance; - private final BigInteger nonce; - private final boolean hasCode; - private final BigInteger callStackDepth; - @Setter boolean abortingCondition; - @Setter boolean failureCondition; +@Setter +public class CreateOobCall implements OobCall { + EWord value; + BigInteger balance; + BigInteger nonce; + boolean hasCode; + BigInteger callStackDepth; + boolean abortingCondition; + boolean failureCondition; public BigInteger valueHi() { return value.hiBigInt(); @@ -45,6 +45,17 @@ public BigInteger valueLo() { return value.loBigInt(); } + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + @Override public Trace trace(Trace trace) { return trace diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/DeploymentOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java similarity index 74% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/DeploymentOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java index f3d332bd9e..3d1cd2f0fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/DeploymentOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -21,16 +21,16 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class DeploymentOobParameters implements OobParameters { - private final EWord size; - @Setter boolean maxCodeSizeException; +@Setter +public class DeploymentOobCall implements OobCall { + EWord size; + boolean maxCodeSizeException; public BigInteger sizeHi() { return size.hiBigInt(); @@ -40,6 +40,17 @@ public BigInteger sizeLo() { return size.loBigInt(); } + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + @Override public Trace trace(Trace trace) { return trace diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java deleted file mode 100644 index af35eebca2..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentReturn.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_DEPLOYMENT; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class DeploymentReturn extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_DEPLOYMENT; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java deleted file mode 100644 index 57990e9425..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ExceptionalCall.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_XCALL; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class ExceptionalCall extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_XCALL; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java deleted file mode 100644 index aaf791a264..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jump.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMP; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class Jump extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_JUMP; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/JumpOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java similarity index 55% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/JumpOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java index cd1970125d..f21a7db110 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/JumpOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java @@ -13,26 +13,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMP; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; -import net.consensys.linea.zktracer.module.oob.Trace; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class JumpOobParameters implements OobParameters { - private final EWord pcNew; - private final BigInteger codeSize; - @Setter boolean jumpGuaranteedException; - @Setter boolean jumpMustBeAttempted; +@Setter +public class JumpOobCall implements OobCall { + EWord pcNew; + BigInteger codeSize; + boolean jumpGuaranteedException; + boolean jumpMustBeAttempted; public BigInteger pcNewHi() { return pcNew.hiBigInt(); @@ -43,7 +44,13 @@ public BigInteger pcNewLo() { } @Override - public Trace trace(Trace trace) { + public int oobInstruction() { + return OOB_INST_JUMP; + } + + @Override + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(pcNewHi())) .data2(bigIntegerToBytes(pcNewLo())) @@ -54,4 +61,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(jumpGuaranteedException)) .data8(booleanToBytes(jumpMustBeAttempted)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobData1(bigIntegerToBytes(pcNewHi())) + .pMiscOobData2(bigIntegerToBytes(pcNewLo())) + .pMiscOobData3(ZERO) + .pMiscOobData4(ZERO) + .pMiscOobData5(bigIntegerToBytes(codeSize)) + .pMiscOobData6(ZERO) + .pMiscOobData7(booleanToBytes(jumpGuaranteedException)) + .pMiscOobData8(booleanToBytes(jumpMustBeAttempted)) + .pMiscOobInst(OOB_INST_JUMP); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jumpi.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jumpi.java deleted file mode 100644 index 67c4a10c02..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/Jumpi.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMPI; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class Jumpi extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_JUMPI; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/JumpiOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobParameters.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/JumpiOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobParameters.java index 652f3ec444..146073aff7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/JumpiOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java deleted file mode 100644 index a6a5f9de01..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopy.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RDC; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class ReturnDataCopy extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_RDC; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ReturnDataCopyOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ReturnDataCopyOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobParameters.java index cadf241f60..3ef00b326f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ReturnDataCopyOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java deleted file mode 100644 index ee8276e3d6..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SStore.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SSTORE; - -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; - -public class SStore extends OobCall { - - @Override - public int oobInstruction() { - return OOB_INST_SSTORE; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/SstoreOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobParameters.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/SstoreOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobParameters.java index cd54b25e77..7d04fe36c3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/SstoreOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/XCallOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/XCallOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobParameters.java index 52e01774d2..106cf9722a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/XCallOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java deleted file mode 100644 index fe1de4c6f1..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile1.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class Blake2FPrecompile1 extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_BLAKE_CDS; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java deleted file mode 100644 index 038228efcd..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2FPrecompile2.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class Blake2FPrecompile2 extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_BLAKE_PARAMS; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/Blake2fCallDataSizeParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/Blake2fCallDataSizeParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeParameters.java index f3e96b8a82..4b57c6439d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/Blake2fCallDataSizeParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/Blake2fParamsParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/Blake2fParamsParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsParameters.java index 305aba4638..ac0d4c8498 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/Blake2fParamsParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java deleted file mode 100644 index a1f75e97b0..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcAdd.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECADD; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class EcAdd extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_ECADD; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java deleted file mode 100644 index d9e74db858..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcMul.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECMUL; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class EcMul extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_ECMUL; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java deleted file mode 100644 index 7f1737928b..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcPairing.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECPAIRING; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class EcPairing extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_ECPAIRING; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java deleted file mode 100644 index bc62fc02b1..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/EcRecover.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECRECOVER; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class EcRecover extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_ECRECOVER; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java deleted file mode 100644 index 570787dac3..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Identity.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class Identity extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_IDENTITY; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpCallDataSizeParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeParameters.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpCallDataSizeParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeParameters.java index b75222e75b..029bc88f57 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpCallDataSizeParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java deleted file mode 100644 index 1b01f69478..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCds.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class ModexpCds extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_CDS; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java deleted file mode 100644 index b25fc73f15..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtract.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class ModexpExtract extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_EXTRACT; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpExtractParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpExtractParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractParameters.java index c5db01cdc4..381d49a467 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpExtractParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java deleted file mode 100644 index e5b01b70de..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLead.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class ModexpLead extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_LEAD; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpLeadParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpLeadParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadParameters.java index 78d86c5039..7ea9626fe9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpLeadParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java deleted file mode 100644 index 55e3a42b6c..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricing.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class ModexpPricing extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_PRICING; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpPricingParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpPricingParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingParameters.java index 6d65d0327f..fbda226a44 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpPricingParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java deleted file mode 100644 index d10734169f..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbs.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class ModexpXbs extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_XBS; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpXbsParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsParameters.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpXbsParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsParameters.java index b0c5ee18d8..d08728d489 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/ModexpXbsParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/PrecompileCommonOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobParameters.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/PrecompileCommonOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobParameters.java index f6df85e656..d0143b1705 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/PrecompileCommonOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobParameters.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.oob.parameters; +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java deleted file mode 100644 index 1f2fc6edd0..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/RipeMd160.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class RipeMd160 extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_RIPEMD; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java deleted file mode 100644 index f4d7eafaae..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Sha2.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class Sha2 extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return OOB_INST_SHA2; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java deleted file mode 100644 index 0ae2677690..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/SimplePrecompileCall.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECADD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECMUL; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECPAIRING; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECRECOVER; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; - -@RequiredArgsConstructor -public class SimplePrecompileCall extends OobCall { - final PrecompileInvocation p; - - @Override - public int oobInstruction() { - return switch (p.precompile()) { - case EC_RECOVER -> OOB_INST_ECRECOVER; - case SHA2_256 -> OOB_INST_SHA2; - case RIPEMD_160 -> OOB_INST_RIPEMD; - case IDENTITY -> OOB_INST_IDENTITY; - case EC_ADD -> OOB_INST_ECADD; - case EC_MUL -> OOB_INST_ECMUL; - case EC_PAIRING -> OOB_INST_ECPAIRING; - default -> throw new IllegalArgumentException("unexpected complex precompile"); - }; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index bf5bc32fb2..e35f54cdb5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -25,20 +25,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2FPrecompile1; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2FPrecompile2; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.EcAdd; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.EcMul; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.EcPairing; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.EcRecover; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Identity; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCds; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtract; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLead; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricing; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbs; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.RipeMd160; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Sha2; @RequiredArgsConstructor public class PrecompileLinesGenerator { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 72e1e35f01..2d13f677eb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -29,7 +29,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.Create; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java index b436ec2819..d8d600d270 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java @@ -21,7 +21,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoad; public class StackRam extends TraceSection { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 154763b279..20671616c6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.oob; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import java.math.BigInteger; @@ -49,6 +48,8 @@ public class Oob implements Module { private final Mod mod; private final Wcp wcp; + private OobOperation oobOperation; + @Override public String moduleKey() { return "OOB"; @@ -65,9 +66,16 @@ public String moduleKey() { Address.ALTBN128_PAIRING, Address.BLAKE2B_F_COMPRESSION); + public void call(OobCall oobCall) { + oobOperation.setOobCall(oobCall); + // TODO: add oobCall to the constructor of oobOperation + } + @Override public void tracePreOpcode(MessageFrame frame) { // This will be renamed to tracePreOp - this.chunks.add(new OobOperation(frame, add, mod, wcp, hub, false, 0, 0)); + // TODO: this implementation will die, we just use call to trigger OOB + oobOperation = new OobOperation(frame, add, mod, wcp, hub, false, 0, 0); + this.chunks.add(oobOperation); OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); if (opCode.isCall()) { @@ -75,19 +83,22 @@ public void tracePreOpcode(MessageFrame frame) { // This will be renamed to trac if (PRECOMPILES_HANDLED_BY_OOB.contains(target)) { if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - OobOperation oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 1, 0); + oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 1, 0); this.chunks.add(oobOperation); boolean validCds = oobOperation.getOutgoingResLo()[0].equals(BigInteger.ONE); if (validCds) { - this.chunks.add(new OobOperation(frame, add, mod, wcp, hub, true, 2, 0)); + oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 2, 0); + this.chunks.add(oobOperation); } } else if (target.equals(Address.MODEXP)) { for (int i = 1; i <= 7; i++) { - this.chunks.add(new OobOperation(frame, add, mod, wcp, hub, true, 0, i)); + oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 0, i); + this.chunks.add(oobOperation); } } else { // Other precompiles case - this.chunks.add(new OobOperation(frame, add, mod, wcp, hub, true, 0, 0)); + oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 0, 0); + this.chunks.add(oobOperation); } } } @@ -142,14 +153,6 @@ final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { } } - public void call(OobCall oobCall, Hub hub) { - // TODO: send the oobCall to OobOperation and fill it with the data - switch (oobCall.oobInstruction()) { - case OOB_INST_CREATE: - oobCall.data1(bigIntegerToBytes(BigInteger.ONE)).data2(bigIntegerToBytes(BigInteger.ONE)); - } - } - @Override public void enterTransaction() { this.chunks.enter(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 9c43204256..324676fe21 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -54,29 +54,30 @@ import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.Setter; import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCallDataSizeParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtractParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLeadParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricingParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobParameters; import net.consensys.linea.zktracer.module.mod.Mod; -import net.consensys.linea.zktracer.module.oob.parameters.Blake2fCallDataSizeParameters; -import net.consensys.linea.zktracer.module.oob.parameters.Blake2fParamsParameters; -import net.consensys.linea.zktracer.module.oob.parameters.CallDataLoadOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.CallOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.CreateOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.DeploymentOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.JumpOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.JumpiOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.ModexpCallDataSizeParameters; -import net.consensys.linea.zktracer.module.oob.parameters.ModexpExtractParameters; -import net.consensys.linea.zktracer.module.oob.parameters.ModexpLeadParameters; -import net.consensys.linea.zktracer.module.oob.parameters.ModexpPricingParameters; -import net.consensys.linea.zktracer.module.oob.parameters.ModexpXbsParameters; -import net.consensys.linea.zktracer.module.oob.parameters.OobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.PrecompileCommonOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.ReturnDataCopyOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.SstoreOobParameters; -import net.consensys.linea.zktracer.module.oob.parameters.XCallOobParameters; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; @@ -93,6 +94,8 @@ public class OobOperation extends ModuleOperation { @EqualsAndHashCode.Include private BigInteger oobInst; @EqualsAndHashCode.Include private OobParameters oobParameters; + @Setter OobCall oobCall; + private boolean isJump; private boolean isJumpi; private boolean isRdc; @@ -158,6 +161,7 @@ public OobOperation( boolean isPrecompile, int blake2FCallNumber, int modexpCallNumber) { + this.add = add; this.mod = mod; this.wcp = wcp; @@ -362,11 +366,11 @@ private void populateColumns(final MessageFrame frame) { if (isInst()) { if (isJump) { - JumpOobParameters jumpOobParameters = - new JumpOobParameters( - EWord.of(frame.getStackItem(0)), BigInteger.valueOf(frame.getCode().getSize())); - oobParameters = jumpOobParameters; - setJump(jumpOobParameters); + JumpOobCall jumpOobCall = (JumpOobCall) oobCall; + jumpOobCall.setPcNew(EWord.of(frame.getStackItem(0))); + jumpOobCall.setCodeSize(BigInteger.valueOf(frame.getCode().getSize())); + oobCall = jumpOobCall; + setJump(jumpOobCall); } else if (isJumpi) { JumpiOobParameters jumpiOobParameters = new JumpiOobParameters( @@ -384,8 +388,8 @@ private void populateColumns(final MessageFrame frame) { oobParameters = rdcOobParameters; setRdc(rdcOobParameters); } else if (isCdl) { - CallDataLoadOobParameters cdlOobParameters = - new CallDataLoadOobParameters( + CallDataLoadOobCall cdlOobParameters = + new CallDataLoadOobCall( EWord.of(frame.getStackItem(0)), BigInteger.valueOf(frame.getInputData().size())); oobParameters = cdlOobParameters; setCdl(cdlOobParameters); @@ -396,11 +400,11 @@ private void populateColumns(final MessageFrame frame) { oobParameters = sstoreOobParameters; setSstore(sstoreOobParameters); } else if (isDeployment) { - final DeploymentOobParameters deploymentOobParameters = - new DeploymentOobParameters(EWord.of(frame.getStackItem(0))); + final DeploymentOobCall deploymentOobCall = + new DeploymentOobCall(EWord.of(frame.getStackItem(0))); - oobParameters = deploymentOobParameters; - setDeployment(deploymentOobParameters); + oobParameters = deploymentOobCall; + setDeployment(deploymentOobCall); } else if (isXCall) { XCallOobParameters xCallOobParameters = new XCallOobParameters(EWord.of(frame.getStackItem(2))); @@ -416,8 +420,8 @@ private void populateColumns(final MessageFrame frame) { value = EWord.of(frame.getStackItem(2)); nonZeroValue = !frame.getStackItem(2).isZero(); } - CallOobParameters callOobParameters = - new CallOobParameters( + CallOobCall callOobParameters = + new CallOobCall( value, callerAccount.getBalance().toUnsignedBigInteger(), // balance (caller address) BigInteger.valueOf(frame.getDepth())); @@ -742,21 +746,21 @@ private void noCall(int k) { } // Methods to populate columns - private void setJump(JumpOobParameters jumpOobParameters) { + private void setJump(JumpOobCall jumpOobCall) { // row i final boolean validPcNew = callToLT( 0, - jumpOobParameters.pcNewHi(), - jumpOobParameters.pcNewLo(), + jumpOobCall.pcNewHi(), + jumpOobCall.pcNewLo(), BigInteger.ZERO, - jumpOobParameters.getCodeSize()); + jumpOobCall.getCodeSize()); // Set jumpGuaranteedException - jumpOobParameters.setJumpGuaranteedException(!validPcNew); + jumpOobCall.setJumpGuaranteedException(!validPcNew); // Set jumpMustBeAttempted - jumpOobParameters.setJumpMustBeAttempted(validPcNew); + jumpOobCall.setJumpMustBeAttempted(validPcNew); } private void setJumpi(JumpiOobParameters jumpiOobParameters) { @@ -820,7 +824,7 @@ private void setRdc(ReturnDataCopyOobParameters rdcOobParameters) { rdcOobParameters.setRdcx(rdcRoob || rdcSoob); } - private void setCdl(CallDataLoadOobParameters cdlOobParameters) { + private void setCdl(CallDataLoadOobCall cdlOobParameters) { // row i final boolean touchesRam = callToLT( @@ -848,18 +852,18 @@ private void setSstore(SstoreOobParameters sstoreOobParameters) { sstoreOobParameters.setSstorex(!sufficientGas); } - private void setDeployment(DeploymentOobParameters deploymentOobParameters) { + private void setDeployment(DeploymentOobCall deploymentOobCall) { // row i final boolean exceedsMaxCodeSize = callToLT( 0, BigInteger.ZERO, BigInteger.valueOf(24576), - deploymentOobParameters.sizeHi(), - deploymentOobParameters.sizeLo()); + deploymentOobCall.sizeHi(), + deploymentOobCall.sizeLo()); // Set maxCodeSizeException - deploymentOobParameters.setMaxCodeSizeException(exceedsMaxCodeSize); + deploymentOobCall.setMaxCodeSizeException(exceedsMaxCodeSize); } private void setXCall(XCallOobParameters xCallOobParameters) { @@ -874,7 +878,7 @@ private void setXCall(XCallOobParameters xCallOobParameters) { xCallOobParameters.setValueIsZero(valueIsZero); } - private void setCall(CallOobParameters callOobParameters) { + private void setCall(CallOobCall callOobParameters) { // row i boolean insufficientBalanceAbort = callToLT( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/OobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/OobParameters.java deleted file mode 100644 index 9ac37260f3..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/parameters/OobParameters.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.oob.parameters; - -import net.consensys.linea.zktracer.module.oob.Trace; -import org.apache.tuweni.bytes.Bytes; - -public interface OobParameters { - Bytes ZERO = Bytes.EMPTY; - Bytes ONE = Bytes.of(1); - - Trace trace(Trace trace); -} From bd7d1ec04d710577c860e9408015ed38bdf3d304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 17:32:19 +0200 Subject: [PATCH 116/461] OOB precompile business --- ...s.java => Blake2fCallDataSizeOobCall.java} | 46 ++-- ...ameters.java => Blake2fParamsOobCall.java} | 44 ++-- ...rs.java => ModexpCallDataSizeOobCall.java} | 43 ++-- ...ameters.java => ModexpExtractOobCall.java} | 48 ++-- ...Parameters.java => ModexpLeadOobCall.java} | 48 ++-- .../oob/precompiles/ModexpPricingOobCall.java | 69 ++++++ ...sParameters.java => ModexpXbsOobCall.java} | 45 ++-- .../oob/precompiles/ModexpXbsParameters.java | 51 ----- .../precompiles/PrecompileCommonOobCall.java | 69 ++++++ .../PrecompileCommonOobParameters.java | 59 ----- .../zktracer/module/oob/OobOperation.java | 206 +++++++++--------- 11 files changed, 425 insertions(+), 303 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/{ModexpPricingParameters.java => Blake2fCallDataSizeOobCall.java} (53%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/{ModexpCallDataSizeParameters.java => Blake2fParamsOobCall.java} (54%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/{Blake2fCallDataSizeParameters.java => ModexpCallDataSizeOobCall.java} (57%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/{ModexpExtractParameters.java => ModexpExtractOobCall.java} (54%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/{ModexpLeadParameters.java => ModexpLeadOobCall.java} (56%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/{Blake2fParamsParameters.java => ModexpXbsOobCall.java} (55%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsParameters.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobParameters.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java similarity index 53% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java index fbda226a44..99a234e1a2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -1,5 +1,5 @@ /* - * Copyright Consensys Software Inc. + * Copyright ConsenSys AG. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -23,31 +23,43 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.oob.Trace; import org.apache.tuweni.bytes.Bytes; @Getter +@Setter @RequiredArgsConstructor -public class ModexpPricingParameters implements OobParameters { - private final BigInteger callGas; - private final BigInteger returnAtCapacity; - @Setter private boolean success; - private final BigInteger exponentLog; - private final int maxMbsBbs; +public class Blake2fCallDataSizeOobCall implements OobCall { - @Setter private BigInteger returnGas; - @Setter private boolean returnAtCapacityNonZero; + final PrecompileInvocation p; + BigInteger cds; + BigInteger returnAtCapacity; + + boolean success; + boolean returnAtCapacityNonZero; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } @Override public Trace trace(Trace trace) { return trace - .data1(bigIntegerToBytes(callGas)) - .data2(ZERO) - .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) - .data5(bigIntegerToBytes(returnGas)) - .data6(bigIntegerToBytes(exponentLog)) - .data7(Bytes.of(maxMbsBbs)) - .data8(booleanToBytes(returnAtCapacityNonZero)); + .data1(ZERO) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(returnAtCapacity)) + .data4(booleanToBytes(success)) // Set after the constructor + .data5(ZERO) + .data6(Bytes.of(0)) + .data7(Bytes.of(0)) + .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java similarity index 54% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java index 029bc88f57..204e6d8083 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java @@ -23,27 +23,45 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.oob.Trace; @Getter +@Setter @RequiredArgsConstructor -public class ModexpCallDataSizeParameters implements OobParameters { - private final BigInteger cds; +public class Blake2fParamsOobCall implements OobCall { - @Setter private boolean extractBbs; - @Setter private boolean extractEbs; - @Setter private boolean extractMbs; + final PrecompileInvocation p; + + BigInteger callGas; + BigInteger blakeR; + BigInteger blakeF; + + boolean success; + BigInteger returnGas; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } @Override public Trace trace(Trace trace) { return trace - .data1(ZERO) - .data2(bigIntegerToBytes(cds)) - .data3(booleanToBytes(extractBbs)) - .data4(booleanToBytes(extractEbs)) - .data5(booleanToBytes(extractMbs)) - .data6(ZERO) - .data7(ZERO) - .data8(ZERO); + .data1(bigIntegerToBytes(callGas)) + .data2(ZERO) + .data3(ZERO) + .data4(booleanToBytes(success)) // Set after the constructor + .data5(bigIntegerToBytes(returnGas)) // Set after the constructor + .data6(bigIntegerToBytes(blakeR)) + .data7(bigIntegerToBytes(blakeF)) + .data8(ZERO); } + } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java similarity index 57% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java index 4b57c6439d..46f701e632 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java @@ -23,28 +23,43 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.oob.Trace; -import org.apache.tuweni.bytes.Bytes; @Getter +@Setter @RequiredArgsConstructor -public class Blake2fCallDataSizeParameters implements OobParameters { - private final BigInteger cds; - private final BigInteger returnAtCapacity; +public class ModexpCallDataSizeOobCall implements OobCall { - @Setter private boolean success; - @Setter private boolean returnAtCapacityNonZero; + final PrecompileInvocation p; + BigInteger cds; + + boolean extractBbs; + boolean extractEbs; + boolean extractMbs; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } @Override public Trace trace(Trace trace) { return trace - .data1(ZERO) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) // Set after the constructor - .data5(ZERO) - .data6(Bytes.of(0)) - .data7(Bytes.of(0)) - .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + .data1(ZERO) + .data2(bigIntegerToBytes(cds)) + .data3(booleanToBytes(extractBbs)) + .data4(booleanToBytes(extractEbs)) + .data5(booleanToBytes(extractMbs)) + .data6(ZERO) + .data7(ZERO) + .data8(ZERO); } + } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java similarity index 54% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java index 381d49a467..8a84fb4d95 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java @@ -23,30 +23,46 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.oob.Trace; @Getter +@Setter @RequiredArgsConstructor -public class ModexpExtractParameters implements OobParameters { - private final BigInteger cds; - private final BigInteger bbs; - private final BigInteger ebs; - private final BigInteger mbs; +public class ModexpExtractOobCall implements OobCall { - @Setter private boolean extractBase; - @Setter private boolean extractExponent; - @Setter private boolean extractModulus; + final PrecompileInvocation p; + BigInteger cds; + BigInteger bbs; + BigInteger ebs; + BigInteger mbs; + + boolean extractBase; + boolean extractExponent; + boolean extractModulus; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } @Override public Trace trace(Trace trace) { return trace - .data1(ZERO) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(bbs)) - .data4(bigIntegerToBytes(ebs)) - .data5(bigIntegerToBytes(mbs)) - .data6(booleanToBytes(extractBase)) - .data7(booleanToBytes(extractExponent)) - .data8(booleanToBytes(extractModulus)); + .data1(ZERO) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(bbs)) + .data4(bigIntegerToBytes(ebs)) + .data5(bigIntegerToBytes(mbs)) + .data6(booleanToBytes(extractBase)) + .data7(booleanToBytes(extractExponent)) + .data8(booleanToBytes(extractModulus)); } + } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java similarity index 56% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java index 7ea9626fe9..01c1332734 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java @@ -23,31 +23,47 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.oob.Trace; import org.apache.tuweni.bytes.Bytes; @Getter +@Setter @RequiredArgsConstructor -public class ModexpLeadParameters implements OobParameters { - private final BigInteger bbs; - private final BigInteger cds; - private final BigInteger ebs; +public class ModexpLeadOobCall implements OobCall { - @Setter boolean loadLead; - @Setter int cdsCutoff; - @Setter int ebsCutoff; - @Setter int subEbs32; + final PrecompileInvocation p; + BigInteger bbs; + BigInteger cds; + BigInteger ebs; + + boolean loadLead; + int cdsCutoff; + int ebsCutoff; + int subEbs32; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } @Override public Trace trace(Trace trace) { return trace - .data1(bigIntegerToBytes(bbs)) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(ebs)) - .data4(booleanToBytes(loadLead)) - .data5(ZERO) - .data6(Bytes.of(cdsCutoff)) - .data7(Bytes.of(ebsCutoff)) - .data8(Bytes.of(subEbs32)); + .data1(bigIntegerToBytes(bbs)) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(ebs)) + .data4(booleanToBytes(loadLead)) + .data5(ZERO) + .data6(Bytes.of(cdsCutoff)) + .data7(Bytes.of(ebsCutoff)) + .data8(Bytes.of(subEbs32)); } + } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java new file mode 100644 index 0000000000..37d5b0a47e --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java @@ -0,0 +1,69 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; + +import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; + +import java.math.BigInteger; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.oob.Trace; +import org.apache.tuweni.bytes.Bytes; + +@Getter +@Setter +@RequiredArgsConstructor +public class ModexpPricingOobCall implements OobCall { + + final PrecompileInvocation p; + BigInteger callGas; + BigInteger returnAtCapacity; + boolean success; + BigInteger exponentLog; + int maxMbsBbs; + + BigInteger returnGas; + boolean returnAtCapacityNonZero; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + + @Override + public Trace trace(Trace trace) { + return trace + .data1(bigIntegerToBytes(callGas)) + .data2(ZERO) + .data3(bigIntegerToBytes(returnAtCapacity)) + .data4(booleanToBytes(success)) + .data5(bigIntegerToBytes(returnGas)) + .data6(bigIntegerToBytes(exponentLog)) + .data7(Bytes.of(maxMbsBbs)) + .data8(booleanToBytes(returnAtCapacityNonZero)); + } + +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java similarity index 55% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java index ac0d4c8498..65b3e65534 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java @@ -23,28 +23,45 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.oob.Trace; @Getter +@Setter @RequiredArgsConstructor -public class Blake2fParamsParameters implements OobParameters { - private final BigInteger callGas; - private final BigInteger blakeR; - private final BigInteger blakeF; +public class ModexpXbsOobCall implements OobCall { - @Setter private boolean success; - @Setter private BigInteger returnGas; + final PrecompileInvocation p; + BigInteger xbsHi; + BigInteger xbsLo; + BigInteger ybsLo; + boolean computeMax; + + BigInteger maxXbsYbs; + boolean xbsNonZero; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } @Override public Trace trace(Trace trace) { return trace - .data1(bigIntegerToBytes(callGas)) - .data2(ZERO) - .data3(ZERO) - .data4(booleanToBytes(success)) // Set after the constructor - .data5(bigIntegerToBytes(returnGas)) // Set after the constructor - .data6(bigIntegerToBytes(blakeR)) - .data7(bigIntegerToBytes(blakeF)) - .data8(ZERO); + .data1(bigIntegerToBytes(xbsHi)) + .data2(bigIntegerToBytes(xbsLo)) + .data3(bigIntegerToBytes(ybsLo)) + .data4(booleanToBytes(computeMax)) + .data5(ZERO) + .data6(ZERO) + .data7(bigIntegerToBytes(maxXbsYbs)) + .data8(booleanToBytes(xbsNonZero)); } + } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsParameters.java deleted file mode 100644 index d08728d489..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsParameters.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; - -import java.math.BigInteger; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import net.consensys.linea.zktracer.module.oob.Trace; - -@Getter -@RequiredArgsConstructor -public class ModexpXbsParameters implements OobParameters { - private final BigInteger xbsHi; - private final BigInteger xbsLo; - private final BigInteger ybsLo; - private final boolean computeMax; - - @Setter private BigInteger maxXbsYbs; - @Setter private boolean xbsNonZero; - - @Override - public Trace trace(Trace trace) { - return trace - .data1(bigIntegerToBytes(xbsHi)) - .data2(bigIntegerToBytes(xbsLo)) - .data3(bigIntegerToBytes(ybsLo)) - .data4(booleanToBytes(computeMax)) - .data5(ZERO) - .data6(ZERO) - .data7(bigIntegerToBytes(maxXbsYbs)) - .data8(booleanToBytes(xbsNonZero)); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java new file mode 100644 index 0000000000..2911cabc72 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java @@ -0,0 +1,69 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; + +import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; + +import java.math.BigInteger; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.oob.Trace; + +@Getter +@Setter +@RequiredArgsConstructor +public class PrecompileCommonOobCall implements OobCall { + + final PrecompileInvocation p; + BigInteger callGas; + BigInteger cds; + BigInteger returnAtCapacity; + boolean success; + BigInteger returnGas; + boolean returnAtCapacityNonZero; + boolean cdsIsZero; // Necessary to compute extractCallData and emptyCallData + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + + @Override + public Trace trace(Trace trace) { + boolean extractCallData = success && !cdsIsZero; + boolean emptyCallData = success && cdsIsZero; + return trace + .data1(bigIntegerToBytes(callGas)) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(returnAtCapacity)) + .data4(booleanToBytes(success)) // Set after the constructor + .data5(bigIntegerToBytes(returnGas)) // Set after the constructor + .data6(booleanToBytes(extractCallData)) // Derived from other parameters + .data7(booleanToBytes(emptyCallData)) // Derived from other parameters + .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + } + +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobParameters.java deleted file mode 100644 index d0143b1705..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobParameters.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; - -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; - -import java.math.BigInteger; - -import lombok.Getter; -import lombok.Setter; -import net.consensys.linea.zktracer.module.oob.Trace; - -@Getter -public class PrecompileCommonOobParameters implements OobParameters { - - private BigInteger callGas; - private BigInteger cds; - private BigInteger returnAtCapacity; - @Setter private boolean success; - @Setter private BigInteger returnGas; - @Setter private boolean returnAtCapacityNonZero; - @Setter private boolean cdsIsZero; // Necessary to compute extractCallData and emptyCallData - - public PrecompileCommonOobParameters( - BigInteger callGas, BigInteger cds, BigInteger returnAtCapacity) { - this.callGas = callGas; - this.cds = cds; - this.returnAtCapacity = returnAtCapacity; - } - - @Override - public Trace trace(Trace trace) { - boolean extractCallData = success && !cdsIsZero; - boolean emptyCallData = success && cdsIsZero; - return trace - .data1(bigIntegerToBytes(callGas)) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) // Set after the constructor - .data5(bigIntegerToBytes(returnGas)) // Set after the constructor - .data6(booleanToBytes(extractCallData)) // Derived from other parameters - .data7(booleanToBytes(emptyCallData)) // Derived from other parameters - .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 324676fe21..3b8f041d9e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -69,14 +69,14 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobParameters; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobParameters; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCallDataSizeParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtractParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLeadParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricingParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtractOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLeadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricingOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; @@ -482,8 +482,8 @@ private void populateColumns(final MessageFrame frame) { EWord.of(frame.getStackItem(returnAtCapacityIndex)).toUnsignedBigInteger(); if (isCommonPrecompile()) { - PrecompileCommonOobParameters prcCommonOobParameters = - new PrecompileCommonOobParameters(callGas, cds, returnAtCapacity); + PrecompileCommonOobCall prcCommonOobParameters = + new PrecompileCommonOobCall(callGas, cds, returnAtCapacity); oobParameters = prcCommonOobParameters; setPrecompile(prcCommonOobParameters); if (isEcRecover || isEcadd || isEcmul) { @@ -540,55 +540,55 @@ private void populateColumns(final MessageFrame frame) { exponentLog = BigInteger.valueOf(8).multiply(ebs.subtract(BigInteger.valueOf(32))); } if (isModexpCds) { - final ModexpCallDataSizeParameters prcModexpCdsParameters = - new ModexpCallDataSizeParameters(cds); + final ModexpCallDataSizeOobCall prcModexpCdsParameters = + new ModexpCallDataSizeOobCall(cds); oobParameters = prcModexpCdsParameters; setModexpCds(prcModexpCdsParameters); } else if (isModexpXbs) { - final ModexpXbsParameters prcModexpXbsParameters; + final ModexpXbsOobCall prcModexpXbsOobCall; if (isModexpBbs) { - prcModexpXbsParameters = - new ModexpXbsParameters( + prcModexpXbsOobCall = + new ModexpXbsOobCall( EWord.of(bbs).hiBigInt(), EWord.of(bbs).loBigInt(), BigInteger.ZERO, false); } else if (isModexpEbs) { - prcModexpXbsParameters = - new ModexpXbsParameters( + prcModexpXbsOobCall = + new ModexpXbsOobCall( EWord.of(ebs).hiBigInt(), EWord.of(ebs).loBigInt(), BigInteger.ZERO, false); } else { // isModexpMbs - prcModexpXbsParameters = - new ModexpXbsParameters( + prcModexpXbsOobCall = + new ModexpXbsOobCall( EWord.of(mbs).hiBigInt(), EWord.of(mbs).loBigInt(), EWord.of(bbs).loBigInt(), true); } - oobParameters = prcModexpXbsParameters; - setModexpXbs(prcModexpXbsParameters); + oobParameters = prcModexpXbsOobCall; + setModexpXbs(prcModexpXbsOobCall); } else if (isModexpLead) { - final ModexpLeadParameters prcModexpLeadParameters = - new ModexpLeadParameters(bbs, cds, ebs); + final ModexpLeadOobCall prcModexpLeadOobCall = + new ModexpLeadOobCall(bbs, cds, ebs); - oobParameters = prcModexpLeadParameters; - setModexpLead(prcModexpLeadParameters); + oobParameters = prcModexpLeadOobCall; + setModexpLead(prcModexpLeadOobCall); } else if (prcModexpPricing) { int maxMbsBbs = max(mbs.intValue(), bbs.intValue()); - final ModexpPricingParameters prcModexpPricingParameters = - new ModexpPricingParameters(callGas, returnAtCapacity, exponentLog, maxMbsBbs); + final ModexpPricingOobCall prcModexpPricingOobCall = + new ModexpPricingOobCall(callGas, returnAtCapacity, exponentLog, maxMbsBbs); - oobParameters = prcModexpPricingParameters; - setPrcModexpPricing(prcModexpPricingParameters); + oobParameters = prcModexpPricingOobCall; + setPrcModexpPricing(prcModexpPricingOobCall); } else if (prcModexpExtract) { - final ModexpExtractParameters prcModexpExtractParameters = - new ModexpExtractParameters(cds, bbs, ebs, mbs); + final ModexpExtractOobCall prcModexpExtractOobCall = + new ModexpExtractOobCall(cds, bbs, ebs, mbs); - oobParameters = prcModexpExtractParameters; - setPrcModexpExtract(prcModexpExtractParameters); + oobParameters = prcModexpExtractOobCall; + setPrcModexpExtract(prcModexpExtractOobCall); } } else if (isBlakePrecompile()) { if (isBlake2FCds) { - final Blake2fCallDataSizeParameters prcBlake2FCdsParameters = - new Blake2fCallDataSizeParameters(cds, returnAtCapacity); + final Blake2fCallDataSizeOobCall prcBlake2FCdsParameters = + new Blake2fCallDataSizeOobCall(cds, returnAtCapacity); oobParameters = prcBlake2FCdsParameters; setBlake2FCds(prcBlake2FCdsParameters); @@ -603,11 +603,11 @@ private void populateColumns(final MessageFrame frame) { BigInteger.valueOf( toUnsignedInt(frame.shadowReadMemory(argsOffset, cds.longValue()).get(212))); - final Blake2fParamsParameters prcBlake2FParamsParameters = - new Blake2fParamsParameters(callGas, blakeR, blakeF); + final Blake2fParamsOobCall prcBlake2FParamsOobCall = + new Blake2fParamsOobCall(callGas, blakeR, blakeF); - oobParameters = prcBlake2FParamsParameters; - setBlake2FParams(prcBlake2FParamsParameters); + oobParameters = prcBlake2FParamsOobCall; + setBlake2FParams(prcBlake2FParamsOobCall); } } else { throw new RuntimeException("no opcode or precompile flag was set to true"); @@ -938,7 +938,7 @@ private void setCreate(CreateOobParameters createOobParameters) { && (createOobParameters.isHasCode() || nonzeroNonce)); } - private void setPrecompile(PrecompileCommonOobParameters prcOobParameters) { + private void setPrecompile(PrecompileCommonOobCall prcOobParameters) { // row i final boolean cdsIsZero = callToISZERO(0, BigInteger.ZERO, prcOobParameters.getCds()); @@ -954,7 +954,7 @@ private void setPrecompile(PrecompileCommonOobParameters prcOobParameters) { } private void setPrcEcRecoverPrcEcaddPrcEcmul( - PrecompileCommonOobParameters prcCommonOobParameters) { + PrecompileCommonOobCall prcCommonOobParameters) { precompileCost = BigInteger.valueOf( 3000L * booleanToInt(isEcRecover) @@ -981,7 +981,7 @@ private void setPrcEcRecoverPrcEcaddPrcEcmul( } private void setPrcSha2PrcRipemdPrcIdentity( - PrecompileCommonOobParameters prcCommonOobParameters) { + PrecompileCommonOobCall prcCommonOobParameters) { // row i + 2 final BigInteger ceil = callToDIV( @@ -1018,7 +1018,7 @@ private void setPrcSha2PrcRipemdPrcIdentity( prcCommonOobParameters.setReturnGas(returnGas); } - private void setEcpairing(PrecompileCommonOobParameters prcCommonOobParameters) { + private void setEcpairing(PrecompileCommonOobCall prcCommonOobParameters) { // row i + 2 final BigInteger remainder = callToMOD( @@ -1064,7 +1064,7 @@ private void setEcpairing(PrecompileCommonOobParameters prcCommonOobParameters) prcCommonOobParameters.setReturnGas(returnGas); } - private void setModexpCds(ModexpCallDataSizeParameters prcModexpCdsParameters) { + private void setModexpCds(ModexpCallDataSizeOobCall prcModexpCdsParameters) { // row i final boolean extractBbs = callToLT( @@ -1098,13 +1098,13 @@ private void setModexpCds(ModexpCallDataSizeParameters prcModexpCdsParameters) { prcModexpCdsParameters.setExtractMbs(extractMbs); } - private void setModexpXbs(ModexpXbsParameters prcModexpXbsParameters) { + private void setModexpXbs(ModexpXbsOobCall prcModexpXbsOobCall) { // row i final boolean compTo512 = callToLT( 0, - prcModexpXbsParameters.getXbsHi(), - prcModexpXbsParameters.getXbsLo(), + prcModexpXbsOobCall.getXbsHi(), + prcModexpXbsOobCall.getXbsLo(), BigInteger.ZERO, BigInteger.valueOf(513)); @@ -1113,34 +1113,34 @@ private void setModexpXbs(ModexpXbsParameters prcModexpXbsParameters) { callToLT( 1, BigInteger.ZERO, - prcModexpXbsParameters.getXbsLo(), + prcModexpXbsOobCall.getXbsLo(), BigInteger.ZERO, - prcModexpXbsParameters.getYbsLo()); + prcModexpXbsOobCall.getYbsLo()); // row i + 2 - callToISZERO(2, BigInteger.ZERO, prcModexpXbsParameters.getXbsLo()); + callToISZERO(2, BigInteger.ZERO, prcModexpXbsOobCall.getXbsLo()); // Set maxXbsYbs and xbsNonZero - if (!prcModexpXbsParameters.isComputeMax()) { - prcModexpXbsParameters.setMaxXbsYbs(BigInteger.ZERO); - prcModexpXbsParameters.setXbsNonZero(false); + if (!prcModexpXbsOobCall.isComputeMax()) { + prcModexpXbsOobCall.setMaxXbsYbs(BigInteger.ZERO); + prcModexpXbsOobCall.setXbsNonZero(false); } else { - prcModexpXbsParameters.setMaxXbsYbs( - comp ? prcModexpXbsParameters.getYbsLo() : prcModexpXbsParameters.getXbsLo()); - prcModexpXbsParameters.setXbsNonZero(!bigIntegerToBoolean(outgoingResLo[2])); + prcModexpXbsOobCall.setMaxXbsYbs( + comp ? prcModexpXbsOobCall.getYbsLo() : prcModexpXbsOobCall.getXbsLo()); + prcModexpXbsOobCall.setXbsNonZero(!bigIntegerToBoolean(outgoingResLo[2])); } } - private void setModexpLead(ModexpLeadParameters prcModexpLeadParameters) { + private void setModexpLead(ModexpLeadOobCall prcModexpLeadOobCall) { // row i - final boolean ebsIsZero = callToISZERO(0, BigInteger.ZERO, prcModexpLeadParameters.getEbs()); + final boolean ebsIsZero = callToISZERO(0, BigInteger.ZERO, prcModexpLeadOobCall.getEbs()); // row i + 1 final boolean ebsLessThan32 = callToLT( 1, BigInteger.ZERO, - prcModexpLeadParameters.getEbs(), + prcModexpLeadOobCall.getEbs(), BigInteger.ZERO, BigInteger.valueOf(32)); @@ -1149,9 +1149,9 @@ private void setModexpLead(ModexpLeadParameters prcModexpLeadParameters) { callToLT( 2, BigInteger.ZERO, - BigInteger.valueOf(96).add(prcModexpLeadParameters.getBbs()), + BigInteger.valueOf(96).add(prcModexpLeadOobCall.getBbs()), BigInteger.ZERO, - prcModexpLeadParameters.getCds()); + prcModexpLeadOobCall.getCds()); // row i + 3 boolean comp = false; @@ -1160,9 +1160,9 @@ private void setModexpLead(ModexpLeadParameters prcModexpLeadParameters) { callToLT( 3, BigInteger.ZERO, - prcModexpLeadParameters + prcModexpLeadOobCall .getCds() - .subtract(BigInteger.valueOf(96).add(prcModexpLeadParameters.getBbs())), + .subtract(BigInteger.valueOf(96).add(prcModexpLeadOobCall.getBbs())), BigInteger.ZERO, BigInteger.valueOf(32)); } else { @@ -1171,37 +1171,37 @@ private void setModexpLead(ModexpLeadParameters prcModexpLeadParameters) { // Set loadLead final boolean loadLead = callDataContainsExponentBytes && !ebsIsZero; - prcModexpLeadParameters.setLoadLead(loadLead); + prcModexpLeadOobCall.setLoadLead(loadLead); // Set cdsCutoff if (!callDataContainsExponentBytes) { - prcModexpLeadParameters.setCdsCutoff(0); + prcModexpLeadOobCall.setCdsCutoff(0); } else { - prcModexpLeadParameters.setCdsCutoff( + prcModexpLeadOobCall.setCdsCutoff( comp - ? (prcModexpLeadParameters + ? (prcModexpLeadOobCall .getCds() - .subtract(BigInteger.valueOf(96).add(prcModexpLeadParameters.getBbs())) + .subtract(BigInteger.valueOf(96).add(prcModexpLeadOobCall.getBbs())) .intValue()) : 32); } // Set ebsCutoff - prcModexpLeadParameters.setEbsCutoff( - ebsLessThan32 ? prcModexpLeadParameters.getEbs().intValue() : 32); + prcModexpLeadOobCall.setEbsCutoff( + ebsLessThan32 ? prcModexpLeadOobCall.getEbs().intValue() : 32); // Set subEbs32 - prcModexpLeadParameters.setSubEbs32( - ebsLessThan32 ? 0 : prcModexpLeadParameters.getEbs().intValue() - 32); + prcModexpLeadOobCall.setSubEbs32( + ebsLessThan32 ? 0 : prcModexpLeadOobCall.getEbs().intValue() - 32); } - private void setPrcModexpPricing(ModexpPricingParameters prcModexpPricingParameters) { + private void setPrcModexpPricing(ModexpPricingOobCall prcModexpPricingOobCall) { // row i final boolean returnAtCapacityIsZero = - callToISZERO(0, BigInteger.ZERO, prcModexpPricingParameters.getReturnAtCapacity()); + callToISZERO(0, BigInteger.ZERO, prcModexpPricingOobCall.getReturnAtCapacity()); // row i + 1 final boolean exponentLogIsZero = - callToISZERO(1, BigInteger.ZERO, prcModexpPricingParameters.getExponentLog()); + callToISZERO(1, BigInteger.ZERO, prcModexpPricingOobCall.getExponentLog()); // row i + 2 final BigInteger fOfMax = @@ -1209,8 +1209,8 @@ private void setPrcModexpPricing(ModexpPricingParameters prcModexpPricingParamet 2, BigInteger.ZERO, BigInteger.valueOf( - (long) prcModexpPricingParameters.getMaxMbsBbs() - * prcModexpPricingParameters.getMaxMbsBbs() + (long) prcModexpPricingOobCall.getMaxMbsBbs() + * prcModexpPricingOobCall.getMaxMbsBbs() + 7), BigInteger.ZERO, BigInteger.valueOf(8)); @@ -1218,7 +1218,7 @@ private void setPrcModexpPricing(ModexpPricingParameters prcModexpPricingParamet // row i + 3 BigInteger bigNumerator; if (!exponentLogIsZero) { - bigNumerator = fOfMax.multiply(prcModexpPricingParameters.getExponentLog()); + bigNumerator = fOfMax.multiply(prcModexpPricingOobCall.getExponentLog()); } else { bigNumerator = fOfMax; } @@ -1237,33 +1237,33 @@ private void setPrcModexpPricing(ModexpPricingParameters prcModexpPricingParamet !callToLT( 5, BigInteger.ZERO, - prcModexpPricingParameters.getCallGas(), + prcModexpPricingOobCall.getCallGas(), BigInteger.ZERO, precompileCost); // Set ramSuccess - prcModexpPricingParameters.setSuccess(ramSuccess); + prcModexpPricingOobCall.setSuccess(ramSuccess); // Set returnGas final BigInteger returnGas = ramSuccess - ? prcModexpPricingParameters.getCallGas().subtract(precompileCost) + ? prcModexpPricingOobCall.getCallGas().subtract(precompileCost) : BigInteger.ZERO; - prcModexpPricingParameters.setReturnGas(returnGas); + prcModexpPricingOobCall.setReturnGas(returnGas); // Set returnAtCapacityNonZero - prcModexpPricingParameters.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); + prcModexpPricingOobCall.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); } - private void setPrcModexpExtract(ModexpExtractParameters prcModexpExtractParameters) { + private void setPrcModexpExtract(ModexpExtractOobCall prcModexpExtractOobCall) { // row i - final boolean bbsIsZero = callToISZERO(0, BigInteger.ZERO, prcModexpExtractParameters.getBbs()); + final boolean bbsIsZero = callToISZERO(0, BigInteger.ZERO, prcModexpExtractOobCall.getBbs()); // row i + 1 - final boolean ebsIsZero = callToISZERO(1, BigInteger.ZERO, prcModexpExtractParameters.getEbs()); + final boolean ebsIsZero = callToISZERO(1, BigInteger.ZERO, prcModexpExtractOobCall.getEbs()); // row i + 2 - final boolean mbsIsZero = callToISZERO(2, BigInteger.ZERO, prcModexpExtractParameters.getMbs()); + final boolean mbsIsZero = callToISZERO(2, BigInteger.ZERO, prcModexpExtractOobCall.getMbs()); // row i + 3 final boolean callDataExtendsBeyondExponent = @@ -1271,24 +1271,24 @@ private void setPrcModexpExtract(ModexpExtractParameters prcModexpExtractParamet 3, BigInteger.ZERO, BigInteger.valueOf(96) - .add(prcModexpExtractParameters.getBbs().add(prcModexpExtractParameters.getEbs())), + .add(prcModexpExtractOobCall.getBbs().add(prcModexpExtractOobCall.getEbs())), BigInteger.ZERO, - prcModexpExtractParameters.getCds()); + prcModexpExtractOobCall.getCds()); // Set extractModulus final boolean extractModulus = callDataExtendsBeyondExponent && !mbsIsZero; - prcModexpExtractParameters.setExtractModulus(extractModulus); + prcModexpExtractOobCall.setExtractModulus(extractModulus); // Set extractBase final boolean extractBase = extractModulus && !bbsIsZero; - prcModexpExtractParameters.setExtractBase(extractBase); + prcModexpExtractOobCall.setExtractBase(extractBase); // Set extractExponent final boolean extractExponent = extractModulus && !ebsIsZero; - prcModexpExtractParameters.setExtractExponent(extractExponent); + prcModexpExtractOobCall.setExtractExponent(extractExponent); } - private void setBlake2FCds(Blake2fCallDataSizeParameters prcBlake2FCdsParameters) { + private void setBlake2FCds(Blake2fCallDataSizeOobCall prcBlake2FCdsParameters) { // row i final boolean validCds = callToEQ( @@ -1309,40 +1309,40 @@ private void setBlake2FCds(Blake2fCallDataSizeParameters prcBlake2FCdsParameters prcBlake2FCdsParameters.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); } - private void setBlake2FParams(Blake2fParamsParameters prcBlake2FParamsParameters) { + private void setBlake2FParams(Blake2fParamsOobCall prcBlake2FParamsOobCall) { // row i final boolean sufficientGas = !callToLT( 0, BigInteger.ZERO, - prcBlake2FParamsParameters.getCallGas(), + prcBlake2FParamsOobCall.getCallGas(), BigInteger.ZERO, - prcBlake2FParamsParameters.getBlakeR()); // = ramSuccess + prcBlake2FParamsOobCall.getBlakeR()); // = ramSuccess // row i + 1 final boolean fIsABit = callToEQ( 1, BigInteger.ZERO, - prcBlake2FParamsParameters.getBlakeF(), + prcBlake2FParamsOobCall.getBlakeF(), BigInteger.ZERO, - prcBlake2FParamsParameters + prcBlake2FParamsOobCall .getBlakeF() - .multiply(prcBlake2FParamsParameters.getBlakeF())); + .multiply(prcBlake2FParamsOobCall.getBlakeF())); // Set ramSuccess final boolean ramSuccess = sufficientGas && fIsABit; - prcBlake2FParamsParameters.setSuccess(ramSuccess); + prcBlake2FParamsOobCall.setSuccess(ramSuccess); // Set returnGas final BigInteger returnGas = ramSuccess - ? (prcBlake2FParamsParameters + ? (prcBlake2FParamsOobCall .getCallGas() - .subtract(prcBlake2FParamsParameters.getBlakeR())) + .subtract(prcBlake2FParamsOobCall.getBlakeR())) : BigInteger.ZERO; - prcBlake2FParamsParameters.setReturnGas(returnGas); + prcBlake2FParamsOobCall.setReturnGas(returnGas); } @Override From 3d7ced4d6d3873b17ae85d588c677af06b5d3e3b Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 18 Jun 2024 17:36:19 +0200 Subject: [PATCH 117/461] feat(oob): update OobCall --- ...piOobParameters.java => JumpiOobCall.java} | 29 +++++-- ...meters.java => ReturnDataCopyOobCall.java} | 25 ++++-- ...eOobParameters.java => SstoreOobCall.java} | 21 +++-- ...llOobParameters.java => XCallOobCall.java} | 23 +++-- .../Blake2fCallDataSizeOobCall.java | 19 ++-- .../oob/precompiles/Blake2fParamsOobCall.java | 20 ++--- .../ModexpCallDataSizeOobCall.java | 20 ++--- .../oob/precompiles/ModexpExtractOobCall.java | 20 ++--- .../oob/precompiles/ModexpLeadOobCall.java | 20 ++--- .../oob/precompiles/ModexpPricingOobCall.java | 20 ++--- .../oob/precompiles/ModexpXbsOobCall.java | 20 ++--- .../precompiles/PrecompileCommonOobCall.java | 20 ++--- .../zktracer/module/oob/OobOperation.java | 86 ++++++++----------- 13 files changed, 189 insertions(+), 154 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/{JumpiOobParameters.java => JumpiOobCall.java} (78%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/{ReturnDataCopyOobParameters.java => ReturnDataCopyOobCall.java} (79%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/{SstoreOobParameters.java => SstoreOobCall.java} (76%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/{XCallOobParameters.java => XCallOobCall.java} (78%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java similarity index 78% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java index 146073aff7..0837e824ac 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java @@ -21,20 +21,20 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class JumpiOobParameters implements OobParameters { - private final EWord pcNew; - private final EWord jumpCondition; - private final BigInteger codeSize; - @Setter boolean jumpNotAttempted; - @Setter boolean jumpGuanranteedException; - @Setter boolean jumpMustBeAttempted; +@Setter +public class JumpiOobCall implements OobCall { + EWord pcNew; + EWord jumpCondition; + BigInteger codeSize; + boolean jumpNotAttempted; + boolean jumpGuanranteedException; + boolean jumpMustBeAttempted; public BigInteger pcNewHi() { return pcNew.hiBigInt(); @@ -52,6 +52,11 @@ public BigInteger jumpConditionLo() { return jumpCondition.loBigInt(); } + @Override + public int oobInstruction() { + return 0; + } + @Override public Trace trace(Trace trace) { return trace @@ -64,4 +69,10 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(jumpGuanranteedException)) .data8(booleanToBytes(jumpMustBeAttempted)); } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java similarity index 79% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java index 3ef00b326f..0ec13bbee9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java @@ -21,18 +21,18 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class ReturnDataCopyOobParameters implements OobParameters { - private final EWord offset; - private final EWord size; - private final BigInteger rds; - @Setter private boolean rdcx; +@Setter +public class ReturnDataCopyOobCall implements OobCall { + EWord offset; + EWord size; + BigInteger rds; + boolean rdcx; public BigInteger offsetHi() { return offset.hiBigInt(); @@ -50,6 +50,17 @@ public BigInteger sizeLo() { return size.loBigInt(); } + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + @Override public Trace trace(Trace trace) { return trace diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java similarity index 76% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java index 7d04fe36c3..c43046b628 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java @@ -21,15 +21,26 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; @Getter -@RequiredArgsConstructor -public class SstoreOobParameters implements OobParameters { - private final BigInteger gas; - @Setter boolean sstorex; +@Setter +public class SstoreOobCall implements OobCall { + BigInteger gas; + boolean sstorex; + + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } @Override public Trace trace(Trace trace) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java similarity index 78% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobParameters.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java index 106cf9722a..ed1756aba7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java @@ -21,17 +21,17 @@ import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter -@RequiredArgsConstructor -public class XCallOobParameters implements OobParameters { - private final EWord value; - @Setter boolean valueIsNonzero; - @Setter boolean valueIsZero; +@Setter +public class XCallOobCall implements OobCall { + EWord value; + boolean valueIsNonzero; + boolean valueIsZero; public BigInteger valueHi() { return value.hiBigInt(); @@ -41,6 +41,17 @@ public BigInteger valueLo() { return value.loBigInt(); } + @Override + public int oobInstruction() { + return 0; + } + + @Override + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { + return null; + } + @Override public Trace trace(Trace trace) { return trace diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java index 99a234e1a2..952f587bcb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -46,20 +46,21 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @Override public Trace trace(Trace trace) { return trace - .data1(ZERO) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) // Set after the constructor - .data5(ZERO) - .data6(Bytes.of(0)) - .data7(Bytes.of(0)) - .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + .data1(ZERO) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(returnAtCapacity)) + .data4(booleanToBytes(success)) // Set after the constructor + .data5(ZERO) + .data6(Bytes.of(0)) + .data7(Bytes.of(0)) + .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java index 204e6d8083..9b5fe12a4a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java @@ -47,21 +47,21 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @Override public Trace trace(Trace trace) { return trace - .data1(bigIntegerToBytes(callGas)) - .data2(ZERO) - .data3(ZERO) - .data4(booleanToBytes(success)) // Set after the constructor - .data5(bigIntegerToBytes(returnGas)) // Set after the constructor - .data6(bigIntegerToBytes(blakeR)) - .data7(bigIntegerToBytes(blakeF)) - .data8(ZERO); + .data1(bigIntegerToBytes(callGas)) + .data2(ZERO) + .data3(ZERO) + .data4(booleanToBytes(success)) // Set after the constructor + .data5(bigIntegerToBytes(returnGas)) // Set after the constructor + .data6(bigIntegerToBytes(blakeR)) + .data7(bigIntegerToBytes(blakeF)) + .data8(ZERO); } - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java index 46f701e632..287820c07a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java @@ -45,21 +45,21 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @Override public Trace trace(Trace trace) { return trace - .data1(ZERO) - .data2(bigIntegerToBytes(cds)) - .data3(booleanToBytes(extractBbs)) - .data4(booleanToBytes(extractEbs)) - .data5(booleanToBytes(extractMbs)) - .data6(ZERO) - .data7(ZERO) - .data8(ZERO); + .data1(ZERO) + .data2(bigIntegerToBytes(cds)) + .data3(booleanToBytes(extractBbs)) + .data4(booleanToBytes(extractEbs)) + .data5(booleanToBytes(extractMbs)) + .data6(ZERO) + .data7(ZERO) + .data8(ZERO); } - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java index 8a84fb4d95..8508214307 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java @@ -48,21 +48,21 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @Override public Trace trace(Trace trace) { return trace - .data1(ZERO) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(bbs)) - .data4(bigIntegerToBytes(ebs)) - .data5(bigIntegerToBytes(mbs)) - .data6(booleanToBytes(extractBase)) - .data7(booleanToBytes(extractExponent)) - .data8(booleanToBytes(extractModulus)); + .data1(ZERO) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(bbs)) + .data4(bigIntegerToBytes(ebs)) + .data5(bigIntegerToBytes(mbs)) + .data6(booleanToBytes(extractBase)) + .data7(booleanToBytes(extractExponent)) + .data8(booleanToBytes(extractModulus)); } - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java index 01c1332734..1c1b01708c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java @@ -49,21 +49,21 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @Override public Trace trace(Trace trace) { return trace - .data1(bigIntegerToBytes(bbs)) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(ebs)) - .data4(booleanToBytes(loadLead)) - .data5(ZERO) - .data6(Bytes.of(cdsCutoff)) - .data7(Bytes.of(ebsCutoff)) - .data8(Bytes.of(subEbs32)); + .data1(bigIntegerToBytes(bbs)) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(ebs)) + .data4(booleanToBytes(loadLead)) + .data5(ZERO) + .data6(Bytes.of(cdsCutoff)) + .data7(Bytes.of(ebsCutoff)) + .data8(Bytes.of(subEbs32)); } - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java index 37d5b0a47e..a0e8e6bfd6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java @@ -49,21 +49,21 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @Override public Trace trace(Trace trace) { return trace - .data1(bigIntegerToBytes(callGas)) - .data2(ZERO) - .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) - .data5(bigIntegerToBytes(returnGas)) - .data6(bigIntegerToBytes(exponentLog)) - .data7(Bytes.of(maxMbsBbs)) - .data8(booleanToBytes(returnAtCapacityNonZero)); + .data1(bigIntegerToBytes(callGas)) + .data2(ZERO) + .data3(bigIntegerToBytes(returnAtCapacity)) + .data4(booleanToBytes(success)) + .data5(bigIntegerToBytes(returnGas)) + .data6(bigIntegerToBytes(exponentLog)) + .data7(Bytes.of(maxMbsBbs)) + .data8(booleanToBytes(returnAtCapacityNonZero)); } - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java index 65b3e65534..92548decfd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java @@ -47,21 +47,21 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @Override public Trace trace(Trace trace) { return trace - .data1(bigIntegerToBytes(xbsHi)) - .data2(bigIntegerToBytes(xbsLo)) - .data3(bigIntegerToBytes(ybsLo)) - .data4(booleanToBytes(computeMax)) - .data5(ZERO) - .data6(ZERO) - .data7(bigIntegerToBytes(maxXbsYbs)) - .data8(booleanToBytes(xbsNonZero)); + .data1(bigIntegerToBytes(xbsHi)) + .data2(bigIntegerToBytes(xbsLo)) + .data3(bigIntegerToBytes(ybsLo)) + .data4(booleanToBytes(computeMax)) + .data5(ZERO) + .data6(ZERO) + .data7(bigIntegerToBytes(maxXbsYbs)) + .data8(booleanToBytes(xbsNonZero)); } - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java index 2911cabc72..f58b942705 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java @@ -47,7 +47,8 @@ public int oobInstruction() { } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace(net.consensys.linea.zktracer.module.hub.Trace trace) { + public net.consensys.linea.zktracer.module.hub.Trace trace( + net.consensys.linea.zktracer.module.hub.Trace trace) { return null; } @@ -56,14 +57,13 @@ public Trace trace(Trace trace) { boolean extractCallData = success && !cdsIsZero; boolean emptyCallData = success && cdsIsZero; return trace - .data1(bigIntegerToBytes(callGas)) - .data2(bigIntegerToBytes(cds)) - .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) // Set after the constructor - .data5(bigIntegerToBytes(returnGas)) // Set after the constructor - .data6(booleanToBytes(extractCallData)) // Derived from other parameters - .data7(booleanToBytes(emptyCallData)) // Derived from other parameters - .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + .data1(bigIntegerToBytes(callGas)) + .data2(bigIntegerToBytes(cds)) + .data3(bigIntegerToBytes(returnAtCapacity)) + .data4(booleanToBytes(success)) // Set after the constructor + .data5(bigIntegerToBytes(returnGas)) // Set after the constructor + .data6(booleanToBytes(extractCallData)) // Derived from other parameters + .data7(booleanToBytes(emptyCallData)) // Derived from other parameters + .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor } - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 3b8f041d9e..8310f788f8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -62,13 +62,12 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobParameters; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobParameters; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobParameters; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCallDataSizeOobCall; @@ -372,16 +371,16 @@ private void populateColumns(final MessageFrame frame) { oobCall = jumpOobCall; setJump(jumpOobCall); } else if (isJumpi) { - JumpiOobParameters jumpiOobParameters = - new JumpiOobParameters( + JumpiOobCall jumpiOobCall = + new JumpiOobCall( EWord.of(frame.getStackItem(0)), EWord.of(frame.getStackItem(1)), BigInteger.valueOf(frame.getCode().getSize())); - oobParameters = jumpiOobParameters; - setJumpi(jumpiOobParameters); + oobParameters = jumpiOobCall; + setJumpi(jumpiOobCall); } else if (isRdc) { - ReturnDataCopyOobParameters rdcOobParameters = - new ReturnDataCopyOobParameters( + ReturnDataCopyOobCall rdcOobParameters = + new ReturnDataCopyOobCall( EWord.of(frame.getStackItem(1)), EWord.of(frame.getStackItem(2)), BigInteger.valueOf(frame.getReturnData().size())); @@ -394,11 +393,11 @@ private void populateColumns(final MessageFrame frame) { oobParameters = cdlOobParameters; setCdl(cdlOobParameters); } else if (isSstore) { - final SstoreOobParameters sstoreOobParameters = - new SstoreOobParameters(BigInteger.valueOf(frame.getRemainingGas())); + final SstoreOobCall sstoreOobCall = + new SstoreOobCall(BigInteger.valueOf(frame.getRemainingGas())); - oobParameters = sstoreOobParameters; - setSstore(sstoreOobParameters); + oobParameters = sstoreOobCall; + setSstore(sstoreOobCall); } else if (isDeployment) { final DeploymentOobCall deploymentOobCall = new DeploymentOobCall(EWord.of(frame.getStackItem(0))); @@ -406,10 +405,9 @@ private void populateColumns(final MessageFrame frame) { oobParameters = deploymentOobCall; setDeployment(deploymentOobCall); } else if (isXCall) { - XCallOobParameters xCallOobParameters = - new XCallOobParameters(EWord.of(frame.getStackItem(2))); - oobParameters = xCallOobParameters; - setXCall(xCallOobParameters); + XCallOobCall xCallOobCall = new XCallOobCall(EWord.of(frame.getStackItem(2))); + oobParameters = xCallOobCall; + setXCall(xCallOobCall); } else if (isCall) { final Account callerAccount = frame.getWorldUpdater().get(frame.getRecipientAddress()); // DELEGATECALL, STATICCALL cases @@ -566,8 +564,7 @@ private void populateColumns(final MessageFrame frame) { oobParameters = prcModexpXbsOobCall; setModexpXbs(prcModexpXbsOobCall); } else if (isModexpLead) { - final ModexpLeadOobCall prcModexpLeadOobCall = - new ModexpLeadOobCall(bbs, cds, ebs); + final ModexpLeadOobCall prcModexpLeadOobCall = new ModexpLeadOobCall(bbs, cds, ebs); oobParameters = prcModexpLeadOobCall; setModexpLead(prcModexpLeadOobCall); @@ -763,31 +760,31 @@ private void setJump(JumpOobCall jumpOobCall) { jumpOobCall.setJumpMustBeAttempted(validPcNew); } - private void setJumpi(JumpiOobParameters jumpiOobParameters) { + private void setJumpi(JumpiOobCall jumpiOobCall) { // row i final boolean validPcNew = callToLT( 0, - jumpiOobParameters.pcNewHi(), - jumpiOobParameters.pcNewLo(), + jumpiOobCall.pcNewHi(), + jumpiOobCall.pcNewLo(), BigInteger.ZERO, - jumpiOobParameters.getCodeSize()); + jumpiOobCall.getCodeSize()); // row i + 1 final boolean jumpCondIsZero = - callToISZERO(1, jumpiOobParameters.jumpConditionHi(), jumpiOobParameters.jumpConditionLo()); + callToISZERO(1, jumpiOobCall.jumpConditionHi(), jumpiOobCall.jumpConditionLo()); // Set jumpNotAttempted - jumpiOobParameters.setJumpNotAttempted(jumpCondIsZero); + jumpiOobCall.setJumpNotAttempted(jumpCondIsZero); // Set jumpGuaranteedException - jumpiOobParameters.setJumpGuanranteedException(!jumpCondIsZero && !validPcNew); + jumpiOobCall.setJumpGuanranteedException(!jumpCondIsZero && !validPcNew); // Set jumpMustBeAttempted - jumpiOobParameters.setJumpMustBeAttempted(!jumpCondIsZero && validPcNew); + jumpiOobCall.setJumpMustBeAttempted(!jumpCondIsZero && validPcNew); } - private void setRdc(ReturnDataCopyOobParameters rdcOobParameters) { + private void setRdc(ReturnDataCopyOobCall rdcOobParameters) { // row i final boolean rdcRoob = !callToISZERO(0, rdcOobParameters.offsetHi(), rdcOobParameters.sizeHi()); @@ -838,7 +835,7 @@ private void setCdl(CallDataLoadOobCall cdlOobParameters) { cdlOobParameters.setCdlOutOfBounds(!touchesRam); } - private void setSstore(SstoreOobParameters sstoreOobParameters) { + private void setSstore(SstoreOobCall sstoreOobCall) { // row i final boolean sufficientGas = callToLT( @@ -846,10 +843,10 @@ private void setSstore(SstoreOobParameters sstoreOobParameters) { BigInteger.ZERO, BigInteger.valueOf(GAS_CONST_G_CALL_STIPEND), BigInteger.ZERO, - sstoreOobParameters.getGas()); + sstoreOobCall.getGas()); // Set sstorex - sstoreOobParameters.setSstorex(!sufficientGas); + sstoreOobCall.setSstorex(!sufficientGas); } private void setDeployment(DeploymentOobCall deploymentOobCall) { @@ -866,16 +863,15 @@ private void setDeployment(DeploymentOobCall deploymentOobCall) { deploymentOobCall.setMaxCodeSizeException(exceedsMaxCodeSize); } - private void setXCall(XCallOobParameters xCallOobParameters) { + private void setXCall(XCallOobCall xCallOobCall) { // row i - boolean valueIsZero = - callToISZERO(0, xCallOobParameters.valueHi(), xCallOobParameters.valueLo()); + boolean valueIsZero = callToISZERO(0, xCallOobCall.valueHi(), xCallOobCall.valueLo()); // Set valueIsNonzero - xCallOobParameters.setValueIsNonzero(!valueIsZero); + xCallOobCall.setValueIsNonzero(!valueIsZero); // Set valueIsZero - xCallOobParameters.setValueIsZero(valueIsZero); + xCallOobCall.setValueIsZero(valueIsZero); } private void setCall(CallOobCall callOobParameters) { @@ -953,8 +949,7 @@ private void setPrecompile(PrecompileCommonOobCall prcOobParameters) { prcOobParameters.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); } - private void setPrcEcRecoverPrcEcaddPrcEcmul( - PrecompileCommonOobCall prcCommonOobParameters) { + private void setPrcEcRecoverPrcEcaddPrcEcmul(PrecompileCommonOobCall prcCommonOobParameters) { precompileCost = BigInteger.valueOf( 3000L * booleanToInt(isEcRecover) @@ -980,8 +975,7 @@ private void setPrcEcRecoverPrcEcaddPrcEcmul( prcCommonOobParameters.setReturnGas(returnGas); } - private void setPrcSha2PrcRipemdPrcIdentity( - PrecompileCommonOobCall prcCommonOobParameters) { + private void setPrcSha2PrcRipemdPrcIdentity(PrecompileCommonOobCall prcCommonOobParameters) { // row i + 2 final BigInteger ceil = callToDIV( @@ -1326,9 +1320,7 @@ private void setBlake2FParams(Blake2fParamsOobCall prcBlake2FParamsOobCall) { BigInteger.ZERO, prcBlake2FParamsOobCall.getBlakeF(), BigInteger.ZERO, - prcBlake2FParamsOobCall - .getBlakeF() - .multiply(prcBlake2FParamsOobCall.getBlakeF())); + prcBlake2FParamsOobCall.getBlakeF().multiply(prcBlake2FParamsOobCall.getBlakeF())); // Set ramSuccess final boolean ramSuccess = sufficientGas && fIsABit; @@ -1337,9 +1329,7 @@ private void setBlake2FParams(Blake2fParamsOobCall prcBlake2FParamsOobCall) { // Set returnGas final BigInteger returnGas = ramSuccess - ? (prcBlake2FParamsOobCall - .getCallGas() - .subtract(prcBlake2FParamsOobCall.getBlakeR())) + ? (prcBlake2FParamsOobCall.getCallGas().subtract(prcBlake2FParamsOobCall.getBlakeR())) : BigInteger.ZERO; prcBlake2FParamsOobCall.setReturnGas(returnGas); From ad07a44b981a32b170982c82262d36a6ab812911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 18:36:00 +0200 Subject: [PATCH 118/461] update of OOB tracers --- .../call/oob/opcodes/CallDataLoadOobCall.java | 29 +++++++---- .../imc/call/oob/opcodes/CallOobCall.java | 29 +++++++---- .../imc/call/oob/opcodes/CreateOobCall.java | 29 +++++++---- .../call/oob/opcodes/DeploymentOobCall.java | 29 +++++++---- .../imc/call/oob/opcodes/JumpOobCall.java | 4 +- .../imc/call/oob/opcodes/JumpiOobCall.java | 27 +++++++--- .../oob/opcodes/ReturnDataCopyOobCall.java | 29 +++++++---- .../imc/call/oob/opcodes/SstoreOobCall.java | 29 +++++++---- .../imc/call/oob/opcodes/XCallOobCall.java | 29 +++++++---- .../Blake2fCallDataSizeOobCall.java | 29 +++++++---- .../oob/precompiles/Blake2fParamsOobCall.java | 29 +++++++---- .../ModexpCallDataSizeOobCall.java | 29 +++++++---- .../oob/precompiles/ModexpExtractOobCall.java | 29 +++++++---- .../oob/precompiles/ModexpLeadOobCall.java | 29 +++++++---- .../oob/precompiles/ModexpPricingOobCall.java | 29 +++++++---- .../oob/precompiles/ModexpXbsOobCall.java | 29 +++++++---- .../precompiles/PrecompileCommonOobCall.java | 50 ++++++++++++++----- 17 files changed, 339 insertions(+), 148 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java index 8fdf55dc6c..4ebf87cb98 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.txndata.Trace.OOB_INST_CDL; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter @@ -43,17 +44,12 @@ public BigInteger offsetLo() { @Override public int oobInstruction() { - return 0; + return OOB_INST_CDL; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(offsetHi())) .data2(bigIntegerToBytes(offsetLo())) @@ -64,4 +60,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(cdlOutOfBounds)) .data8(ZERO); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(offsetHi())) + .pMiscOobData2(bigIntegerToBytes(offsetLo())) + .pMiscOobData3(ZERO) + .pMiscOobData4(ZERO) + .pMiscOobData5(bigIntegerToBytes(cds)) + .pMiscOobData6(ZERO) + .pMiscOobData7(booleanToBytes(cdlOutOfBounds)) + .pMiscOobData8(ZERO); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java index d33eba265e..10e3647870 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CALL; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter @@ -45,17 +46,12 @@ public BigInteger valueLo() { @Override public int oobInstruction() { - return 0; + return OOB_INST_CALL; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(valueHi())) .data2(bigIntegerToBytes(valueLo())) @@ -66,4 +62,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(valueIsNonzero)) .data8(booleanToBytes(abortingCondition)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(valueHi())) + .pMiscOobData2(bigIntegerToBytes(valueLo())) + .pMiscOobData3(bigIntegerToBytes(balance)) + .pMiscOobData4(ZERO) + .pMiscOobData5(ZERO) + .pMiscOobData6(bigIntegerToBytes(callStackDepth)) + .pMiscOobData7(booleanToBytes(valueIsNonzero)) + .pMiscOobData8(booleanToBytes(abortingCondition)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java index b90b2bdacb..3391b1122c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter @@ -47,17 +48,12 @@ public BigInteger valueLo() { @Override public int oobInstruction() { - return 0; + return OOB_INST_CREATE; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(valueHi())) .data2(bigIntegerToBytes(valueLo())) @@ -68,4 +64,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(abortingCondition)) .data8(booleanToBytes(failureCondition)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(valueHi())) + .pMiscOobData2(bigIntegerToBytes(valueLo())) + .pMiscOobData3(bigIntegerToBytes(balance)) + .pMiscOobData4(bigIntegerToBytes(nonce)) + .pMiscOobData5(booleanToBytes(hasCode)) + .pMiscOobData6(bigIntegerToBytes(callStackDepth)) + .pMiscOobData7(booleanToBytes(abortingCondition)) + .pMiscOobData8(booleanToBytes(failureCondition)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java index 3d1cd2f0fc..b1cfc6fce6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_DEPLOYMENT; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter @@ -42,17 +43,12 @@ public BigInteger sizeLo() { @Override public int oobInstruction() { - return 0; + return OOB_INST_DEPLOYMENT; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(sizeHi())) .data2(bigIntegerToBytes(sizeLo())) @@ -63,4 +59,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(maxCodeSizeException)) .data8(ZERO); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(sizeHi())) + .pMiscOobData2(bigIntegerToBytes(sizeLo())) + .pMiscOobData3(ZERO) + .pMiscOobData4(ZERO) + .pMiscOobData5(ZERO) + .pMiscOobData6(ZERO) + .pMiscOobData7(booleanToBytes(maxCodeSizeException)) + .pMiscOobData8(ZERO); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java index f21a7db110..89d704e425 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java @@ -66,6 +66,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) .pMiscOobData1(bigIntegerToBytes(pcNewHi())) .pMiscOobData2(bigIntegerToBytes(pcNewLo())) .pMiscOobData3(ZERO) @@ -73,7 +74,6 @@ public Trace trace(Trace trace) { .pMiscOobData5(bigIntegerToBytes(codeSize)) .pMiscOobData6(ZERO) .pMiscOobData7(booleanToBytes(jumpGuaranteedException)) - .pMiscOobData8(booleanToBytes(jumpMustBeAttempted)) - .pMiscOobInst(OOB_INST_JUMP); + .pMiscOobData8(booleanToBytes(jumpMustBeAttempted)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java index 0837e824ac..3408d95829 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMPI; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter @@ -54,11 +55,27 @@ public BigInteger jumpConditionLo() { @Override public int oobInstruction() { - return 0; + return OOB_INST_JUMPI; } @Override public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(pcNewHi())) + .pMiscOobData2(bigIntegerToBytes(pcNewLo())) + .pMiscOobData3(bigIntegerToBytes(jumpConditionHi())) + .pMiscOobData4(bigIntegerToBytes(jumpConditionLo())) + .pMiscOobData5(bigIntegerToBytes(codeSize)) + .pMiscOobData6(booleanToBytes(jumpNotAttempted)) + .pMiscOobData7(booleanToBytes(jumpGuanranteedException)) + .pMiscOobData8(booleanToBytes(jumpMustBeAttempted)); + } + + @Override + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(pcNewHi())) .data2(bigIntegerToBytes(pcNewLo())) @@ -69,10 +86,4 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(jumpGuanranteedException)) .data8(booleanToBytes(jumpMustBeAttempted)); } - - @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java index 0ec13bbee9..baf314ed1b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RDC; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter @@ -52,17 +53,12 @@ public BigInteger sizeLo() { @Override public int oobInstruction() { - return 0; + return OOB_INST_RDC; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(offsetHi())) .data2(bigIntegerToBytes(offsetLo())) @@ -73,4 +69,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(rdcx)) .data8(ZERO); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(offsetHi())) + .pMiscOobData2(bigIntegerToBytes(offsetLo())) + .pMiscOobData3(bigIntegerToBytes(sizeHi())) + .pMiscOobData4(bigIntegerToBytes(sizeLo())) + .pMiscOobData5(bigIntegerToBytes(rds)) + .pMiscOobData6(ZERO) + .pMiscOobData7(booleanToBytes(rdcx)) + .pMiscOobData8(ZERO); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java index c43046b628..9f60f435d0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SSTORE; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; @Getter @Setter @@ -33,17 +34,12 @@ public class SstoreOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_SSTORE; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(ZERO) .data2(ZERO) @@ -54,4 +50,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(sstorex)) .data8(ZERO); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(ZERO) + .pMiscOobData2(ZERO) + .pMiscOobData3(ZERO) + .pMiscOobData4(ZERO) + .pMiscOobData5(bigIntegerToBytes(gas)) + .pMiscOobData6(ZERO) + .pMiscOobData7(booleanToBytes(sstorex)) + .pMiscOobData8(ZERO); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java index ed1756aba7..b0cd852e29 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_XCALL; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -22,8 +23,8 @@ import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.oob.Trace; import net.consensys.linea.zktracer.types.EWord; @Getter @@ -43,17 +44,12 @@ public BigInteger valueLo() { @Override public int oobInstruction() { - return 0; + return OOB_INST_XCALL; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(valueHi())) .data2(bigIntegerToBytes(valueLo())) @@ -64,4 +60,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(valueIsNonzero)) .data8(booleanToBytes(valueIsZero)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(valueHi())) + .pMiscOobData2(bigIntegerToBytes(valueLo())) + .pMiscOobData3(ZERO) + .pMiscOobData4(ZERO) + .pMiscOobData5(ZERO) + .pMiscOobData6(ZERO) + .pMiscOobData7(booleanToBytes(valueIsNonzero)) + .pMiscOobData8(booleanToBytes(valueIsZero)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java index 952f587bcb..1241486d54 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; import org.apache.tuweni.bytes.Bytes; @Getter @@ -42,17 +43,12 @@ public class Blake2fCallDataSizeOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_BLAKE_CDS; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(ZERO) .data2(bigIntegerToBytes(cds)) @@ -63,4 +59,19 @@ public Trace trace(Trace trace) { .data7(Bytes.of(0)) .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(ZERO) + .pMiscOobData2(bigIntegerToBytes(cds)) + .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) + .pMiscOobData4(booleanToBytes(success)) // Set after the constructor + .pMiscOobData5(ZERO) + .pMiscOobData6(Bytes.of(0)) + .pMiscOobData7(Bytes.of(0)) + .pMiscOobData8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java index 9b5fe12a4a..d8053f83cd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; @Getter @Setter @@ -43,17 +44,12 @@ public class Blake2fParamsOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_BLAKE_PARAMS; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(callGas)) .data2(ZERO) @@ -64,4 +60,19 @@ public Trace trace(Trace trace) { .data7(bigIntegerToBytes(blakeF)) .data8(ZERO); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(callGas)) + .pMiscOobData2(ZERO) + .pMiscOobData3(ZERO) + .pMiscOobData4(booleanToBytes(success)) // Set after the constructor + .pMiscOobData5(bigIntegerToBytes(returnGas)) // Set after the constructor + .pMiscOobData6(bigIntegerToBytes(blakeR)) + .pMiscOobData7(bigIntegerToBytes(blakeF)) + .pMiscOobData8(ZERO); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java index 287820c07a..97c3a3bcff 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; @Getter @Setter @@ -41,17 +42,12 @@ public class ModexpCallDataSizeOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_MODEXP_CDS; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(ZERO) .data2(bigIntegerToBytes(cds)) @@ -62,4 +58,19 @@ public Trace trace(Trace trace) { .data7(ZERO) .data8(ZERO); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(ZERO) + .pMiscOobData2(bigIntegerToBytes(cds)) + .pMiscOobData3(booleanToBytes(extractBbs)) + .pMiscOobData4(booleanToBytes(extractEbs)) + .pMiscOobData5(booleanToBytes(extractMbs)) + .pMiscOobData6(ZERO) + .pMiscOobData7(ZERO) + .pMiscOobData8(ZERO); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java index 8508214307..157d132857 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; @Getter @Setter @@ -44,17 +45,12 @@ public class ModexpExtractOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_MODEXP_EXTRACT; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(ZERO) .data2(bigIntegerToBytes(cds)) @@ -65,4 +61,19 @@ public Trace trace(Trace trace) { .data7(booleanToBytes(extractExponent)) .data8(booleanToBytes(extractModulus)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(ZERO) + .pMiscOobData2(bigIntegerToBytes(cds)) + .pMiscOobData3(bigIntegerToBytes(bbs)) + .pMiscOobData4(bigIntegerToBytes(ebs)) + .pMiscOobData5(bigIntegerToBytes(mbs)) + .pMiscOobData6(booleanToBytes(extractBase)) + .pMiscOobData7(booleanToBytes(extractExponent)) + .pMiscOobData8(booleanToBytes(extractModulus)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java index 1c1b01708c..c5edb7a71d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; import org.apache.tuweni.bytes.Bytes; @Getter @@ -45,17 +46,12 @@ public class ModexpLeadOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_MODEXP_LEAD; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(bbs)) .data2(bigIntegerToBytes(cds)) @@ -66,4 +62,19 @@ public Trace trace(Trace trace) { .data7(Bytes.of(ebsCutoff)) .data8(Bytes.of(subEbs32)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(bbs)) + .pMiscOobData2(bigIntegerToBytes(cds)) + .pMiscOobData3(bigIntegerToBytes(ebs)) + .pMiscOobData4(booleanToBytes(loadLead)) + .pMiscOobData5(ZERO) + .pMiscOobData6(Bytes.of(cdsCutoff)) + .pMiscOobData7(Bytes.of(ebsCutoff)) + .pMiscOobData8(Bytes.of(subEbs32)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java index a0e8e6bfd6..0e9698acda 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; import org.apache.tuweni.bytes.Bytes; @Getter @@ -45,17 +46,12 @@ public class ModexpPricingOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_MODEXP_PRICING; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(callGas)) .data2(ZERO) @@ -66,4 +62,19 @@ public Trace trace(Trace trace) { .data7(Bytes.of(maxMbsBbs)) .data8(booleanToBytes(returnAtCapacityNonZero)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(callGas)) + .pMiscOobData2(ZERO) + .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) + .pMiscOobData4(booleanToBytes(success)) + .pMiscOobData5(bigIntegerToBytes(returnGas)) + .pMiscOobData6(bigIntegerToBytes(exponentLog)) + .pMiscOobData7(Bytes.of(maxMbsBbs)) + .pMiscOobData8(booleanToBytes(returnAtCapacityNonZero)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java index 92548decfd..20c0d107e0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; @Getter @Setter @@ -43,17 +44,12 @@ public class ModexpXbsOobCall implements OobCall { @Override public int oobInstruction() { - return 0; + return OOB_INST_MODEXP_XBS; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; - } - - @Override - public Trace trace(Trace trace) { + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(xbsHi)) .data2(bigIntegerToBytes(xbsLo)) @@ -64,4 +60,19 @@ public Trace trace(Trace trace) { .data7(bigIntegerToBytes(maxXbsYbs)) .data8(booleanToBytes(xbsNonZero)); } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(xbsHi)) + .pMiscOobData2(bigIntegerToBytes(xbsLo)) + .pMiscOobData3(bigIntegerToBytes(ybsLo)) + .pMiscOobData4(booleanToBytes(computeMax)) + .pMiscOobData5(ZERO) + .pMiscOobData6(ZERO) + .pMiscOobData7(bigIntegerToBytes(maxXbsYbs)) + .pMiscOobData8(booleanToBytes(xbsNonZero)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java index f58b942705..2fb0cbf802 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -23,9 +24,9 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.oob.Trace; @Getter @Setter @@ -41,29 +42,54 @@ public class PrecompileCommonOobCall implements OobCall { boolean returnAtCapacityNonZero; boolean cdsIsZero; // Necessary to compute extractCallData and emptyCallData - @Override - public int oobInstruction() { - return 0; + public boolean getExtractCallData() { + return success && !cdsIsZero; + } + + public boolean getCallDataIsEmpty() { + return success && cdsIsZero; } @Override - public net.consensys.linea.zktracer.module.hub.Trace trace( - net.consensys.linea.zktracer.module.hub.Trace trace) { - return null; + public int oobInstruction() { + return switch (p.precompile().address.toInt()) { + case 1 -> OOB_INST_ECRECOVER; + case 2 -> OOB_INST_SHA2; + case 3 -> OOB_INST_RIPEMD; + case 4 -> OOB_INST_IDENTITY; + case 6 -> OOB_INST_ECADD; + case 7 -> OOB_INST_ECMUL; + case 8 -> OOB_INST_ECPAIRING; + default -> throw new RuntimeException("precompile not 'common'"); + }; } @Override - public Trace trace(Trace trace) { - boolean extractCallData = success && !cdsIsZero; - boolean emptyCallData = success && cdsIsZero; + public net.consensys.linea.zktracer.module.oob.Trace trace( + net.consensys.linea.zktracer.module.oob.Trace trace) { return trace .data1(bigIntegerToBytes(callGas)) .data2(bigIntegerToBytes(cds)) .data3(bigIntegerToBytes(returnAtCapacity)) .data4(booleanToBytes(success)) // Set after the constructor .data5(bigIntegerToBytes(returnGas)) // Set after the constructor - .data6(booleanToBytes(extractCallData)) // Derived from other parameters - .data7(booleanToBytes(emptyCallData)) // Derived from other parameters + .data6(booleanToBytes(getExtractCallData())) // Derived from other parameters + .data7(booleanToBytes(getCallDataIsEmpty())) // Derived from other parameters .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor } + + @Override + public Trace trace(Trace trace) { + return trace + .pMiscOobFlag(true) + .pMiscOobInst(oobInstruction()) + .pMiscOobData1(bigIntegerToBytes(callGas)) + .pMiscOobData2(bigIntegerToBytes(cds)) + .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) + .pMiscOobData4(booleanToBytes(success)) // Set after the constructor + .pMiscOobData5(bigIntegerToBytes(returnGas)) // Set after the constructor + .pMiscOobData6(booleanToBytes(getExtractCallData())) // Derived from other parameters + .pMiscOobData7(booleanToBytes(getCallDataIsEmpty())) // Derived from other parameters + .pMiscOobData8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + } } From 6b75d993d71dedfe504e6cd627e22a42598596e6 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 18 Jun 2024 18:51:18 +0200 Subject: [PATCH 119/461] updated OobOperation wrt to OobCall for precompioles --- .../linea/zktracer/module/oob/Oob.java | 2 +- .../zktracer/module/oob/OobOperation.java | 152 ++++++++---------- 2 files changed, 68 insertions(+), 86 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 20671616c6..c24e8c0954 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -108,7 +108,7 @@ final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { int nRows = chunk.nRows(); for (int ct = 0; ct < nRows; ct++) { - trace = chunk.getOobParameters().trace(trace); + trace = chunk.getOobCall().trace(trace); // Note: if a value is bigger than 128, do not use Bytes.of and use Bytes.ofUnsignedType // instead (according to size) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 8310f788f8..e221f6d122 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -62,6 +62,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; @@ -91,9 +92,7 @@ @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) public class OobOperation extends ModuleOperation { @EqualsAndHashCode.Include private BigInteger oobInst; - @EqualsAndHashCode.Include private OobParameters oobParameters; - - @Setter OobCall oobCall; + @EqualsAndHashCode.Include @Setter private OobCall oobCall; private boolean isJump; private boolean isJumpi; @@ -371,42 +370,39 @@ private void populateColumns(final MessageFrame frame) { oobCall = jumpOobCall; setJump(jumpOobCall); } else if (isJumpi) { - JumpiOobCall jumpiOobCall = - new JumpiOobCall( - EWord.of(frame.getStackItem(0)), - EWord.of(frame.getStackItem(1)), - BigInteger.valueOf(frame.getCode().getSize())); - oobParameters = jumpiOobCall; + JumpiOobCall jumpiOobCall = (JumpiOobCall) oobCall; + jumpiOobCall.setPcNew(EWord.of(frame.getStackItem(0))); + jumpiOobCall.setJumpCondition(EWord.of(frame.getStackItem(1))); + jumpiOobCall.setCodeSize(BigInteger.valueOf(frame.getCode().getSize())); + oobCall = jumpiOobCall; setJumpi(jumpiOobCall); } else if (isRdc) { - ReturnDataCopyOobCall rdcOobParameters = - new ReturnDataCopyOobCall( - EWord.of(frame.getStackItem(1)), - EWord.of(frame.getStackItem(2)), - BigInteger.valueOf(frame.getReturnData().size())); - oobParameters = rdcOobParameters; - setRdc(rdcOobParameters); + ReturnDataCopyOobCall rdcOobCall = (ReturnDataCopyOobCall) oobCall; + rdcOobCall.setOffset(EWord.of(frame.getStackItem(0))); + rdcOobCall.setSize(EWord.of(frame.getStackItem(1))); + rdcOobCall.setRds(BigInteger.valueOf(frame.getReturnData().size())); + oobCall = rdcOobCall; + setRdc(rdcOobCall); } else if (isCdl) { - CallDataLoadOobCall cdlOobParameters = - new CallDataLoadOobCall( - EWord.of(frame.getStackItem(0)), BigInteger.valueOf(frame.getInputData().size())); - oobParameters = cdlOobParameters; - setCdl(cdlOobParameters); + CallDataLoadOobCall cdlOobCall = (CallDataLoadOobCall) oobCall; + cdlOobCall.setOffset(EWord.of(frame.getStackItem(0))); + cdlOobCall.setCds(BigInteger.valueOf(frame.getInputData().size())); + oobCall = cdlOobCall; + setCdl(cdlOobCall); } else if (isSstore) { - final SstoreOobCall sstoreOobCall = - new SstoreOobCall(BigInteger.valueOf(frame.getRemainingGas())); - - oobParameters = sstoreOobCall; + final SstoreOobCall sstoreOobCall = (SstoreOobCall) oobCall; + sstoreOobCall.setGas(BigInteger.valueOf(frame.getRemainingGas())); + oobCall = sstoreOobCall; setSstore(sstoreOobCall); } else if (isDeployment) { - final DeploymentOobCall deploymentOobCall = - new DeploymentOobCall(EWord.of(frame.getStackItem(0))); - - oobParameters = deploymentOobCall; + final DeploymentOobCall deploymentOobCall = (DeploymentOobCall) oobCall; + deploymentOobCall.setSize(EWord.of(frame.getStackItem(0))); + oobCall = deploymentOobCall; setDeployment(deploymentOobCall); } else if (isXCall) { - XCallOobCall xCallOobCall = new XCallOobCall(EWord.of(frame.getStackItem(2))); - oobParameters = xCallOobCall; + XCallOobCall xCallOobCall = (XCallOobCall) oobCall; + xCallOobCall.setValue(EWord.of(frame.getStackItem(2))); + oobCall = xCallOobCall; setXCall(xCallOobCall); } else if (isCall) { final Account callerAccount = frame.getWorldUpdater().get(frame.getRecipientAddress()); @@ -418,13 +414,12 @@ private void populateColumns(final MessageFrame frame) { value = EWord.of(frame.getStackItem(2)); nonZeroValue = !frame.getStackItem(2).isZero(); } - CallOobCall callOobParameters = - new CallOobCall( - value, - callerAccount.getBalance().toUnsignedBigInteger(), // balance (caller address) - BigInteger.valueOf(frame.getDepth())); - oobParameters = callOobParameters; - setCall(callOobParameters); + CallOobCall callOobCall = (CallOobCall) oobCall; + callOobCall.setValue(value); + callOobCall.setBalance(callerAccount.getBalance().toUnsignedBigInteger()); + callOobCall.setCallStackDepth(BigInteger.valueOf(frame.getDepth())); + oobCall = callOobCall; + setCall(callOobCall); } else if (isCreate) { final Account creatorAccount = frame.getWorldUpdater().get(frame.getRecipientAddress()); final Address deploymentAddress = getDeploymentAddress(frame); @@ -437,16 +432,14 @@ private void populateColumns(final MessageFrame frame) { hasCode = deployedAccount.hasCode(); } - final CreateOobParameters createOobParameters = - new CreateOobParameters( - EWord.of(frame.getStackItem(0)), - creatorAccount.getBalance().toUnsignedBigInteger(), // balance (creator address) - BigInteger.valueOf(nonce), // nonce (deployment address) - hasCode, // has_code (deployment address) - BigInteger.valueOf(frame.getDepth())); - - oobParameters = createOobParameters; - setCreate(createOobParameters); + final CreateOobCall createOobCall = (CreateOobCall) oobCall; + createOobCall.setValue(EWord.of(frame.getStackItem(0))); + createOobCall.setBalance(creatorAccount.getBalance().toUnsignedBigInteger()); + createOobCall.setNonce(BigInteger.valueOf(nonce)); + createOobCall.setHasCode(hasCode); + createOobCall.setCallStackDepth(BigInteger.valueOf(frame.getDepth())); + oobCall = createOobCall; + setCreate(createOobCall); } } else if (isPrecompile()) { // DELEGATECALL, STATICCALL cases @@ -784,24 +777,18 @@ private void setJumpi(JumpiOobCall jumpiOobCall) { jumpiOobCall.setJumpMustBeAttempted(!jumpCondIsZero && validPcNew); } - private void setRdc(ReturnDataCopyOobCall rdcOobParameters) { + private void setRdc(ReturnDataCopyOobCall rdcOobCall) { // row i - final boolean rdcRoob = - !callToISZERO(0, rdcOobParameters.offsetHi(), rdcOobParameters.sizeHi()); + final boolean rdcRoob = !callToISZERO(0, rdcOobCall.offsetHi(), rdcOobCall.sizeHi()); // row i + 1 if (!rdcRoob) { - callToADD( - 1, - BigInteger.ZERO, - rdcOobParameters.offsetLo(), - BigInteger.ZERO, - rdcOobParameters.sizeLo()); + callToADD(1, BigInteger.ZERO, rdcOobCall.offsetLo(), BigInteger.ZERO, rdcOobCall.sizeLo()); } else { noCall(1); } final BigInteger sum = - addFlag[1] ? rdcOobParameters.offsetLo().add(rdcOobParameters.sizeLo()) : BigInteger.ZERO; + addFlag[1] ? rdcOobCall.offsetLo().add(rdcOobCall.sizeLo()) : BigInteger.ZERO; // row i + 2 boolean rdcSoob = false; @@ -812,27 +799,23 @@ private void setRdc(ReturnDataCopyOobCall rdcOobParameters) { EWord.of(sum).hiBigInt(), EWord.of(sum).loBigInt(), BigInteger.ZERO, - rdcOobParameters.getRds()); + rdcOobCall.getRds()); } else { noCall(2); } // Set rdcx - rdcOobParameters.setRdcx(rdcRoob || rdcSoob); + rdcOobCall.setRdcx(rdcRoob || rdcSoob); } - private void setCdl(CallDataLoadOobCall cdlOobParameters) { + private void setCdl(CallDataLoadOobCall cdlOobCall) { // row i final boolean touchesRam = callToLT( - 0, - cdlOobParameters.offsetHi(), - cdlOobParameters.offsetLo(), - BigInteger.ZERO, - cdlOobParameters.getCds()); + 0, cdlOobCall.offsetHi(), cdlOobCall.offsetLo(), BigInteger.ZERO, cdlOobCall.getCds()); // Set cdlOutOfBounds - cdlOobParameters.setCdlOutOfBounds(!touchesRam); + cdlOobCall.setCdlOutOfBounds(!touchesRam); } private void setSstore(SstoreOobCall sstoreOobCall) { @@ -874,64 +857,63 @@ private void setXCall(XCallOobCall xCallOobCall) { xCallOobCall.setValueIsZero(valueIsZero); } - private void setCall(CallOobCall callOobParameters) { + private void setCall(CallOobCall callOobCall) { // row i boolean insufficientBalanceAbort = callToLT( 0, BigInteger.ZERO, - callOobParameters.getBalance(), - callOobParameters.valueHi(), - callOobParameters.valueLo()); + callOobCall.getBalance(), + callOobCall.valueHi(), + callOobCall.valueLo()); // row i + 1 final boolean callStackDepthAbort = !callToLT( 1, BigInteger.ZERO, - callOobParameters.getCallStackDepth(), + callOobCall.getCallStackDepth(), BigInteger.ZERO, BigInteger.valueOf(1024)); // row i + 2 - boolean valueIsZero = callToISZERO(2, callOobParameters.valueHi(), callOobParameters.valueLo()); + boolean valueIsZero = callToISZERO(2, callOobCall.valueHi(), callOobCall.valueLo()); // Set valueIsNonzero - callOobParameters.setValueIsNonzero(!valueIsZero); + callOobCall.setValueIsNonzero(!valueIsZero); // Set abortingCondition - callOobParameters.setAbortingCondition(insufficientBalanceAbort || callStackDepthAbort); + callOobCall.setAbortingCondition(insufficientBalanceAbort || callStackDepthAbort); } - private void setCreate(CreateOobParameters createOobParameters) { + private void setCreate(CreateOobCall createOobCall) { // row i final boolean insufficientBalanceAbort = callToLT( 0, BigInteger.ZERO, - createOobParameters.getBalance(), - createOobParameters.valueHi(), - createOobParameters.valueLo()); + createOobCall.getBalance(), + createOobCall.valueHi(), + createOobCall.valueLo()); // row i + 1 final boolean callStackDepthAbort = !callToLT( 1, BigInteger.ZERO, - createOobParameters.getCallStackDepth(), + createOobCall.getCallStackDepth(), BigInteger.ZERO, BigInteger.valueOf(1024)); // row i + 2 - final boolean nonzeroNonce = !callToISZERO(2, BigInteger.ZERO, createOobParameters.getNonce()); + final boolean nonzeroNonce = !callToISZERO(2, BigInteger.ZERO, createOobCall.getNonce()); // Set aborting condition - createOobParameters.setAbortingCondition(insufficientBalanceAbort || callStackDepthAbort); + createOobCall.setAbortingCondition(insufficientBalanceAbort || callStackDepthAbort); // Set failureCondition - createOobParameters.setFailureCondition( - !createOobParameters.isAbortingCondition() - && (createOobParameters.isHasCode() || nonzeroNonce)); + createOobCall.setFailureCondition( + !createOobCall.isAbortingCondition() && (createOobCall.isHasCode() || nonzeroNonce)); } private void setPrecompile(PrecompileCommonOobCall prcOobParameters) { From 371e82ac4d4e264ff28f5fdda096589efd752eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 18:55:59 +0200 Subject: [PATCH 120/461] JUMPs --- .../Blake2fCallDataSizeOobCall.java | 8 ++++---- .../module/hub/section/JumpSection.java | 20 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java index 1241486d54..1b6ad7e9f4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -55,8 +55,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data3(bigIntegerToBytes(returnAtCapacity)) .data4(booleanToBytes(success)) // Set after the constructor .data5(ZERO) - .data6(Bytes.of(0)) - .data7(Bytes.of(0)) + .data6(ZERO) + .data7(ZERO) .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor } @@ -70,8 +70,8 @@ public Trace trace(Trace trace) { .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) .pMiscOobData4(booleanToBytes(success)) // Set after the constructor .pMiscOobData5(ZERO) - .pMiscOobData6(Bytes.of(0)) - .pMiscOobData7(Bytes.of(0)) + .pMiscOobData6(ZERO) + .pMiscOobData7(ZERO) .pMiscOobData8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index 702f5130e5..6604b81358 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -26,6 +26,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.opcode.OpCode; import org.hyperledger.besu.datatypes.Address; @@ -69,32 +71,32 @@ public static void appendToTrace(Hub hub, WorldView worldView) { // MISCELLANEOUS fragment ///////////////////////// - ImcFragment miscRow = ImcFragment.empty(hub); + ImcFragment miscellaneousRow = ImcFragment.empty(hub); OobCall oobCall; boolean mustAttemptJump = false; switch (hub.opCode()) { case OpCode.JUMP -> { - JumpOobCall jumpOobCall = new JumpOobCall(hub); - miscRow.callOob(jumpOobCall); - mustAttemptJump = jumpOobCall.getJumpMustBeAttempted(); + JumpOobCall jumpOobCall = new JumpOobCall(); + miscellaneousRow.callOob(jumpOobCall); + mustAttemptJump = jumpOobCall.isJumpMustBeAttempted(); oobCall = jumpOobCall; } case OpCode.JUMPI -> { - JumpiOobCall jumpiOobCall = new JumpiOobCall(hub); - miscRow.callOob(jumpiOobCall); - mustAttemptJump = jumpiOobCall.getJumpMustBeAttempted(); + JumpiOobCall jumpiOobCall = new JumpiOobCall(); + miscellaneousRow.callOob(jumpiOobCall); + mustAttemptJump = jumpiOobCall.isJumpMustBeAttempted(); oobCall = jumpiOobCall; } default -> throw new RuntimeException( hub.opCode().name() + " not part of the JUMP instruction family"); } - miscRow.callOob(oobCall); + miscellaneousRow.callOob(oobCall); // CONTEXT, ACCOUNT, MISCELLANEOUS ////////////////////////////////// currentSection.addFragmentsWithoutStack( - hub, contextRowCurrentContext, accountRowCodeAccount, miscRow); + hub, contextRowCurrentContext, accountRowCodeAccount, miscellaneousRow); // jump destination vetting /////////////////////////// From 9b3691907ab968d11a46f2b8938d83b8d087d063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 19:03:06 +0200 Subject: [PATCH 121/461] hubSuccess vs ramSuccess distinction in OobCall specialization --- .../oob/precompiles/Blake2fCallDataSizeOobCall.java | 7 +++---- .../call/oob/precompiles/Blake2fParamsOobCall.java | 6 +++--- .../call/oob/precompiles/ModexpPricingOobCall.java | 6 +++--- .../oob/precompiles/PrecompileCommonOobCall.java | 10 +++++----- .../module/hub/precompiles/EcRecoverMetadata.java | 2 +- .../zktracer/module/hub/section/CreateSection.java | 2 +- .../linea/zktracer/module/oob/OobOperation.java | 12 ++++++------ 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java index 1b6ad7e9f4..216d14dd36 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -27,7 +27,6 @@ import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import org.apache.tuweni.bytes.Bytes; @Getter @Setter @@ -38,7 +37,7 @@ public class Blake2fCallDataSizeOobCall implements OobCall { BigInteger cds; BigInteger returnAtCapacity; - boolean success; + boolean hubSuccess; boolean returnAtCapacityNonZero; @Override @@ -53,7 +52,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data1(ZERO) .data2(bigIntegerToBytes(cds)) .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) // Set after the constructor + .data4(booleanToBytes(hubSuccess)) // Set after the constructor .data5(ZERO) .data6(ZERO) .data7(ZERO) @@ -68,7 +67,7 @@ public Trace trace(Trace trace) { .pMiscOobData1(ZERO) .pMiscOobData2(bigIntegerToBytes(cds)) .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) - .pMiscOobData4(booleanToBytes(success)) // Set after the constructor + .pMiscOobData4(booleanToBytes(hubSuccess)) // Set after the constructor .pMiscOobData5(ZERO) .pMiscOobData6(ZERO) .pMiscOobData7(ZERO) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java index d8053f83cd..3536dd1e38 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java @@ -39,7 +39,7 @@ public class Blake2fParamsOobCall implements OobCall { BigInteger blakeR; BigInteger blakeF; - boolean success; + boolean ramSuccess; BigInteger returnGas; @Override @@ -54,7 +54,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data1(bigIntegerToBytes(callGas)) .data2(ZERO) .data3(ZERO) - .data4(booleanToBytes(success)) // Set after the constructor + .data4(booleanToBytes(ramSuccess)) // Set after the constructor .data5(bigIntegerToBytes(returnGas)) // Set after the constructor .data6(bigIntegerToBytes(blakeR)) .data7(bigIntegerToBytes(blakeF)) @@ -69,7 +69,7 @@ public Trace trace(Trace trace) { .pMiscOobData1(bigIntegerToBytes(callGas)) .pMiscOobData2(ZERO) .pMiscOobData3(ZERO) - .pMiscOobData4(booleanToBytes(success)) // Set after the constructor + .pMiscOobData4(booleanToBytes(ramSuccess)) // Set after the constructor .pMiscOobData5(bigIntegerToBytes(returnGas)) // Set after the constructor .pMiscOobData6(bigIntegerToBytes(blakeR)) .pMiscOobData7(bigIntegerToBytes(blakeF)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java index 0e9698acda..87c71412e1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java @@ -37,7 +37,7 @@ public class ModexpPricingOobCall implements OobCall { final PrecompileInvocation p; BigInteger callGas; BigInteger returnAtCapacity; - boolean success; + boolean ramSuccess; BigInteger exponentLog; int maxMbsBbs; @@ -56,7 +56,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data1(bigIntegerToBytes(callGas)) .data2(ZERO) .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) + .data4(booleanToBytes(ramSuccess)) .data5(bigIntegerToBytes(returnGas)) .data6(bigIntegerToBytes(exponentLog)) .data7(Bytes.of(maxMbsBbs)) @@ -71,7 +71,7 @@ public Trace trace(Trace trace) { .pMiscOobData1(bigIntegerToBytes(callGas)) .pMiscOobData2(ZERO) .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) - .pMiscOobData4(booleanToBytes(success)) + .pMiscOobData4(booleanToBytes(ramSuccess)) .pMiscOobData5(bigIntegerToBytes(returnGas)) .pMiscOobData6(bigIntegerToBytes(exponentLog)) .pMiscOobData7(Bytes.of(maxMbsBbs)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java index 2fb0cbf802..df89d1949b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java @@ -37,17 +37,17 @@ public class PrecompileCommonOobCall implements OobCall { BigInteger callGas; BigInteger cds; BigInteger returnAtCapacity; - boolean success; + boolean hubSuccess; BigInteger returnGas; boolean returnAtCapacityNonZero; boolean cdsIsZero; // Necessary to compute extractCallData and emptyCallData public boolean getExtractCallData() { - return success && !cdsIsZero; + return hubSuccess && !cdsIsZero; } public boolean getCallDataIsEmpty() { - return success && cdsIsZero; + return hubSuccess && cdsIsZero; } @Override @@ -71,7 +71,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data1(bigIntegerToBytes(callGas)) .data2(bigIntegerToBytes(cds)) .data3(bigIntegerToBytes(returnAtCapacity)) - .data4(booleanToBytes(success)) // Set after the constructor + .data4(booleanToBytes(hubSuccess)) // Set after the constructor .data5(bigIntegerToBytes(returnGas)) // Set after the constructor .data6(booleanToBytes(getExtractCallData())) // Derived from other parameters .data7(booleanToBytes(getCallDataIsEmpty())) // Derived from other parameters @@ -86,7 +86,7 @@ public Trace trace(Trace trace) { .pMiscOobData1(bigIntegerToBytes(callGas)) .pMiscOobData2(bigIntegerToBytes(cds)) .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) - .pMiscOobData4(booleanToBytes(success)) // Set after the constructor + .pMiscOobData4(booleanToBytes(hubSuccess)) // Set after the constructor .pMiscOobData5(bigIntegerToBytes(returnGas)) // Set after the constructor .pMiscOobData6(booleanToBytes(getExtractCallData())) // Derived from other parameters .pMiscOobData7(booleanToBytes(getCallDataIsEmpty())) // Derived from other parameters diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/EcRecoverMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/EcRecoverMetadata.java index 0e3754178b..74c6c79f99 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/EcRecoverMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/EcRecoverMetadata.java @@ -19,7 +19,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; /** - * ECRECOVER success must be captured at *CALL-time, when the data is still available. + * ECRECOVER hubSuccess must be captured at *CALL-time, when the data is still available. * * @param recoverySuccessful whether the recovery process is successful */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 2d13f677eb..82649a90ba 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -90,7 +90,7 @@ public CreateSection( this.addStack(hub); - // Will be traced in one (and only one!) of these depending on the success of + // Will be traced in one (and only one!) of these depending on the hubSuccess of // the operation hub.defers().postExec(this); hub.defers().nextContext(this, hub.currentFrame().id()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index e221f6d122..93bfd0cc88 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -949,7 +949,7 @@ private void setPrcEcRecoverPrcEcaddPrcEcmul(PrecompileCommonOobCall prcCommonOo // Set hubSuccess final boolean hubSuccess = !insufficientGas; - prcCommonOobParameters.setSuccess(hubSuccess); + prcCommonOobParameters.setHubSuccess(hubSuccess); // Set returnGas final BigInteger returnGas = @@ -986,7 +986,7 @@ private void setPrcSha2PrcRipemdPrcIdentity(PrecompileCommonOobCall prcCommonOob // Set hubSuccess final boolean hubSuccess = !insufficientGas; - prcCommonOobParameters.setSuccess(hubSuccess); + prcCommonOobParameters.setHubSuccess(hubSuccess); // Set returnGas final BigInteger returnGas = @@ -1032,7 +1032,7 @@ private void setEcpairing(PrecompileCommonOobCall prcCommonOobParameters) { // Set hubSuccess final boolean hubSuccess = isMultipleOf192 && !insufficientGas; - prcCommonOobParameters.setSuccess(hubSuccess); + prcCommonOobParameters.setHubSuccess(hubSuccess); // Set returnGas final BigInteger returnGas = @@ -1218,7 +1218,7 @@ private void setPrcModexpPricing(ModexpPricingOobCall prcModexpPricingOobCall) { precompileCost); // Set ramSuccess - prcModexpPricingOobCall.setSuccess(ramSuccess); + prcModexpPricingOobCall.setRamSuccess(ramSuccess); // Set returnGas final BigInteger returnGas = @@ -1279,7 +1279,7 @@ private void setBlake2FCds(Blake2fCallDataSizeOobCall prcBlake2FCdsParameters) { callToISZERO(1, BigInteger.ZERO, prcBlake2FCdsParameters.getReturnAtCapacity()); // Set hubSuccess - prcBlake2FCdsParameters.setSuccess(validCds); + prcBlake2FCdsParameters.setHubSuccess(validCds); // Set returnAtCapacityNonZero prcBlake2FCdsParameters.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); @@ -1306,7 +1306,7 @@ private void setBlake2FParams(Blake2fParamsOobCall prcBlake2FParamsOobCall) { // Set ramSuccess final boolean ramSuccess = sufficientGas && fIsABit; - prcBlake2FParamsOobCall.setSuccess(ramSuccess); + prcBlake2FParamsOobCall.setRamSuccess(ramSuccess); // Set returnGas final BigInteger returnGas = From 401a7f9b8d0dfa5e7e14cb7bd351c086e9b83bc2 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 18 Jun 2024 20:01:42 +0200 Subject: [PATCH 122/461] feat(oob): completed update using OobCall --- .../module/hub/fragment/imc/ImcFragment.java | 24 ++- .../precompiles/PrecompileLinesGenerator.java | 78 ++++--- .../module/hub/section/CreateSection.java | 3 +- .../zktracer/module/hub/section/StackRam.java | 3 +- .../linea/zktracer/module/oob/Oob.java | 78 +++++-- .../zktracer/module/oob/OobOperation.java | 193 +++++++++--------- 6 files changed, 223 insertions(+), 156 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index d52dc7dea3..383a41a263 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -31,7 +31,13 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; @@ -115,9 +121,9 @@ public static ImcFragment forCall( switch (hub.opCode()) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { if (hub.opCode().equals(OpCode.CALL) && hub.pch().exceptions().any()) { - r.callOob(new ExceptionalCall()); + r.callOob(new XCallOobCall()); } else { - r.callOob(new Call()); + r.callOob(new CallOobCall()); } } default -> throw new IllegalArgumentException("unexpected opcode for IMC/CALL"); @@ -197,18 +203,18 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { if (hub.pch().signals().oob()) { switch (hub.opCode()) { case JUMP -> r.callOob(new JumpOobCall()); - case JUMPI -> r.callOob(new Jumpi()); - case CALLDATALOAD -> r.callOob(new CallDataLoad()); - case SSTORE -> r.callOob(new SStore()); + case JUMPI -> r.callOob(new JumpiOobCall()); + case CALLDATALOAD -> r.callOob(new CallDataLoadOobCall()); + case SSTORE -> r.callOob(new SstoreOobCall()); case CALL, CALLCODE -> { - r.callOob(new Call()); + r.callOob(new CallOobCall()); } case DELEGATECALL, STATICCALL -> { - r.callOob(new Call()); + r.callOob(new CallOobCall()); } case RETURN -> { if (hub.currentFrame().isDeployment()) { - r.callOob(new DeploymentReturn()); + r.callOob(new DeploymentOobCall()); } } default -> throw new IllegalArgumentException( @@ -225,7 +231,7 @@ public ImcFragment callOob(OobCall f) { } else { oobIsSet = true; } - this.hub.oob().call(f, this.hub); + this.hub.oob().call(f); this.moduleCalls.add(f); return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index e35f54cdb5..92be65d044 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -25,6 +25,14 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtractOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLeadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricingOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobCall; @RequiredArgsConstructor public class PrecompileLinesGenerator { @@ -33,14 +41,14 @@ public static List generateFor(final Hub hub, final PrecompileInv switch (p.precompile()) { case EC_RECOVER -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new EcRecover(p))); + r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); } else { final boolean recoverySuccessful = ((EcRecoverMetadata) p.metadata()).recoverySuccessful(); r.add( ImcFragment.empty(hub) - .callOob(new EcRecover(p)) + .callOob(new PrecompileCommonOobCall(p)) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() @@ -61,11 +69,11 @@ public static List generateFor(final Hub hub, final PrecompileInv } case SHA2_256 -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new Sha2(p))); + r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); } else { r.add( ImcFragment.empty(hub) - .callOob(new Sha2(p)) + .callOob(new PrecompileCommonOobCall(p)) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forSha2(hub, p, 0))); r.add( @@ -80,11 +88,11 @@ public static List generateFor(final Hub hub, final PrecompileInv } case RIPEMD_160 -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new RipeMd160(p))); + r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); } else { r.add( ImcFragment.empty(hub) - .callOob(new Sha2(p)) + .callOob(new PrecompileCommonOobCall(p)) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() @@ -105,11 +113,11 @@ public static List generateFor(final Hub hub, final PrecompileInv } case IDENTITY -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new Identity(p))); + r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); } else { r.add( ImcFragment.empty(hub) - .callOob(new Identity(p)) + .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forIdentity(hub, p, 0))); r.add(ImcFragment.empty(hub).callMmu(MmuCall.forIdentity(hub, p, 1))); } @@ -120,22 +128,22 @@ public static List generateFor(final Hub hub, final PrecompileInv final int ebsInt = m.ebs().toUnsignedBigInteger().intValueExact(); final int mbsInt = m.mbs().toUnsignedBigInteger().intValueExact(); - r.add(ImcFragment.empty(hub).callOob(new ModexpCds(p))); + r.add(ImcFragment.empty(hub).callOob(new ModexpCallDataSizeOobCall(p))); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbs(p)) + .callOob(new ModexpXbsOobCall(p)) .callMmu(m.extractBbs() ? MmuCall.forModExp(hub, p, 2) : MmuCall.nop())); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbs(p)) + .callOob(new ModexpXbsOobCall(p)) .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 3) : MmuCall.nop())); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbs(p)) + .callOob(new ModexpXbsOobCall(p)) .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 4) : MmuCall.nop())); final ImcFragment line5 = ImcFragment.empty(hub) - .callOob(new ModexpLead(p)) + .callOob(new ModexpLeadOobCall(p)) .callMmu(m.loadRawLeadingWord() ? MmuCall.forModExp(hub, p, 5) : MmuCall.nop()); if (m.loadRawLeadingWord()) { line5.callExp( @@ -145,14 +153,14 @@ public static List generateFor(final Hub hub, final PrecompileInv Math.min(ebsInt, 32))); } r.add(line5); - r.add(ImcFragment.empty(hub).callOob(new ModexpPricing(p))); + r.add(ImcFragment.empty(hub).callOob(new ModexpPricingOobCall(p))); if (p.ramFailure()) { r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) - .callOob(new ModexpExtract(p)) + .callOob(new ModexpExtractOobCall(p)) .callMmu(m.extractModulus() ? MmuCall.forModExp(hub, p, 7) : MmuCall.nop())); if (m.extractModulus()) { @@ -176,13 +184,19 @@ public static List generateFor(final Hub hub, final PrecompileInv } case EC_ADD -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new EcAdd(p))); + r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (p.ramFailure()) { - r.add(ImcFragment.empty(hub).callOob(new EcAdd(p)).callMmu(MmuCall.forEcAdd(hub, p, 0))); + r.add( + ImcFragment.empty(hub) + .callOob(new PrecompileCommonOobCall(p)) + .callMmu(MmuCall.forEcAdd(hub, p, 0))); r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { - r.add(ImcFragment.empty(hub).callOob(new EcAdd(p)).callMmu(MmuCall.forEcAdd(hub, p, 0))); + r.add( + ImcFragment.empty(hub) + .callOob(new PrecompileCommonOobCall(p)) + .callMmu(MmuCall.forEcAdd(hub, p, 0))); r.add( ImcFragment.empty(hub) .callMmu( @@ -200,13 +214,19 @@ public static List generateFor(final Hub hub, final PrecompileInv } case EC_MUL -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new EcMul(p))); + r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (p.ramFailure()) { - r.add(ImcFragment.empty(hub).callOob(new EcMul(p)).callMmu(MmuCall.forEcMul(hub, p, 0))); + r.add( + ImcFragment.empty(hub) + .callOob(new PrecompileCommonOobCall(p)) + .callMmu(MmuCall.forEcMul(hub, p, 0))); r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { - r.add(ImcFragment.empty(hub).callOob(new EcMul(p)).callMmu(MmuCall.forEcMul(hub, p, 0))); + r.add( + ImcFragment.empty(hub) + .callOob(new PrecompileCommonOobCall(p)) + .callMmu(MmuCall.forEcMul(hub, p, 0))); r.add( ImcFragment.empty(hub) .callMmu( @@ -224,18 +244,18 @@ public static List generateFor(final Hub hub, final PrecompileInv } case EC_PAIRING -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new EcPairing(p))); + r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) - .callOob(new EcPairing(p)) + .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcPairing(hub, p, 0))); r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) - .callOob(new EcPairing(p)) + .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcPairing(hub, p, 0))); r.add(ImcFragment.empty(hub).callMmu(MmuCall.forEcPairing(hub, p, 1))); r.add( @@ -251,21 +271,21 @@ public static List generateFor(final Hub hub, final PrecompileInv } case BLAKE2F -> { if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new Blake2FPrecompile1(p))); + r.add(ImcFragment.empty(hub).callOob(new Blake2fCallDataSizeOobCall(p))); } else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) - .callOob(new Blake2FPrecompile1(p)) + .callOob(new Blake2fCallDataSizeOobCall(p)) .callMmu(MmuCall.forBlake2f(hub, p, 0))); - r.add(ImcFragment.empty(hub).callOob(new Blake2FPrecompile2(p))); + r.add(ImcFragment.empty(hub).callOob(new Blake2fParamsOobCall(p))); } else { r.add( ImcFragment.empty(hub) - .callOob(new Blake2FPrecompile1(p)) + .callOob(new Blake2fCallDataSizeOobCall(p)) .callMmu(MmuCall.forBlake2f(hub, p, 0))); r.add( ImcFragment.empty(hub) - .callOob(new Blake2FPrecompile2(p)) + .callOob(new Blake2fParamsOobCall(p)) .callMmu(MmuCall.forBlake2f(hub, p, 1))); r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 2))); r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 3))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 82649a90ba..6839e4e1b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -29,6 +29,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; @@ -155,7 +156,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces final ImcFragment commonImcFragment = ImcFragment.empty(hub) - .callOob(new Create()) + .callOob(new CreateOobCall()) .callMxp(MxpCall.build(hub)) .callStp( new StpCall( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java index d8d600d270..b0af0d5d1f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java @@ -21,6 +21,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; public class StackRam extends TraceSection { @@ -34,7 +35,7 @@ public static void appendToTrace(Hub hub) { imcFragment.callMxp(mxpCall); } case CALLDATALOAD -> { - OobCall oobCall = new CallDataLoad(); + OobCall oobCall = new CallDataLoadOobCall(); imcFragment.callOob(oobCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index c24e8c0954..cf33ccb34e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -15,9 +15,22 @@ package net.consensys.linea.zktracer.module.oob; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECADD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECMUL; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECPAIRING; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECRECOVER; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.List; @@ -31,10 +44,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; @RequiredArgsConstructor /** Implementation of a {@link Module} for out of bounds. */ @@ -55,25 +65,58 @@ public String moduleKey() { return "OOB"; } - static final List
PRECOMPILES_HANDLED_BY_OOB = + static final List PRECOMPILES_HANDLED_BY_OOB = List.of( - Address.ECREC, - Address.SHA256, - Address.RIPEMD160, - Address.ID, - Address.ALTBN128_ADD, - Address.ALTBN128_MUL, - Address.ALTBN128_PAIRING, - Address.BLAKE2B_F_COMPRESSION); + OOB_INST_ECRECOVER, + OOB_INST_SHA2, + OOB_INST_RIPEMD, + OOB_INST_IDENTITY, + OOB_INST_ECADD, + OOB_INST_ECMUL, + OOB_INST_ECPAIRING, + OOB_INST_BLAKE_CDS, + OOB_INST_BLAKE_PARAMS, + OOB_INST_MODEXP_CDS, + OOB_INST_MODEXP_XBS, + OOB_INST_MODEXP_LEAD, + OOB_INST_MODEXP_PRICING, + OOB_INST_MODEXP_EXTRACT); public void call(OobCall oobCall) { - oobOperation.setOobCall(oobCall); - // TODO: add oobCall to the constructor of oobOperation + // TODO: this logic can be refined. It is quick-and-dirty for now + boolean isPrecompile = PRECOMPILES_HANDLED_BY_OOB.contains(oobCall.oobInstruction()); + int blake2FCallNumber = + switch (oobCall.oobInstruction()) { + case OOB_INST_BLAKE_CDS -> 1; + case OOB_INST_BLAKE_PARAMS -> 2; + default -> 0; + }; + int modexpCallNumber = + switch (oobCall.oobInstruction()) { + case OOB_INST_MODEXP_CDS -> 1; + case OOB_INST_MODEXP_XBS -> 2; + case OOB_INST_MODEXP_LEAD -> 3; + case OOB_INST_MODEXP_PRICING -> 4; + case OOB_INST_MODEXP_EXTRACT -> 5; + default -> 0; + }; + OobOperation oobOperation = + new OobOperation( + oobCall, + hub.messageFrame(), + add, + mod, + wcp, + hub, + isPrecompile, + blake2FCallNumber, + modexpCallNumber); + this.chunks.add(oobOperation); } @Override - public void tracePreOpcode(MessageFrame frame) { // This will be renamed to tracePreOp - // TODO: this implementation will die, we just use call to trigger OOB + public void tracePreOpcode(MessageFrame frame) { // TODO: maybe move in the hub + /* oobOperation = new OobOperation(frame, add, mod, wcp, hub, false, 0, 0); this.chunks.add(oobOperation); OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); @@ -102,6 +145,7 @@ public void tracePreOpcode(MessageFrame frame) { // This will be renamed to trac } } } + */ } final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 93bfd0cc88..ebcae54ab4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -151,6 +151,7 @@ public class OobOperation extends ModuleOperation { private final int modexpCallNumber; public OobOperation( + OobCall oobCall, final MessageFrame frame, final Add add, final Mod mod, @@ -159,6 +160,7 @@ public OobOperation( boolean isPrecompile, int blake2FCallNumber, int modexpCallNumber) { + this.oobCall = oobCall; this.add = add; this.mod = mod; @@ -473,16 +475,19 @@ private void populateColumns(final MessageFrame frame) { EWord.of(frame.getStackItem(returnAtCapacityIndex)).toUnsignedBigInteger(); if (isCommonPrecompile()) { - PrecompileCommonOobCall prcCommonOobParameters = - new PrecompileCommonOobCall(callGas, cds, returnAtCapacity); - oobParameters = prcCommonOobParameters; - setPrecompile(prcCommonOobParameters); + PrecompileCommonOobCall prcCommonOobCall = (PrecompileCommonOobCall) oobCall; + + prcCommonOobCall.setCallGas(callGas); + prcCommonOobCall.setCds(cds); + prcCommonOobCall.setReturnAtCapacity(returnAtCapacity); + oobCall = prcCommonOobCall; + setPrcCommon(prcCommonOobCall); if (isEcRecover || isEcadd || isEcmul) { - setPrcEcRecoverPrcEcaddPrcEcmul(prcCommonOobParameters); + setPrcEcRecoverPrcEcaddPrcEcmul(prcCommonOobCall); } else if (isSha2 || isRipemd || isIdentity) { - setPrcSha2PrcRipemdPrcIdentity(prcCommonOobParameters); + setPrcSha2PrcRipemdPrcIdentity(prcCommonOobCall); } else if (isEcpairing) { - setEcpairing(prcCommonOobParameters); + setEcpairing(prcCommonOobCall); } } else if (isModexpPrecompile()) { final Bytes unpaddedCallData = frame.shadowReadMemory(argsOffset, cds.longValue()); @@ -531,57 +536,66 @@ private void populateColumns(final MessageFrame frame) { exponentLog = BigInteger.valueOf(8).multiply(ebs.subtract(BigInteger.valueOf(32))); } if (isModexpCds) { - final ModexpCallDataSizeOobCall prcModexpCdsParameters = - new ModexpCallDataSizeOobCall(cds); - oobParameters = prcModexpCdsParameters; - setModexpCds(prcModexpCdsParameters); + final ModexpCallDataSizeOobCall prcModexpCdsCall = (ModexpCallDataSizeOobCall) oobCall; + prcModexpCdsCall.setCds(cds); + oobCall = prcModexpCdsCall; + setModexpCds(prcModexpCdsCall); } else if (isModexpXbs) { final ModexpXbsOobCall prcModexpXbsOobCall; if (isModexpBbs) { - prcModexpXbsOobCall = - new ModexpXbsOobCall( - EWord.of(bbs).hiBigInt(), EWord.of(bbs).loBigInt(), BigInteger.ZERO, false); + prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; + prcModexpXbsOobCall.setXbsHi(EWord.of(bbs).hiBigInt()); + prcModexpXbsOobCall.setXbsLo(EWord.of(bbs).loBigInt()); + prcModexpXbsOobCall.setYbsLo(BigInteger.ZERO); + prcModexpXbsOobCall.setComputeMax(false); } else if (isModexpEbs) { - prcModexpXbsOobCall = - new ModexpXbsOobCall( - EWord.of(ebs).hiBigInt(), EWord.of(ebs).loBigInt(), BigInteger.ZERO, false); + prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; + prcModexpXbsOobCall.setXbsHi(EWord.of(ebs).hiBigInt()); + prcModexpXbsOobCall.setXbsLo(EWord.of(ebs).loBigInt()); + prcModexpXbsOobCall.setYbsLo(BigInteger.ZERO); + prcModexpXbsOobCall.setComputeMax(false); } else { // isModexpMbs - prcModexpXbsOobCall = - new ModexpXbsOobCall( - EWord.of(mbs).hiBigInt(), - EWord.of(mbs).loBigInt(), - EWord.of(bbs).loBigInt(), - true); + prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; + prcModexpXbsOobCall.setXbsHi(EWord.of(mbs).hiBigInt()); + prcModexpXbsOobCall.setXbsLo(EWord.of(mbs).loBigInt()); + prcModexpXbsOobCall.setYbsLo(EWord.of(bbs).loBigInt()); + prcModexpXbsOobCall.setComputeMax(true); } - oobParameters = prcModexpXbsOobCall; + oobCall = prcModexpXbsOobCall; setModexpXbs(prcModexpXbsOobCall); } else if (isModexpLead) { - final ModexpLeadOobCall prcModexpLeadOobCall = new ModexpLeadOobCall(bbs, cds, ebs); - - oobParameters = prcModexpLeadOobCall; + final ModexpLeadOobCall prcModexpLeadOobCall = (ModexpLeadOobCall) oobCall; + prcModexpLeadOobCall.setBbs(bbs); + prcModexpLeadOobCall.setCds(cds); + prcModexpLeadOobCall.setEbs(ebs); + oobCall = prcModexpLeadOobCall; setModexpLead(prcModexpLeadOobCall); } else if (prcModexpPricing) { int maxMbsBbs = max(mbs.intValue(), bbs.intValue()); - final ModexpPricingOobCall prcModexpPricingOobCall = - new ModexpPricingOobCall(callGas, returnAtCapacity, exponentLog, maxMbsBbs); - - oobParameters = prcModexpPricingOobCall; + final ModexpPricingOobCall prcModexpPricingOobCall = (ModexpPricingOobCall) oobCall; + prcModexpPricingOobCall.setCallGas(callGas); + prcModexpPricingOobCall.setReturnAtCapacity(returnAtCapacity); + prcModexpPricingOobCall.setExponentLog(exponentLog); + prcModexpPricingOobCall.setMaxMbsBbs(maxMbsBbs); + oobCall = prcModexpPricingOobCall; setPrcModexpPricing(prcModexpPricingOobCall); } else if (prcModexpExtract) { - final ModexpExtractOobCall prcModexpExtractOobCall = - new ModexpExtractOobCall(cds, bbs, ebs, mbs); - - oobParameters = prcModexpExtractOobCall; + final ModexpExtractOobCall prcModexpExtractOobCall = (ModexpExtractOobCall) oobCall; + prcModexpExtractOobCall.setCds(cds); + prcModexpExtractOobCall.setBbs(bbs); + prcModexpExtractOobCall.setEbs(ebs); + prcModexpExtractOobCall.setMbs(mbs); + oobCall = prcModexpExtractOobCall; setPrcModexpExtract(prcModexpExtractOobCall); } } else if (isBlakePrecompile()) { if (isBlake2FCds) { - final Blake2fCallDataSizeOobCall prcBlake2FCdsParameters = - new Blake2fCallDataSizeOobCall(cds, returnAtCapacity); - - oobParameters = prcBlake2FCdsParameters; - setBlake2FCds(prcBlake2FCdsParameters); + final Blake2fCallDataSizeOobCall prcBlake2FCdsCall = (Blake2fCallDataSizeOobCall) oobCall; + prcBlake2FCdsCall.setCds(cds); + prcBlake2FCdsCall.setReturnAtCapacity(returnAtCapacity); + oobCall = prcBlake2FCdsCall; + setBlake2FCds(prcBlake2FCdsCall); } else if (isBlake2FParams) { final BigInteger blakeR = frame @@ -593,10 +607,12 @@ private void populateColumns(final MessageFrame frame) { BigInteger.valueOf( toUnsignedInt(frame.shadowReadMemory(argsOffset, cds.longValue()).get(212))); - final Blake2fParamsOobCall prcBlake2FParamsOobCall = - new Blake2fParamsOobCall(callGas, blakeR, blakeF); + final Blake2fParamsOobCall prcBlake2FParamsOobCall = (Blake2fParamsOobCall) oobCall; + prcBlake2FParamsOobCall.setCallGas(callGas); + prcBlake2FParamsOobCall.setBlakeR(blakeR); + prcBlake2FParamsOobCall.setBlakeF(blakeF); - oobParameters = prcBlake2FParamsOobCall; + oobCall = prcBlake2FParamsOobCall; setBlake2FParams(prcBlake2FParamsOobCall); } } else { @@ -916,22 +932,22 @@ private void setCreate(CreateOobCall createOobCall) { !createOobCall.isAbortingCondition() && (createOobCall.isHasCode() || nonzeroNonce)); } - private void setPrecompile(PrecompileCommonOobCall prcOobParameters) { + private void setPrcCommon(PrecompileCommonOobCall prcOobCall) { // row i - final boolean cdsIsZero = callToISZERO(0, BigInteger.ZERO, prcOobParameters.getCds()); + final boolean cdsIsZero = callToISZERO(0, BigInteger.ZERO, prcOobCall.getCds()); // row i + 1 final boolean returnAtCapacityIsZero = - callToISZERO(1, BigInteger.ZERO, prcOobParameters.getReturnAtCapacity()); + callToISZERO(1, BigInteger.ZERO, prcOobCall.getReturnAtCapacity()); // Set cdsIsZero - prcOobParameters.setCdsIsZero(cdsIsZero); + prcOobCall.setCdsIsZero(cdsIsZero); // Set returnAtCapacityIsZero - prcOobParameters.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); + prcOobCall.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); } - private void setPrcEcRecoverPrcEcaddPrcEcmul(PrecompileCommonOobCall prcCommonOobParameters) { + private void setPrcEcRecoverPrcEcaddPrcEcmul(PrecompileCommonOobCall prcCommonOobCall) { precompileCost = BigInteger.valueOf( 3000L * booleanToInt(isEcRecover) @@ -941,29 +957,25 @@ private void setPrcEcRecoverPrcEcaddPrcEcmul(PrecompileCommonOobCall prcCommonOo // row i + 2 final boolean insufficientGas = callToLT( - 2, - BigInteger.ZERO, - prcCommonOobParameters.getCallGas(), - BigInteger.ZERO, - precompileCost); + 2, BigInteger.ZERO, prcCommonOobCall.getCallGas(), BigInteger.ZERO, precompileCost); // Set hubSuccess final boolean hubSuccess = !insufficientGas; - prcCommonOobParameters.setHubSuccess(hubSuccess); + prcCommonOobCall.setHubSuccess(hubSuccess); // Set returnGas final BigInteger returnGas = - hubSuccess ? prcCommonOobParameters.getCallGas().subtract(precompileCost) : BigInteger.ZERO; - prcCommonOobParameters.setReturnGas(returnGas); + hubSuccess ? prcCommonOobCall.getCallGas().subtract(precompileCost) : BigInteger.ZERO; + prcCommonOobCall.setReturnGas(returnGas); } - private void setPrcSha2PrcRipemdPrcIdentity(PrecompileCommonOobCall prcCommonOobParameters) { + private void setPrcSha2PrcRipemdPrcIdentity(PrecompileCommonOobCall prcCommonOobCall) { // row i + 2 final BigInteger ceil = callToDIV( 2, BigInteger.ZERO, - prcCommonOobParameters.getCds().add(BigInteger.valueOf(31)), + prcCommonOobCall.getCds().add(BigInteger.valueOf(31)), BigInteger.ZERO, BigInteger.valueOf(32)); @@ -978,29 +990,25 @@ private void setPrcSha2PrcRipemdPrcIdentity(PrecompileCommonOobCall prcCommonOob // row i + 3 final boolean insufficientGas = callToLT( - 3, - BigInteger.ZERO, - prcCommonOobParameters.getCallGas(), - BigInteger.ZERO, - precompileCost); + 3, BigInteger.ZERO, prcCommonOobCall.getCallGas(), BigInteger.ZERO, precompileCost); // Set hubSuccess final boolean hubSuccess = !insufficientGas; - prcCommonOobParameters.setHubSuccess(hubSuccess); + prcCommonOobCall.setHubSuccess(hubSuccess); // Set returnGas final BigInteger returnGas = - hubSuccess ? prcCommonOobParameters.getCallGas().subtract(precompileCost) : BigInteger.ZERO; - prcCommonOobParameters.setReturnGas(returnGas); + hubSuccess ? prcCommonOobCall.getCallGas().subtract(precompileCost) : BigInteger.ZERO; + prcCommonOobCall.setReturnGas(returnGas); } - private void setEcpairing(PrecompileCommonOobCall prcCommonOobParameters) { + private void setEcpairing(PrecompileCommonOobCall prcCommonOobCall) { // row i + 2 final BigInteger remainder = callToMOD( 2, BigInteger.ZERO, - prcCommonOobParameters.getCds(), + prcCommonOobCall.getCds(), BigInteger.ZERO, BigInteger.valueOf(192)); @@ -1013,7 +1021,7 @@ private void setEcpairing(PrecompileCommonOobCall prcCommonOobParameters) { BigInteger.valueOf(45000) .add( BigInteger.valueOf(34000) - .multiply(prcCommonOobParameters.getCds().divide(BigInteger.valueOf(192)))); + .multiply(prcCommonOobCall.getCds().divide(BigInteger.valueOf(192)))); } // row i + 4 @@ -1021,57 +1029,44 @@ private void setEcpairing(PrecompileCommonOobCall prcCommonOobParameters) { if (isMultipleOf192) { insufficientGas = callToLT( - 4, - BigInteger.ZERO, - prcCommonOobParameters.getCallGas(), - BigInteger.ZERO, - precompileCost); + 4, BigInteger.ZERO, prcCommonOobCall.getCallGas(), BigInteger.ZERO, precompileCost); } else { noCall(4); } // Set hubSuccess final boolean hubSuccess = isMultipleOf192 && !insufficientGas; - prcCommonOobParameters.setHubSuccess(hubSuccess); + prcCommonOobCall.setHubSuccess(hubSuccess); // Set returnGas final BigInteger returnGas = - hubSuccess ? prcCommonOobParameters.getCallGas().subtract(precompileCost) : BigInteger.ZERO; - prcCommonOobParameters.setReturnGas(returnGas); + hubSuccess ? prcCommonOobCall.getCallGas().subtract(precompileCost) : BigInteger.ZERO; + prcCommonOobCall.setReturnGas(returnGas); } - private void setModexpCds(ModexpCallDataSizeOobCall prcModexpCdsParameters) { + private void setModexpCds(ModexpCallDataSizeOobCall prcModexpCdsCall) { // row i final boolean extractBbs = - callToLT( - 0, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, prcModexpCdsParameters.getCds()); + callToLT(0, BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO, prcModexpCdsCall.getCds()); // row i + 1 final boolean extractEbs = callToLT( - 1, - BigInteger.ZERO, - prcModexpCdsParameters.getCds(), - BigInteger.ZERO, - BigInteger.valueOf(32)); + 1, BigInteger.ZERO, prcModexpCdsCall.getCds(), BigInteger.ZERO, BigInteger.valueOf(32)); // row i + 2 final boolean extractMbs = callToLT( - 2, - BigInteger.ZERO, - prcModexpCdsParameters.getCds(), - BigInteger.ZERO, - BigInteger.valueOf(64)); + 2, BigInteger.ZERO, prcModexpCdsCall.getCds(), BigInteger.ZERO, BigInteger.valueOf(64)); // Set extractBbs - prcModexpCdsParameters.setExtractBbs(extractBbs); + prcModexpCdsCall.setExtractBbs(extractBbs); // Set extractEbs - prcModexpCdsParameters.setExtractEbs(extractEbs); + prcModexpCdsCall.setExtractEbs(extractEbs); // Set extractMbs - prcModexpCdsParameters.setExtractMbs(extractMbs); + prcModexpCdsCall.setExtractMbs(extractMbs); } private void setModexpXbs(ModexpXbsOobCall prcModexpXbsOobCall) { @@ -1264,25 +1259,25 @@ private void setPrcModexpExtract(ModexpExtractOobCall prcModexpExtractOobCall) { prcModexpExtractOobCall.setExtractExponent(extractExponent); } - private void setBlake2FCds(Blake2fCallDataSizeOobCall prcBlake2FCdsParameters) { + private void setBlake2FCds(Blake2fCallDataSizeOobCall prcBlake2FCdsCall) { // row i final boolean validCds = callToEQ( 0, BigInteger.ZERO, - prcBlake2FCdsParameters.getCds(), + prcBlake2FCdsCall.getCds(), BigInteger.ZERO, BigInteger.valueOf(213)); // row i + 1 final boolean returnAtCapacityIsZero = - callToISZERO(1, BigInteger.ZERO, prcBlake2FCdsParameters.getReturnAtCapacity()); + callToISZERO(1, BigInteger.ZERO, prcBlake2FCdsCall.getReturnAtCapacity()); // Set hubSuccess - prcBlake2FCdsParameters.setHubSuccess(validCds); + prcBlake2FCdsCall.setHubSuccess(validCds); // Set returnAtCapacityNonZero - prcBlake2FCdsParameters.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); + prcBlake2FCdsCall.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); } private void setBlake2FParams(Blake2fParamsOobCall prcBlake2FParamsOobCall) { From 71e4ff07dc664efea1f4d42e06be231bbbda455f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 20:03:03 +0200 Subject: [PATCH 123/461] simple jump tests --- .../instructionprocessing/JumpTests.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java new file mode 100644 index 0000000000..452b9ba7aa --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -0,0 +1,85 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import net.consensys.linea.zktracer.testing.EvmExtension; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class JumpTests { + + /** + * NOTE: the bytecode we propose will at time use the following offsets (unless the initial push + * is large!) bytecode: PUSHX pcNew // offsets: 0, 1 JUMP // offset: 2 INVALID // offset: 3 + * JUMPDEST // offset: 4 PUSH1 0x5b // offsets: 5, 6 <- 0x5b is the byte value of JUMPDEST + */ + Bytes testCodeForJumpScenario(String pcNew) { + return BytecodeCompiler.newProgram() + .push(pcNew) + .op(OpCode.JUMP) + .op(OpCode.INVALID) + .op(OpCode.JUMPDEST) + .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST + .compile(); + } + + @Test + void jumpOntoJumpDestTest() { + BytecodeRunner.of(testCodeForJumpScenario("4")).run(); + } + + @Test + void jumpOntoInvalidTest() { + BytecodeRunner.of(testCodeForJumpScenario("3")).run(); + } + + @Test + void jumpOntoJumpDestByteOwnedBySomePush() { + BytecodeRunner.of(testCodeForJumpScenario("5")).run(); + } + + @Test + void jumpOutOfBoundsSmall() { + BytecodeRunner.of(testCodeForJumpScenario("0xff")).run(); + } + + @Test + void jumpOutOfBoundsMaxUint128() { + BytecodeRunner.of(testCodeForJumpScenario("0xffffffffffffffffffffffffffffffff")).run(); + } + + @Test + void jumpOutOfBoundsTwoToThe128() { + BytecodeRunner.of(testCodeForJumpScenario("0x0100000000000000000000000000000000")).run(); + } + + @Test + void jumpOutOfBoundsTwoToThe128Plus4() { + BytecodeRunner.of(testCodeForJumpScenario("0x0100000000000000000000000000000004")).run(); + } + + @Test + void jumpOutOfBoundsMaxUint256() { + BytecodeRunner.of( + testCodeForJumpScenario( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .run(); + } +} From 9852659ca54efc6fbe2c7dd96cdde17b808a9a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 18 Jun 2024 20:50:33 +0200 Subject: [PATCH 124/461] ras --- .../linea/zktracer/module/oob/OobOperation.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index ebcae54ab4..12b65b309e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -369,42 +369,35 @@ private void populateColumns(final MessageFrame frame) { JumpOobCall jumpOobCall = (JumpOobCall) oobCall; jumpOobCall.setPcNew(EWord.of(frame.getStackItem(0))); jumpOobCall.setCodeSize(BigInteger.valueOf(frame.getCode().getSize())); - oobCall = jumpOobCall; setJump(jumpOobCall); } else if (isJumpi) { JumpiOobCall jumpiOobCall = (JumpiOobCall) oobCall; jumpiOobCall.setPcNew(EWord.of(frame.getStackItem(0))); jumpiOobCall.setJumpCondition(EWord.of(frame.getStackItem(1))); jumpiOobCall.setCodeSize(BigInteger.valueOf(frame.getCode().getSize())); - oobCall = jumpiOobCall; setJumpi(jumpiOobCall); } else if (isRdc) { ReturnDataCopyOobCall rdcOobCall = (ReturnDataCopyOobCall) oobCall; rdcOobCall.setOffset(EWord.of(frame.getStackItem(0))); rdcOobCall.setSize(EWord.of(frame.getStackItem(1))); rdcOobCall.setRds(BigInteger.valueOf(frame.getReturnData().size())); - oobCall = rdcOobCall; setRdc(rdcOobCall); } else if (isCdl) { CallDataLoadOobCall cdlOobCall = (CallDataLoadOobCall) oobCall; cdlOobCall.setOffset(EWord.of(frame.getStackItem(0))); cdlOobCall.setCds(BigInteger.valueOf(frame.getInputData().size())); - oobCall = cdlOobCall; setCdl(cdlOobCall); } else if (isSstore) { final SstoreOobCall sstoreOobCall = (SstoreOobCall) oobCall; sstoreOobCall.setGas(BigInteger.valueOf(frame.getRemainingGas())); - oobCall = sstoreOobCall; setSstore(sstoreOobCall); } else if (isDeployment) { final DeploymentOobCall deploymentOobCall = (DeploymentOobCall) oobCall; deploymentOobCall.setSize(EWord.of(frame.getStackItem(0))); - oobCall = deploymentOobCall; setDeployment(deploymentOobCall); } else if (isXCall) { XCallOobCall xCallOobCall = (XCallOobCall) oobCall; xCallOobCall.setValue(EWord.of(frame.getStackItem(2))); - oobCall = xCallOobCall; setXCall(xCallOobCall); } else if (isCall) { final Account callerAccount = frame.getWorldUpdater().get(frame.getRecipientAddress()); @@ -420,7 +413,6 @@ private void populateColumns(final MessageFrame frame) { callOobCall.setValue(value); callOobCall.setBalance(callerAccount.getBalance().toUnsignedBigInteger()); callOobCall.setCallStackDepth(BigInteger.valueOf(frame.getDepth())); - oobCall = callOobCall; setCall(callOobCall); } else if (isCreate) { final Account creatorAccount = frame.getWorldUpdater().get(frame.getRecipientAddress()); @@ -440,7 +432,6 @@ private void populateColumns(final MessageFrame frame) { createOobCall.setNonce(BigInteger.valueOf(nonce)); createOobCall.setHasCode(hasCode); createOobCall.setCallStackDepth(BigInteger.valueOf(frame.getDepth())); - oobCall = createOobCall; setCreate(createOobCall); } } else if (isPrecompile()) { @@ -480,7 +471,6 @@ private void populateColumns(final MessageFrame frame) { prcCommonOobCall.setCallGas(callGas); prcCommonOobCall.setCds(cds); prcCommonOobCall.setReturnAtCapacity(returnAtCapacity); - oobCall = prcCommonOobCall; setPrcCommon(prcCommonOobCall); if (isEcRecover || isEcadd || isEcmul) { setPrcEcRecoverPrcEcaddPrcEcmul(prcCommonOobCall); @@ -538,7 +528,6 @@ private void populateColumns(final MessageFrame frame) { if (isModexpCds) { final ModexpCallDataSizeOobCall prcModexpCdsCall = (ModexpCallDataSizeOobCall) oobCall; prcModexpCdsCall.setCds(cds); - oobCall = prcModexpCdsCall; setModexpCds(prcModexpCdsCall); } else if (isModexpXbs) { final ModexpXbsOobCall prcModexpXbsOobCall; @@ -562,14 +551,12 @@ private void populateColumns(final MessageFrame frame) { prcModexpXbsOobCall.setYbsLo(EWord.of(bbs).loBigInt()); prcModexpXbsOobCall.setComputeMax(true); } - oobCall = prcModexpXbsOobCall; setModexpXbs(prcModexpXbsOobCall); } else if (isModexpLead) { final ModexpLeadOobCall prcModexpLeadOobCall = (ModexpLeadOobCall) oobCall; prcModexpLeadOobCall.setBbs(bbs); prcModexpLeadOobCall.setCds(cds); prcModexpLeadOobCall.setEbs(ebs); - oobCall = prcModexpLeadOobCall; setModexpLead(prcModexpLeadOobCall); } else if (prcModexpPricing) { int maxMbsBbs = max(mbs.intValue(), bbs.intValue()); @@ -578,7 +565,6 @@ private void populateColumns(final MessageFrame frame) { prcModexpPricingOobCall.setReturnAtCapacity(returnAtCapacity); prcModexpPricingOobCall.setExponentLog(exponentLog); prcModexpPricingOobCall.setMaxMbsBbs(maxMbsBbs); - oobCall = prcModexpPricingOobCall; setPrcModexpPricing(prcModexpPricingOobCall); } else if (prcModexpExtract) { final ModexpExtractOobCall prcModexpExtractOobCall = (ModexpExtractOobCall) oobCall; @@ -586,7 +572,6 @@ private void populateColumns(final MessageFrame frame) { prcModexpExtractOobCall.setBbs(bbs); prcModexpExtractOobCall.setEbs(ebs); prcModexpExtractOobCall.setMbs(mbs); - oobCall = prcModexpExtractOobCall; setPrcModexpExtract(prcModexpExtractOobCall); } } else if (isBlakePrecompile()) { @@ -594,7 +579,6 @@ private void populateColumns(final MessageFrame frame) { final Blake2fCallDataSizeOobCall prcBlake2FCdsCall = (Blake2fCallDataSizeOobCall) oobCall; prcBlake2FCdsCall.setCds(cds); prcBlake2FCdsCall.setReturnAtCapacity(returnAtCapacity); - oobCall = prcBlake2FCdsCall; setBlake2FCds(prcBlake2FCdsCall); } else if (isBlake2FParams) { final BigInteger blakeR = @@ -612,7 +596,6 @@ private void populateColumns(final MessageFrame frame) { prcBlake2FParamsOobCall.setBlakeR(blakeR); prcBlake2FParamsOobCall.setBlakeF(blakeF); - oobCall = prcBlake2FParamsOobCall; setBlake2FParams(prcBlake2FParamsOobCall); } } else { From 8676be23f82ea1df17cdc16808176e050c08a1df Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 18 Jun 2024 21:47:00 +0200 Subject: [PATCH 125/461] fix(oob): refined the logic of different calls to modexp and blake2f and only used gloabal constants --- .../linea/zktracer/module/oob/Oob.java | 63 +---- .../zktracer/module/oob/OobOperation.java | 223 +++++++++--------- 2 files changed, 113 insertions(+), 173 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index cf33ccb34e..7eeec03302 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -15,22 +15,9 @@ package net.consensys.linea.zktracer.module.oob; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECADD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECMUL; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECPAIRING; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECRECOVER; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.List; @@ -65,52 +52,8 @@ public String moduleKey() { return "OOB"; } - static final List PRECOMPILES_HANDLED_BY_OOB = - List.of( - OOB_INST_ECRECOVER, - OOB_INST_SHA2, - OOB_INST_RIPEMD, - OOB_INST_IDENTITY, - OOB_INST_ECADD, - OOB_INST_ECMUL, - OOB_INST_ECPAIRING, - OOB_INST_BLAKE_CDS, - OOB_INST_BLAKE_PARAMS, - OOB_INST_MODEXP_CDS, - OOB_INST_MODEXP_XBS, - OOB_INST_MODEXP_LEAD, - OOB_INST_MODEXP_PRICING, - OOB_INST_MODEXP_EXTRACT); - public void call(OobCall oobCall) { - // TODO: this logic can be refined. It is quick-and-dirty for now - boolean isPrecompile = PRECOMPILES_HANDLED_BY_OOB.contains(oobCall.oobInstruction()); - int blake2FCallNumber = - switch (oobCall.oobInstruction()) { - case OOB_INST_BLAKE_CDS -> 1; - case OOB_INST_BLAKE_PARAMS -> 2; - default -> 0; - }; - int modexpCallNumber = - switch (oobCall.oobInstruction()) { - case OOB_INST_MODEXP_CDS -> 1; - case OOB_INST_MODEXP_XBS -> 2; - case OOB_INST_MODEXP_LEAD -> 3; - case OOB_INST_MODEXP_PRICING -> 4; - case OOB_INST_MODEXP_EXTRACT -> 5; - default -> 0; - }; - OobOperation oobOperation = - new OobOperation( - oobCall, - hub.messageFrame(), - add, - mod, - wcp, - hub, - isPrecompile, - blake2FCallNumber, - modexpCallNumber); + OobOperation oobOperation = new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub); this.chunks.add(oobOperation); } @@ -160,7 +103,7 @@ final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { .stamp(stamp) .ct((short) ct) .ctMax((short) chunk.maxCt()) - .oobInst(bigIntegerToBytes(chunk.getOobInst())) + .oobInst(bigIntegerToBytes(BigInteger.valueOf(chunk.getOobInst()))) .isJump(chunk.isJump()) .isJumpi(chunk.isJumpi()) .isRdc(chunk.isRdc()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 12b65b309e..fe39587ebd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -20,6 +20,29 @@ import static java.lang.Math.max; import static java.lang.Math.min; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.GAS_CONST_G_CALL_STIPEND; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CALL; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CDL; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_DEPLOYMENT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECADD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECMUL; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECPAIRING; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECRECOVER; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMP; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMPI; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RDC; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SSTORE; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_XCALL; import static net.consensys.linea.zktracer.module.oob.Trace.CT_MAX_BLAKE2F_CDS; import static net.consensys.linea.zktracer.module.oob.Trace.CT_MAX_BLAKE2F_PARAMS; import static net.consensys.linea.zktracer.module.oob.Trace.CT_MAX_CALL; @@ -91,7 +114,7 @@ @Getter @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) public class OobOperation extends ModuleOperation { - @EqualsAndHashCode.Include private BigInteger oobInst; + @EqualsAndHashCode.Include private int oobInst; @EqualsAndHashCode.Include @Setter private OobCall oobCall; private boolean isJump; @@ -136,7 +159,7 @@ public class OobOperation extends ModuleOperation { private final BigInteger[] outgoingResLo; - private BigInteger wghtSum; + private int wghtSum; private BigInteger precompileCost; @@ -144,22 +167,15 @@ public class OobOperation extends ModuleOperation { private final Add add; private final Mod mod; private final Wcp wcp; - private final Hub hub; - private final int blake2FCallNumber; - private final int modexpCallNumber; - public OobOperation( OobCall oobCall, final MessageFrame frame, final Add add, final Mod mod, final Wcp wcp, - final Hub hub, - boolean isPrecompile, - int blake2FCallNumber, - int modexpCallNumber) { + final Hub hub) { this.oobCall = oobCall; this.add = add; @@ -167,14 +183,7 @@ public OobOperation( this.wcp = wcp; this.hub = hub; - this.blake2FCallNumber = blake2FCallNumber; - this.modexpCallNumber = modexpCallNumber; - - if (isPrecompile) { - setPrecomileFlagsAndWghtSumAndIncomingInst(frame); - } else { - setOpCodeFlagsAndWghtSumAndIncomingInst(frame); - } + setFlagsAndWghtSumAndIncomingInst(); // Init arrays int nRows = nRows(); @@ -193,112 +202,100 @@ public OobOperation( populateColumns(frame); } - private void setOpCodeFlagsAndWghtSumAndIncomingInst(MessageFrame frame) { - final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - // In the case of CALLs and CREATEs this value will be replaced - wghtSum = BigInteger.valueOf(Byte.toUnsignedInt(opCode.byteValue())); - - switch (opCode) { - case JUMP: + private void setFlagsAndWghtSumAndIncomingInst() { + switch (oobCall.oobInstruction()) { + case OOB_INST_JUMP -> { isJump = true; - break; - case JUMPI: + wghtSum = OOB_INST_JUMP; + } + case OOB_INST_JUMPI -> { isJumpi = true; - break; - case RETURNDATACOPY: + wghtSum = OOB_INST_JUMPI; + } + case OOB_INST_RDC -> { isRdc = true; - break; - case CALLDATALOAD: + wghtSum = OOB_INST_RDC; + } + case OOB_INST_CDL -> { isCdl = true; - break; - case CALL, CALLCODE, DELEGATECALL, STATICCALL: - if (opCode == OpCode.CALL - && !hub.pch().exceptions().stackUnderflow() - && hub.pch().exceptions().any()) { - isXCall = true; - wghtSum = BigInteger.valueOf(0xCC); - } else { - isCall = true; - wghtSum = BigInteger.valueOf(0xCA); - } - break; - case CREATE, CREATE2: + wghtSum = OOB_INST_CDL; + } + case OOB_INST_CALL -> { + isCall = true; + wghtSum = OOB_INST_CALL; + } + case OOB_INST_XCALL -> { + isXCall = true; + wghtSum = OOB_INST_XCALL; + } + case OOB_INST_CREATE -> { isCreate = true; - wghtSum = BigInteger.valueOf(0xCE); - break; - case SSTORE: + wghtSum = OOB_INST_CREATE; + } + case OOB_INST_SSTORE -> { isSstore = true; - break; - case RETURN: + wghtSum = OOB_INST_SSTORE; + } + case OOB_INST_DEPLOYMENT -> { isDeployment = true; - break; - default: - throw new IllegalArgumentException("OpCode not relevant for Oob"); - } - oobInst = wghtSum; - } - - private void setPrecomileFlagsAndWghtSumAndIncomingInst(MessageFrame frame) { - final Address target = Words.toAddress(frame.getStackItem(1)); - - if (target.equals(Address.ECREC)) { - isEcRecover = true; - wghtSum = Bytes.fromHexString("FF01").toUnsignedBigInteger(); - } else if (target.equals(Address.SHA256)) { - isSha2 = true; - wghtSum = Bytes.fromHexString("FF02").toUnsignedBigInteger(); - } else if (target.equals(Address.RIPEMD160)) { - isRipemd = true; - wghtSum = Bytes.fromHexString("FF03").toUnsignedBigInteger(); - } else if (target.equals(Address.ID)) { - isIdentity = true; - wghtSum = Bytes.fromHexString("FF04").toUnsignedBigInteger(); - } else if (target.equals(Address.ALTBN128_ADD)) { - isEcadd = true; - wghtSum = Bytes.fromHexString("FF06").toUnsignedBigInteger(); - } else if (target.equals(Address.ALTBN128_MUL)) { - isEcmul = true; - wghtSum = Bytes.fromHexString("FF07").toUnsignedBigInteger(); - } else if (target.equals(Address.ALTBN128_PAIRING)) { - isEcpairing = true; - wghtSum = Bytes.fromHexString("FF08").toUnsignedBigInteger(); - } else if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - if (blake2FCallNumber == 1) { + wghtSum = OOB_INST_DEPLOYMENT; + } + case OOB_INST_ECRECOVER -> { + isEcRecover = true; + wghtSum = OOB_INST_ECRECOVER; + } + case OOB_INST_SHA2 -> { + isSha2 = true; + wghtSum = OOB_INST_SHA2; + } + case OOB_INST_RIPEMD -> { + isRipemd = true; + wghtSum = OOB_INST_RIPEMD; + } + case OOB_INST_IDENTITY -> { + isIdentity = true; + wghtSum = OOB_INST_IDENTITY; + } + case OOB_INST_ECADD -> { + isEcadd = true; + wghtSum = OOB_INST_ECADD; + } + case OOB_INST_ECMUL -> { + isEcmul = true; + wghtSum = OOB_INST_ECMUL; + } + case OOB_INST_ECPAIRING -> { + isEcpairing = true; + wghtSum = OOB_INST_ECPAIRING; + } + case OOB_INST_BLAKE_CDS -> { isBlake2FCds = true; - wghtSum = Bytes.fromHexString("FA09").toUnsignedBigInteger(); - } else if (blake2FCallNumber == 2) { + wghtSum = OOB_INST_BLAKE_CDS; + } + case OOB_INST_BLAKE_PARAMS -> { isBlake2FParams = true; - wghtSum = Bytes.fromHexString("FB09").toUnsignedBigInteger(); + wghtSum = OOB_INST_BLAKE_PARAMS; } - } else if (target.equals(Address.MODEXP)) { - switch (modexpCallNumber) { - case 1: - isModexpCds = true; - wghtSum = Bytes.fromHexString("FA05").toUnsignedBigInteger(); - case 2: - isModexpXbs = true; - isModexpBbs = true; - wghtSum = Bytes.fromHexString("FB05").toUnsignedBigInteger(); - case 3: - isModexpXbs = true; - isModexpEbs = true; - wghtSum = Bytes.fromHexString("FB05").toUnsignedBigInteger(); - case 4: - isModexpXbs = true; - isModexpMbs = true; - wghtSum = Bytes.fromHexString("FB05").toUnsignedBigInteger(); - case 5: - isModexpLead = true; - wghtSum = Bytes.fromHexString("FC05").toUnsignedBigInteger(); - case 6: - prcModexpPricing = true; - wghtSum = Bytes.fromHexString("FD05").toUnsignedBigInteger(); - case 7: - prcModexpExtract = true; - wghtSum = Bytes.fromHexString("FE05").toUnsignedBigInteger(); + case OOB_INST_MODEXP_CDS -> { + isModexpCds = true; + wghtSum = OOB_INST_MODEXP_CDS; + } + case OOB_INST_MODEXP_XBS -> { + isModexpXbs = true; + wghtSum = OOB_INST_MODEXP_XBS; + } + case OOB_INST_MODEXP_LEAD -> { + isModexpLead = true; + wghtSum = OOB_INST_MODEXP_LEAD; + } + case OOB_INST_MODEXP_PRICING -> { + prcModexpPricing = true; + wghtSum = OOB_INST_MODEXP_PRICING; + } + case OOB_INST_MODEXP_EXTRACT -> { + prcModexpExtract = true; + wghtSum = OOB_INST_MODEXP_EXTRACT; } - } else { - throw new IllegalArgumentException("Precompile not relevant for Oob"); } oobInst = wghtSum; } From d467f101c97a2db32d521a8053672f207525e73c Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 18 Jun 2024 21:48:37 +0200 Subject: [PATCH 126/461] fix(oob): minor fix --- .../main/java/net/consensys/linea/zktracer/module/oob/Oob.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 7eeec03302..d25d51035d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -53,8 +53,7 @@ public String moduleKey() { } public void call(OobCall oobCall) { - OobOperation oobOperation = new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub); - this.chunks.add(oobOperation); + this.chunks.add(new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub)); } @Override From f005fbd4b34060a5d92e196b6cdeecd7f7cf12d0 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 19 Jun 2024 12:58:47 +0530 Subject: [PATCH 127/461] minor cleaning --- .../linea/zktracer/module/hub/Hub.java | 51 ++++--------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 2d5c480e8e..e38b962e86 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -725,7 +725,6 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope } this.defers.runPostExec(this, frame, operationResult); - this.romLex.tracePostOpcode(frame); if (this.previousOperationWasCallToEcPrecompile) { this.ecData.getEcDataOperation().returnData(frame.getReturnData()); @@ -736,52 +735,22 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope } switch (this.opCodeData().instructionFamily()) { - case ADD -> { - if (this.pch.exceptions().noStackException()) { - this.add.tracePostOpcode(frame); - } - } - case MOD -> { - if (this.pch.exceptions().noStackException()) { - this.mod.tracePostOpcode(frame); - } - } - case MUL -> { - if (this.pch.exceptions().noStackException()) { - this.mul.tracePostOpcode(frame); - } - } - case EXT -> { - if (this.pch.exceptions().noStackException()) { - this.ext.tracePostOpcode(frame); - } - } - case WCP -> { - if (this.pch.exceptions().noStackException()) { - this.wcp.tracePostOpcode(frame); - } - } + case ADD -> {} + case MOD -> {} + case MUL -> {} + case EXT -> {} + case WCP -> {} case BIN -> {} - case SHF -> { - if (this.pch.exceptions().noStackException()) { - this.shf.tracePostOpcode(frame); - } - } + case SHF -> {} case KEC -> {} case CONTEXT -> {} case ACCOUNT -> {} case COPY -> {} case TRANSACTION -> {} case BATCH -> { - if (this.currentFrame().opCode() == OpCode.BLOCKHASH) { - this.blockhash.tracePostOpcode(frame); - } - } - case STACK_RAM -> { - if (this.pch.exceptions().noStackException()) { - this.mxp.tracePostOpcode(frame); - } + this.blockhash.tracePostOpcode(frame); } + case STACK_RAM -> {} case STORAGE -> {} case JUMP -> {} case MACHINE_STATE -> {} @@ -789,7 +758,9 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope case DUP -> {} case SWAP -> {} case LOG -> {} - case CREATE -> {} + case CREATE -> { + this.romLex.tracePostOpcode(frame); + } case CALL -> {} case HALT -> {} case INVALID -> {} From ceb424d32350903093ab6185f34c5628e27af9a1 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 19 Jun 2024 15:51:31 +0530 Subject: [PATCH 128/461] fix relative block number in hub tracing --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 1 - .../zktracer/module/hub/fragment/CommonFragment.java | 4 ++-- .../linea/zktracer/module/hub/transients/Conflation.java | 8 +------- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index e38b962e86..1fb42c70a4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -409,7 +409,6 @@ public void popTransaction() { /** Tracing Operation, triggered by Besu hook */ @Override public void traceStartConflation(long blockCount) { - this.transients.conflation().update(); for (Module m : this.modules) { m.traceStartConflation(blockCount); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index acfcddb198..bd79a3bec0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -130,8 +130,8 @@ public static CommonFragment fromHub( return CommonFragment.builder() .hub(hub) - .absoluteTransactionNumber(hub.transients().tx().getAbsoluteTransactionNumber()) - .relativeBlockNumber(hub.transients().conflation().number()) + .absoluteTransactionNumber(hub.txStack().current().getAbsoluteTransactionNumber()) + .relativeBlockNumber(hub.txStack().current().getRelativeBlockNumber()) .hubProcessingPhase(hub.state.getProcessingPhase()) .stamps(hub.state.stamps().snapshot()) .instructionFamily(hub.opCodeData().instructionFamily()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java index 48366ab62d..84cdff02f2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java @@ -26,8 +26,7 @@ @Accessors(fluent = true) @Getter public class Conflation { - private int number = 0; - private DeploymentInfo deploymentInfo; + private final DeploymentInfo deploymentInfo = new DeploymentInfo(); private final List logs = new ArrayList<>(100); public int log(LogInvocation logInvocation) { @@ -38,9 +37,4 @@ public int log(LogInvocation logInvocation) { public int currentLogId() { return this.logs.size() - 1; } - - public void update() { - this.number++; - this.deploymentInfo = new DeploymentInfo(); - } } From 2cd5e518d72a925d7750aea3c656ce3c14ce06e5 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 19 Jun 2024 14:46:14 +0200 Subject: [PATCH 129/461] fix(oob): improved ctMax computation and managed modexpXbs cases --- .../zktracer/module/oob/ModexpXbsCase.java | 15 ++++ .../linea/zktracer/module/oob/Oob.java | 17 ++++- .../zktracer/module/oob/OobOperation.java | 74 +++++++++++-------- 3 files changed, 72 insertions(+), 34 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java new file mode 100644 index 0000000000..a319ac37ed --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java @@ -0,0 +1,15 @@ +package net.consensys.linea.zktracer.module.oob; + +enum ModexpXbsCase { + NONE, + OOB_INST_MODEXP_BBS, + OOB_INST_MODEXP_EBS, + OOB_INST_MODEXP_MBS; + + public ModexpXbsCase next() { + // Values() returns an array containing all the values of the enum in order + // this.ordinal() returns the ordinal of this enum constant (its position in its enum + // declaration) + return values()[(this.ordinal() + 1) % values().length]; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index d25d51035d..8f72aabbc5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.oob; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import java.math.BigInteger; @@ -52,8 +53,20 @@ public String moduleKey() { return "OOB"; } + ModexpXbsCase modexpXbsCase = ModexpXbsCase.NONE; + public void call(OobCall oobCall) { - this.chunks.add(new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub)); + // If the call is a modexpXbs, set the modexpXbsCase + if (oobCall.oobInstruction() == OOB_INST_MODEXP_XBS) { + modexpXbsCase = modexpXbsCase.next(); + } + // Add the operation to the chunks + this.chunks.add( + new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub, modexpXbsCase)); + // Reset the modexpXbsCase after the operation + if (modexpXbsCase == ModexpXbsCase.OOB_INST_MODEXP_MBS) { + modexpXbsCase = ModexpXbsCase.NONE; + } } @Override @@ -101,7 +114,7 @@ final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { trace .stamp(stamp) .ct((short) ct) - .ctMax((short) chunk.maxCt()) + .ctMax((short) chunk.getMaxCt()) .oobInst(bigIntegerToBytes(BigInteger.valueOf(chunk.getOobInst()))) .isJump(chunk.isJump()) .isJumpi(chunk.isJumpi()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index fe39587ebd..2d43d924dc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -117,6 +117,7 @@ public class OobOperation extends ModuleOperation { @EqualsAndHashCode.Include private int oobInst; @EqualsAndHashCode.Include @Setter private OobCall oobCall; + private int maxCt; private boolean isJump; private boolean isJumpi; private boolean isRdc; @@ -169,13 +170,16 @@ public class OobOperation extends ModuleOperation { private final Wcp wcp; private final Hub hub; + ModexpXbsCase modexpXbsCase; + public OobOperation( OobCall oobCall, final MessageFrame frame, final Add add, final Mod mod, final Wcp wcp, - final Hub hub) { + final Hub hub, + ModexpXbsCase modexpXbsCase) { this.oobCall = oobCall; this.add = add; @@ -183,7 +187,9 @@ public OobOperation( this.wcp = wcp; this.hub = hub; - setFlagsAndWghtSumAndIncomingInst(); + this.modexpXbsCase = modexpXbsCase; + + setFlagsAndWghtSumAndIncomingInstAndMaxCt(); // Init arrays int nRows = nRows(); @@ -202,99 +208,128 @@ public OobOperation( populateColumns(frame); } - private void setFlagsAndWghtSumAndIncomingInst() { + private void setFlagsAndWghtSumAndIncomingInstAndMaxCt() { switch (oobCall.oobInstruction()) { case OOB_INST_JUMP -> { isJump = true; wghtSum = OOB_INST_JUMP; + maxCt = CT_MAX_JUMP; } case OOB_INST_JUMPI -> { isJumpi = true; wghtSum = OOB_INST_JUMPI; + maxCt = CT_MAX_JUMPI; } case OOB_INST_RDC -> { isRdc = true; wghtSum = OOB_INST_RDC; + maxCt = CT_MAX_RDC; } case OOB_INST_CDL -> { isCdl = true; wghtSum = OOB_INST_CDL; + maxCt = CT_MAX_CDL; } case OOB_INST_CALL -> { isCall = true; wghtSum = OOB_INST_CALL; + maxCt = CT_MAX_CALL; } case OOB_INST_XCALL -> { isXCall = true; wghtSum = OOB_INST_XCALL; + maxCt = CT_MAX_XCALL; } case OOB_INST_CREATE -> { isCreate = true; wghtSum = OOB_INST_CREATE; + maxCt = CT_MAX_CREATE; } case OOB_INST_SSTORE -> { isSstore = true; wghtSum = OOB_INST_SSTORE; + maxCt = CT_MAX_SSTORE; } case OOB_INST_DEPLOYMENT -> { isDeployment = true; wghtSum = OOB_INST_DEPLOYMENT; + maxCt = CT_MAX_DEPLOYMENT; } case OOB_INST_ECRECOVER -> { isEcRecover = true; wghtSum = OOB_INST_ECRECOVER; + maxCt = CT_MAX_ECRECOVER; } case OOB_INST_SHA2 -> { isSha2 = true; wghtSum = OOB_INST_SHA2; + maxCt = CT_MAX_SHA2; } case OOB_INST_RIPEMD -> { isRipemd = true; wghtSum = OOB_INST_RIPEMD; + maxCt = CT_MAX_RIPEMD; } case OOB_INST_IDENTITY -> { isIdentity = true; wghtSum = OOB_INST_IDENTITY; + maxCt = CT_MAX_IDENTITY; } case OOB_INST_ECADD -> { isEcadd = true; wghtSum = OOB_INST_ECADD; + maxCt = CT_MAX_ECADD; } case OOB_INST_ECMUL -> { isEcmul = true; wghtSum = OOB_INST_ECMUL; + maxCt = CT_MAX_ECMUL; } case OOB_INST_ECPAIRING -> { isEcpairing = true; wghtSum = OOB_INST_ECPAIRING; + maxCt = CT_MAX_ECPAIRING; } case OOB_INST_BLAKE_CDS -> { isBlake2FCds = true; wghtSum = OOB_INST_BLAKE_CDS; + maxCt = CT_MAX_BLAKE2F_CDS; } case OOB_INST_BLAKE_PARAMS -> { isBlake2FParams = true; wghtSum = OOB_INST_BLAKE_PARAMS; + maxCt = CT_MAX_BLAKE2F_PARAMS; } case OOB_INST_MODEXP_CDS -> { isModexpCds = true; wghtSum = OOB_INST_MODEXP_CDS; + maxCt = CT_MAX_MODEXP_CDS; } case OOB_INST_MODEXP_XBS -> { isModexpXbs = true; + switch (modexpXbsCase) { + case OOB_INST_MODEXP_BBS -> isModexpBbs = true; + case OOB_INST_MODEXP_EBS -> isModexpEbs = true; + case OOB_INST_MODEXP_MBS -> isModexpMbs = true; + case NONE -> throw new IllegalArgumentException("Invalid modexpXbsCase"); + } wghtSum = OOB_INST_MODEXP_XBS; + maxCt = CT_MAX_MODEXP_XBS; } case OOB_INST_MODEXP_LEAD -> { isModexpLead = true; wghtSum = OOB_INST_MODEXP_LEAD; + maxCt = CT_MAX_MODEXP_LEAD; } case OOB_INST_MODEXP_PRICING -> { prcModexpPricing = true; wghtSum = OOB_INST_MODEXP_PRICING; + maxCt = CT_MAX_MODEXP_PRICING; } case OOB_INST_MODEXP_EXTRACT -> { prcModexpExtract = true; wghtSum = OOB_INST_MODEXP_EXTRACT; + maxCt = CT_MAX_MODEXP_EXTRACT; } } oobInst = wghtSum; @@ -328,34 +363,8 @@ public boolean isPrecompile() { return isCommonPrecompile() || isBlakePrecompile() || isModexpPrecompile(); } - public int maxCt() { - return CT_MAX_JUMP * booleanToInt(isJump) - + CT_MAX_JUMPI * booleanToInt(isJumpi) - + CT_MAX_RDC * booleanToInt(isRdc) - + CT_MAX_CDL * booleanToInt(isCdl) - + CT_MAX_XCALL * booleanToInt(isXCall) - + CT_MAX_CALL * booleanToInt(isCall) - + CT_MAX_CREATE * booleanToInt(isCreate) - + CT_MAX_SSTORE * booleanToInt(isSstore) - + CT_MAX_DEPLOYMENT * booleanToInt(isDeployment) - + CT_MAX_ECRECOVER * booleanToInt(isEcRecover) - + CT_MAX_SHA2 * booleanToInt(isSha2) - + CT_MAX_RIPEMD * booleanToInt(isRipemd) - + CT_MAX_IDENTITY * booleanToInt(isIdentity) - + CT_MAX_ECADD * booleanToInt(isEcadd) - + CT_MAX_ECMUL * booleanToInt(isEcmul) - + CT_MAX_ECPAIRING * booleanToInt(isEcpairing) - + CT_MAX_BLAKE2F_CDS * booleanToInt(isBlake2FCds) - + CT_MAX_BLAKE2F_PARAMS * booleanToInt(isBlake2FParams) - + CT_MAX_MODEXP_CDS * booleanToInt(isModexpCds) - + CT_MAX_MODEXP_XBS * booleanToInt(isModexpXbs) - + CT_MAX_MODEXP_LEAD * booleanToInt(isModexpLead) - + CT_MAX_MODEXP_PRICING * booleanToInt(prcModexpPricing) - + CT_MAX_MODEXP_EXTRACT * booleanToInt(prcModexpExtract); - } - public int nRows() { - return maxCt() + 1; + return maxCt + 1; } private void populateColumns(final MessageFrame frame) { @@ -540,13 +549,14 @@ private void populateColumns(final MessageFrame frame) { prcModexpXbsOobCall.setXbsLo(EWord.of(ebs).loBigInt()); prcModexpXbsOobCall.setYbsLo(BigInteger.ZERO); prcModexpXbsOobCall.setComputeMax(false); - } else { - // isModexpMbs + } else if (isModexpMbs) { prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; prcModexpXbsOobCall.setXbsHi(EWord.of(mbs).hiBigInt()); prcModexpXbsOobCall.setXbsLo(EWord.of(mbs).loBigInt()); prcModexpXbsOobCall.setYbsLo(EWord.of(bbs).loBigInt()); prcModexpXbsOobCall.setComputeMax(true); + } else { + throw new RuntimeException("modexpXbsCase is not set to a valid value"); } setModexpXbs(prcModexpXbsOobCall); } else if (isModexpLead) { From 6917fcb2c8fc43e0a2c99c450879f9372d1e030b Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 19 Jun 2024 15:49:55 +0200 Subject: [PATCH 130/461] fix(oob): minor fix --- .../main/java/net/consensys/linea/zktracer/module/oob/Oob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 8f72aabbc5..a10db5f28c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -56,7 +56,7 @@ public String moduleKey() { ModexpXbsCase modexpXbsCase = ModexpXbsCase.NONE; public void call(OobCall oobCall) { - // If the call is a modexpXbs, set the modexpXbsCase + // If OOB_INST_MODEXP_XBS is executed, set the modexpXbsCase if (oobCall.oobInstruction() == OOB_INST_MODEXP_XBS) { modexpXbsCase = modexpXbsCase.next(); } From 5ff08f23a3d0508a89f8839a4601df0e9e082480 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 19 Jun 2024 18:27:18 +0200 Subject: [PATCH 131/461] feat(exp): managed expCall filling and flow --- .../linea/zktracer/module/exp/Exp.java | 15 +- .../zktracer/module/exp/ExpLogOperation.java | 88 ------ .../zktracer/module/exp/ExpOperation.java | 279 ++++++++++++++++-- .../module/exp/ModexpLogOperation.java | 198 ------------- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/fragment/imc/ImcFragment.java | 25 +- .../hub/fragment/imc/call/exp/ExpCall.java | 23 ++ ...lForExpPricing.java => ExplogExpCall.java} | 18 +- ...Computation.java => ModexplogExpCall.java} | 32 +- .../Blake2fCallDataSizeOobCall.java | 2 - .../precompiles/PrecompileLinesGenerator.java | 9 +- 11 files changed, 356 insertions(+), 335 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCall.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/{ExpCallForExpPricing.java => ExplogExpCall.java} (78%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/{ExpCallForModexpLogComputation.java => ModexplogExpCall.java} (61%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java index 2b06dc5846..5ed92c538e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java @@ -23,8 +23,8 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForExpPricing; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; import net.consensys.linea.zktracer.module.wcp.Wcp; @Slf4j @@ -34,6 +34,7 @@ public class Exp implements Module { private final StackedSet chunks = new StackedSet<>(); private final Wcp wcp; + private final Hub hub; @Override public String moduleKey() { @@ -60,13 +61,19 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - public void callExpLogCall(final ExpCallForExpPricing c) { + /* + public void callExpLogCall(final ExplogExpCall c) { this.chunks.add(ExpLogOperation.fromExpLogCall(this.wcp, c)); } - public void callModExpLogCall(final ExpCallForModexpLogComputation c) { + public void callModExpLogCall(final ModexplogExpCall c) { this.chunks.add(ModexpLogOperation.fromExpLogCall(this.wcp, c)); } + */ + + public void call(ExpCall expCall) { + this.chunks.add(new ExpOperation(expCall, wcp, hub)); + } @Override public void commit(List buffers) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java deleted file mode 100644 index 249d069a41..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.exp; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_EXPLOG; -import static net.consensys.linea.zktracer.module.exp.Trace.ISZERO; -import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_CMPTN_EXP_LOG; -import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_PRPRC_EXP_LOG; -import static net.consensys.linea.zktracer.opcode.gas.GasConstants.G_EXP_BYTE; - -import lombok.EqualsAndHashCode; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForExpPricing; -import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -@RequiredArgsConstructor -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -public class ExpLogOperation extends ExpOperation { - @EqualsAndHashCode.Include private final EWord exponent; - private final long dynCost; - - @Override - protected boolean isExpLog() { - return true; - } - - public static ExpLogOperation fromExpLogCall(final Wcp wcp, final ExpCallForExpPricing c) { - final ExpLogOperation r = - new ExpLogOperation(c.exponent(), (long) G_EXP_BYTE.cost() * c.exponent().byteLength()); - r.wcp = wcp; - r.preCompute(); - - return r; - } - - @Override - public void preCompute() { - pMacroExpInst = EXP_INST_EXPLOG; - pMacroData1 = this.exponent.hi(); - pMacroData2 = this.exponent.lo(); - pMacroData5 = Bytes.ofUnsignedLong(this.dynCost); - initArrays(MAX_CT_PRPRC_EXP_LOG + 1); - - // Preprocessing - // First row - pPreprocessingWcpFlag[0] = true; - pPreprocessingWcpArg1Hi[0] = Bytes.EMPTY; - pPreprocessingWcpArg1Lo[0] = this.exponent.hi(); - pPreprocessingWcpArg2Hi[0] = Bytes.EMPTY; - pPreprocessingWcpArg2Lo[0] = Bytes.EMPTY; - pPreprocessingWcpInst[0] = UnsignedByte.of(ISZERO); - final boolean expnHiIsZero = wcp.callISZERO(this.exponent.hi()); - ; - pPreprocessingWcpRes[0] = expnHiIsZero; - - // Linking constraints and fill rawAcc - pComputationPltJmp = 16; - pComputationRawAcc = this.exponent.hi(); - if (expnHiIsZero) { - pComputationRawAcc = this.exponent.lo(); - } - - // Fill trimAcc - short maxCt = (short) MAX_CT_CMPTN_EXP_LOG; - for (short i = 0; i < maxCt + 1; i++) { - boolean pltBit = i >= pComputationPltJmp; - byte rawByte = pComputationRawAcc.get(i); - byte trimByte = pltBit ? 0 : rawByte; - pComputationTrimAcc = Bytes.concatenate(pComputationTrimAcc, Bytes.of(trimByte)); - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index fa6de58dd4..4b25a10954 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -15,19 +15,42 @@ package net.consensys.linea.zktracer.module.exp; +import static com.google.common.math.BigIntegerMath.log2; +import static java.lang.Math.min; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_ISZERO; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_LT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_EXPLOG; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_MODEXPLOG; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGEPO; +import static net.consensys.linea.zktracer.module.exp.Trace.ISZERO; import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_CMPTN_EXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_CMPTN_MODEXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_PRPRC_EXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_PRPRC_MODEXP_LOG; +import static net.consensys.linea.zktracer.opcode.gas.GasConstants.G_EXP_BYTE; +import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import static net.consensys.linea.zktracer.types.Utils.leftPadTo; +import java.math.BigInteger; +import java.math.RoundingMode; + +import lombok.EqualsAndHashCode; import lombok.Getter; import net.consensys.linea.zktracer.container.ModuleOperation; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexplogExpCall; +import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.wcp.Wcp; +import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; @Getter -public abstract class ExpOperation extends ModuleOperation { +public class ExpOperation extends ModuleOperation { protected short pComputationPltJmp = 0; protected Bytes pComputationRawAcc; // (last row) paired with RawByte protected Bytes pComputationTrimAcc = Bytes.EMPTY; // (last row) paired with TrimByte @@ -48,31 +71,204 @@ public abstract class ExpOperation extends ModuleOperation { protected UnsignedByte[] pPreprocessingWcpInst; protected boolean[] pPreprocessingWcpRes; - protected Wcp wcp; + boolean isExpLog; - protected abstract boolean isExpLog(); + // EXPLOG specific + @EqualsAndHashCode.Include private EWord exponent; + private long dynCost; - protected void initArrays(int pPreprocessingLen) { - pPreprocessingWcpFlag = new boolean[pPreprocessingLen]; - pPreprocessingWcpArg1Hi = new Bytes[pPreprocessingLen]; - pPreprocessingWcpArg1Lo = new Bytes[pPreprocessingLen]; - pPreprocessingWcpArg2Hi = new Bytes[pPreprocessingLen]; - pPreprocessingWcpArg2Lo = new Bytes[pPreprocessingLen]; - pPreprocessingWcpInst = new UnsignedByte[pPreprocessingLen]; - pPreprocessingWcpRes = new boolean[pPreprocessingLen]; + // MODEXPLOG specific + @EqualsAndHashCode.Include private EWord rawLead; + @EqualsAndHashCode.Include private int cdsCutoff; + @EqualsAndHashCode.Include private int ebsCutoff; + private BigInteger leadLog; + private EWord trim; + + ExpCall expCall; + private Wcp wcp; + private Hub hub; + + public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { + this.expCall = expCall; + this.wcp = wcp; + this.hub = hub; + if (expCall.expInstruction() == EXP_INST_EXPLOG) { + this.isExpLog = true; + ExplogExpCall explogExpCall = (ExplogExpCall) expCall; + + // Extract inputs + this.exponent = EWord.of(hub.messageFrame().getStackItem(1)); + this.dynCost = (long) G_EXP_BYTE.cost() * exponent.byteLength(); + + // Fill expCall + explogExpCall.setExponent(exponent); + explogExpCall.setDynCost(dynCost); + + // Execute preprocessing + preComputeForExplog(); + } else if (expCall.expInstruction() == EXP_INST_MODEXPLOG) { + this.isExpLog = false; + ModexplogExpCall modexplogExpCall = (ModexplogExpCall) expCall; + + // Extract inputs + PrecompileInvocation precompileInvocation = modexplogExpCall.getPrecompileInvocation(); + ModExpMetadata modexpMetadata = (ModExpMetadata) precompileInvocation.metadata(); + final int bbsInt = modexpMetadata.bbs().toUnsignedBigInteger().intValueExact(); + final int ebsInt = modexpMetadata.ebs().toUnsignedBigInteger().intValueExact(); + this.rawLead = modexpMetadata.rawLeadingWord(); + this.cdsCutoff = + Math.min((int) (precompileInvocation.callDataSource().length() - 96 - bbsInt), 32); + this.ebsCutoff = Math.min(ebsInt, 32); + this.leadLog = + BigInteger.valueOf(LeadLogTrimLead.fromArgs(rawLead, cdsCutoff, ebsCutoff).leadLog()); + + // Fill expCall + modexplogExpCall.setRawLeadingWord(rawLead); + modexplogExpCall.setCdsCutoff(cdsCutoff); + modexplogExpCall.setEbsCutoff(ebsCutoff); + modexplogExpCall.setLeadLog(leadLog); + + // Execute preprocessing + preComputeForModexpLog(); + } } - @Override - protected int computeLineCount() { - // We assume MAX_CT_MACRO_EXP_LOG = MAX_CT_MACRO_MODEXP_LOG = 0; - if (this.isExpLog()) { - return MAX_CT_CMPTN_EXP_LOG + MAX_CT_PRPRC_EXP_LOG + 3; + public void preComputeForExplog() { + pMacroExpInst = EXP_INST_EXPLOG; + pMacroData1 = this.exponent.hi(); + pMacroData2 = this.exponent.lo(); + pMacroData5 = Bytes.ofUnsignedLong(this.dynCost); + initArrays(MAX_CT_PRPRC_EXP_LOG + 1); + + // Preprocessing + // First row + pPreprocessingWcpFlag[0] = true; + pPreprocessingWcpArg1Hi[0] = Bytes.EMPTY; + pPreprocessingWcpArg1Lo[0] = this.exponent.hi(); + pPreprocessingWcpArg2Hi[0] = Bytes.EMPTY; + pPreprocessingWcpArg2Lo[0] = Bytes.EMPTY; + pPreprocessingWcpInst[0] = UnsignedByte.of(ISZERO); + final boolean expnHiIsZero = wcp.callISZERO(this.exponent.hi()); + ; + pPreprocessingWcpRes[0] = expnHiIsZero; + + // Linking constraints and fill rawAcc + pComputationPltJmp = 16; + pComputationRawAcc = this.exponent.hi(); + if (expnHiIsZero) { + pComputationRawAcc = this.exponent.lo(); } - return MAX_CT_CMPTN_MODEXP_LOG + MAX_CT_PRPRC_MODEXP_LOG + 3; + // Fill trimAcc + short maxCt = (short) MAX_CT_CMPTN_EXP_LOG; + for (short i = 0; i < maxCt + 1; i++) { + boolean pltBit = i >= pComputationPltJmp; + byte rawByte = pComputationRawAcc.get(i); + byte trimByte = pltBit ? 0 : rawByte; + pComputationTrimAcc = Bytes.concatenate(pComputationTrimAcc, Bytes.of(trimByte)); + } } - public abstract void preCompute(); + public void preComputeForModexpLog() { + pMacroExpInst = EXP_INST_MODEXPLOG; + pMacroData1 = this.rawLead.hi(); + pMacroData2 = this.rawLead.lo(); + pMacroData3 = Bytes.of(this.cdsCutoff); + pMacroData4 = Bytes.of(this.ebsCutoff); + pMacroData5 = bigIntegerToBytes(this.leadLog); + initArrays(MAX_CT_PRPRC_MODEXP_LOG + 1); + + // Preprocessing + final BigInteger trimLimb = + this.trim.hi().isZero() ? this.trim.loBigInt() : this.trim.hiBigInt(); + final int trimLog = trimLimb.signum() == 0 ? 0 : log2(trimLimb, RoundingMode.FLOOR); + final int nBitsOfLeadingByteExcludingLeadingBit = trimLog % 8; + final int nBytesExcludingLeadingByte = trimLog / 8; + + // First row + pPreprocessingWcpFlag[0] = true; + pPreprocessingWcpArg1Hi[0] = Bytes.of(0); + pPreprocessingWcpArg1Lo[0] = Bytes.of(this.cdsCutoff); + pPreprocessingWcpArg2Hi[0] = Bytes.of(0); + pPreprocessingWcpArg2Lo[0] = Bytes.of(this.ebsCutoff); + pPreprocessingWcpInst[0] = UnsignedByte.of(EVM_INST_LT); + pPreprocessingWcpRes[0] = wcp.callLT(Bytes.of(this.cdsCutoff), Bytes.of(this.ebsCutoff)); + final int minCutoff = min(this.cdsCutoff, this.ebsCutoff); + + // Second row + pPreprocessingWcpFlag[1] = true; + pPreprocessingWcpArg1Hi[1] = Bytes.of(0); + pPreprocessingWcpArg1Lo[1] = Bytes.of(minCutoff); + pPreprocessingWcpArg2Hi[1] = Bytes.of(0); + pPreprocessingWcpArg2Lo[1] = Bytes.of(LLARGEPO); + pPreprocessingWcpInst[1] = UnsignedByte.of(EVM_INST_LT); + final boolean minCutoffLeq16 = wcp.callLT(Bytes.of(minCutoff), Bytes.of(LLARGEPO)); + pPreprocessingWcpRes[1] = minCutoffLeq16; + + // Third row + pPreprocessingWcpFlag[2] = true; + pPreprocessingWcpArg1Hi[2] = Bytes.of(0); + pPreprocessingWcpArg1Lo[2] = Bytes.of(this.ebsCutoff); + pPreprocessingWcpArg2Hi[2] = Bytes.of(0); + pPreprocessingWcpArg2Lo[2] = Bytes.of(LLARGEPO); + pPreprocessingWcpInst[2] = UnsignedByte.of(EVM_INST_LT); + pPreprocessingWcpRes[2] = wcp.callLT(Bytes.of(this.ebsCutoff), Bytes.of(LLARGEPO)); + + // Fourth row + pPreprocessingWcpFlag[3] = true; + pPreprocessingWcpArg1Hi[3] = Bytes.of(0); + pPreprocessingWcpArg1Lo[3] = this.rawLead.hi(); + pPreprocessingWcpArg2Hi[3] = Bytes.of(0); + pPreprocessingWcpArg2Lo[3] = Bytes.of(0); + pPreprocessingWcpInst[3] = UnsignedByte.of(EVM_INST_ISZERO); + final boolean rawHiPartIsZero = wcp.callISZERO(this.rawLead.hi()); + pPreprocessingWcpRes[3] = rawHiPartIsZero; + + // Fifth row + final int paddedBase2Log = + 8 * nBytesExcludingLeadingByte + nBitsOfLeadingByteExcludingLeadingBit; + + pPreprocessingWcpFlag[4] = true; + pPreprocessingWcpArg1Hi[4] = Bytes.of(0); + pPreprocessingWcpArg1Lo[4] = Bytes.of(paddedBase2Log); + pPreprocessingWcpArg2Hi[4] = Bytes.of(0); + pPreprocessingWcpArg2Lo[4] = Bytes.of(0); + pPreprocessingWcpInst[4] = UnsignedByte.of(EVM_INST_ISZERO); + pPreprocessingWcpRes[4] = wcp.callISZERO(Bytes.of(paddedBase2Log)); + + // Linking constraints and fill rawAcc + if (minCutoffLeq16) { + pComputationRawAcc = leftPadTo(this.rawLead.hi(), LLARGE); + } else if (!rawHiPartIsZero) { + pComputationRawAcc = leftPadTo(this.rawLead.hi(), LLARGE); + } else { + pComputationRawAcc = leftPadTo(this.rawLead.lo(), LLARGE); + } + + // Fill pltJmp + if (minCutoffLeq16) { + pComputationPltJmp = (short) minCutoff; + } else { + if (!rawHiPartIsZero) { + pComputationPltJmp = (short) 16; + } else { + pComputationPltJmp = (short) (minCutoff - 16); + } + } + + // Fill trimAcc + final short maxCt = (short) MAX_CT_CMPTN_MODEXP_LOG; + for (short i = 0; i < maxCt + 1; i++) { + final boolean pltBit = i >= pComputationPltJmp; + final byte rawByte = pComputationRawAcc.get(i); + final byte trimByte = pltBit ? 0 : rawByte; + pComputationTrimAcc = Bytes.concatenate(pComputationTrimAcc, Bytes.of(trimByte)); + if (trimByte != 0 && pComputationMsb.toInteger() == 0) { + // Fill msb + pComputationMsb = UnsignedByte.of(trimByte); + } + } + } final void traceComputation(int stamp, Trace trace) { boolean tanzb; @@ -159,4 +355,51 @@ final void tracePreprocessing(int stamp, Trace trace) { .fillAndValidateRow(); } } + + private boolean isExpLog() { + return isExpLog; + } + + protected void initArrays(int pPreprocessingLen) { + pPreprocessingWcpFlag = new boolean[pPreprocessingLen]; + pPreprocessingWcpArg1Hi = new Bytes[pPreprocessingLen]; + pPreprocessingWcpArg1Lo = new Bytes[pPreprocessingLen]; + pPreprocessingWcpArg2Hi = new Bytes[pPreprocessingLen]; + pPreprocessingWcpArg2Lo = new Bytes[pPreprocessingLen]; + pPreprocessingWcpInst = new UnsignedByte[pPreprocessingLen]; + pPreprocessingWcpRes = new boolean[pPreprocessingLen]; + } + + @Override + protected int computeLineCount() { + // We assume MAX_CT_MACRO_EXP_LOG = MAX_CT_MACRO_MODEXP_LOG = 0; + if (this.isExpLog()) { + return MAX_CT_CMPTN_EXP_LOG + MAX_CT_PRPRC_EXP_LOG + 3; + } + return MAX_CT_CMPTN_MODEXP_LOG + MAX_CT_PRPRC_MODEXP_LOG + 3; + } + + public record LeadLogTrimLead(int leadLog, BigInteger trim) { + public static LeadLogTrimLead fromArgs(EWord rawLead, int cdsCutoff, int ebsCutoff) { + // min_cutoff + final int minCutoff = min(cdsCutoff, ebsCutoff); + + BigInteger mask = new BigInteger("FF".repeat(minCutoff), 16); + if (minCutoff < 32) { + // 32 - minCutoff is the shift distance in bytes, but we need bits + mask = mask.shiftLeft(8 * (32 - minCutoff)); + } + + // trim (keep only minCutoff bytes of rawLead) + final BigInteger trim = rawLead.toUnsignedBigInteger().and(mask); + + // lead (keep only minCutoff bytes of rawLead and potentially pad to ebsCutoff with 0's) + final BigInteger lead = trim.shiftRight(8 * (32 - ebsCutoff)); + + // lead_log (same as EYP) + final int leadLog = lead.signum() == 0 ? 0 : log2(lead, RoundingMode.FLOOR); + + return new LeadLogTrimLead(leadLog, trim); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java deleted file mode 100644 index c9cb6b0c73..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.exp; - -import static com.google.common.math.BigIntegerMath.log2; -import static java.lang.Math.min; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_ISZERO; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_LT; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_MODEXPLOG; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGEPO; -import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_CMPTN_MODEXP_LOG; -import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_PRPRC_MODEXP_LOG; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; - -import java.math.BigInteger; -import java.math.RoundingMode; - -import lombok.EqualsAndHashCode; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; -import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; - -@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) -@RequiredArgsConstructor -public class ModexpLogOperation extends ExpOperation { - public record LeadLogTrimLead(int leadLog, BigInteger trim) { - public static LeadLogTrimLead fromArgs(EWord rawLead, int cdsCutoff, int ebsCutoff) { - // min_cutoff - final int minCutoff = min(cdsCutoff, ebsCutoff); - - BigInteger mask = new BigInteger("FF".repeat(minCutoff), 16); - if (minCutoff < 32) { - // 32 - minCutoff is the shift distance in bytes, but we need bits - mask = mask.shiftLeft(8 * (32 - minCutoff)); - } - - // trim (keep only minCutoff bytes of rawLead) - final BigInteger trim = rawLead.toUnsignedBigInteger().and(mask); - - // lead (keep only minCutoff bytes of rawLead and potentially pad to ebsCutoff with 0's) - final BigInteger lead = trim.shiftRight(8 * (32 - ebsCutoff)); - - // lead_log (same as EYP) - final int leadLog = lead.signum() == 0 ? 0 : log2(lead, RoundingMode.FLOOR); - - return new LeadLogTrimLead(leadLog, trim); - } - } - - @EqualsAndHashCode.Include private final EWord rawLead; - @EqualsAndHashCode.Include private final int cdsCutoff; - @EqualsAndHashCode.Include private final int ebsCutoff; - private final BigInteger leadLog; - private final EWord trim; - - @Override - protected boolean isExpLog() { - return false; - } - - public static ModexpLogOperation fromExpLogCall( - final Wcp wcp, final ExpCallForModexpLogComputation c) { - final LeadLogTrimLead leadLogTrimLead = - LeadLogTrimLead.fromArgs(c.rawLeadingWord(), c.cdsCutoff(), c.ebsCutoff()); - - final ModexpLogOperation modExpLogOperation = - new ModexpLogOperation( - c.rawLeadingWord(), - c.cdsCutoff(), - c.ebsCutoff(), - BigInteger.valueOf(leadLogTrimLead.leadLog), - EWord.of(leadLogTrimLead.trim)); - - modExpLogOperation.wcp = wcp; - modExpLogOperation.preCompute(); - return modExpLogOperation; - } - - @Override - public void preCompute() { - pMacroExpInst = EXP_INST_MODEXPLOG; - pMacroData1 = this.rawLead.hi(); - pMacroData2 = this.rawLead.lo(); - pMacroData3 = Bytes.of(this.cdsCutoff); - pMacroData4 = Bytes.of(this.ebsCutoff); - pMacroData5 = bigIntegerToBytes(this.leadLog); - initArrays(MAX_CT_PRPRC_MODEXP_LOG + 1); - - // Preprocessing - final BigInteger trimLimb = - this.trim.hi().isZero() ? this.trim.loBigInt() : this.trim.hiBigInt(); - final int trimLog = trimLimb.signum() == 0 ? 0 : log2(trimLimb, RoundingMode.FLOOR); - final int nBitsOfLeadingByteExcludingLeadingBit = trimLog % 8; - final int nBytesExcludingLeadingByte = trimLog / 8; - - // First row - pPreprocessingWcpFlag[0] = true; - pPreprocessingWcpArg1Hi[0] = Bytes.of(0); - pPreprocessingWcpArg1Lo[0] = Bytes.of(this.cdsCutoff); - pPreprocessingWcpArg2Hi[0] = Bytes.of(0); - pPreprocessingWcpArg2Lo[0] = Bytes.of(this.ebsCutoff); - pPreprocessingWcpInst[0] = UnsignedByte.of(EVM_INST_LT); - pPreprocessingWcpRes[0] = wcp.callLT(Bytes.of(this.cdsCutoff), Bytes.of(this.ebsCutoff)); - final int minCutoff = min(this.cdsCutoff, this.ebsCutoff); - - // Second row - pPreprocessingWcpFlag[1] = true; - pPreprocessingWcpArg1Hi[1] = Bytes.of(0); - pPreprocessingWcpArg1Lo[1] = Bytes.of(minCutoff); - pPreprocessingWcpArg2Hi[1] = Bytes.of(0); - pPreprocessingWcpArg2Lo[1] = Bytes.of(LLARGEPO); - pPreprocessingWcpInst[1] = UnsignedByte.of(EVM_INST_LT); - final boolean minCutoffLeq16 = wcp.callLT(Bytes.of(minCutoff), Bytes.of(LLARGEPO)); - pPreprocessingWcpRes[1] = minCutoffLeq16; - - // Third row - pPreprocessingWcpFlag[2] = true; - pPreprocessingWcpArg1Hi[2] = Bytes.of(0); - pPreprocessingWcpArg1Lo[2] = Bytes.of(this.ebsCutoff); - pPreprocessingWcpArg2Hi[2] = Bytes.of(0); - pPreprocessingWcpArg2Lo[2] = Bytes.of(LLARGEPO); - pPreprocessingWcpInst[2] = UnsignedByte.of(EVM_INST_LT); - pPreprocessingWcpRes[2] = wcp.callLT(Bytes.of(this.ebsCutoff), Bytes.of(LLARGEPO)); - - // Fourth row - pPreprocessingWcpFlag[3] = true; - pPreprocessingWcpArg1Hi[3] = Bytes.of(0); - pPreprocessingWcpArg1Lo[3] = this.rawLead.hi(); - pPreprocessingWcpArg2Hi[3] = Bytes.of(0); - pPreprocessingWcpArg2Lo[3] = Bytes.of(0); - pPreprocessingWcpInst[3] = UnsignedByte.of(EVM_INST_ISZERO); - final boolean rawHiPartIsZero = wcp.callISZERO(this.rawLead.hi()); - pPreprocessingWcpRes[3] = rawHiPartIsZero; - - // Fifth row - final int paddedBase2Log = - 8 * nBytesExcludingLeadingByte + nBitsOfLeadingByteExcludingLeadingBit; - - pPreprocessingWcpFlag[4] = true; - pPreprocessingWcpArg1Hi[4] = Bytes.of(0); - pPreprocessingWcpArg1Lo[4] = Bytes.of(paddedBase2Log); - pPreprocessingWcpArg2Hi[4] = Bytes.of(0); - pPreprocessingWcpArg2Lo[4] = Bytes.of(0); - pPreprocessingWcpInst[4] = UnsignedByte.of(EVM_INST_ISZERO); - pPreprocessingWcpRes[4] = wcp.callISZERO(Bytes.of(paddedBase2Log)); - - // Linking constraints and fill rawAcc - if (minCutoffLeq16) { - pComputationRawAcc = leftPadTo(this.rawLead.hi(), LLARGE); - } else if (!rawHiPartIsZero) { - pComputationRawAcc = leftPadTo(this.rawLead.hi(), LLARGE); - } else { - pComputationRawAcc = leftPadTo(this.rawLead.lo(), LLARGE); - } - - // Fill pltJmp - if (minCutoffLeq16) { - pComputationPltJmp = (short) minCutoff; - } else { - if (!rawHiPartIsZero) { - pComputationPltJmp = (short) 16; - } else { - pComputationPltJmp = (short) (minCutoff - 16); - } - } - - // Fill trimAcc - final short maxCt = (short) MAX_CT_CMPTN_MODEXP_LOG; - for (short i = 0; i < maxCt + 1; i++) { - final boolean pltBit = i >= pComputationPltJmp; - final byte rawByte = pComputationRawAcc.get(i); - final byte trimByte = pltBit ? 0 : rawByte; - pComputationTrimAcc = Bytes.concatenate(pComputationTrimAcc, Bytes.of(trimByte)); - if (trimByte != 0 && pComputationMsb.toInteger() == 0) { - // Fill msb - pComputationMsb = UnsignedByte.of(trimByte); - } - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 1fb42c70a4..163c0357d5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -308,7 +308,7 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.pch = new PlatformController(this); this.mxp = new Mxp(this); - this.exp = new Exp(this.wcp); + this.exp = new Exp(this.wcp, this); this.romLex = new RomLex(this); this.rom = new Rom(this.romLex); this.rlpTxn = new RlpTxn(this.romLex); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 383a41a263..e81fb50dd0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -27,8 +27,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForExpPricing; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; @@ -170,7 +170,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { } if (hub.pch().signals().exp()) { - r.callExp(new ExpCallForExpPricing(EWord.of(hub.messageFrame().getStackItem(1)))); + r.callExp(new ExplogExpCall()); } if (hub.pch().signals().exp() && !hub.pch().exceptions().stackException()) { @@ -250,7 +250,19 @@ public ImcFragment callMmu(MmuCall f) { return this; } - public ImcFragment callExp(ExpCallForExpPricing f) { + public ImcFragment callExp(ExpCall f) { + if (expIsSet) { + throw new IllegalStateException("EXP already called"); + } else { + expIsSet = true; + } + this.hub.exp().call(f); + this.moduleCalls.add(f); + return this; + } + + /* + public ImcFragment callExp(ExplogExpCall f) { if (expIsSet) { throw new IllegalStateException("EXP already called"); } else { @@ -260,8 +272,10 @@ public ImcFragment callExp(ExpCallForExpPricing f) { this.moduleCalls.add(f); return this; } + */ - public ImcFragment callExp(ExpCallForModexpLogComputation f) { + /* + public ImcFragment callExp(ModexplogExpCall f) { if (modExpIsSet) { throw new IllegalStateException("MODEXP already called"); } else { @@ -271,6 +285,7 @@ public ImcFragment callExp(ExpCallForModexpLogComputation f) { this.moduleCalls.add(f); return this; } + */ public ImcFragment callMxp(MxpCall f) { if (mxpIsSet) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCall.java new file mode 100644 index 0000000000..499e31489a --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCall.java @@ -0,0 +1,23 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp; + +import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; + +/** This interface defines the API required to execute a call to the EXP module. */ +public interface ExpCall extends TraceSubFragment { + public int expInstruction(); +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCallForExpPricing.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExplogExpCall.java similarity index 78% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCallForExpPricing.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExplogExpCall.java index 5e54c621f9..a91408a59f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCallForExpPricing.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExplogExpCall.java @@ -16,14 +16,24 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_EXPLOG; -import static net.consensys.linea.zktracer.opcode.gas.GasConstants.G_EXP_BYTE; +import lombok.Getter; +import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; -public record ExpCallForExpPricing(EWord exponent) implements TraceSubFragment { +@Getter +@Setter +public class ExplogExpCall implements ExpCall { + EWord exponent; + long dynCost; + + @Override + public int expInstruction() { + return EXP_INST_EXPLOG; + } + @Override public Trace trace(Trace trace) { return trace @@ -31,6 +41,6 @@ public Trace trace(Trace trace) { .pMiscExpInst(EXP_INST_EXPLOG) .pMiscExpData1(exponent.hi()) .pMiscExpData2(exponent.lo()) - .pMiscExpData5(Bytes.ofUnsignedShort(G_EXP_BYTE.cost() * exponent.byteLength())); + .pMiscExpData5(Bytes.ofUnsignedLong(this.dynCost)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCallForModexpLogComputation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexplogExpCall.java similarity index 61% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCallForModexpLogComputation.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexplogExpCall.java index ddcf7be2e4..2fe5bf1ba3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCallForModexpLogComputation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexplogExpCall.java @@ -15,14 +15,33 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp; -import net.consensys.linea.zktracer.module.exp.ModexpLogOperation; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_MODEXPLOG; +import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; + +import java.math.BigInteger; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; +import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; -public record ExpCallForModexpLogComputation(EWord rawLeadingWord, int cdsCutoff, int ebsCutoff) - implements TraceSubFragment { +@Setter +@Getter +@RequiredArgsConstructor +public class ModexplogExpCall implements ExpCall { + final PrecompileInvocation precompileInvocation; + EWord rawLeadingWord; + int cdsCutoff; + int ebsCutoff; + BigInteger leadLog; + + @Override + public int expInstruction() { + return EXP_INST_MODEXPLOG; + } @Override public Trace trace(Trace trace) { @@ -32,9 +51,6 @@ public Trace trace(Trace trace) { .pMiscExpData2(rawLeadingWord.lo()) .pMiscExpData3(Bytes.ofUnsignedShort(cdsCutoff)) .pMiscExpData4(Bytes.ofUnsignedShort(ebsCutoff)) - .pMiscExpData5( - Bytes.ofUnsignedShort( - ModexpLogOperation.LeadLogTrimLead.fromArgs(rawLeadingWord, cdsCutoff, ebsCutoff) - .leadLog())); + .pMiscExpData5(bigIntegerToBytes(this.leadLog)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java index 216d14dd36..d64cd1e608 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -32,11 +32,9 @@ @Setter @RequiredArgsConstructor public class Blake2fCallDataSizeOobCall implements OobCall { - final PrecompileInvocation p; BigInteger cds; BigInteger returnAtCapacity; - boolean hubSuccess; boolean returnAtCapacityNonZero; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index 92be65d044..ce515582ea 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -23,7 +23,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCallForModexpLogComputation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexplogExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsOobCall; @@ -146,15 +146,10 @@ public static List generateFor(final Hub hub, final PrecompileInv .callOob(new ModexpLeadOobCall(p)) .callMmu(m.loadRawLeadingWord() ? MmuCall.forModExp(hub, p, 5) : MmuCall.nop()); if (m.loadRawLeadingWord()) { - line5.callExp( - new ExpCallForModexpLogComputation( - m.rawLeadingWord(), - Math.min((int) (p.callDataSource().length() - 96 - bbsInt), 32), - Math.min(ebsInt, 32))); + line5.callExp(new ModexplogExpCall(p)); } r.add(line5); r.add(ImcFragment.empty(hub).callOob(new ModexpPricingOobCall(p))); - if (p.ramFailure()) { r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); } else { From ec55405f2359dbb24cbb139be53e88c4e8b45a82 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 19 Jun 2024 22:00:41 +0200 Subject: [PATCH 132/461] fix(oob): modexpxbs business --- .../call/oob/precompiles/ModexpXbsCase.java | 22 +++++++++++++++++++ .../oob/precompiles/ModexpXbsOobCall.java | 1 + .../precompiles/PrecompileLinesGenerator.java | 7 +++--- .../zktracer/module/oob/ModexpXbsCase.java | 15 ------------- .../linea/zktracer/module/oob/Oob.java | 15 +------------ .../zktracer/module/oob/OobOperation.java | 12 ++++------ 6 files changed, 32 insertions(+), 40 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsCase.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsCase.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsCase.java new file mode 100644 index 0000000000..df7519ea6b --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsCase.java @@ -0,0 +1,22 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; + +public enum ModexpXbsCase { + OOB_INST_MODEXP_BBS, + OOB_INST_MODEXP_EBS, + OOB_INST_MODEXP_MBS; +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java index 20c0d107e0..1b98b905f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java @@ -34,6 +34,7 @@ public class ModexpXbsOobCall implements OobCall { final PrecompileInvocation p; + final ModexpXbsCase modexpXbsCase; BigInteger xbsHi; BigInteger xbsLo; BigInteger ybsLo; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index ce515582ea..cb94b88dac 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtractOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLeadOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricingOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsCase; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobCall; @@ -131,15 +132,15 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add(ImcFragment.empty(hub).callOob(new ModexpCallDataSizeOobCall(p))); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbsOobCall(p)) + .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_BBS)) .callMmu(m.extractBbs() ? MmuCall.forModExp(hub, p, 2) : MmuCall.nop())); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbsOobCall(p)) + .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_EBS)) .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 3) : MmuCall.nop())); r.add( ImcFragment.empty(hub) - .callOob(new ModexpXbsOobCall(p)) + .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_MBS)) .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 4) : MmuCall.nop())); final ImcFragment line5 = ImcFragment.empty(hub) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java deleted file mode 100644 index a319ac37ed..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/ModexpXbsCase.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.consensys.linea.zktracer.module.oob; - -enum ModexpXbsCase { - NONE, - OOB_INST_MODEXP_BBS, - OOB_INST_MODEXP_EBS, - OOB_INST_MODEXP_MBS; - - public ModexpXbsCase next() { - // Values() returns an array containing all the values of the enum in order - // this.ordinal() returns the ordinal of this enum constant (its position in its enum - // declaration) - return values()[(this.ordinal() + 1) % values().length]; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index a10db5f28c..cfd3aff5af 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.oob; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import java.math.BigInteger; @@ -53,20 +52,8 @@ public String moduleKey() { return "OOB"; } - ModexpXbsCase modexpXbsCase = ModexpXbsCase.NONE; - public void call(OobCall oobCall) { - // If OOB_INST_MODEXP_XBS is executed, set the modexpXbsCase - if (oobCall.oobInstruction() == OOB_INST_MODEXP_XBS) { - modexpXbsCase = modexpXbsCase.next(); - } - // Add the operation to the chunks - this.chunks.add( - new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub, modexpXbsCase)); - // Reset the modexpXbsCase after the operation - if (modexpXbsCase == ModexpXbsCase.OOB_INST_MODEXP_MBS) { - modexpXbsCase = ModexpXbsCase.NONE; - } + this.chunks.add(new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub)); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 2d43d924dc..fea6e6cf28 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -170,16 +170,13 @@ public class OobOperation extends ModuleOperation { private final Wcp wcp; private final Hub hub; - ModexpXbsCase modexpXbsCase; - public OobOperation( OobCall oobCall, final MessageFrame frame, final Add add, final Mod mod, final Wcp wcp, - final Hub hub, - ModexpXbsCase modexpXbsCase) { + final Hub hub) { this.oobCall = oobCall; this.add = add; @@ -187,8 +184,6 @@ public OobOperation( this.wcp = wcp; this.hub = hub; - this.modexpXbsCase = modexpXbsCase; - setFlagsAndWghtSumAndIncomingInstAndMaxCt(); // Init arrays @@ -307,12 +302,13 @@ private void setFlagsAndWghtSumAndIncomingInstAndMaxCt() { } case OOB_INST_MODEXP_XBS -> { isModexpXbs = true; - switch (modexpXbsCase) { + + switch (((ModexpXbsOobCall) oobCall).getModexpXbsCase()) { case OOB_INST_MODEXP_BBS -> isModexpBbs = true; case OOB_INST_MODEXP_EBS -> isModexpEbs = true; case OOB_INST_MODEXP_MBS -> isModexpMbs = true; - case NONE -> throw new IllegalArgumentException("Invalid modexpXbsCase"); } + wghtSum = OOB_INST_MODEXP_XBS; maxCt = CT_MAX_MODEXP_XBS; } From d0f9ff801554ac389451cd5093658e423f1a1d7a Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 19 Jun 2024 22:17:24 +0200 Subject: [PATCH 133/461] fix(oob): minor fixes --- .../net/consensys/linea/zktracer/module/exp/Exp.java | 10 ---------- .../linea/zktracer/module/exp/ExpOperation.java | 9 ++++++--- .../{ModexplogExpCall.java => ModexpLogExpCall.java} | 4 ++-- .../hub/precompiles/PrecompileLinesGenerator.java | 4 ++-- .../linea/zktracer/module/hub/signals/Signals.java | 2 +- 5 files changed, 11 insertions(+), 18 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/{ModexplogExpCall.java => ModexpLogExpCall.java} (94%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java index 5ed92c538e..eacf71c2c4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java @@ -61,16 +61,6 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - /* - public void callExpLogCall(final ExplogExpCall c) { - this.chunks.add(ExpLogOperation.fromExpLogCall(this.wcp, c)); - } - - public void callModExpLogCall(final ModexplogExpCall c) { - this.chunks.add(ModexpLogOperation.fromExpLogCall(this.wcp, c)); - } - */ - public void call(ExpCall expCall) { this.chunks.add(new ExpOperation(expCall, wcp, hub)); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index 4b25a10954..6265249e1c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -35,13 +35,14 @@ import java.math.BigInteger; import java.math.RoundingMode; +import com.google.common.base.Preconditions; import lombok.EqualsAndHashCode; import lombok.Getter; import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexplogExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexpLogExpCall; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.wcp.Wcp; @@ -108,13 +109,15 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { preComputeForExplog(); } else if (expCall.expInstruction() == EXP_INST_MODEXPLOG) { this.isExpLog = false; - ModexplogExpCall modexplogExpCall = (ModexplogExpCall) expCall; + ModexpLogExpCall modexplogExpCall = (ModexpLogExpCall) expCall; // Extract inputs - PrecompileInvocation precompileInvocation = modexplogExpCall.getPrecompileInvocation(); + PrecompileInvocation precompileInvocation = modexplogExpCall.getP(); ModExpMetadata modexpMetadata = (ModExpMetadata) precompileInvocation.metadata(); final int bbsInt = modexpMetadata.bbs().toUnsignedBigInteger().intValueExact(); final int ebsInt = modexpMetadata.ebs().toUnsignedBigInteger().intValueExact(); + Preconditions.checkArgument( + precompileInvocation.callDataSource().length() - 96 - bbsInt >= 0); this.rawLead = modexpMetadata.rawLeadingWord(); this.cdsCutoff = Math.min((int) (precompileInvocation.callDataSource().length() - 96 - bbsInt), 32); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexplogExpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexpLogExpCall.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexplogExpCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexpLogExpCall.java index 2fe5bf1ba3..57afebb62d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexplogExpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexpLogExpCall.java @@ -31,8 +31,8 @@ @Setter @Getter @RequiredArgsConstructor -public class ModexplogExpCall implements ExpCall { - final PrecompileInvocation precompileInvocation; +public class ModexpLogExpCall implements ExpCall { + final PrecompileInvocation p; EWord rawLeadingWord; int cdsCutoff; int ebsCutoff; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index cb94b88dac..5dbeb03d8c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -23,7 +23,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexplogExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexpLogExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsOobCall; @@ -147,7 +147,7 @@ public static List generateFor(final Hub hub, final PrecompileInv .callOob(new ModexpLeadOobCall(p)) .callMmu(m.loadRawLeadingWord() ? MmuCall.forModExp(hub, p, 5) : MmuCall.nop()); if (m.loadRawLeadingWord()) { - line5.callExp(new ModexplogExpCall(p)); + line5.callExp(new ModexpLogExpCall(p)); } r.add(line5); r.add(ImcFragment.empty(hub).callOob(new ModexpPricingOobCall(p))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index bbe93eeb1c..ab3860c8ad 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -253,7 +253,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H } case EXP -> { - this.exp = true; + this.exp = true; // TODO: use expCall instead this.mul = !ex.outOfGasException(); } From f7a7d53f37dd1db6efe0f6293fdccea1132f1ce0 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 20 Jun 2024 11:51:24 +0530 Subject: [PATCH 134/461] fix java issues --- .../consensys/linea/zktracer/ZkTracer.java | 2 +- .../linea/zktracer/module/add/Add.java | 8 ++++--- .../linea/zktracer/module/bin/Bin.java | 8 ++----- .../zktracer/module/blockhash/Blockhash.java | 9 +++++++ .../linea/zktracer/module/hub/Hub.java | 9 ++++--- .../precompiles/PrecompileCommonOobCall.java | 2 +- .../zktracer/module/oob/OobOperation.java | 24 ++++++++++++------- .../linea/zktracer/module/wcp/Wcp.java | 11 ++++----- .../linea/zktracer/types/Conversions.java | 21 ++++++++++++++++ 9 files changed, 62 insertions(+), 32 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index c5360b26c5..6e7279d4f5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -253,7 +253,7 @@ public void traceEndTransaction( public void tracePreExecution(final MessageFrame frame) { if (frame.getCode().getSize() > 0) { try { - this.hub.tracePreOpcode(frame); + this.hub.tracePreExecution(frame); this.pin55.ifPresent(x -> x.tracePreOpcode(frame)); } catch (final Exception e) { this.tracingExceptions.add(e); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Add.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Add.java index bb448aaffe..54b1c5a794 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Add.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Add.java @@ -23,7 +23,6 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -31,7 +30,6 @@ /** Implementation of a {@link Module} for addition/subtraction. */ @RequiredArgsConstructor public class Add implements Module { - private final Hub hub; /** A set of the operations to trace */ private final StackedSet chunks = new StackedSet<>(); @@ -53,7 +51,11 @@ public void popTransaction() { @Override public void tracePreOpcode(MessageFrame frame) { - this.chunks.add(new AddOperation(hub.opCode(), frame.getStackItem(0), frame.getStackItem(1))); + this.chunks.add( + new AddOperation( + OpCode.of(frame.getCurrentOperation().getOpcode()), + frame.getStackItem(0), + frame.getStackItem(1))); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Bin.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Bin.java index 38da54aab4..554ac73c0f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Bin.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Bin.java @@ -22,21 +22,17 @@ import net.consensys.linea.zktracer.bytestheta.BaseBytes; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.evm.frame.MessageFrame; /** Implementation of a {@link Module} for addition/subtraction. */ public class Bin implements Module { - private final Hub hub; /** A set of the operations to trace */ private final StackedSet chunks = new StackedSet<>(); - public Bin(final Hub hub) { - this.hub = hub; - } + public Bin() {} @Override public String moduleKey() { @@ -55,7 +51,7 @@ public void popTransaction() { @Override public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = this.hub.opCode(); + final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0)); final Bytes32 arg2 = opCode == OpCode.NOT ? Bytes32.ZERO : Bytes32.leftPad(frame.getStackItem(1)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java index 3512e73b1a..2fc8b63972 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java @@ -28,6 +28,7 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.wcp.Wcp; +import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -80,6 +81,10 @@ public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) @Override public void tracePreOpcode(MessageFrame frame) { + final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); + if (opCode != OpCode.BLOCKHASH) { + return; + } this.opcodeArgument = Bytes32.leftPad(frame.getStackItem(0)); lowerBound = this.wcp.callGEQ( @@ -99,6 +104,10 @@ public void tracePreOpcode(MessageFrame frame) { @Override public void tracePostOpcode(MessageFrame frame) { + final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); + if (opCode != OpCode.BLOCKHASH) { + return; + } final Bytes32 result = Bytes32.leftPad(frame.getStackItem(0)); this.operations.add( new BlockhashOperation( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 163c0357d5..2c5a671ac3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -173,10 +173,10 @@ public int lineCount() { /** List of all modules of the ZK-evm */ // stateless modules - @Getter private final Wcp wcp = new Wcp(this); + @Getter private final Wcp wcp = new Wcp(); - private final Module add = new Add(this); - private final Module bin = new Bin(this); + private final Module add = new Add(); + private final Module bin = new Bin(); private final Blockdata blockdata; private final Blockhash blockhash = new Blockhash(wcp); private final Euc euc; @@ -664,8 +664,7 @@ public void traceContextExit(MessageFrame frame) { } } - @Override - public void tracePreOpcode(final MessageFrame frame) { + public void tracePreExecution(final MessageFrame frame) { Preconditions.checkArgument( this.state().processingPhase != TX_SKIP, "There can't be any execution if the HUB is in the a skip phase"); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java index df89d1949b..ffc946211d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java @@ -52,7 +52,7 @@ public boolean getCallDataIsEmpty() { @Override public int oobInstruction() { - return switch (p.precompile().address.toInt()) { + return switch (p.precompile().address.trimLeadingZeros().toInt()) { case 1 -> OOB_INST_ECRECOVER; case 2 -> OOB_INST_SHA2; case 3 -> OOB_INST_RIPEMD; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index fea6e6cf28..35243b3904 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -71,6 +71,8 @@ import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBoolean; import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; +import static net.consensys.linea.zktracer.types.Conversions.hiPart; +import static net.consensys.linea.zktracer.types.Conversions.lowPart; import java.math.BigInteger; import java.math.RoundingMode; @@ -460,9 +462,10 @@ private void populateColumns(final MessageFrame frame) { final BigInteger cds = EWord.of(frame.getStackItem(cdsIndex)).toUnsignedBigInteger(); // Note that this check will disappear since it will be the MXP module taking care of it - if (cds.compareTo(EWord.of(frame.getStackItem(cdsIndex)).loBigInt()) > 0) { - throw new IllegalArgumentException("cds hi part is non-zero"); - } + /* TODO: reenable this check */ + // if (cds.compareTo(EWord.of(frame.getStackItem(cdsIndex)).loBigInt()) > 0) { + // throw new IllegalArgumentException("cds hi part is non-zero"); + // } final BigInteger returnAtCapacity = EWord.of(frame.getStackItem(returnAtCapacityIndex)).toUnsignedBigInteger(); @@ -693,7 +696,11 @@ private boolean callToGT( return r; } - private boolean callToISZERO(int k, BigInteger arg1Hi, BigInteger arg1Lo) { + private boolean callToISZERO(final int k, final BigInteger arg1) { + return callToISZERO(k, hiPart(arg1), lowPart(arg1)); + } + + private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInteger arg1Lo) { final EWord arg1 = EWord.of(arg1Hi, arg1Lo); addFlag[k] = false; modFlag[k] = false; @@ -920,11 +927,10 @@ private void setCreate(CreateOobCall createOobCall) { private void setPrcCommon(PrecompileCommonOobCall prcOobCall) { // row i - final boolean cdsIsZero = callToISZERO(0, BigInteger.ZERO, prcOobCall.getCds()); + final boolean cdsIsZero = callToISZERO(0, prcOobCall.getCds()); // row i + 1 - final boolean returnAtCapacityIsZero = - callToISZERO(1, BigInteger.ZERO, prcOobCall.getReturnAtCapacity()); + final boolean returnAtCapacityIsZero = callToISZERO(1, prcOobCall.getReturnAtCapacity()); // Set cdsIsZero prcOobCall.setCdsIsZero(cdsIsZero); @@ -993,8 +999,8 @@ private void setEcpairing(PrecompileCommonOobCall prcCommonOobCall) { final BigInteger remainder = callToMOD( 2, - BigInteger.ZERO, - prcCommonOobCall.getCds(), + hiPart(prcCommonOobCall.getCds()), + lowPart(prcCommonOobCall.getCds()), BigInteger.ZERO, BigInteger.valueOf(192)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Wcp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Wcp.java index 9ad4597551..6bc80d3edc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Wcp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/wcp/Wcp.java @@ -30,7 +30,6 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; @@ -43,11 +42,9 @@ public class Wcp implements Module { /** count the number of rows that could be added after the sequencer counts the number of line */ public final Deque additionalRows = new ArrayDeque<>(); - private final Hub hub; private boolean batchUnderConstruction; - public Wcp(Hub hub) { - this.hub = hub; + public Wcp() { this.batchUnderConstruction = true; } @@ -75,12 +72,12 @@ public void traceStartConflation(final long blockCount) { @Override public void tracePreOpcode(final MessageFrame frame) { - final OpCode opcode = this.hub.opCode(); + final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0)); final Bytes32 arg2 = - (opcode != OpCode.ISZERO) ? Bytes32.leftPad(frame.getStackItem(1)) : Bytes32.ZERO; + (opCode != OpCode.ISZERO) ? Bytes32.leftPad(frame.getStackItem(1)) : Bytes32.ZERO; - this.operations.add(new WcpOperation(opcode.byteValue(), arg1, arg2)); + this.operations.add(new WcpOperation(opCode.byteValue(), arg1, arg2)); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java index 8e6345b5f0..c233f0c3f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.types; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; + import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; @@ -27,6 +29,7 @@ public class Conversions { public static final Bytes ONE = Bytes.of(1); public static final BigInteger UNSIGNED_LONG_MASK = BigInteger.ONE.shiftLeft(Long.SIZE).subtract(BigInteger.ONE); + public static int LIMB_BIT_SIZE = 8 * LLARGE; public static Bytes bigIntegerToBytes(final BigInteger input) { Bytes bytes; @@ -147,4 +150,22 @@ public static Bytes booleanToBytes(boolean x) { public static long bytesToLong(final Bytes input) { return input.trimLeadingZeros().toLong(); } + + public static BigInteger hiPart(final BigInteger input) { + if (input.bitLength() <= LIMB_BIT_SIZE) { + return BigInteger.ZERO; + } + final Bytes inputBytes = bigIntegerToBytes(input); + final Bytes hiBytes = inputBytes.slice(0, inputBytes.size() - LLARGE); + return hiBytes.toUnsignedBigInteger(); + } + + public static BigInteger lowPart(final BigInteger input) { + if (input.bitLength() <= LIMB_BIT_SIZE) { + return input; + } + final Bytes inputBytes = bigIntegerToBytes(input); + final Bytes lowBytes = inputBytes.slice(inputBytes.size() - LLARGE, LLARGE); + return lowBytes.toUnsignedBigInteger(); + } } From da62ebd252be4247a89e52c8507ed693d56c1e5d Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 20 Jun 2024 10:34:09 +0200 Subject: [PATCH 135/461] feat(oob): added preconditions to methods supposed to received arguments of at most 16 bytes --- .../zktracer/module/oob/OobOperation.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 35243b3904..35042d09e3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -77,6 +77,7 @@ import java.math.BigInteger; import java.math.RoundingMode; +import com.google.common.base.Preconditions; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -613,6 +614,10 @@ private void populateColumns(final MessageFrame frame) { // Constraint systems for populating lookups private void callToADD( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { + Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); final EWord arg1 = EWord.of(arg1Hi, arg1Lo); final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = true; @@ -632,6 +637,10 @@ private void callToADD( private BigInteger callToDIV( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { + Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); final EWord arg1 = EWord.of(arg1Hi, arg1Lo); final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; @@ -648,6 +657,10 @@ private BigInteger callToDIV( private BigInteger callToMOD( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { + Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); final EWord arg1 = EWord.of(arg1Hi, arg1Lo); final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; @@ -664,6 +677,10 @@ private BigInteger callToMOD( private boolean callToLT( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { + Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); final EWord arg1 = EWord.of(arg1Hi, arg1Lo); final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; @@ -681,6 +698,10 @@ private boolean callToLT( private boolean callToGT( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { + Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); final EWord arg1 = EWord.of(arg1Hi, arg1Lo); final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; @@ -697,10 +718,14 @@ private boolean callToGT( } private boolean callToISZERO(final int k, final BigInteger arg1) { + // TODO: temporary hack to manage cases where the supposed to be lo part is greater than 16 + // bytes, kill it return callToISZERO(k, hiPart(arg1), lowPart(arg1)); } private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInteger arg1Lo) { + Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); final EWord arg1 = EWord.of(arg1Hi, arg1Lo); addFlag[k] = false; modFlag[k] = false; @@ -717,6 +742,10 @@ private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInte private boolean callToEQ( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { + Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); final EWord arg1 = EWord.of(arg1Hi, arg1Lo); final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; From 789034840308de6dc78b81765f8414f7f235ac40 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 20 Jun 2024 11:08:09 +0200 Subject: [PATCH 136/461] fix(oob): added temporary hack to manage case in which cds and r at c are greater than 16 bytes --- .../zktracer/module/oob/OobOperation.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 35042d09e3..0c958af963 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -71,7 +71,6 @@ import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBoolean; import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; -import static net.consensys.linea.zktracer.types.Conversions.hiPart; import static net.consensys.linea.zktracer.types.Conversions.lowPart; import java.math.BigInteger; @@ -717,12 +716,6 @@ private boolean callToGT( return r; } - private boolean callToISZERO(final int k, final BigInteger arg1) { - // TODO: temporary hack to manage cases where the supposed to be lo part is greater than 16 - // bytes, kill it - return callToISZERO(k, hiPart(arg1), lowPart(arg1)); - } - private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInteger arg1Lo) { Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); @@ -956,10 +949,20 @@ private void setCreate(CreateOobCall createOobCall) { private void setPrcCommon(PrecompileCommonOobCall prcOobCall) { // row i - final boolean cdsIsZero = callToISZERO(0, prcOobCall.getCds()); + final boolean cdsIsZero = + callToISZERO( + 0, + BigInteger.ZERO, + lowPart(prcOobCall.getCds())); // TODO: kill it, cds should already be smaller than // row i + 1 - final boolean returnAtCapacityIsZero = callToISZERO(1, prcOobCall.getReturnAtCapacity()); + final boolean returnAtCapacityIsZero = + callToISZERO( + 1, + BigInteger.ZERO, + lowPart( + prcOobCall + .getReturnAtCapacity())); // TODO: kill it, r@c should already be smaller than // Set cdsIsZero prcOobCall.setCdsIsZero(cdsIsZero); @@ -1028,8 +1031,9 @@ private void setEcpairing(PrecompileCommonOobCall prcCommonOobCall) { final BigInteger remainder = callToMOD( 2, - hiPart(prcCommonOobCall.getCds()), - lowPart(prcCommonOobCall.getCds()), + BigInteger.ZERO, + lowPart(prcCommonOobCall.getCds()), // TODO: kill it, cds should already be smaller than + // 16 bytes BigInteger.ZERO, BigInteger.valueOf(192)); From adc4a61be97091e7c5789b650157411d1e6e443b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 20 Jun 2024 15:27:42 +0530 Subject: [PATCH 137/461] fix mmu and mxp stamp in hub + enhance mmu call (wip) --- .../linea/zktracer/module/hub/Hub.java | 1 - .../linea/zktracer/module/hub/State.java | 27 ++++++++----------- .../module/hub/fragment/CommonFragment.java | 4 +-- .../module/hub/fragment/TraceSubFragment.java | 9 ++++++- .../module/hub/fragment/imc/ImcFragment.java | 2 +- .../module/hub/fragment/imc/call/MxpCall.java | 4 ++- .../hub/fragment/imc/call/mmu/MmuCall.java | 10 +++++-- .../fragment/imc/call/mmu/opcode/Create2.java | 2 +- .../call/mmu/opcode/ReturnFromDeployment.java | 8 +++--- .../module/hub/section/TraceSection.java | 2 +- .../linea/zktracer/module/mmu/MmuData.java | 8 ++++++ 11 files changed, 46 insertions(+), 31 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 2c5a671ac3..c5bb7f1775 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -992,7 +992,6 @@ void processStateExec(MessageFrame frame) { this.state.stamps().incrementHubStamp(); this.pch.setup(frame); - this.state.stamps().stampSubmodules(this.pch()); this.handleStack(frame); this.triggerModules(frame); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index ea1c376772..c030c2c7b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -25,7 +25,6 @@ import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.State.TxState.Stamps; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; -import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; @@ -160,35 +159,31 @@ TxState spinOff() { @Getter public static class Stamps { private int hub = 0; - private int mmu = 0; - private int mxp = 0; - private int hashInfo = 0; // TODO: doesn't exist anymore private int log = 0; // TODO: implement this + private int mxp = 0; // increments only at commit time + private int mmu = 0; // increments only at commit time public Stamps() {} - public Stamps(int hubStamp, int mmuStamp, int mxpStamp, int hashInfoStamp) { + public Stamps(final int hubStamp, final int logStamp) { this.hub = hubStamp; - this.mmu = mmuStamp; - this.mxp = mxpStamp; - this.hashInfo = hashInfoStamp; + this.log = logStamp; } public Stamps snapshot() { - return new Stamps(this.hub, this.mmu, this.mxp, this.hashInfo); + return new Stamps(this.hub, this.log); } public void incrementHubStamp() { this.hub++; } - void stampSubmodules(final PlatformController platformController) { - if (platformController.signals().mmu()) { - this.mmu++; - } - if (platformController.signals().mxp()) { - this.mxp++; - } + public void incrementMmuStamp() { + this.mmu++; + } + + public void incrementMxpStamp() { + this.mxp++; } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index bd79a3bec0..ee88cd748f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -239,8 +239,8 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .contextMayChange(contextMayChange) .exceptionAhoy(exceptions.any()) .logInfoStamp(this.stamps.log()) - .mmuStamp(this.stamps.mmu()) - .mxpStamp(this.stamps.mxp()) + .mmuStamp(this.hub.state().stamps().mmu()) + .mxpStamp(this.hub.state.stamps().mxp()) // nontrivial dom / sub are traced in storage or account fragments only .contextNumber(contextNumber) .contextNumberNew(contextNumberNew) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java index 57f5ed0f79..5e167ce150 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java @@ -16,10 +16,17 @@ package net.consensys.linea.zktracer.module.hub.fragment; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; public interface TraceSubFragment { - Trace trace(Trace trace); + default Trace trace(Trace trace) { + return trace; + } + + default Trace trace(Trace trace, State.TxState.Stamps stamps) { + return trace(trace); + } default void postConflationRetcon(final Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index e81fb50dd0..6aa79bb760 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -314,7 +314,7 @@ public Trace trace(Trace trace) { trace.peekAtMiscellaneous(true); for (TraceSubFragment subFragment : this.moduleCalls) { - subFragment.trace(trace); + subFragment.trace(trace, this.hub.state.stamps()); } return trace; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index 1f4e45fb4a..537cf7a9ca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.opcode.OpCodeData; @@ -54,7 +55,8 @@ public final boolean type4InstructionMayTriggerNonTrivialOperation(Hub hub) { return !getMemoryExpansionException(hub) && !this.size1.isZero(); } - public Trace trace(Trace trace) { + public Trace trace(Trace trace, State.TxState.Stamps stamps) { + stamps.incrementMxpStamp(); return trace .pMiscMxpFlag(true) .pMiscMxpInst(this.opCodeData.mnemonic().byteValue()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index fb2ec57b85..240a8e9049 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -61,6 +61,7 @@ import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import java.util.Arrays; +import java.util.Optional; import com.google.common.base.Preconditions; import lombok.Getter; @@ -68,6 +69,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.CodeCopy; @@ -110,6 +112,9 @@ public class MmuCall implements TraceSubFragment { protected Bytes limb2 = Bytes.EMPTY; protected long phase = 0; + private Optional sourceRamBytes = Optional.empty(); + private Optional targetRamBytes = Optional.empty(); + protected boolean exoIsRlpTxn = false; protected boolean exoIsLog = false; protected boolean exoIsRom = false; @@ -164,7 +169,7 @@ public static MmuCall nop() { public static MmuCall sha3(final Hub hub) { return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) - .auxId(hub.state().stamps().hashInfo()) + .auxId(hub.state().stamps().hub()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(1))) .referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(1))) @@ -689,7 +694,8 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int } @Override - public Trace trace(Trace trace) { + public Trace trace(Trace trace, State.TxState.Stamps stamps) { + stamps.incrementMmuStamp(); return trace .pMiscMmuFlag(this.enabled()) .pMiscMmuInst( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java index 3a18430a54..7d666744b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java @@ -38,7 +38,7 @@ public Create2(final Hub hub) { this.hub.romLex().createDefers().register(this); this.sourceId(hub.currentFrame().contextNumber()) - .auxId(hub.state().stamps().hashInfo()) + .auxId(hub.state().stamps().hub()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(2))) .referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(2))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java index ebd450df88..8561165b60 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java @@ -30,7 +30,7 @@ */ public class ReturnFromDeployment extends MmuCall { private final Hub hub; - private ContractMetadata contract; + private final ContractMetadata contract; public ReturnFromDeployment(final Hub hub) { super(MMU_INST_RAM_TO_EXO_WITH_PADDING); @@ -40,12 +40,10 @@ public ReturnFromDeployment(final Hub hub) { // TODO: get the metaDaa directly from the hub final Address contractAddress = hub.currentFrame().frame().getContractAddress(); final int depNumber = hub.transients().conflation().deploymentInfo().number(contractAddress); - final ContractMetadata contractMetadata = - ContractMetadata.underDeployment(contractAddress, depNumber); - this.contract = contractMetadata; + this.contract = ContractMetadata.underDeployment(contractAddress, depNumber); this.sourceId(hub.currentFrame().contextNumber()) - .auxId(hub.state().stamps().hashInfo()) + .auxId(hub.state().stamps().hub()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(1))) .referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(1))) 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 e2cfaca676..bac5bbc888 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 @@ -58,8 +58,8 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { Preconditions.checkNotNull(common); Preconditions.checkNotNull(specific); + specific.trace(trace); // Warn: need to be called before common.trace to update stamps common.trace(trace, stackInt, stackHeight); - specific.trace(trace); return trace.fillAndValidateRow(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java index a25324c18a..f125a6ba1d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java @@ -103,6 +103,10 @@ public void mmuToMmioInstruction(final MmuToMmioInstruction mmuToMmioInstruction } public void setSourceRamBytes() { + if (this.mmuCall.sourceRamBytes().isPresent()) { + this.sourceRamBytes(this.mmuCall.sourceRamBytes().get()); + return; + } final MmuToMmioConstantValues mmuToMmioConstantValues = this.mmuToMmioConstantValues(); final long sourceContextNumber = mmuToMmioConstantValues.sourceContextNumber(); @@ -113,6 +117,10 @@ public void setSourceRamBytes() { } public void setTargetRamBytes() { + if (this.mmuCall.targetRamBytes().isPresent()) { + this.targetRamBytes(this.mmuCall.targetRamBytes().get()); + return; + } final MmuToMmioConstantValues mmuToMmioConstantValues = this.mmuToMmioConstantValues(); final long targetContextNumber = mmuToMmioConstantValues.targetContextNumber(); From 2369ae52f0cccb8d6505d071521c51ffb3a528f0 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 20 Jun 2024 12:01:39 +0200 Subject: [PATCH 138/461] fix(exp): fixed issue with trim --- .../zktracer/module/exp/ExpOperation.java | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index 6265249e1c..4913547514 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -52,6 +52,8 @@ @Getter public class ExpOperation extends ModuleOperation { + @EqualsAndHashCode.Include ExpCall expCall; + protected short pComputationPltJmp = 0; protected Bytes pComputationRawAcc; // (last row) paired with RawByte protected Bytes pComputationTrimAcc = Bytes.EMPTY; // (last row) paired with TrimByte @@ -74,18 +76,6 @@ public class ExpOperation extends ModuleOperation { boolean isExpLog; - // EXPLOG specific - @EqualsAndHashCode.Include private EWord exponent; - private long dynCost; - - // MODEXPLOG specific - @EqualsAndHashCode.Include private EWord rawLead; - @EqualsAndHashCode.Include private int cdsCutoff; - @EqualsAndHashCode.Include private int ebsCutoff; - private BigInteger leadLog; - private EWord trim; - - ExpCall expCall; private Wcp wcp; private Hub hub; @@ -98,15 +88,15 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { ExplogExpCall explogExpCall = (ExplogExpCall) expCall; // Extract inputs - this.exponent = EWord.of(hub.messageFrame().getStackItem(1)); - this.dynCost = (long) G_EXP_BYTE.cost() * exponent.byteLength(); + EWord exponent = EWord.of(hub.messageFrame().getStackItem(1)); + long dynCost = (long) G_EXP_BYTE.cost() * exponent.byteLength(); // Fill expCall explogExpCall.setExponent(exponent); explogExpCall.setDynCost(dynCost); // Execute preprocessing - preComputeForExplog(); + preComputeForExplog(explogExpCall); } else if (expCall.expInstruction() == EXP_INST_MODEXPLOG) { this.isExpLog = false; ModexpLogExpCall modexplogExpCall = (ModexpLogExpCall) expCall; @@ -118,11 +108,11 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { final int ebsInt = modexpMetadata.ebs().toUnsignedBigInteger().intValueExact(); Preconditions.checkArgument( precompileInvocation.callDataSource().length() - 96 - bbsInt >= 0); - this.rawLead = modexpMetadata.rawLeadingWord(); - this.cdsCutoff = + EWord rawLead = modexpMetadata.rawLeadingWord(); + int cdsCutoff = Math.min((int) (precompileInvocation.callDataSource().length() - 96 - bbsInt), 32); - this.ebsCutoff = Math.min(ebsInt, 32); - this.leadLog = + int ebsCutoff = Math.min(ebsInt, 32); + BigInteger leadLog = BigInteger.valueOf(LeadLogTrimLead.fromArgs(rawLead, cdsCutoff, ebsCutoff).leadLog()); // Fill expCall @@ -132,34 +122,34 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { modexplogExpCall.setLeadLog(leadLog); // Execute preprocessing - preComputeForModexpLog(); + preComputeForModexpLog(modexplogExpCall); } } - public void preComputeForExplog() { + public void preComputeForExplog(ExplogExpCall explogExpCall) { pMacroExpInst = EXP_INST_EXPLOG; - pMacroData1 = this.exponent.hi(); - pMacroData2 = this.exponent.lo(); - pMacroData5 = Bytes.ofUnsignedLong(this.dynCost); + pMacroData1 = explogExpCall.getExponent().hi(); + pMacroData2 = explogExpCall.getExponent().lo(); + pMacroData5 = Bytes.ofUnsignedLong(explogExpCall.getDynCost()); initArrays(MAX_CT_PRPRC_EXP_LOG + 1); // Preprocessing // First row pPreprocessingWcpFlag[0] = true; pPreprocessingWcpArg1Hi[0] = Bytes.EMPTY; - pPreprocessingWcpArg1Lo[0] = this.exponent.hi(); + pPreprocessingWcpArg1Lo[0] = explogExpCall.getExponent().hi(); pPreprocessingWcpArg2Hi[0] = Bytes.EMPTY; pPreprocessingWcpArg2Lo[0] = Bytes.EMPTY; pPreprocessingWcpInst[0] = UnsignedByte.of(ISZERO); - final boolean expnHiIsZero = wcp.callISZERO(this.exponent.hi()); + final boolean expnHiIsZero = wcp.callISZERO(explogExpCall.getExponent().hi()); ; pPreprocessingWcpRes[0] = expnHiIsZero; // Linking constraints and fill rawAcc pComputationPltJmp = 16; - pComputationRawAcc = this.exponent.hi(); + pComputationRawAcc = explogExpCall.getExponent().hi(); if (expnHiIsZero) { - pComputationRawAcc = this.exponent.lo(); + pComputationRawAcc = explogExpCall.getExponent().lo(); } // Fill trimAcc @@ -172,18 +162,25 @@ public void preComputeForExplog() { } } - public void preComputeForModexpLog() { + public void preComputeForModexpLog(ModexpLogExpCall modexplogExpCall) { pMacroExpInst = EXP_INST_MODEXPLOG; - pMacroData1 = this.rawLead.hi(); - pMacroData2 = this.rawLead.lo(); - pMacroData3 = Bytes.of(this.cdsCutoff); - pMacroData4 = Bytes.of(this.ebsCutoff); - pMacroData5 = bigIntegerToBytes(this.leadLog); + pMacroData1 = modexplogExpCall.getRawLeadingWord().hi(); + pMacroData2 = modexplogExpCall.getRawLeadingWord().lo(); + pMacroData3 = Bytes.of(modexplogExpCall.getCdsCutoff()); + pMacroData4 = Bytes.of(modexplogExpCall.getEbsCutoff()); + pMacroData5 = bigIntegerToBytes(modexplogExpCall.getLeadLog()); initArrays(MAX_CT_PRPRC_MODEXP_LOG + 1); // Preprocessing - final BigInteger trimLimb = - this.trim.hi().isZero() ? this.trim.loBigInt() : this.trim.hiBigInt(); + EWord trim = + EWord.of( + LeadLogTrimLead.fromArgs( + modexplogExpCall.getRawLeadingWord(), + modexplogExpCall.getCdsCutoff(), + modexplogExpCall.getEbsCutoff()) + .trim()); + + final BigInteger trimLimb = trim.hi().isZero() ? trim.loBigInt() : trim.hiBigInt(); final int trimLog = trimLimb.signum() == 0 ? 0 : log2(trimLimb, RoundingMode.FLOOR); final int nBitsOfLeadingByteExcludingLeadingBit = trimLog % 8; final int nBytesExcludingLeadingByte = trimLog / 8; @@ -191,12 +188,14 @@ public void preComputeForModexpLog() { // First row pPreprocessingWcpFlag[0] = true; pPreprocessingWcpArg1Hi[0] = Bytes.of(0); - pPreprocessingWcpArg1Lo[0] = Bytes.of(this.cdsCutoff); + pPreprocessingWcpArg1Lo[0] = Bytes.of(modexplogExpCall.getCdsCutoff()); pPreprocessingWcpArg2Hi[0] = Bytes.of(0); - pPreprocessingWcpArg2Lo[0] = Bytes.of(this.ebsCutoff); + pPreprocessingWcpArg2Lo[0] = Bytes.of(modexplogExpCall.getEbsCutoff()); pPreprocessingWcpInst[0] = UnsignedByte.of(EVM_INST_LT); - pPreprocessingWcpRes[0] = wcp.callLT(Bytes.of(this.cdsCutoff), Bytes.of(this.ebsCutoff)); - final int minCutoff = min(this.cdsCutoff, this.ebsCutoff); + pPreprocessingWcpRes[0] = + wcp.callLT( + Bytes.of(modexplogExpCall.getCdsCutoff()), Bytes.of(modexplogExpCall.getEbsCutoff())); + final int minCutoff = min(modexplogExpCall.getCdsCutoff(), modexplogExpCall.getEbsCutoff()); // Second row pPreprocessingWcpFlag[1] = true; @@ -211,20 +210,21 @@ public void preComputeForModexpLog() { // Third row pPreprocessingWcpFlag[2] = true; pPreprocessingWcpArg1Hi[2] = Bytes.of(0); - pPreprocessingWcpArg1Lo[2] = Bytes.of(this.ebsCutoff); + pPreprocessingWcpArg1Lo[2] = Bytes.of(modexplogExpCall.getEbsCutoff()); pPreprocessingWcpArg2Hi[2] = Bytes.of(0); pPreprocessingWcpArg2Lo[2] = Bytes.of(LLARGEPO); pPreprocessingWcpInst[2] = UnsignedByte.of(EVM_INST_LT); - pPreprocessingWcpRes[2] = wcp.callLT(Bytes.of(this.ebsCutoff), Bytes.of(LLARGEPO)); + pPreprocessingWcpRes[2] = + wcp.callLT(Bytes.of(modexplogExpCall.getEbsCutoff()), Bytes.of(LLARGEPO)); // Fourth row pPreprocessingWcpFlag[3] = true; pPreprocessingWcpArg1Hi[3] = Bytes.of(0); - pPreprocessingWcpArg1Lo[3] = this.rawLead.hi(); + pPreprocessingWcpArg1Lo[3] = modexplogExpCall.getRawLeadingWord().hi(); pPreprocessingWcpArg2Hi[3] = Bytes.of(0); pPreprocessingWcpArg2Lo[3] = Bytes.of(0); pPreprocessingWcpInst[3] = UnsignedByte.of(EVM_INST_ISZERO); - final boolean rawHiPartIsZero = wcp.callISZERO(this.rawLead.hi()); + final boolean rawHiPartIsZero = wcp.callISZERO(modexplogExpCall.getRawLeadingWord().hi()); pPreprocessingWcpRes[3] = rawHiPartIsZero; // Fifth row @@ -241,11 +241,11 @@ public void preComputeForModexpLog() { // Linking constraints and fill rawAcc if (minCutoffLeq16) { - pComputationRawAcc = leftPadTo(this.rawLead.hi(), LLARGE); + pComputationRawAcc = leftPadTo(modexplogExpCall.getRawLeadingWord().hi(), LLARGE); } else if (!rawHiPartIsZero) { - pComputationRawAcc = leftPadTo(this.rawLead.hi(), LLARGE); + pComputationRawAcc = leftPadTo(modexplogExpCall.getRawLeadingWord().hi(), LLARGE); } else { - pComputationRawAcc = leftPadTo(this.rawLead.lo(), LLARGE); + pComputationRawAcc = leftPadTo(modexplogExpCall.getRawLeadingWord().lo(), LLARGE); } // Fill pltJmp From c06fec627999e87bc3b90d3529f66d04b99ae22e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 21 Jun 2024 17:40:06 +0530 Subject: [PATCH 139/461] enhance MmuCall, implement LOGX instruction in HUB --- .../linea/zktracer/module/hub/Hub.java | 5 +- .../linea/zktracer/module/hub/State.java | 8 +- .../module/hub/fragment/CommonFragment.java | 2 +- .../module/hub/fragment/imc/ImcFragment.java | 2 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 31 +++- .../fragment/imc/call/mmu/opcode/LogX.java | 49 ------- .../module/hub/section/LogSection.java | 80 ++++++++++ .../module/hub/section/TraceSection.java | 6 +- .../zktracer/module/mmu/MmuOperation.java | 4 + .../linea/zktracer/runtime/LogInvocation.java | 54 ++----- .../zktracer/types/MemorySegmentSnapshot.java | 39 ----- .../zktracer/module/rlptxrcpt/LogTest.java | 45 ++++++ .../module/rlptxrcpt/RandomTxrcptTests.java | 137 ------------------ zkevm-constraints | 2 +- 14 files changed, 183 insertions(+), 281 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/LogX.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c5bb7f1775..509f1a0d7d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -96,7 +96,6 @@ import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.*; import net.consensys.linea.zktracer.opcode.gas.projector.GasProjector; -import net.consensys.linea.zktracer.runtime.LogInvocation; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.runtime.callstack.CallStack; @@ -1099,9 +1098,7 @@ void traceOperation(MessageFrame frame) { case CONTEXT -> this.addTraceSection( new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); case LOG -> { - this.addTraceSection( - new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); - LogInvocation.forOpcode(this); + new LogSection(this); } case ACCOUNT -> { TraceSection accountSection = new AccountSection(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index c030c2c7b9..ae24379f30 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -158,8 +158,8 @@ TxState spinOff() { @Accessors(fluent = true) @Getter public static class Stamps { - private int hub = 0; - private int log = 0; // TODO: implement this + private int hub = 0; // increments during execution + private int log = 0; // increments at RunPostTx private int mxp = 0; // increments only at commit time private int mmu = 0; // increments only at commit time @@ -185,6 +185,10 @@ public void incrementMmuStamp() { public void incrementMxpStamp() { this.mxp++; } + + public int incrementLogStamp() { + return this.log++; + } } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java index ee88cd748f..d5a6511165 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java @@ -240,7 +240,7 @@ public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { .exceptionAhoy(exceptions.any()) .logInfoStamp(this.stamps.log()) .mmuStamp(this.hub.state().stamps().mmu()) - .mxpStamp(this.hub.state.stamps().mxp()) + .mxpStamp(this.hub.state().stamps().mxp()) // nontrivial dom / sub are traced in storage or account fragments only .contextNumber(contextNumber) .contextNumberNew(contextNumberNew) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 6aa79bb760..dda1871618 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -188,7 +188,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { case MLOAD -> r.callMmu(MmuCall.mload(hub)); case MSTORE -> r.callMmu(MmuCall.mstore(hub)); case MSTORE8 -> r.callMmu(MmuCall.mstore8(hub)); - case LOG0, LOG1, LOG2, LOG3, LOG4 -> r.callMmu(MmuCall.log(hub)); + // case LOG0, LOG1, LOG2, LOG3, LOG4 -> r.callMmu(MmuCall.log(hub)); done elsewhere case CREATE -> r.callMmu(MmuCall.create(hub)); case RETURN -> r.callMmu( hub.currentFrame().isDeployment() diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 240a8e9049..35e3da5007 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu; +import static net.consensys.linea.zktracer.module.Util.slice; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EMPTY_RIPEMD_HI; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EMPTY_RIPEMD_LO; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EMPTY_SHA2_HI; @@ -76,11 +77,11 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.Create; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.Create2; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.ExtCodeCopy; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.LogX; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.ReturnFromDeployment; import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.runtime.LogInvocation; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; @@ -114,6 +115,7 @@ public class MmuCall implements TraceSubFragment { private Optional sourceRamBytes = Optional.empty(); private Optional targetRamBytes = Optional.empty(); + private Optional exoBytes = Optional.empty(); protected boolean exoIsRlpTxn = false; protected boolean exoIsLog = false; @@ -137,8 +139,8 @@ public final MmuCall setLog() { return this.exoIsLog(true).updateExoSum(EXO_SUM_WEIGHT_LOG); } - public final MmuCall setRom() { - return this.exoIsRom(true).updateExoSum(EXO_SUM_WEIGHT_ROM); + public final void setRom() { + this.exoIsRom(true).updateExoSum(EXO_SUM_WEIGHT_ROM); } public final MmuCall setKec() { @@ -224,6 +226,23 @@ private static int callDataContextNumber(final Hub hub) { : hub.callStack().parent().contextNumber(); } + public static MmuCall LogX(final Hub hub, final LogInvocation logInvocation) { + return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + .sourceId(logInvocation.callFrame.contextNumber()) + .targetId(hub.state.stamps().incrementLogStamp()) + .sourceOffset(logInvocation.offset) + .size(logInvocation.size) + .referenceSize(logInvocation.size) + .sourceRamBytes(Optional.of(logInvocation.ramSourceBytes)) + .exoBytes( + Optional.of( + slice( + logInvocation.ramSourceBytes, + (int) Words.clampedToLong(logInvocation.offset), + (int) logInvocation.size))) + .setLog(); + } + public static MmuCall codeCopy(final Hub hub) { return new CodeCopy(hub); } @@ -273,9 +292,9 @@ public static MmuCall mstore8(final Hub hub) { .limb2(storedValue.lo()); } - public static MmuCall log(final Hub hub) { - return new LogX(hub); - } + // public static MmuCall log(final Hub hub) { + // return new LogX(hub); + // } public static MmuCall create(final Hub hub) { return new Create(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/LogX.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/LogX.java deleted file mode 100644 index ba3fb63b69..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/LogX.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode; - -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.types.EWord; -import org.hyperledger.besu.evm.internal.Words; - -/** - * A specialization of the generic {@link MmuCall} that disables the MMU call if the LOG that - * triggered eventually sees its context reverted. - */ -public class LogX extends MmuCall { - private final Hub hub; - private final int logId; - - public LogX(final Hub hub) { - super(MMU_INST_RAM_TO_EXO_WITH_PADDING); - this.hub = hub; - this.logId = hub.transients().conflation().currentLogId(); - - this.sourceId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) - .size(Words.clampedToLong(hub.messageFrame().getStackItem(1))) - .referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(1))) - .setLog(); - } - - @Override - public boolean enabled() { - return !this.hub.transients().conflation().logs().get(this.logId).reverted(); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java new file mode 100644 index 0000000000..01b6ad74ea --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -0,0 +1,80 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section; + +import java.util.Optional; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.runtime.LogInvocation; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class LogSection implements PostTransactionDefer { + + final LogCommonSection sectionPrequel; + final ContextFragment finalContextRow; + + final boolean mxpX; + final boolean oogX; + + Optional miscFragment = Optional.empty(); + Optional mxpSubFragment = Optional.empty(); + Optional logData = Optional.empty(); + + public LogSection(Hub hub) { + this.sectionPrequel = new LogCommonSection(hub, ContextFragment.readCurrentContextData(hub)); + hub.addTraceSection(sectionPrequel); + this.finalContextRow = ContextFragment.executionProvidesEmptyReturnData(hub); + + this.mxpX = hub.pch().exceptions().memoryExpansionException(); + this.oogX = hub.pch().exceptions().outOfGasException(); + + if (hub.currentFrame().frame().isStatic()) { + // static exception + sectionPrequel.addFragmentsWithoutStack(hub, finalContextRow); + } else { + logData = Optional.of(new LogInvocation(hub)); + mxpSubFragment = Optional.of(MxpCall.build(hub)); + miscFragment = Optional.of(ImcFragment.empty(hub)); // TODO: .callMxp(mxpSubFragment.get())); + hub.defers().postTx(this); + } + } + + @Override + public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (logData.isPresent()) { + final boolean mmuTrigger = !this.logData.get().reverted() && this.logData.get().size != 0; + if (mmuTrigger) { + miscFragment.get().callMmu(MmuCall.LogX(hub, this.logData.get())); + } + this.sectionPrequel.addFragment(hub, logData.get().callFrame, miscFragment.get()); + if (mxpX || oogX) { + this.sectionPrequel.addFragment(hub, logData.get().callFrame, finalContextRow); + } + } + } + + public static class LogCommonSection extends TraceSection { + public LogCommonSection(Hub hub, ContextFragment fragment) { + this.addFragmentsAndStack(hub, fragment); + } + } +} 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 bac5bbc888..a6f388eb30 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 @@ -76,7 +76,7 @@ public Trace trace(Trace trace, int stackInt, int stackHeight) { @Getter @Setter private TxTrace parentTrace; /** A list of {@link TraceLine} representing the trace lines associated with this section. */ - @Getter List lines = new ArrayList<>(32); + @Getter List lines = new ArrayList<>(32); // TODO: Overkill no ? /** * Fill the columns shared by all type of lines. @@ -135,8 +135,8 @@ public final void addFragmentsWithoutStack( * @param fragments the fragments to add to the section */ public final void addFragmentsWithoutStack(Hub hub, TraceFragment... fragments) { - for (TraceFragment chunk : fragments) { - this.addFragment(hub, hub.currentFrame(), chunk); + for (TraceFragment fragment : fragments) { + this.addFragment(hub, hub.currentFrame(), fragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java index 3fa8100046..9689045a21 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java @@ -142,6 +142,10 @@ public void getCFI() { } public void setExoBytes(ExoSumDecoder exoSumDecoder) { + if (mmuData.mmuCall().exoBytes().isPresent()) { + mmuData.exoBytes(mmuData.mmuCall().exoBytes().get()); + return; + } final int exoSum = mmuData.hubToMmuValues().exoSum(); if (exoSum != 0) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogInvocation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogInvocation.java index 56a232c4de..06b3ec5235 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogInvocation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogInvocation.java @@ -15,51 +15,29 @@ package net.consensys.linea.zktracer.runtime; -import java.util.ArrayList; -import java.util.List; - -import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.runtime.callstack.CallStack; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; -@RequiredArgsConstructor public class LogInvocation { - private final CallStack callStack; - private final Bytes payload; - private final List topics; - private final int callFrameId; - - public static int forOpcode(final Hub hub) { - final List topics = new ArrayList<>(4); - final Bytes payload = hub.transients().op().logData(); - switch (hub.opCode()) { - case LOG0 -> {} - case LOG1 -> topics.add(hub.messageFrame().getStackItem(2)); - case LOG2 -> { - topics.add(hub.messageFrame().getStackItem(2)); - topics.add(hub.messageFrame().getStackItem(3)); - } - case LOG3 -> { - topics.add(hub.messageFrame().getStackItem(2)); - topics.add(hub.messageFrame().getStackItem(3)); - topics.add(hub.messageFrame().getStackItem(4)); - } - case LOG4 -> { - topics.add(hub.messageFrame().getStackItem(2)); - topics.add(hub.messageFrame().getStackItem(3)); - topics.add(hub.messageFrame().getStackItem(4)); - topics.add(hub.messageFrame().getStackItem(5)); - } - default -> throw new IllegalStateException("not a LOG operation"); - } + public final CallFrame callFrame; + public final Bytes ramSourceBytes; + public final EWord offset; + public final long size; - return hub.transients() - .conflation() - .log(new LogInvocation(hub.callStack(), payload, topics, hub.currentFrame().id())); + public LogInvocation(Hub hub) { + this.callFrame = hub.currentFrame(); + final MessageFrame messageFrame = callFrame.frame(); + offset = EWord.of(messageFrame.getStackItem(0)); + size = Words.clampedToLong(messageFrame.getStackItem(1)); + this.ramSourceBytes = + size == 0 ? Bytes.EMPTY : messageFrame.shadowReadMemory(0, messageFrame.memoryByteSize()); } public boolean reverted() { - return this.callStack.getById(this.callFrameId).hasReverted(); + return this.callFrame.hasReverted(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java index 84323ac8ee..5c2f28d597 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.types; -import java.util.Arrays; - import lombok.Getter; import lombok.experimental.Accessors; @@ -33,41 +31,4 @@ private MemorySegmentSnapshot(UnsignedByte[] memory, boolean clean) { this.memory = memory; this.clean = clean; } - - public UnsignedByte[] limbAtIndex(final int index) { - UnsignedByte[] limb = UnsignedByte.EMPTY_BYTES16; - int limbIndex = Math.min(16 * (index + 1), memory.length) - 16 * index; - - if (limbIndex >= 0) { - System.arraycopy(memory, 16 * index, limb, 0, limbIndex); - } - - return limb; - } - - public void updateLimb(int limbIndex, UnsignedByte[] valNew) { - if (clean) { - clean = false; - this.memory = Arrays.copyOf(memory, memory.length); - } - - int potNewLen = (limbIndex + 1) * 16; - expand(potNewLen); - - int copyLen = potNewLen - 1 - (limbIndex * 16); - System.arraycopy(valNew, 0, memory, limbIndex * 16, copyLen); - } - - /** - * Should be called once per RAM macro-instruction. - * - * @param potNewLen expanded memory length - */ - private void expand(int potNewLen) { - if (potNewLen <= memory.length) { - return; - } - - this.memory = Arrays.copyOf(memory, memory.length + potNewLen); - } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java new file mode 100644 index 0000000000..f7f9982c73 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java @@ -0,0 +1,45 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.rlptxrcpt; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import net.consensys.linea.zktracer.testing.EvmExtension; +import org.apache.tuweni.bytes.Bytes32; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class LogTest { + @Test + void log2Test() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push( + Bytes32.fromHexString( + "0x00112233445566778899AABBCCDDEE0000112233445566778899AABBCCDDEE00")) + .push(1) + .op(OpCode.MSTORE) + .push(Bytes32.fromHexString("0x00070b1c100000070b1c100000070b1c100000070b1c1000")) + .push(Bytes32.fromHexString("0x00070b1c200000070b1c200000070b1c200000070b1c2000")) + .push(33) // size + .push(4) // offset + .op(OpCode.LOG2) + .compile()) + .run(); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java deleted file mode 100644 index 398bf29f8b..0000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.rlptxrcpt; - -import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randData; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyTransaction; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.crypto.KeyPair; -import org.hyperledger.besu.datatypes.AccessListEntry; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.log.Log; -import org.hyperledger.besu.evm.log.LogTopic; - -public class RandomTxrcptTests { - private static final int RND_TX_COUNT = 5; - private final Random rnd = new Random(666); - - // @Test - // public void testRandomTxrcpt() { - // RlpTxrcpt rlpTxrcpt = new RlpTxrcpt(); - // OpCodes.load(); - // - // // SET UP THE WORLD - // KeyPair keyPair = new SECP256K1().generateKeyPair(); - // Address senderAddress = - // Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - // - // ToyAccount senderAccount = - // ToyAccount.builder().balance(Wei.of(5)).nonce(32).address(senderAddress).build(); - // - // // Create few tx - // for (int i = 0; i < RND_TX_COUNT; i++) { - // final Transaction tx = randTransaction(senderAccount, keyPair); - // - // // Create a mock test receipt - // - // final Bytes output = Bytes.random(20); - // final boolean status = rnd.nextBoolean(); - // final List logs = randomListLog(rnd.nextInt(10)); - // final long gasUsed = rnd.nextLong(21000, 0xfffffffffffffffL); - // - // // Call the module - // rlpTxrcpt.enterTransaction(); - // rlpTxrcpt.traceEndTx(null, tx, status, output, logs, gasUsed); - // } - // - // // - // // Check the trace - // // - // // TODO: uncomment the test - // // assertThat( - // // CorsetValidator.validate( - // // new ZkTraceBuilder() - // // .addTrace(rlpTxrcpt) - // // .addTrace(logInfo) - // // .addTrace(logData) - // // .build() - // // .toJson()) - // // isValid()) - // // .isTrue(); - // } - - private Log randomLog(int nbTopic) { - Bytes data = randData(false); - - List topics = new ArrayList<>(); - for (int i = 0; i < nbTopic; i++) { - topics.add(LogTopic.of(Bytes.random(32))); - } - return new Log(Address.wrap(Bytes.random(20)), data, topics); - } - - private List randomListLog(int nLog) { - List logs = new java.util.ArrayList<>(List.of()); - for (int i = 0; i < nLog; i++) { - logs.add(randomLog(rnd.nextInt(0, 5))); - } - return logs; - } - - private Transaction randTransaction(ToyAccount senderAccount, KeyPair keyPair) { - int txType = rnd.nextInt(0, 3); - final List accessList = new ArrayList<>(); - return switch (txType) { - case 0 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.FRONTIER) - .gasLimit(10_000_000L) - .value(Wei.of(BigInteger.valueOf(2_500))) - .payload(Bytes.EMPTY) - .build(); - case 1 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.ACCESS_LIST) - .gasLimit(10_000_000L) - .value(Wei.of(BigInteger.valueOf(2_500))) - .payload(Bytes.EMPTY) - .accessList(accessList) - .build(); - - case 2 -> ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.EIP1559) - .gasLimit(10_000_000L) - .value(Wei.of(BigInteger.valueOf(2_500))) - .payload(Bytes.EMPTY) - .build(); - default -> throw new IllegalStateException("Unexpected value: " + txType); - }; - } -} diff --git a/zkevm-constraints b/zkevm-constraints index 4e868acfa4..16d984503a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 4e868acfa46282f86db85910500821fbe293e284 +Subproject commit 16d984503aa70910abfa2b22af354c41562b16e4 From afb5bbe86b2111d91c0e2a6fbabeff79a90a192b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 21 Jun 2024 17:44:31 +0530 Subject: [PATCH 140/461] ras blockhash --- .../zktracer/module/blockhash/Blockhash.java | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java index 2fc8b63972..7b3e841817 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java @@ -82,43 +82,42 @@ public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) @Override public void tracePreOpcode(MessageFrame frame) { final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - if (opCode != OpCode.BLOCKHASH) { - return; - } - this.opcodeArgument = Bytes32.leftPad(frame.getStackItem(0)); - lowerBound = - this.wcp.callGEQ( - opcodeArgument, Bytes.ofUnsignedLong(this.absoluteBlockNumber - BLOCKHASH_MAX_HISTORY)); - upperBound = this.wcp.callLT(opcodeArgument, Bytes.ofUnsignedLong(this.absoluteBlockNumber)); - - /* To prove the lex order of BLOCK_NUMBER_HI/LO, we call WCP at endConflation, so we need to add rows in WCP now. - If a BLOCK_NUMBER is already called at least two times, no need for additional rows in WCP*/ - final int numberOfCall = this.numberOfCall.getOrDefault(this.opcodeArgument, 0); - if (numberOfCall < 2) { - this.wcp.additionalRows.push( - this.wcp.additionalRows.pop() - + Math.max(Math.min(LLARGE, this.opcodeArgument.trimLeadingZeros().size()), 1)); - this.numberOfCall.replace(this.opcodeArgument, numberOfCall, numberOfCall + 1); + if (opCode == OpCode.BLOCKHASH) { + this.opcodeArgument = Bytes32.leftPad(frame.getStackItem(0)); + lowerBound = + this.wcp.callGEQ( + opcodeArgument, + Bytes.ofUnsignedLong(this.absoluteBlockNumber - BLOCKHASH_MAX_HISTORY)); + upperBound = this.wcp.callLT(opcodeArgument, Bytes.ofUnsignedLong(this.absoluteBlockNumber)); + + /* To prove the lex order of BLOCK_NUMBER_HI/LO, we call WCP at endConflation, so we need to add rows in WCP now. + If a BLOCK_NUMBER is already called at least two times, no need for additional rows in WCP*/ + final int numberOfCall = this.numberOfCall.getOrDefault(this.opcodeArgument, 0); + if (numberOfCall < 2) { + this.wcp.additionalRows.push( + this.wcp.additionalRows.pop() + + Math.max(Math.min(LLARGE, this.opcodeArgument.trimLeadingZeros().size()), 1)); + this.numberOfCall.replace(this.opcodeArgument, numberOfCall, numberOfCall + 1); + } } } @Override public void tracePostOpcode(MessageFrame frame) { final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - if (opCode != OpCode.BLOCKHASH) { - return; - } - final Bytes32 result = Bytes32.leftPad(frame.getStackItem(0)); - this.operations.add( - new BlockhashOperation( - this.relativeBlock, - this.opcodeArgument, - this.absoluteBlockNumber, - lowerBound, - upperBound, - result)); - if (result != Bytes32.ZERO) { - blockHashMap.put(this.opcodeArgument, result); + if (opCode == OpCode.BLOCKHASH) { + final Bytes32 result = Bytes32.leftPad(frame.getStackItem(0)); + this.operations.add( + new BlockhashOperation( + this.relativeBlock, + this.opcodeArgument, + this.absoluteBlockNumber, + lowerBound, + upperBound, + result)); + if (result != Bytes32.ZERO) { + blockHashMap.put(this.opcodeArgument, result); + } } } From 55684f7bc215f7fc72bb1696826672076abad832 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 24 Jun 2024 15:38:16 +0530 Subject: [PATCH 141/461] fix .yml file --- .../linea/zktracer/module/blockhash/Blockhash.java | 4 ++-- .../module/hub/fragment/imc/call/mmu/MmuCall.java | 3 +-- arithmetization/src/main/resources/opcodes.yml | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java index 7b3e841817..19ed1b57c4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java @@ -123,10 +123,10 @@ public void tracePostOpcode(MessageFrame frame) { @Override public void traceEndConflation(WorldView state) { - final BlockhashComparator BLOCKHASH_COMPARATOR = new BlockhashComparator(); this.sortedOperations.addAll(this.operations); - this.sortedOperations.sort(BLOCKHASH_COMPARATOR); if (!this.sortedOperations.isEmpty()) { + final BlockhashComparator BLOCKHASH_COMPARATOR = new BlockhashComparator(); + this.sortedOperations.sort(BLOCKHASH_COMPARATOR); this.wcp.callGEQ(this.sortedOperations.get(0).opcodeArgument(), Bytes32.ZERO); for (int i = 1; i < this.sortedOperations.size(); i++) { this.wcp.callGEQ( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 35e3da5007..2efe6e6d0e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -98,7 +98,6 @@ @Getter @Accessors(fluent = true) public class MmuCall implements TraceSubFragment { - protected boolean enabled = true; protected int instruction = 0; protected int sourceId = 0; protected int targetId = 0; @@ -716,7 +715,7 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int public Trace trace(Trace trace, State.TxState.Stamps stamps) { stamps.incrementMmuStamp(); return trace - .pMiscMmuFlag(this.enabled()) + .pMiscMmuFlag(true) .pMiscMmuInst( this.instruction() == -1 ? 0 diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml index 775a222c63..a20eb291bd 100644 --- a/arithmetization/src/main/resources/opcodes.yml +++ b/arithmetization/src/main/resources/opcodes.yml @@ -575,7 +575,7 @@ opcodes: value: 0x51 instructionFamily: STACK_RAM stackSettings: - pattern: ONE_ONE + pattern: LOAD_STORE alpha: 1 delta: 1 nbAdded: 1 @@ -589,7 +589,7 @@ opcodes: value: 0x52 instructionFamily: STACK_RAM stackSettings: - pattern: TWO_ZERO + pattern: LOAD_STORE alpha: 0 delta: 2 nbAdded: 0 @@ -603,7 +603,7 @@ opcodes: value: 0x53 instructionFamily: STACK_RAM stackSettings: - pattern: TWO_ZERO + pattern: LOAD_STORE alpha: 0 delta: 2 nbAdded: 0 @@ -1550,7 +1550,7 @@ opcodes: delta: 2 nbAdded: 0 nbRemoved: 2 - staticGas: S_MXP + staticGas: G_ZERO flag1: true billing: byByte: @@ -1637,6 +1637,6 @@ opcodes: delta: 1 nbAdded: 0 nbRemoved: 1 - staticGas: S_MXP + staticGas: S_MXP #TODO check forbiddenInStatic: true flag4: true From c5e0ec0481af1ce6a563af876e65c693484fa21d Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 25 Jun 2024 17:37:09 +0530 Subject: [PATCH 142/461] feat: infos for shared columns are stored and computed once in the Section instead of in the commonFragment --- .../linea/zktracer/module/hub/Hub.java | 62 ++--- .../linea/zktracer/module/hub/TxTrace.java | 6 +- .../module/hub/fragment/TraceFragment.java | 1 + .../fragment/{ => common}/CommonFragment.java | 164 +++++-------- .../fragment/common/CommonFragmentValues.java | 107 +++++++++ .../module/hub/section/AccountSection.java | 1 + .../module/hub/section/ContextLogSection.java | 1 + .../module/hub/section/CopySection.java | 1 + .../module/hub/section/CreateSection.java | 16 +- .../module/hub/section/ExpSection.java | 5 +- .../module/hub/section/JumpSection.java | 11 +- .../module/hub/section/KeccakSection.java | 8 +- .../module/hub/section/LogSection.java | 7 +- .../module/hub/section/SloadSection.java | 9 +- .../module/hub/section/SstoreSection.java | 12 +- .../module/hub/section/StackOnlySection.java | 6 +- .../zktracer/module/hub/section/StackRam.java | 1 + .../module/hub/section/StopSection.java | 4 +- .../module/hub/section/TraceSection.java | 226 ++++++++---------- .../hub/section/TransactionSection.java | 1 + .../section/TxFinalizationPostTxDefer.java | 3 +- .../hub/section/TxInitializationSection.java | 5 +- .../hub/section/TxPreWarmingMacroSection.java | 3 +- .../hub/section/TxSkippedSectionDefers.java | 3 +- .../hub/section/calls/FailedCallSection.java | 5 +- .../hub/section/calls/NoCodeCallSection.java | 13 +- .../calls/SmartContractCallSection.java | 12 +- .../zktracer/module/hub/StupidCreateTBD.java | 64 ----- 28 files changed, 349 insertions(+), 408 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/{ => common}/CommonFragment.java (68%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 509f1a0d7d..74063d5e79 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -686,10 +686,13 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope final boolean unexceptional = exceptions.none(); final boolean exceptional = exceptions.any(); + // TODO: Might be dangerous : in some cases, we add fragments at the end of the transaction ... + // In LogSection it is manually added + // adds the final context row to reset the caller's return data if (exceptional) { this.currentTraceSection() - .addFragmentsWithoutStack(this, ContextFragment.executionProvidesEmptyReturnData(this)); + .addFragmentsWithoutStack(ContextFragment.executionProvidesEmptyReturnData(this)); } // Setting gas cost IN MOST CASES @@ -699,22 +702,13 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope // * make sure this aligns with exception handling of the zkevm // * write a method `final boolean requiresGasCost()` (huge switch case) if ((!memoryExpansionException & outOfGasException) || unexceptional) { - for (TraceSection.TraceLine line : currentSection.lines()) { - line.common().gasCost(gasCost); - line.common().gasNext(unexceptional ? line.common().gasActual() - gasCost : 0); - } - - // we add a context fragment updating the CALLER CONTEXT's - // return data to be empty - if (exceptions.any()) { - currentSection.addFragment( - this, this.currentFrame(), ContextFragment.executionProvidesEmptyReturnData(this)); - } + currentSection.commonValues.gasCost(gasCost); + currentSection.commonValues.gasNext( + unexceptional ? currentSection.commonValues.gasActual - gasCost : 0); } else { - for (TraceSection.TraceLine line : currentSection.lines()) { - line.common().gasCost(0xdeadbeefL); // TODO: fill with correct values --- likely 0 - line.common().gasNext(0); - } + currentSection.commonValues.gasCost( + 0xdeadbeefL); // TODO: fill with correct values --- likely 0 + currentSection.commonValues.gasNext(0); } if (this.currentFrame().opCode().isCreate() && operationResult.getHaltReason() == null) { @@ -952,7 +946,7 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { return; } - StackContext pending = this.currentFrame().pending(); + final StackContext pending = this.currentFrame().pending(); for (int i = 0; i < pending.lines().size(); i++) { StackLine line = pending.lines().get(i); @@ -964,20 +958,21 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { } // This works because we are certain that the stack chunks are the first. - ((StackFragment) section.lines().get(i).specific()) + ((StackFragment) section.fragments().get(i)) .stackOps() .get(line.resultColumn() - 1) .value(result); } } - if (this.pch.exceptions().none()) { - for (TraceSection.TraceLine line : section.lines()) { - if (line.specific() instanceof StackFragment stackFragment) { - stackFragment.feedHashedValue(frame); - } - } - } + // TODO: this seems useless now + // if (this.pch.exceptions().none()) { + // for (TraceSection.TraceLine line : section.fragments()) { + // if (line.specific() instanceof StackFragment stackFragment) { + // stackFragment.feedHashedValue(frame); + // } + // } + // } } void processStateExec(MessageFrame frame) { @@ -1103,8 +1098,7 @@ void traceOperation(MessageFrame frame) { case ACCOUNT -> { TraceSection accountSection = new AccountSection(this); if (this.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { - accountSection.addFragment( - this, this.currentFrame(), ContextFragment.readCurrentContextData(this)); + accountSection.addFragment(ContextFragment.readCurrentContextData(this)); } final Bytes rawTargetAddress = @@ -1129,8 +1123,6 @@ void traceOperation(MessageFrame frame) { final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 0); accountSection.addFragment( - this, - this.currentFrame(), this.factories .accountFragment() .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps)); @@ -1139,8 +1131,6 @@ void traceOperation(MessageFrame frame) { final DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); accountSection.addFragment( - this, - this.currentFrame(), this.factories .accountFragment() .make(accountBefore, accountAfter, undoingDomSubStamps)); @@ -1180,8 +1170,6 @@ void traceOperation(MessageFrame frame) { DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 0); copySection.addFragment( - this, - this.currentFrame(), this.currentFrame().opCode() == OpCode.EXTCODECOPY ? this.factories .accountFragment() @@ -1195,15 +1183,12 @@ void traceOperation(MessageFrame frame) { DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); copySection.addFragment( - this, - this.currentFrame(), this.factories .accountFragment() .make(accountAfter, accountBefore, undoingDomSubStamps)); } } else { - copySection.addFragment( - this, this.currentFrame(), ContextFragment.readCurrentContextData(this)); + copySection.addFragment(ContextFragment.readCurrentContextData(this)); } this.addTraceSection(copySection); } @@ -1411,8 +1396,7 @@ void traceOperation(MessageFrame frame) { // In all cases, add a context fragment if an exception occurred if (this.pch().exceptions().any()) { this.currentTraceSection() - .addFragment( - this, this.currentFrame(), ContextFragment.executionProvidesEmptyReturnData(this)); + .addFragment(ContextFragment.executionProvidesEmptyReturnData(this)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 19023356ba..5b999c6532 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -95,9 +95,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces public void commit(Trace hubTrace) { for (TraceSection opSection : this.trace) { opSection.seal(); - for (TraceSection.TraceLine line : opSection.lines()) { - line.trace(hubTrace, opSection.stackHeight(), opSection.stackHeightNew()); - } + opSection.trace(hubTrace); } } @@ -107,7 +105,7 @@ public void commit(Trace hubTrace) { public int lineCount() { if (this.cachedLineCount == 0) { for (TraceSection s : trace) { - this.cachedLineCount += s.lines().size(); + this.cachedLineCount += s.fragments().size(); } } return this.cachedLineCount; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceFragment.java index 2b5bc4055a..64c58dd2eb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceFragment.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.module.hub.fragment; import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.common.CommonFragment; /** * A TraceFragment represents a piece of a trace line; either a {@link CommonFragment} present in diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java similarity index 68% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java index d5a6511165..c68d7d1cb7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java @@ -13,26 +13,20 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment; +package net.consensys.linea.zktracer.module.hub.fragment.common; -import static net.consensys.linea.zktracer.opcode.OpCode.SSTORE; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; import java.math.BigInteger; import java.util.function.Supplier; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; +import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; -import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; -import net.consensys.linea.zktracer.opcode.InstructionFamily; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; @@ -51,41 +45,21 @@ import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true, chain = false) -@Builder +@RequiredArgsConstructor public final class CommonFragment implements TraceFragment { - private final Hub hub; - private final int absoluteTransactionNumber; - private final int relativeBlockNumber; - private final HubProcessingPhase hubProcessingPhase; - private final State.TxState.Stamps stamps; - private final InstructionFamily instructionFamily; - private final Exceptions exceptions; - private final AbortingConditions abortingConditions; - private final FailureConditions failureConditions; - private final int callFrameId; - private final int callerContextNumber; - @Getter private final int contextNumber; - private final int contextNumberNew; - private final int revertStamp; - @Getter final short height; - @Getter final short heightNew; - @Getter private final int pc; - @Setter private int pcNew; - private int codeDeploymentNumber; - private final boolean codeDeploymentStatus; - @Setter long gasExpected; - @Getter long gasActual; - @Setter long gasCost; - @Setter long gasNext; - @Getter private final long refundDelta; - @Setter private long gasRefund; - @Getter @Setter private boolean twoLineInstruction; - @Getter @Setter private boolean twoLineInstructionCounter; - @Getter @Setter private int numberOfNonStackRows; - @Getter @Setter private int nonStackRowsCounter; - - public static CommonFragment fromHub( + private final CommonFragmentValues commonFragmentValues; + private final int nonStackRowsCounter; + private final boolean twoLineInstructionCounter; + + public CommonFragment( + CommonFragmentValues commonValues, int stackLineCounter, int nonStackLineCounter) { + this.commonFragmentValues = commonValues; + this.twoLineInstructionCounter = stackLineCounter == 1; + this.nonStackRowsCounter = nonStackLineCounter; + } + + /* public static CommonFragment fromHub( final Hub hub, final CallFrame callFrame, boolean counterTli, @@ -94,7 +68,7 @@ public static CommonFragment fromHub( final boolean noStackException = hub.pch().exceptions().noStackException(); final long refundDelta = - noStackException ? Hub.GAS_PROJECTOR.of(callFrame.frame(), hub.opCode()).refund() : 0; + noStackException ? Hub.GfAS_PROJECTOR.of(callFrame.frame(), hub.opCode()).refund() : 0; // TODO: partial solution, will not work in general final long gasExpected = hub.expectedGas(); @@ -159,8 +133,9 @@ public static CommonFragment fromHub( .numberOfNonStackRows(numberOfNonStackRows) .build(); } + */ - private static int computePcNew( + static int computePcNew( final Hub hub, final int pc, boolean noStackException, boolean hubInExecPhase) { OpCode opCode = hub.opCode(); if (!(noStackException && hubInExecPhase)) { @@ -196,74 +171,53 @@ private static int computePcNew( } public boolean txReverts() { - return hub.txStack() - .getByAbsoluteTransactionNumber(this.absoluteTransactionNumber) - .statusCode(); + return commonFragmentValues.txMetadata.statusCode(); } - @Override public Trace trace(Trace trace) { - throw new UnsupportedOperationException("should never be called"); - } - - public Trace trace(Trace trace, int stackHeight, int stackHeightNew) { - final CallFrame frame = this.hub.callStack().getById(this.callFrameId); - final TransactionProcessingMetadata tx = - hub.txStack().getByAbsoluteTransactionNumber(this.absoluteTransactionNumber); - final int codeFragmentIndex = - this.hubProcessingPhase == HubProcessingPhase.TX_EXEC - ? this.hub.getCfiByMetaData( - frame.byteCodeAddress(), frame.codeDeploymentNumber(), frame.isDeployment()) - : 0; - final boolean selfReverts = frame.selfReverts(); - final boolean getsReverted = frame.getsReverted(); - final boolean willRevert = frame.willRevert(); - final boolean contextMayChange = - this.hubProcessingPhase == HubProcessingPhase.TX_EXEC - && ((instructionFamily == InstructionFamily.CALL - || instructionFamily == InstructionFamily.CREATE - || instructionFamily == InstructionFamily.HALT - || instructionFamily == InstructionFamily.INVALID) - || exceptions.any()); + final CallFrame frame = commonFragmentValues.callFrame; + final TransactionProcessingMetadata tx = commonFragmentValues.txMetadata; return trace .absoluteTransactionNumber(tx.getAbsoluteTransactionNumber()) - .batchNumber(this.relativeBlockNumber) - .txSkip(this.hubProcessingPhase == HubProcessingPhase.TX_SKIP) - .txWarm(this.hubProcessingPhase == HubProcessingPhase.TX_WARM) - .txInit(this.hubProcessingPhase == HubProcessingPhase.TX_INIT) - .txExec(this.hubProcessingPhase == HubProcessingPhase.TX_EXEC) - .txFinl(this.hubProcessingPhase == HubProcessingPhase.TX_FINAL) - .hubStamp(this.stamps.hub()) + .batchNumber(tx.getRelativeBlockNumber()) + .txSkip(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_SKIP) + .txWarm(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_WARM) + .txInit(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_INIT) + .txExec(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_EXEC) + .txFinl(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_FINAL) + .hubStamp(commonFragmentValues.hubStamp) .hubStampTransactionEnd(tx.getHubStampTransactionEnd()) - .contextMayChange(contextMayChange) - .exceptionAhoy(exceptions.any()) - .logInfoStamp(this.stamps.log()) - .mmuStamp(this.hub.state().stamps().mmu()) - .mxpStamp(this.hub.state().stamps().mxp()) + .contextMayChange(commonFragmentValues.contextMayChange) + .exceptionAhoy(commonFragmentValues.exceptionAhoy) + .logInfoStamp(commonFragmentValues.logStamp) + .mmuStamp(commonFragmentValues.stamps.mmu()) + .mxpStamp(commonFragmentValues.stamps.mxp()) // nontrivial dom / sub are traced in storage or account fragments only - .contextNumber(contextNumber) - .contextNumberNew(contextNumberNew) - .callerContextNumber(callerContextNumber) - .contextWillRevert(willRevert) - .contextGetsReverted(getsReverted) - .contextSelfReverts(selfReverts) - .contextRevertStamp(revertStamp) - .codeFragmentIndex(codeFragmentIndex) - .programCounter(pc) - .programCounterNew(pcNew) - .height((short) stackHeight) - .heightNew((short) stackHeightNew) + .contextNumber( + commonFragmentValues.hubProcessingPhase == TX_EXEC ? frame.contextNumber() : 0) + .contextNumberNew(commonFragmentValues.contextNumberNew) + .callerContextNumber( + commonFragmentValues.callStack.getById(frame.parentFrame()).contextNumber()) + .contextWillRevert(frame.willRevert()) + .contextGetsReverted(frame.getsReverted()) + .contextSelfReverts(frame.selfReverts()) + .contextRevertStamp(commonFragmentValues.cnRevertStamp) + .codeFragmentIndex(commonFragmentValues.codeFragmentIndex) + .programCounter(commonFragmentValues.pc) + .programCounterNew(commonFragmentValues.pcNew) + .height(commonFragmentValues.height) + .heightNew(commonFragmentValues.heightNew) // peeking flags are traced in the respective fragments - .gasExpected(gasExpected) - .gasActual(gasActual) - .gasCost(Bytes.ofUnsignedLong(gasCost)) - .gasNext(gasNext) - .refundCounter(gasRefund) - .refundCounterNew(gasRefund + (willRevert ? 0 : refundDelta)) - .twoLineInstruction(twoLineInstruction) + .gasExpected(commonFragmentValues.gasExpected) + .gasActual(commonFragmentValues.gasActual) + .gasCost(Bytes.ofUnsignedLong(commonFragmentValues.gasCost)) + .gasNext(commonFragmentValues.gasNext) + .refundCounter(commonFragmentValues.gasRefund) + .refundCounterNew(commonFragmentValues.gasRefundNew) + .twoLineInstruction(commonFragmentValues.TLI) .counterTli(twoLineInstructionCounter) - .nonStackRows((short) numberOfNonStackRows) + .nonStackRows((short) commonFragmentValues.numberOfNonStackRows) .counterNsr((short) nonStackRowsCounter); } @@ -357,8 +311,4 @@ static long gasCostSload(Hub hub, WorldView world) { ? ZkTracer.gasCalculator.getWarmStorageReadCost() : ZkTracer.gasCalculator.getColdSloadCost()); } - - static long Bull() { - return 0x1337; - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java new file mode 100644 index 0000000000..49144a4083 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java @@ -0,0 +1,107 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.common; + +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; +import static net.consensys.linea.zktracer.module.hub.fragment.common.CommonFragment.computePcNew; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; +import net.consensys.linea.zktracer.module.hub.State; +import net.consensys.linea.zktracer.opcode.InstructionFamily; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.runtime.callstack.CallStack; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; + +@Accessors(fluent = true) +@RequiredArgsConstructor +public class CommonFragmentValues { + public final TransactionProcessingMetadata txMetadata; + public final HubProcessingPhase hubProcessingPhase; + public final int hubStamp; + public final CallStack callStack; + public final State.TxState.Stamps stamps; // for MMU and MXP stamps + @Setter public int logStamp; // TODO + @Getter final CallFrame callFrame; + public final boolean exceptionAhoy; + public final int contextNumberNew; + public final int cnRevertStamp; + public final int pc; + public final int pcNew; + final short height; + final short heightNew; + public final long gasExpected; + public final long gasActual; + public final boolean contextMayChange; + @Setter long gasCost; // Set at Post Execution + @Setter long gasNext; // Set at Post Execution + @Getter public final long refundDelta; + @Setter public long gasRefund; // TODO + @Setter public long gasRefundNew; /* TODO gasRefund + (willRevert ? 0 : refundDelta) */ + @Setter public int numberOfNonStackRows; + @Setter public boolean TLI; + @Setter public int codeFragmentIndex = -1; + + public CommonFragmentValues(Hub hub) { + final boolean noStackException = hub.pch().exceptions().noStackException(); + final InstructionFamily instructionFamily = hub.opCode().getData().instructionFamily(); + + this.txMetadata = hub.txStack().current(); + this.hubProcessingPhase = hub.state().getProcessingPhase(); + this.hubStamp = hub.state().stamps().hub(); + this.callStack = hub.callStack(); + this.stamps = hub.state().stamps(); + this.callFrame = hub.currentFrame(); + this.exceptionAhoy = hub.pch().exceptions().any(); + this.contextNumberNew = + hub.contextNumberNew( + callFrame); // TODO this should be in seal method, looking at CN of following section + this.cnRevertStamp = 0; // TODO + this.pc = hubProcessingPhase == TX_EXEC ? hub.currentFrame().pc() : 0; + this.pcNew = + computePcNew( + hub, + pc, + noStackException, + hub.state.getProcessingPhase() + == TX_EXEC); // TODO this should be in seal method, looking at PC of following + this.height = (short) callFrame.stack().getHeight(); + this.heightNew = + (short) + callFrame + .stack() + .getHeightNew(); // TODO this should be in seal method, looking at height of + // following + this.refundDelta = + noStackException ? Hub.GAS_PROJECTOR.of(callFrame.frame(), hub.opCode()).refund() : 0; + + // TODO: partial solution, will not work in general + this.gasExpected = hub.expectedGas(); + this.gasActual = hub.remainingGas(); + + this.contextMayChange = + hubProcessingPhase == HubProcessingPhase.TX_EXEC + && ((instructionFamily == InstructionFamily.CALL + || instructionFamily == InstructionFamily.CREATE + || instructionFamily == InstructionFamily.HALT + || instructionFamily == InstructionFamily.INVALID) + || exceptionAhoy); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index d4d595b806..387b6f49f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -20,6 +20,7 @@ public class AccountSection extends TraceSection { public AccountSection(Hub hub, TraceFragment... chunks) { + super(hub); this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java index a9ca7cde22..bf7787ea47 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java @@ -20,6 +20,7 @@ public class ContextLogSection extends TraceSection { public ContextLogSection(Hub hub, TraceFragment... chunks) { + super(hub); this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java index f282066d9f..88dd5ca6c4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java @@ -20,6 +20,7 @@ public class CopySection extends TraceSection { public CopySection(Hub hub, TraceFragment... chunks) { + super(hub); this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 6839e4e1b9..487c1eb7cc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -76,6 +76,7 @@ private boolean targetHasCode() { public CreateSection( Hub hub, AccountSnapshot oldCreatorSnapshot, AccountSnapshot oldCreatedSnapshot) { + super(hub); this.creatorContextId = hub.currentFrame().id(); this.opCode = hub.opCode(); this.emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); @@ -171,24 +172,21 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces 0)); this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); - this.addFragmentsWithoutStack(hub, scenarioFragment); + this.addFragmentsWithoutStack(scenarioFragment); if (this.exceptions.staticException()) { this.addFragmentsWithoutStack( - hub, ImcFragment.empty(hub), ContextFragment.readCurrentContextData(hub), ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.exceptions.memoryExpansionException()) { this.addFragmentsWithoutStack( - hub, ImcFragment.empty(hub).callMxp(MxpCall.build(hub)), ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.exceptions.outOfGasException()) { this.addFragmentsWithoutStack( - hub, commonImcFragment, ContextFragment.executionProvidesEmptyReturnData(hub)); + commonImcFragment, ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.aborts.any()) { this.addFragmentsWithoutStack( - hub, commonImcFragment, ContextFragment.readCurrentContextData(hub), accountFragmentFactory.make( @@ -199,7 +197,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces } else if (this.failures.any()) { if (creatorWillRevert) { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, @@ -220,7 +217,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces ContextFragment.nonExecutionEmptyReturnData(hub)); } else { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, @@ -237,7 +233,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces if (this.emptyInitCode) { if (creatorWillRevert) { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, @@ -258,7 +253,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces ContextFragment.nonExecutionEmptyReturnData(hub)); } else { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, @@ -276,7 +270,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces if (this.createSuccessful) { if (creatorWillRevert) { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, @@ -298,7 +291,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces } else { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, @@ -313,7 +305,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces } else { if (creatorWillRevert) { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, @@ -344,7 +335,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces ContextFragment.initializeExecutionContext(hub)); } else { this.addFragmentsWithoutStack( - hub, commonImcFragment, accountFragmentFactory.make( oldCreatorSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java index 67d3321ae9..56309b8a4b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java @@ -19,7 +19,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; public class ExpSection extends TraceSection { - public ExpSection(Hub hub, TraceFragment... chunks) { - this.addFragmentsAndStack(hub, hub.currentFrame(), chunks); + public ExpSection(Hub hub, TraceFragment... fragments) { + super(hub); + this.addFragmentsAndStack(hub, fragments); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index 6604b81358..62c43c476d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -36,8 +36,8 @@ public class JumpSection extends TraceSection { public static void appendToTrace(Hub hub, WorldView worldView) { - final JumpSection currentSection = new JumpSection(); - currentSection.addFragmentsAndStack(hub); + final JumpSection currentSection = new JumpSection(hub); + currentSection.addFragmentsAndStack(hub); // TODO strange to not give any fragments if (hub.pch().exceptions().outOfGasException()) { return; @@ -96,7 +96,7 @@ public static void appendToTrace(Hub hub, WorldView worldView) { // CONTEXT, ACCOUNT, MISCELLANEOUS ////////////////////////////////// currentSection.addFragmentsWithoutStack( - hub, contextRowCurrentContext, accountRowCodeAccount, miscellaneousRow); + contextRowCurrentContext, accountRowCodeAccount, miscellaneousRow); // jump destination vetting /////////////////////////// @@ -105,9 +105,12 @@ public static void appendToTrace(Hub hub, WorldView worldView) { } } - private JumpSection() {} + private JumpSection(Hub hub) { + super(hub); + } public JumpSection(Hub hub, TraceFragment... chunks) { + super(hub); this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 324d074acd..a0ecacce37 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -28,11 +28,11 @@ public class KeccakSection extends TraceSection { public static void appendToTrace(Hub hub) { - final KeccakSection currentSection = new KeccakSection(); + final KeccakSection currentSection = new KeccakSection(hub); hub.addTraceSection(currentSection); ImcFragment imcFragment = ImcFragment.empty(hub); - currentSection.addFragmentsAndStack(hub, hub.currentFrame(), imcFragment); + currentSection.addFragmentsAndStack(hub, imcFragment); MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); @@ -57,5 +57,7 @@ public static void appendToTrace(Hub hub) { } } - private KeccakSection() {} + private KeccakSection(Hub hub) { + super(hub); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index 01b6ad74ea..5522db9932 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -49,7 +49,7 @@ public LogSection(Hub hub) { if (hub.currentFrame().frame().isStatic()) { // static exception - sectionPrequel.addFragmentsWithoutStack(hub, finalContextRow); + sectionPrequel.addFragmentsWithoutStack(finalContextRow); } else { logData = Optional.of(new LogInvocation(hub)); mxpSubFragment = Optional.of(MxpCall.build(hub)); @@ -65,15 +65,16 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces if (mmuTrigger) { miscFragment.get().callMmu(MmuCall.LogX(hub, this.logData.get())); } - this.sectionPrequel.addFragment(hub, logData.get().callFrame, miscFragment.get()); + this.sectionPrequel.addFragment(miscFragment.get()); if (mxpX || oogX) { - this.sectionPrequel.addFragment(hub, logData.get().callFrame, finalContextRow); + this.sectionPrequel.addFragment(finalContextRow); } } } public static class LogCommonSection extends TraceSection { public LogCommonSection(Hub hub, ContextFragment fragment) { + super(hub); this.addFragmentsAndStack(hub, fragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index c08b9d578e..162e9a8be8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -29,12 +29,10 @@ @Getter public class SloadSection extends TraceSection { - - final Hub hub; final WorldView world; private SloadSection(Hub hub, WorldView world) { - this.hub = hub; + super(hub); this.world = world; } @@ -56,8 +54,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { StorageFragment doingSload = doingSload(hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent); - sloadSection.addFragmentsAndStack( - hub, hub.currentFrame(), readCurrentContext, miscFragmentForSload, doingSload); + sloadSection.addFragmentsAndStack(hub, readCurrentContext, miscFragmentForSload, doingSload); final boolean outOfGasException = hub.pch().exceptions().outOfGasException(); final boolean contextWillRevert = hub.callStack().current().willRevert(); @@ -68,7 +65,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { undoingSload(hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent); // TODO: make sure we trace a context when there is an exception - sloadSection.addFragment(hub, hub.currentFrame(), undoingSload); + sloadSection.addFragment(undoingSload); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index b46373548f..8a9d232d6f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -30,12 +30,10 @@ @Getter public class SstoreSection extends TraceSection { - - final Hub hub; final WorldView world; private SstoreSection(Hub hub, WorldView world) { - this.hub = hub; + super(hub); this.world = world; } @@ -61,7 +59,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { // CONTEXT fragment ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); - currentSection.addFragmentsAndStack(hub, hub.currentFrame(), readCurrentContext); + currentSection.addFragmentsAndStack(hub, readCurrentContext); if (staticContextException) { return; @@ -69,7 +67,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { // MISC fragment ImcFragment miscForSstore = ImcFragment.forOpcode(hub, hub.messageFrame()); - currentSection.addFragment(hub, hub.currentFrame(), miscForSstore); + currentSection.addFragment(miscForSstore); if (sstoreException) { return; @@ -80,14 +78,14 @@ public static void appendSectionTo(Hub hub, WorldView world) { doingSstore( hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); - currentSection.addFragment(hub, hub.currentFrame(), doingSstore); + currentSection.addFragment(doingSstore); // STORAGE fragment (for undoing) if (outOfGasException || contextWillRevert) { StorageFragment undoingSstore = undoingSstore( hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); - currentSection.addFragment(hub, hub.currentFrame(), undoingSstore); + currentSection.addFragment(undoingSstore); } } 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 35ec4baa13..869fc544f4 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 @@ -16,10 +16,10 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; public class StackOnlySection extends TraceSection { - public StackOnlySection(Hub hub, TraceFragment... chunks) { - this.addFragmentsAndStack(hub, chunks); + public StackOnlySection(Hub hub) { + super(hub); + this.addStack(hub); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java index b0af0d5d1f..79af1e5ed5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java @@ -64,6 +64,7 @@ public static void appendToTrace(Hub hub) { } public StackRam(Hub hub, TraceFragment... chunks) { + super(hub); this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java index 369496aa62..a5277f509b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java @@ -43,6 +43,7 @@ public static void appendTo(Hub hub) { } private StopSection(Hub hub, TraceFragment... fragments) { + super(hub); this.addFragmentsAndStack(hub, fragments); } @@ -80,7 +81,6 @@ public static StopSection deploymentStopSection(Hub hub) { if (hub.currentFrame().willRevert()) { // undoing of the above stopWhileDeploying.addFragmentsWithoutStack( - hub, accountFragmentFactory.make( afterEmptyDeployment, beforeEmptyDeployment, @@ -88,7 +88,7 @@ public static StopSection deploymentStopSection(Hub hub) { executionProvidesEmptyReturnData(hub)); } else { - stopWhileDeploying.addFragmentsWithoutStack(hub, executionProvidesEmptyReturnData(hub)); + stopWhileDeploying.addFragmentsWithoutStack(executionProvidesEmptyReturnData(hub)); } return stopWhileDeploying; 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 a6f388eb30..6a35d0af6a 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 @@ -24,82 +24,85 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.DeploymentExceptions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.TxTrace; -import net.consensys.linea.zktracer.module.hub.fragment.CommonFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.common.CommonFragment; +import net.consensys.linea.zktracer.module.hub.fragment.common.CommonFragmentValues; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.stack.StackLine; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.worldstate.WorldView; +import org.hyperledger.besu.evm.internal.Words; @Accessors(fluent = true) /** A TraceSection gather the trace lines linked to a single operation */ public abstract class TraceSection { - private WorldView world; - @Getter private int stackHeight = 0; - @Getter private int stackHeightNew = 0; - - /** - * A TraceLine stores the information required to generate a trace line. - * - * @param common data required to trace shared columns - * @param specific data required to trace perspective-specific columns - */ - public record TraceLine(CommonFragment common, TraceFragment specific) { - /** - * Trace the line in the given trace builder. - * - * @param trace where to trace the line - * @return the trace builder - */ - public Trace trace(Trace trace, int stackInt, int stackHeight) { - Preconditions.checkNotNull(common); - Preconditions.checkNotNull(specific); - - specific.trace(trace); // Warn: need to be called before common.trace to update stamps - common.trace(trace, stackInt, stackHeight); - - return trace.fillAndValidateRow(); - } - } + private final Hub hub; + public final CommonFragmentValues commonValues; + @Getter List fragments = new ArrayList<>(); + @Getter private int stackHeight = 0; // To delete + @Getter private int stackHeightNew = 0; // To delete /** Count the stack lines */ - @Getter private int stackRowsCounter; + @Getter private int stackRowsCounter = 0; /** Count the non-stack lines */ - public int nonStackRowCounter; - - public int numberOfNonStackRows; + public int nonStackRowCounter = 0; + public int numberOfNonStackRows = -1; @Getter @Setter private TxTrace parentTrace; - /** A list of {@link TraceLine} representing the trace lines associated with this section. */ - @Getter List lines = new ArrayList<>(32); // TODO: Overkill no ? - - /** - * Fill the columns shared by all type of lines. - * - * @return a {@link CommonFragment} representing the shared columns - */ - private CommonFragment traceCommon(Hub hub, CallFrame frame) { - return CommonFragment.fromHub( - hub, frame, this.stackRowsCounter == 2, this.nonStackRowCounter, this.numberOfNonStackRows); + /** Default creator for an empty section. */ + public TraceSection(Hub hub) { + this.hub = hub; + this.commonValues = new CommonFragmentValues(hub); } - /** Default creator for an empty section. */ - public TraceSection() {} + /// ** + // * A TraceLine stores the information required to generate a trace line. + // * + // * @param common data required to trace shared columns + // * @param specific data required to trace perspective-specific columns + // */ + // public record TraceLine(CommonFragment common, TraceFragment specific) { + // /** + // * Trace the line in the given trace builder. + // * + // * @param trace where to trace the line + // * @return the trace builder + // */ + // public Trace trace(Trace trace, int stackInt, int stackHeight) { + // Preconditions.checkNotNull(common); + // Preconditions.checkNotNull(specific); + // + // specific.trace(trace); // Warn: need to be called before common.trace to update stamps + // common.trace(trace, stackInt, stackHeight); + // + // return trace.fillAndValidateRow(); + // } + // } + + /// ** + // * Fill the columns shared by all type of lines. + // * + // * @return a {@link CommonFragment} representing the shared columns + // */ + // private CommonFragment traceCommon(Hub hub, CallFrame frame) { + // return CommonFragment.fromHub( + // hub, frame, this.stackRowsCounter == 2, this.nonStackRowCounter, + // this.numberOfNonStackRows); + // } /** - * Add a fragment to the section while pairing it to its common piece. + * Add a fragment to the section. * - * @param hub the execution context * @param fragment the fragment to insert */ - public final void addFragment(Hub hub, CallFrame callFrame, TraceFragment fragment) { + public final void addFragment(TraceFragment fragment) { Preconditions.checkArgument(!(fragment instanceof CommonFragment)); - this.lines.add(new TraceLine(traceCommon(hub, callFrame), fragment)); + this.fragments.add(fragment); } /** @@ -109,61 +112,31 @@ public final void addFragment(Hub hub, CallFrame callFrame, TraceFragment fragme */ public final void addStack(Hub hub) { for (var stackFragment : this.makeStackFragments(hub, hub.currentFrame())) { - this.stackHeight = hub.currentFrame().stack().getHeight(); - this.stackHeightNew = hub.currentFrame().stack().getHeightNew(); - this.addFragment(hub, hub.currentFrame(), stackFragment); + this.addFragment(stackFragment); } } /** - * Create several {@link TraceLine} within this section for the specified fragments. + * Add several fragments within this section for the specified fragments. * - * @param hub the Hub linked to fragments execution * @param fragments the fragments to add to the section */ - public final void addFragmentsWithoutStack( - Hub hub, CallFrame callFrame, TraceFragment... fragments) { + public final void addFragmentsWithoutStack(TraceFragment... fragments) { for (TraceFragment f : fragments) { - this.addFragment(hub, callFrame, f); - } - } - - /** - * Create several {@link TraceLine} within this section for the specified fragments. - * - * @param hub the Hub linked to fragments execution - * @param fragments the fragments to add to the section - */ - public final void addFragmentsWithoutStack(Hub hub, TraceFragment... fragments) { - for (TraceFragment fragment : fragments) { - this.addFragment(hub, hub.currentFrame(), fragment); + this.addFragment(f); } } /** - * Insert {@link TraceLine} related to the current state of the stack, then insert the provided + * Insert Stack fragments related to the current state of the stack, then insert the provided * fragments in a single swoop. * * @param hub the execution context - * @param callFrame the {@link CallFrame} containing the execution context; typically the current - * one in the hub for most instructions, but may be the parent one for e.g. CREATE* - * @param fragments the fragments to insert - */ - public final void addFragmentsAndStack(Hub hub, CallFrame callFrame, TraceFragment... fragments) { - this.addStack(hub); - this.addFragmentsWithoutStack(hub, callFrame, fragments); - } - - /** - * Insert {@link TraceLine} related to the current state of the stack of the current {@link - * CallFrame}, then insert the provided fragments in a single swoop. - * - * @param hub the execution context * @param fragments the fragments to insert */ public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { this.addStack(hub); - this.addFragmentsWithoutStack(hub, hub.currentFrame(), fragments); + this.addFragmentsWithoutStack(fragments); } /** @@ -171,36 +144,25 @@ public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { * post-hoc. */ public void seal() { - final int numberOfNonStackRows = - (int) this.lines.stream().filter(l -> !(l.specific instanceof StackFragment)).count(); - int nonStackLineCounter = 0; - for (TraceLine line : this.lines) { - if (!(line.specific instanceof StackFragment)) { - nonStackLineCounter++; - line.common.nonStackRowsCounter(nonStackLineCounter); - } - line.common.numberOfNonStackRows(numberOfNonStackRows); - } + commonValues.numberOfNonStackRows( + (int) this.fragments.stream().filter(l -> !(l instanceof StackFragment)).count()); + commonValues.TLI( + (int) this.fragments.stream().filter(l -> (l instanceof StackFragment)).count() == 2); + commonValues.codeFragmentIndex( + this.commonValues.hubProcessingPhase == HubProcessingPhase.TX_EXEC + ? this.hub.getCfiByMetaData( + this.commonValues.callFrame().byteCodeAddress(), + this.commonValues.callFrame().codeDeploymentNumber(), + this.commonValues.callFrame().isDeployment()) + : 0); } - /** - * Returns whether the opcode encoded in this section is part of a reverted context. As it is - * section-specific, we simply take the first one. - * - * @return true if the context reverted - */ public final boolean hasReverted() { - return this.lines.get(0).common.txReverts(); + return this.commonValues.callFrame().hasReverted(); } - /** - * Returns the gas refund delta incurred by this operation. As it is section-specific, we simply - * take the first one. - * - * @return the gas delta - */ public final long refundDelta() { - return this.lines.get(0).common.refundDelta(); + return this.commonValues.refundDelta(); } /** @@ -209,9 +171,9 @@ public final long refundDelta() { * @param contEx the computed exceptions */ public void setContextExceptions(DeploymentExceptions contEx) { - for (TraceLine line : this.lines) { - if (line.specific instanceof StackFragment fragment) { - fragment.contextExceptions(contEx); + for (TraceFragment fragment : this.fragments) { + if (fragment instanceof StackFragment) { + ((StackFragment) fragment).contextExceptions(contEx); } } } @@ -249,26 +211,42 @@ private List makeStackFragments(final Hub hub, CallFrame f) { } public void triggerHashInfo(Bytes hash) { - - for (TraceSection.TraceLine line : this.lines()) { - if (line.specific() instanceof StackFragment) { - ((StackFragment) line.specific()).hashInfoFlag = true; - ((StackFragment) line.specific()).hash = hash; + for (TraceFragment fragment : this.fragments()) { + if (fragment instanceof StackFragment) { + ((StackFragment) fragment).hashInfoFlag = true; + ((StackFragment) fragment).hash = hash; } } } public void triggerJumpDestinationVetting(Hub hub) { + final int pcNew = Words.clampedToInt(hub.messageFrame().getStackItem(0)); + final boolean invalidJumpDestination = hub.messageFrame().getCode().isJumpDestInvalid(pcNew); - int pcNew = hub.messageFrame().getStackItem(0).toInt(); + for (TraceFragment fragment : this.fragments()) { + if (fragment instanceof StackFragment) { + ((StackFragment) fragment).jumpDestinationVettingRequired(true); + ((StackFragment) fragment).validJumpDestination(invalidJumpDestination); + } + } + } - boolean invalidJumpDestination = hub.messageFrame().getCode().isJumpDestInvalid(pcNew); + public void trace(Trace hubTrace) { + int stackLineCounter = -1; + int nonStackLineCounter = 0; - for (TraceSection.TraceLine line : this.lines()) { - if (line.specific() instanceof StackFragment) { - ((StackFragment) line.specific()).jumpDestinationVettingRequired(true); - ((StackFragment) line.specific()).validJumpDestination(invalidJumpDestination); + for (TraceFragment specificFragment : fragments()) { + if (specificFragment instanceof StackFragment) { + stackLineCounter++; + } else { + nonStackLineCounter++; } + + specificFragment.trace(hubTrace); + final CommonFragment commonFragment = + new CommonFragment(commonValues, stackLineCounter, nonStackLineCounter); + commonFragment.trace(hubTrace); + hubTrace.fillAndValidateRow(); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java index 4e235bd859..0c45602610 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java @@ -20,6 +20,7 @@ public class TransactionSection extends TraceSection { public TransactionSection(Hub hub, TraceFragment... chunks) { + super(hub); this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java index 9fb4e3126b..dd976254e9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java @@ -226,7 +226,8 @@ private boolean noAccountCollision() { public class TxFinalizationSection extends TraceSection { public TxFinalizationSection(Hub hub, TraceFragment... fragments) { - this.addFragmentsWithoutStack(hub, fragments); + super(hub); + this.addFragmentsWithoutStack(fragments); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 9510c90c44..143133494e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -40,7 +40,7 @@ public TxInitializationSection(Hub hub, WorldView world) { hub.state.setProcessingPhase(TX_INIT); hub.state.stamps().incrementHubStamp(); - TransactionProcessingMetadata tx = hub.txStack().current(); + final TransactionProcessingMetadata tx = hub.txStack().current(); final boolean isDeployment = tx.isDeployment(); final Address toAddress = tx.getEffectiveTo(); final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); @@ -117,7 +117,8 @@ public TxInitializationSection(Hub hub, WorldView world) { public class InitializationSection extends TraceSection { public InitializationSection(Hub hub, TraceFragment... fragments) { - this.addFragmentsWithoutStack(hub, fragments); + super(hub); + this.addFragmentsWithoutStack(fragments); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 3830d481d1..59577b1911 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -141,7 +141,8 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { public class TxPrewarmingSection extends TraceSection { public TxPrewarmingSection(Hub hub, TraceFragment fragment) { - this.addFragmentsWithoutStack(hub, fragment); + super(hub); + this.addFragmentsWithoutStack(fragment); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java index 79e055fd7d..a05ce6edc2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java @@ -136,7 +136,8 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces public class TxSkippedSection extends TraceSection { public TxSkippedSection(Hub hub, TraceFragment... fragments) { - this.addFragmentsWithoutStack(hub, fragments); + super(hub); + this.addFragmentsWithoutStack(fragments); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java index b99fef20ef..020ebb7099 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java @@ -20,7 +20,8 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class FailedCallSection extends TraceSection { - public FailedCallSection(Hub hub, TraceFragment... chunks) { - this.addFragmentsAndStack(hub, hub.currentFrame(), chunks); + public FailedCallSection(Hub hub, TraceFragment... fragments) { + super(hub); + this.addFragmentsAndStack(hub, fragments); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index bbb628bf9c..83c1622fba 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -65,6 +65,7 @@ public NoCodeCallSection( AccountSnapshot preCallCalledAccountSnapshot, Bytes rawCalledAddress, ImcFragment imcFragment) { + super(hub); this.rawCalledAddress = rawCalledAddress; this.precompileInvocation = targetPrecompile; this.preCallCallerAccountSnapshot = preCallCallerAccountSnapshot; @@ -118,8 +119,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); this.addFragmentsWithoutStack( - hub, - callerCallFrame, this.scenarioFragment, this.imcFragment, ContextFragment.readCurrentContextData(hub), @@ -136,8 +135,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces if (precompileInvocation.isPresent()) { if (this.callSuccessful && callerCallFrame.hasReverted()) { this.addFragmentsWithoutStack( - hub, - callerCallFrame, accountFragmentFactory.make( this.postCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot, @@ -148,19 +145,16 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); } this.addFragmentsWithoutStack( - hub, ScenarioFragment.forPrecompileEpilogue( hub, precompileInvocation.get(), callerCallFrame.id(), calledCallFrameId)); for (TraceFragment f : this.maybePrecompileLines.orElseThrow( () -> new IllegalStateException("missing precompile lines"))) { - this.addFragment(hub, callerCallFrame, f); + this.addFragment(f); } } else { if (callerCallFrame.hasReverted()) { this.addFragmentsWithoutStack( - hub, - callerCallFrame, accountFragmentFactory.make( this.postCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot, @@ -170,8 +164,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces this.preCallCalledAccountSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); } - this.addFragmentsWithoutStack( - hub, callerCallFrame, ContextFragment.nonExecutionEmptyReturnData(hub)); + this.addFragmentsWithoutStack(ContextFragment.nonExecutionEmptyReturnData(hub)); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index c2a74ad374..cb629fcfc1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -58,6 +58,7 @@ public SmartContractCallSection( AccountSnapshot preCallCalleeAccountSnapshot, Bytes rawCalledAddress, ImcFragment imcFragment) { + super(hub); this.rawCalledAddress = rawCalledAddress; this.callerCallFrame = hub.currentFrame(); this.calledCallFrameId = hub.callStack().futureId(); @@ -131,8 +132,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces DomSubStampsSubFragment.standardDomSubStamps(hub, 1); this.addFragmentsWithoutStack( - hub, - callerCallFrame, this.scenarioFragment, ContextFragment.readCurrentContextData(hub), this.imcFragment, @@ -151,8 +150,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces // TODO: get the right account snapshots if (callerCallFrame.willRevert() && calledCallFrame.selfReverts()) { this.addFragmentsWithoutStack( - hub, - callerCallFrame, accountFragmentFactory.make( this.inCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot, @@ -172,8 +169,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces // TODO: get the right account snapshots if (callerCallFrame.willRevert() && !calledCallFrame.selfReverts()) { this.addFragmentsWithoutStack( - hub, - callerCallFrame, accountFragmentFactory.make( this.inCallCallerAccountSnapshot, this.preCallCallerAccountSnapshot, @@ -190,8 +185,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces if (!callerCallFrame.willRevert() && calledCallFrame.selfReverts()) { if (calledCallFrame.selfReverts()) { this.addFragmentsWithoutStack( - hub, - callerCallFrame, accountFragmentFactory.make( this.inCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot, @@ -203,7 +196,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces } } - this.addFragmentsWithoutStack( - hub, callerCallFrame, ContextFragment.enterContext(hub, calledCallFrame)); + this.addFragmentsWithoutStack(ContextFragment.enterContext(hub, calledCallFrame)); } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java deleted file mode 100644 index 9ac0c78e56..0000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StupidCreateTBD.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub; - -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.EvmExtension; -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -public class StupidCreateTBD { - - @Test - void testStupidCreateTBD() { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push( - Bytes.fromHexString( - "0x63deadbeef000000000000000000000000000000000000000000000000000000")) - .push(Bytes.of(0x00)) - .op(OpCode.MSTORE) - .push(0x05) - .push(0x00) - .push(0x00) - .op(OpCode.CREATE) - .op(OpCode.DUP1) - .compile()) - .run(); - } - - @Test - void TestReturnDataCopyAlternative() { - BytecodeCompiler program = BytecodeCompiler.newProgram(); - - program - .push("63deadbeef000000000000000000000000000000000000000000000000000000") - .push(0) - .op(OpCode.MSTORE) - .push(0x04) - .push(0) - .push(0) - .op(OpCode.CREATE) - .op(OpCode.DUP1); - - BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); - bytecodeRunner.run(); - } -} From e38a3eea1fe8c818e0d11caa1ae91091a5b42ca0 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 25 Jun 2024 18:21:07 +0530 Subject: [PATCH 143/461] cleaning --- .../linea/zktracer/module/hub/TxTrace.java | 3 + .../hub/fragment/common/CommonFragment.java | 113 ------------------ .../fragment/common/CommonFragmentValues.java | 58 ++++++--- .../module/hub/section/TraceSection.java | 58 +-------- 4 files changed, 50 insertions(+), 182 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 5b999c6532..cd13b72e0c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -68,6 +68,9 @@ public boolean isEmpty() { */ public void add(TraceSection section) { section.parentTrace(this); + if (!this.trace.isEmpty()) { + this.trace.getLast().nextSection(section); + } this.trace.add(section); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java index c68d7d1cb7..cb1ab8e9a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java @@ -17,7 +17,6 @@ import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; -import java.math.BigInteger; import java.util.function.Supplier; import lombok.RequiredArgsConstructor; @@ -27,7 +26,6 @@ import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -59,117 +57,6 @@ public CommonFragment( this.nonStackRowsCounter = nonStackLineCounter; } - /* public static CommonFragment fromHub( - final Hub hub, - final CallFrame callFrame, - boolean counterTli, - int counterNsr, - int numberOfNonStackRows) { - - final boolean noStackException = hub.pch().exceptions().noStackException(); - final long refundDelta = - noStackException ? Hub.GfAS_PROJECTOR.of(callFrame.frame(), hub.opCode()).refund() : 0; - - // TODO: partial solution, will not work in general - final long gasExpected = hub.expectedGas(); - final long gasActual = hub.remainingGas(); - - // final boolean gasCostComputationIsRequired = - // (hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC) - // & noStackException - // & (hub.pch().exceptions().outOfGasException() || - // hub.pch().exceptions().none()); - // final long gasCost = - // gasCostComputationIsRequired - // ? CommonFragment.computeGasCost(hub, callFrame.frame().getWorldUpdater()) - // : 0; - // - // final long gasNext = - // hub.pch().exceptions().any() - // ? 0 - // : Math.max( - // gasActual - gasCost, 0); // TODO: ugly, to fix just to not trace negative - // value - - final int height = hub.currentFrame().stack().getHeight(); - final int heightNew = - (noStackException - ? height - - hub.opCode().getData().stackSettings().delta() - + hub.opCode().getData().stackSettings().alpha() - : 0); - final boolean hubInExecPhase = hub.state.getProcessingPhase() == HubProcessingPhase.TX_EXEC; - final int pc = hubInExecPhase ? callFrame.pc() : 0; - final int pcNew = computePcNew(hub, pc, noStackException, hubInExecPhase); - - return CommonFragment.builder() - .hub(hub) - .absoluteTransactionNumber(hub.txStack().current().getAbsoluteTransactionNumber()) - .relativeBlockNumber(hub.txStack().current().getRelativeBlockNumber()) - .hubProcessingPhase(hub.state.getProcessingPhase()) - .stamps(hub.state.stamps().snapshot()) - .instructionFamily(hub.opCodeData().instructionFamily()) - .exceptions(hub.pch().exceptions().snapshot()) - .abortingConditions(hub.pch().abortingConditions().snapshot()) - .failureConditions(hub.pch().failureConditions().snapshot()) - .callFrameId(callFrame.id()) - .contextNumber(hubInExecPhase ? callFrame.contextNumber() : 0) - .contextNumberNew(hub.contextNumberNew(callFrame)) - .pc(pc) - .pcNew(pcNew) - .height((short) height) - .heightNew((short) heightNew) - .codeDeploymentNumber(callFrame.codeDeploymentNumber()) - .codeDeploymentStatus(callFrame.isDeployment()) - .gasExpected(gasExpected) - .gasActual(gasActual) - // .gasCost(gasCost) - // .gasNext(gasNext) - .callerContextNumber(hub.callStack().getParentOf(callFrame.id()).contextNumber()) - .refundDelta(refundDelta) - .twoLineInstruction(hub.opCodeData().stackSettings().twoLinesInstruction()) - .twoLineInstructionCounter(counterTli) - .nonStackRowsCounter(counterNsr) - .numberOfNonStackRows(numberOfNonStackRows) - .build(); - } - */ - - static int computePcNew( - final Hub hub, final int pc, boolean noStackException, boolean hubInExecPhase) { - OpCode opCode = hub.opCode(); - if (!(noStackException && hubInExecPhase)) { - return 0; - } - - if (opCode.getData().isPush()) { - return pc + opCode.byteValue() - OpCode.PUSH1.byteValue() + 2; - } - - if (opCode.isJump()) { - final BigInteger prospectivePcNew = - hub.currentFrame().frame().getStackItem(0).toUnsignedBigInteger(); - final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); - - final int attemptedPcNew = - codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() : 0; - - if (opCode.equals(OpCode.JUMP)) { - return attemptedPcNew; - } - - if (opCode.equals(OpCode.JUMPI)) { - BigInteger condition = hub.currentFrame().frame().getStackItem(1).toUnsignedBigInteger(); - if (!condition.equals(BigInteger.ZERO)) { - return attemptedPcNew; - } - } - } - ; - - return pc + 1; - } - public boolean txReverts() { return commonFragmentValues.txMetadata.statusCode(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java index 49144a4083..f76e7bea2c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java @@ -16,7 +16,8 @@ package net.consensys.linea.zktracer.module.hub.fragment.common; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; -import static net.consensys.linea.zktracer.module.hub.fragment.common.CommonFragment.computePcNew; + +import java.math.BigInteger; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -26,6 +27,7 @@ import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.opcode.InstructionFamily; +import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -70,25 +72,12 @@ public CommonFragmentValues(Hub hub) { this.stamps = hub.state().stamps(); this.callFrame = hub.currentFrame(); this.exceptionAhoy = hub.pch().exceptions().any(); - this.contextNumberNew = - hub.contextNumberNew( - callFrame); // TODO this should be in seal method, looking at CN of following section + this.contextNumberNew = hub.contextNumberNew(callFrame); this.cnRevertStamp = 0; // TODO this.pc = hubProcessingPhase == TX_EXEC ? hub.currentFrame().pc() : 0; - this.pcNew = - computePcNew( - hub, - pc, - noStackException, - hub.state.getProcessingPhase() - == TX_EXEC); // TODO this should be in seal method, looking at PC of following + this.pcNew = computePcNew(hub, pc, noStackException, hub.state.getProcessingPhase() == TX_EXEC); this.height = (short) callFrame.stack().getHeight(); - this.heightNew = - (short) - callFrame - .stack() - .getHeightNew(); // TODO this should be in seal method, looking at height of - // following + this.heightNew = (short) callFrame.stack().getHeightNew(); this.refundDelta = noStackException ? Hub.GAS_PROJECTOR.of(callFrame.frame(), hub.opCode()).refund() : 0; @@ -104,4 +93,39 @@ public CommonFragmentValues(Hub hub) { || instructionFamily == InstructionFamily.INVALID) || exceptionAhoy); } + + static int computePcNew( + final Hub hub, final int pc, boolean noStackException, boolean hubInExecPhase) { + OpCode opCode = hub.opCode(); + if (!(noStackException && hubInExecPhase)) { + return 0; + } + + if (opCode.getData().isPush()) { + return pc + opCode.byteValue() - OpCode.PUSH1.byteValue() + 2; + } + + if (opCode.isJump()) { + final BigInteger prospectivePcNew = + hub.currentFrame().frame().getStackItem(0).toUnsignedBigInteger(); + final BigInteger codeSize = BigInteger.valueOf(hub.currentFrame().code().getSize()); + + final int attemptedPcNew = + codeSize.compareTo(prospectivePcNew) > 0 ? prospectivePcNew.intValueExact() : 0; + + if (opCode.equals(OpCode.JUMP)) { + return attemptedPcNew; + } + + if (opCode.equals(OpCode.JUMPI)) { + BigInteger condition = hub.currentFrame().frame().getStackItem(1).toUnsignedBigInteger(); + if (!condition.equals(BigInteger.ZERO)) { + return attemptedPcNew; + } + } + } + ; + + return pc + 1; + } } 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 6a35d0af6a..509bf6603c 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 @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; + import java.util.ArrayList; import java.util.List; @@ -24,7 +26,6 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.DeploymentExceptions; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.TxTrace; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; @@ -42,17 +43,8 @@ public abstract class TraceSection { private final Hub hub; public final CommonFragmentValues commonValues; @Getter List fragments = new ArrayList<>(); - @Getter private int stackHeight = 0; // To delete - @Getter private int stackHeightNew = 0; // To delete - - /** Count the stack lines */ - @Getter private int stackRowsCounter = 0; - - /** Count the non-stack lines */ - public int nonStackRowCounter = 0; - - public int numberOfNonStackRows = -1; @Getter @Setter private TxTrace parentTrace; + @Setter public TraceSection nextSection = null; /** Default creator for an empty section. */ public TraceSection(Hub hub) { @@ -60,41 +52,6 @@ public TraceSection(Hub hub) { this.commonValues = new CommonFragmentValues(hub); } - /// ** - // * A TraceLine stores the information required to generate a trace line. - // * - // * @param common data required to trace shared columns - // * @param specific data required to trace perspective-specific columns - // */ - // public record TraceLine(CommonFragment common, TraceFragment specific) { - // /** - // * Trace the line in the given trace builder. - // * - // * @param trace where to trace the line - // * @return the trace builder - // */ - // public Trace trace(Trace trace, int stackInt, int stackHeight) { - // Preconditions.checkNotNull(common); - // Preconditions.checkNotNull(specific); - // - // specific.trace(trace); // Warn: need to be called before common.trace to update stamps - // common.trace(trace, stackInt, stackHeight); - // - // return trace.fillAndValidateRow(); - // } - // } - - /// ** - // * Fill the columns shared by all type of lines. - // * - // * @return a {@link CommonFragment} representing the shared columns - // */ - // private CommonFragment traceCommon(Hub hub, CallFrame frame) { - // return CommonFragment.fromHub( - // hub, frame, this.stackRowsCounter == 2, this.nonStackRowCounter, - // this.numberOfNonStackRows); - // } - /** * Add a fragment to the section. * @@ -139,17 +96,14 @@ public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { this.addFragmentsWithoutStack(fragments); } - /** - * This method is called when the TraceSection is finished, to build required information - * post-hoc. - */ + /** This method is called at commit time, to build required information post-hoc. */ public void seal() { commonValues.numberOfNonStackRows( (int) this.fragments.stream().filter(l -> !(l instanceof StackFragment)).count()); commonValues.TLI( (int) this.fragments.stream().filter(l -> (l instanceof StackFragment)).count() == 2); commonValues.codeFragmentIndex( - this.commonValues.hubProcessingPhase == HubProcessingPhase.TX_EXEC + this.commonValues.hubProcessingPhase == TX_EXEC ? this.hub.getCfiByMetaData( this.commonValues.callFrame().byteCodeAddress(), this.commonValues.callFrame().codeDeploymentNumber(), @@ -179,7 +133,7 @@ public void setContextExceptions(DeploymentExceptions contEx) { } private List makeStackFragments(final Hub hub, CallFrame f) { - List r = new ArrayList<>(2); + final List r = new ArrayList<>(2); if (f.pending().lines().isEmpty()) { for (int i = 0; i < (f.opCodeData().stackSettings().twoLinesInstruction() ? 2 : 1); i++) { r.add( From dee4ee15cc8ad65634d1c04654fb813854042ac7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 26 Jun 2024 11:02:34 +0530 Subject: [PATCH 144/461] fix log stamp in HUB --- .../consensys/linea/zktracer/module/hub/Hub.java | 4 +--- .../linea/zktracer/module/hub/TxTrace.java | 10 ++++++++-- .../module/hub/fragment/StackFragment.java | 3 +++ .../hub/fragment/common/CommonFragmentValues.java | 2 +- .../module/hub/fragment/imc/call/mmu/MmuCall.java | 2 +- .../zktracer/module/hub/section/LogSection.java | 14 +++++--------- .../zktracer/module/hub/section/TraceSection.java | 8 ++++++++ .../linea/zktracer/module/rlptxrcpt/LogTest.java | 3 +++ 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 74063d5e79..3f2502df04 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -686,9 +686,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope final boolean unexceptional = exceptions.none(); final boolean exceptional = exceptions.any(); - // TODO: Might be dangerous : in some cases, we add fragments at the end of the transaction ... - // In LogSection it is manually added - + /* TODO: Might be dangerous : in some cases, we add fragments at the end of the transaction, we need an other mechanism ... */ // adds the final context row to reset the caller's return data if (exceptional) { this.currentTraceSection() diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index cd13b72e0c..29436e0c68 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -68,8 +68,14 @@ public boolean isEmpty() { */ public void add(TraceSection section) { section.parentTrace(this); - if (!this.trace.isEmpty()) { - this.trace.getLast().nextSection(section); + // Link the current section with the previous and next one + final TraceSection previousSection = this.trace.isEmpty() ? null : this.trace.getLast(); + if (previousSection != null) { + previousSection.nextSection(section); + section.previousSection(previousSection); + } else { + // If this section is the first section of the transaction, set the logStamp + section.commonValues.logStamp(section.commonValues.stamps.log()); } this.trace.add(section); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 7b85663513..5bf42c4cfa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -25,6 +25,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.DeploymentExceptions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; @@ -58,6 +59,7 @@ public final class StackFragment implements TraceFragment { @Setter private boolean jumpDestinationVettingRequired; @Setter private boolean validJumpDestination; private final boolean willRevert; + private final State.TxState.Stamps stamps; private StackFragment( final Hub hub, @@ -128,6 +130,7 @@ private StackFragment( } this.willRevert = willRevert; + this.stamps = hub.state().stamps(); } public static StackFragment prepare( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java index f76e7bea2c..1b824cfd76 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java @@ -40,7 +40,7 @@ public class CommonFragmentValues { public final int hubStamp; public final CallStack callStack; public final State.TxState.Stamps stamps; // for MMU and MXP stamps - @Setter public int logStamp; // TODO + @Setter public int logStamp = -1; @Getter final CallFrame callFrame; public final boolean exceptionAhoy; public final int contextNumberNew; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 2efe6e6d0e..b7bfcd216a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -228,7 +228,7 @@ private static int callDataContextNumber(final Hub hub) { public static MmuCall LogX(final Hub hub, final LogInvocation logInvocation) { return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(logInvocation.callFrame.contextNumber()) - .targetId(hub.state.stamps().incrementLogStamp()) + .targetId(hub.state.stamps().log()) .sourceOffset(logInvocation.offset) .size(logInvocation.size) .referenceSize(logInvocation.size) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index 5522db9932..0a49e8e185 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -30,7 +30,6 @@ public class LogSection implements PostTransactionDefer { final LogCommonSection sectionPrequel; - final ContextFragment finalContextRow; final boolean mxpX; final boolean oogX; @@ -42,15 +41,11 @@ public class LogSection implements PostTransactionDefer { public LogSection(Hub hub) { this.sectionPrequel = new LogCommonSection(hub, ContextFragment.readCurrentContextData(hub)); hub.addTraceSection(sectionPrequel); - this.finalContextRow = ContextFragment.executionProvidesEmptyReturnData(hub); this.mxpX = hub.pch().exceptions().memoryExpansionException(); this.oogX = hub.pch().exceptions().outOfGasException(); - if (hub.currentFrame().frame().isStatic()) { - // static exception - sectionPrequel.addFragmentsWithoutStack(finalContextRow); - } else { + if (!hub.currentFrame().frame().isStatic()) { logData = Optional.of(new LogInvocation(hub)); mxpSubFragment = Optional.of(MxpCall.build(hub)); miscFragment = Optional.of(ImcFragment.empty(hub)); // TODO: .callMxp(mxpSubFragment.get())); @@ -61,14 +56,15 @@ public LogSection(Hub hub) { @Override public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (logData.isPresent()) { + if (!this.logData.get().reverted()) { + hub.state.stamps().incrementLogStamp(); + this.sectionPrequel.commonValues.logStamp(hub.state.stamps().log()); + } final boolean mmuTrigger = !this.logData.get().reverted() && this.logData.get().size != 0; if (mmuTrigger) { miscFragment.get().callMmu(MmuCall.LogX(hub, this.logData.get())); } this.sectionPrequel.addFragment(miscFragment.get()); - if (mxpX || oogX) { - this.sectionPrequel.addFragment(finalContextRow); - } } } 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 509bf6603c..0b9c3ff1cc 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 @@ -44,6 +44,9 @@ public abstract class TraceSection { public final CommonFragmentValues commonValues; @Getter List fragments = new ArrayList<>(); @Getter @Setter private TxTrace parentTrace; + /* A link to the previous section */ + @Setter public TraceSection previousSection = null; + /* A link to the next section */ @Setter public TraceSection nextSection = null; /** Default creator for an empty section. */ @@ -109,6 +112,11 @@ public void seal() { this.commonValues.callFrame().codeDeploymentNumber(), this.commonValues.callFrame().isDeployment()) : 0); + + /* If the logStamp hasn't been set (either by being first section of the tx, or by the LogSection), set it to the previous section logStamp */ + if (commonValues.logStamp == -1) { + commonValues.logStamp(this.previousSection.commonValues.logStamp); + } } public final boolean hasReverted() { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java index f7f9982c73..cb4f83d54b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java @@ -39,6 +39,9 @@ void log2Test() { .push(33) // size .push(4) // offset .op(OpCode.LOG2) + // .push(1) + // .push(0) + // .op(OpCode.MSTORE) .compile()) .run(); } From 6943d337e4949b5101420f317b77cd9629bd375b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 26 Jun 2024 11:24:08 +0530 Subject: [PATCH 145/461] fix constraints issue --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index 16d984503a..c0ec1e191a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 16d984503aa70910abfa2b22af354c41562b16e4 +Subproject commit c0ec1e191ac700b4f05864c9f2a5842a3e9b5399 From 5413f169ecadf223237d8f398b2e20c148022109 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 27 Jun 2024 11:26:40 +0530 Subject: [PATCH 146/461] perf: specify max nb of rows for LOGX --- .../module/hub/section/LogSection.java | 50 +++++++++++-------- .../module/hub/section/TraceSection.java | 14 +++++- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index 0a49e8e185..9ee2d2497a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.hub.section; -import java.util.Optional; - import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; @@ -29,48 +27,58 @@ public class LogSection implements PostTransactionDefer { - final LogCommonSection sectionPrequel; + LogCommonSection sectionPrequel; + + final boolean isStatic; final boolean mxpX; final boolean oogX; - Optional miscFragment = Optional.empty(); - Optional mxpSubFragment = Optional.empty(); - Optional logData = Optional.empty(); + ImcFragment miscFragment; + MxpCall mxpSubFragment; + LogInvocation logData; public LogSection(Hub hub) { - this.sectionPrequel = new LogCommonSection(hub, ContextFragment.readCurrentContextData(hub)); - hub.addTraceSection(sectionPrequel); - this.mxpX = hub.pch().exceptions().memoryExpansionException(); this.oogX = hub.pch().exceptions().outOfGasException(); - if (!hub.currentFrame().frame().isStatic()) { - logData = Optional.of(new LogInvocation(hub)); - mxpSubFragment = Optional.of(MxpCall.build(hub)); - miscFragment = Optional.of(ImcFragment.empty(hub)); // TODO: .callMxp(mxpSubFragment.get())); - hub.defers().postTx(this); + // Static Case + if (hub.currentFrame().frame().isStatic()) { + isStatic = true; + hub.addTraceSection( + new LogCommonSection(hub, (short) 4, ContextFragment.readCurrentContextData(hub))); + return; } + + // General Case + isStatic = false; + this.sectionPrequel = + new LogCommonSection(hub, (short) 5, ContextFragment.readCurrentContextData(hub)); + hub.addTraceSection(sectionPrequel); + logData = new LogInvocation(hub); + mxpSubFragment = MxpCall.build(hub); + miscFragment = ImcFragment.empty(hub); // TODO: .callMxp(mxpSubFragment.get())); + hub.defers().postTx(this); } @Override public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (logData.isPresent()) { - if (!this.logData.get().reverted()) { + if (!isStatic) { + if (!this.logData.reverted()) { hub.state.stamps().incrementLogStamp(); this.sectionPrequel.commonValues.logStamp(hub.state.stamps().log()); } - final boolean mmuTrigger = !this.logData.get().reverted() && this.logData.get().size != 0; + final boolean mmuTrigger = !this.logData.reverted() && this.logData.size != 0; if (mmuTrigger) { - miscFragment.get().callMmu(MmuCall.LogX(hub, this.logData.get())); + miscFragment.callMmu(MmuCall.LogX(hub, this.logData)); } - this.sectionPrequel.addFragment(miscFragment.get()); + this.sectionPrequel.addFragment(miscFragment); } } public static class LogCommonSection extends TraceSection { - public LogCommonSection(Hub hub, ContextFragment fragment) { - super(hub); + public LogCommonSection(Hub hub, short maxNbOfRows, ContextFragment fragment) { + super(hub, maxNbOfRows); this.addFragmentsAndStack(hub, fragment); } } 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 0b9c3ff1cc..8047898220 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 @@ -42,17 +42,27 @@ public abstract class TraceSection { private final Hub hub; public final CommonFragmentValues commonValues; - @Getter List fragments = new ArrayList<>(); + @Getter List fragments; @Getter @Setter private TxTrace parentTrace; /* A link to the previous section */ @Setter public TraceSection previousSection = null; /* A link to the next section */ @Setter public TraceSection nextSection = null; - /** Default creator for an empty section. */ + /** Default creator for an empty section. Prefer the creator where we specify the max nb o rows */ public TraceSection(Hub hub) { this.hub = hub; this.commonValues = new CommonFragmentValues(hub); + this.fragments = + new ArrayList<>( + 22); // 22 is the maximum number of lines in a section (Successfull reverted Modexp) + } + + /** Default creator specifying the max number of rows the section can contain. */ + public TraceSection(final Hub hub, final short maxNbOfLines) { + this.hub = hub; + this.commonValues = new CommonFragmentValues(hub); + this.fragments = new ArrayList<>(maxNbOfLines); } /** From 7631402f0a66f52af2629616b7cfb3bca4fc3351 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 27 Jun 2024 11:44:15 +0530 Subject: [PATCH 147/461] perf: specify nb of Rows for non opcode sections --- .../module/hub/section/TxFinalizationPostTxDefer.java | 2 +- .../zktracer/module/hub/section/TxInitializationSection.java | 4 ++-- .../zktracer/module/hub/section/TxPreWarmingMacroSection.java | 4 ++-- .../zktracer/module/hub/section/TxSkippedSectionDefers.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java index dd976254e9..57c8f51ade 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java @@ -226,7 +226,7 @@ private boolean noAccountCollision() { public class TxFinalizationSection extends TraceSection { public TxFinalizationSection(Hub hub, TraceFragment... fragments) { - super(hub); + super(hub, (short) (txMetadata.statusCode() ? 3 : 4)); this.addFragmentsWithoutStack(fragments); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 143133494e..e6a9e19086 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -115,9 +115,9 @@ public TxInitializationSection(Hub hub, WorldView world) { hub.state.setProcessingPhase(TX_EXEC); } - public class InitializationSection extends TraceSection { + public static class InitializationSection extends TraceSection { public InitializationSection(Hub hub, TraceFragment... fragments) { - super(hub); + super(hub, (short) 5); this.addFragmentsWithoutStack(fragments); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 59577b1911..fb5a2c0501 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -139,9 +139,9 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { }); } - public class TxPrewarmingSection extends TraceSection { + public static class TxPrewarmingSection extends TraceSection { public TxPrewarmingSection(Hub hub, TraceFragment fragment) { - super(hub); + super(hub, (short) 1); this.addFragmentsWithoutStack(fragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java index a05ce6edc2..cc7986ffd4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java @@ -134,9 +134,9 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces TransactionFragment.prepare(hub.txStack().current()))); } - public class TxSkippedSection extends TraceSection { + public static class TxSkippedSection extends TraceSection { public TxSkippedSection(Hub hub, TraceFragment... fragments) { - super(hub); + super(hub, (short) 4); this.addFragmentsWithoutStack(fragments); } } From b99310d7d6aae8a2886141d37f0b4ebef9595a9e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 28 Jun 2024 15:49:00 +0530 Subject: [PATCH 148/461] perf(imc-fragment): preallocate 5 module calls --- .../linea/zktracer/module/hub/fragment/imc/ImcFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index dda1871618..e1b9ac6826 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -53,7 +53,7 @@ */ public class ImcFragment implements TraceFragment { /** the list of modules to trigger withing this fragment. */ - private final List moduleCalls = new ArrayList<>(); + private final List moduleCalls = new ArrayList<>(5); private final Hub hub; From 04c11896e982033f7ab988d496e352e705e0a9f1 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 28 Jun 2024 16:28:05 +0530 Subject: [PATCH 149/461] disabling almost all HUB constraints --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index c0ec1e191a..bd2f695785 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit c0ec1e191ac700b4f05864c9f2a5842a3e9b5399 +Subproject commit bd2f69578513189a904322b85d1863cd861a21da From 6b2d055da068adcfcd7224651983f164e8f733fc Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 28 Jun 2024 17:18:14 +0530 Subject: [PATCH 150/461] perf: 1 or 2 row for StackOnly section --- .../linea/zktracer/module/hub/section/StackOnlySection.java | 2 +- zkevm-constraints | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 869fc544f4..48eee57d3c 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); + super(hub, (short) (hub.opCode().getData().stackSettings().twoLinesInstruction() ? 2 : 1)); this.addStack(hub); } } diff --git a/zkevm-constraints b/zkevm-constraints index bd2f695785..255677b629 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit bd2f69578513189a904322b85d1863cd861a21da +Subproject commit 255677b629dceaacffb053c79a4ee947c3a106d7 From a844b792b3fa81e826a470cc2cb6f64ae9161081 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 28 Jun 2024 16:36:15 +0200 Subject: [PATCH 151/461] fix(oob): temporary hack to manages calls to wcp from oob manage arguments greater than 16 bytes --- .../zktracer/module/oob/OobOperation.java | 115 ++++++++++-------- 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 0c958af963..038f203d9a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -71,12 +71,10 @@ import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBoolean; import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; -import static net.consensys.linea.zktracer.types.Conversions.lowPart; import java.math.BigInteger; import java.math.RoundingMode; -import com.google.common.base.Preconditions; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -613,12 +611,15 @@ private void populateColumns(final MessageFrame frame) { // Constraint systems for populating lookups private void callToADD( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = EWord.of(arg1Hi, arg1Lo); - final EWord arg2 = EWord.of(arg2Hi, arg2Lo); + // TODO: reactivate preconditions and remove conditional initialization + // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); + final EWord arg1 = + arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); + final EWord arg2 = + arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); addFlag[k] = true; modFlag[k] = false; wcpFlag[k] = false; @@ -636,12 +637,15 @@ private void callToADD( private BigInteger callToDIV( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = EWord.of(arg1Hi, arg1Lo); - final EWord arg2 = EWord.of(arg2Hi, arg2Lo); + // TODO: reactivate preconditions and remove conditional initialization + // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); + final EWord arg1 = + arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); + final EWord arg2 = + arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); addFlag[k] = false; modFlag[k] = true; wcpFlag[k] = false; @@ -656,12 +660,15 @@ private BigInteger callToDIV( private BigInteger callToMOD( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = EWord.of(arg1Hi, arg1Lo); - final EWord arg2 = EWord.of(arg2Hi, arg2Lo); + // TODO: reactivate preconditions and remove conditional initialization + // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); + final EWord arg1 = + arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); + final EWord arg2 = + arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); addFlag[k] = false; modFlag[k] = true; wcpFlag[k] = false; @@ -676,12 +683,15 @@ private BigInteger callToMOD( private boolean callToLT( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = EWord.of(arg1Hi, arg1Lo); - final EWord arg2 = EWord.of(arg2Hi, arg2Lo); + // TODO: reactivate preconditions and remove conditional initialization + // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); + final EWord arg1 = + arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); + final EWord arg2 = + arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; @@ -697,12 +707,15 @@ private boolean callToLT( private boolean callToGT( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = EWord.of(arg1Hi, arg1Lo); - final EWord arg2 = EWord.of(arg2Hi, arg2Lo); + // TODO: reactivate preconditions and remove conditional initialization + // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); + final EWord arg1 = + arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); + final EWord arg2 = + arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; @@ -717,9 +730,11 @@ private boolean callToGT( } private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInteger arg1Lo) { - Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - final EWord arg1 = EWord.of(arg1Hi, arg1Lo); + // TODO: reactivate preconditions and remove conditional initialization + // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + final EWord arg1 = + arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; @@ -735,12 +750,15 @@ private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInte private boolean callToEQ( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = EWord.of(arg1Hi, arg1Lo); - final EWord arg2 = EWord.of(arg2Hi, arg2Lo); + // TODO: reactivate preconditions and remove conditional initialization + // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); + // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); + final EWord arg1 = + arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); + final EWord arg2 = + arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; @@ -949,20 +967,11 @@ private void setCreate(CreateOobCall createOobCall) { private void setPrcCommon(PrecompileCommonOobCall prcOobCall) { // row i - final boolean cdsIsZero = - callToISZERO( - 0, - BigInteger.ZERO, - lowPart(prcOobCall.getCds())); // TODO: kill it, cds should already be smaller than + final boolean cdsIsZero = callToISZERO(0, BigInteger.ZERO, prcOobCall.getCds()); // row i + 1 final boolean returnAtCapacityIsZero = - callToISZERO( - 1, - BigInteger.ZERO, - lowPart( - prcOobCall - .getReturnAtCapacity())); // TODO: kill it, r@c should already be smaller than + callToISZERO(1, BigInteger.ZERO, prcOobCall.getReturnAtCapacity()); // Set cdsIsZero prcOobCall.setCdsIsZero(cdsIsZero); @@ -1032,7 +1041,7 @@ private void setEcpairing(PrecompileCommonOobCall prcCommonOobCall) { callToMOD( 2, BigInteger.ZERO, - lowPart(prcCommonOobCall.getCds()), // TODO: kill it, cds should already be smaller than + prcCommonOobCall.getCds(), // 16 bytes BigInteger.ZERO, BigInteger.valueOf(192)); From 7b0db22deb4b941c0b95350f6f9932d0b0d2d55d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 20 Jun 2024 13:00:06 +0200 Subject: [PATCH 152/461] fix(JUMP): JUMPs always produce a section --- .../linea/zktracer/module/hub/section/JumpSection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index 62c43c476d..5cc1866459 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -39,12 +39,12 @@ public static void appendToTrace(Hub hub, WorldView worldView) { final JumpSection currentSection = new JumpSection(hub); currentSection.addFragmentsAndStack(hub); // TODO strange to not give any fragments + hub.addTraceSection(currentSection); + if (hub.pch().exceptions().outOfGasException()) { return; } - hub.addTraceSection(currentSection); - // CONTEXT fragment /////////////////// ContextFragment contextRowCurrentContext = ContextFragment.readCurrentContextData(hub); From 4719b52287070a834fef091eecb38dcb15586347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 26 Jun 2024 15:01:59 +0200 Subject: [PATCH 153/461] StpCall update (wip) --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/fragment/imc/ImcFragment.java | 43 ++-- .../module/hub/fragment/imc/call/StpCall.java | 138 ++++++++-- .../linea/zktracer/module/stp/Stp.java | 82 +++--- .../stp/{StpChunk.java => StpOperation.java} | 236 ++++++++---------- .../linea/zktracer/opcode/OpCode.java | 7 +- .../linea/zktracer/types/AddressUtils.java | 6 +- 7 files changed, 308 insertions(+), 206 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/{StpChunk.java => StpOperation.java} (53%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 3f2502df04..15054dcda0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -572,7 +572,7 @@ public void traceContextEnter(MessageFrame frame) { this.transients.conflation().deploymentInfo().number(codeAddress); final int callDataOffsetStackArgument = - callStack.current().opCode().callHasSixArgument() ? 2 : 3; + callStack.current().opCode().callMayNotTransferValue() ? 2 : 3; final long callDataOffset = isDeployment diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index e1b9ac6826..0ce7d7c613 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc; -import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; - import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -140,23 +138,28 @@ public static ImcFragment forCall( final long stipend = value.isZero() ? 0 : GasConstants.G_CALL_STIPEND.cost(); final long upfrontCost = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()).total(); - r.callStp( - new StpCall( - hub.opCode().byteValue(), - EWord.of(gas), - value, - calledAccount.isPresent(), - calledAccount - .map(a -> hub.messageFrame().isAddressWarm(a.getAddress())) - .orElse(false), - hub.pch().exceptions().outOfGasException(), - upfrontCost, - Math.max( - Words.unsignedMin( - allButOneSixtyFourth(hub.messageFrame().getRemainingGas() - upfrontCost), - gas), - 0), - stipend)); + // TODO: @Olivier get memory expansion gas + long memoryExpansionGas = 0xdeadbeefL; + StpCall stpCall = new StpCall(hub.messageFrame(), memoryExpansionGas); + + r.callStp(stpCall); + + // EWord.of(gas), + // value, + // calledAccount.isPresent(), + // calledAccount + // .map(a -> hub.messageFrame().isAddressWarm(a.getAddress())) + // .orElse(false), + // hub.pch().exceptions().outOfGasException(), + // upfrontCost, + // Math.max( + // Words.unsignedMin( + // allButOneSixtyFourth(hub.messageFrame().getRemainingGas() - + // upfrontCost), + // gas), + // 0), + // stipend) + // ); } return r; @@ -304,7 +307,7 @@ public ImcFragment callStp(StpCall f) { } else { stpIsSet = true; } - // TODO: this.hub.stp().call(f, this.hub); + this.hub.stp().call(f, hub.messageFrame()); this.moduleCalls.add(f); return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java index 25709625a3..ad8eefb952 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java @@ -15,27 +15,137 @@ package net.consensys.linea.zktracer.module.hub.fragment.imc.call; +import java.math.BigInteger; + +import com.google.common.base.Preconditions; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; + +@Getter +@Setter +@Accessors(fluent = true) +public class StpCall implements TraceSubFragment { + final Hub hub; + final long memoryExpansionGas; + OpCode opCode; + long gasActual; + EWord gas; // for CALL's only + EWord value; + boolean exists; + boolean warm; + long upfrontGasCost; + boolean outOfGasException; + long gasPaidOutOfPocket; + long stipend; + + public StpCall(Hub hub, long memoryExpansionGas) { + this.hub = hub; + this.memoryExpansionGas = memoryExpansionGas; + this.opCode = hub.opCode(); + this.gasActual = hub.messageFrame().getRemainingGas(); + Preconditions.checkArgument(this.opCode.isCall() || this.opCode.isCreate()); + } + + public StpCall stpCallForCalls(Hub hub, long memoryExpansionGas) { + // set up hub, memoryExpansionGas, opCode and gasActual; + StpCall stpCall = new StpCall(hub, memoryExpansionGas); + MessageFrame frame = hub.messageFrame(); + + final boolean instructionCanTransferValue = stpCall.opCode.callCanTransferValue(); + final boolean isCALL = stpCall.opCode.equals(OpCode.CALL); + final Address to = Words.toAddress(frame.getStackItem(1)); + Account toAccount = frame.getWorldUpdater().getAccount(to); + stpCall.gas = EWord.of(frame.getStackItem(0)); + stpCall.value = (instructionCanTransferValue) ? EWord.of(frame.getStackItem(2)) : EWord.ZERO; + stpCall.exists = toAccount != null ? !toAccount.isEmpty() : false; + stpCall.warm = frame.isAddressWarm(to); + stpCall.upfrontGasCost = memoryExpansionGas; + + final boolean nonzeroValueTransfer = !value.isZero(); + final boolean callWouldLeadToAccountCreation = + isCALL && nonzeroValueTransfer && !stpCall.exists; + if (nonzeroValueTransfer) { + stpCall.upfrontGasCost += GasConstants.G_CALL_VALUE.cost(); + } + if (stpCall.warm) { + stpCall.upfrontGasCost += GasConstants.G_WARM_ACCESS.cost(); + } else { + stpCall.upfrontGasCost += GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); + } + // TODO: in the previous implementation (in Stp.java) + // ``toExists`` was only computed for CALLCODE (which is wrong) + // now it's for both CALL and CALLCODE. + // Check in tests if this is right. + if (callWouldLeadToAccountCreation) { + stpCall.upfrontGasCost += GasConstants.G_NEW_ACCOUNT.cost(); + } + + stpCall.outOfGasException = stpCall.gasActual < stpCall.upfrontGasCost; + stpCall.gasPaidOutOfPocket = stpCall.computeGasPaidOutOfPocketForCalls(); + stpCall.stipend = !outOfGasException && nonzeroValueTransfer ? GasConstants.G_CALL_STIPEND.cost() : 0; + + return stpCall; + } + + private long computeGasPaidOutOfPocketForCalls() { + if (outOfGasException) { + return gasPaidOutOfPocket = 0; + } else { + long gasMinusUpfront = gasActual - upfrontGasCost; + long oneSixtyFourths = gasMinusUpfront >> 6; + long maxGasAllowance = gasMinusUpfront - oneSixtyFourths; + return + gas().toUnsignedBigInteger().compareTo(BigInteger.valueOf(maxGasAllowance)) > 0 + ? maxGasAllowance + : gas.toLong(); + } + } + + public StpCall stpCallForCreates(Hub hub, long memoryExpansionGas) { + // set up hub, memoryExpansionGas, opCode and gasActual; + StpCall stpCall = new StpCall(hub, memoryExpansionGas); + MessageFrame frame = hub.messageFrame(); + + // TODO: in old Stp.java was given the balance + // rather than the value of the instruction; + // how did it not blow up in tests ? + stpCall.gas = EWord.ZERO; // irrelevant + stpCall.value = EWord.of(frame.getStackItem(0)); + stpCall.exists = false; // irrelevant + stpCall.warm = false; // irrelevant + stpCall.upfrontGasCost = GasConstants.G_CREATE.cost() + stpCall.memoryExpansionGas; + stpCall.outOfGasException = stpCall.gasActual < stpCall.upfrontGasCost; + stpCall.gasPaidOutOfPocket = stpCall.computeGasPaidOutOfPocketForCreates(); + stpCall.stipend = 0; // irrelevant + return stpCall; + } + + private long computeGasPaidOutOfPocketForCreates() { + if (outOfGasException) { + return 0; + } else { + long gasMinusUpfrontCost = gasActual - upfrontGasCost; + return gasMinusUpfrontCost - (gasMinusUpfrontCost >> 6); + } + } -public record StpCall( - byte opCode, - EWord gas, - EWord value, - boolean exists, - boolean warm, - boolean outOfGasException, - long upfront, - long outOfPocket, - long stipend) - implements TraceSubFragment { @Override public Trace trace(Trace trace) { return trace .pMiscStpFlag(true) - .pMiscStpInstruction(opCode) + .pMiscStpInstruction(opCode.byteValue()) .pMiscStpGasHi(gas.hi()) .pMiscStpGasLo(gas.lo()) .pMiscStpValueHi(value.hi()) @@ -43,8 +153,8 @@ public Trace trace(Trace trace) { .pMiscStpExists(exists) .pMiscStpWarmth(warm) .pMiscStpOogx(outOfGasException) - .pMiscStpGasUpfrontGasCost(Bytes.ofUnsignedLong(upfront)) - .pMiscStpGasPaidOutOfPocket(Bytes.ofUnsignedLong(outOfPocket)) + .pMiscStpGasUpfrontGasCost(Bytes.ofUnsignedLong(upfrontGasCost)) + .pMiscStpGasPaidOutOfPocket(Bytes.ofUnsignedLong(gasPaidOutOfPocket)) .pMiscStpGasStipend(stipend); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java index 26fcde80a4..211699e40a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java @@ -27,10 +27,12 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -42,26 +44,30 @@ public class Stp implements Module { private final Wcp wcp; private final Mod mod; + public void call(StpCall stpCall, MessageFrame messageFrame) { + this.operations.add(new StpOperation(stpCall, messageFrame)); + } + @Override public String moduleKey() { return "STP"; } - private final StackedSet chunks = new StackedSet<>(); + private final StackedSet operations = new StackedSet<>(); @Override public void enterTransaction() { - this.chunks.enter(); + this.operations.enter(); } @Override public void popTransaction() { - this.chunks.pop(); + this.operations.pop(); } @Override public int lineCount() { - return this.chunks.lineCount(); + return this.operations.lineCount(); } @Override @@ -75,47 +81,57 @@ public void tracePreOpcode(final MessageFrame frame) { switch (opCode) { case CREATE, CREATE2 -> { - final StpChunk chunk = getCreateData(frame); - this.chunks.add(chunk); - this.wcp.callLT(longToBytes32(chunk.gasActual()), Bytes32.ZERO); - this.wcp.callLT(longToBytes32(chunk.gasActual()), longToBytes32(chunk.gasPrelim())); - if (!chunk.oogx()) { - this.mod.callDIV(longToBytes32(chunk.getGDiff()), longToBytes32(64L)); + final StpOperation stpOperation = stpOperationForCreate(frame); + StpCall stpCall = stpOperation.stpCall(); + this.operations.add(stpOperation); + this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); + this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); + if (!stpCall.outOfGasException()) { + this.mod.callDIV(longToBytes32(stpOperation.getGDiff()), longToBytes32(64L)); } } case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { - final StpChunk chunk = getCallData(frame); - this.chunks.add(chunk); - this.wcp.callLT(longToBytes32(chunk.gasActual()), Bytes32.ZERO); - if (callCanTransferValue(chunk.opCode())) { - this.wcp.callISZERO(Bytes32.leftPad(chunk.value())); + final StpOperation stpOperation = stpOperationForCall(frame); + StpCall stpCall = stpOperation.stpCall(); + this.operations.add(stpOperation); + this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); + if (callCanTransferValue(stpCall.opCode())) { + this.wcp.callISZERO(Bytes32.leftPad(stpCall.value())); } - this.wcp.callLT(longToBytes32(chunk.gasActual()), longToBytes32(chunk.gasPrelim())); - if (!chunk.oogx()) { - this.mod.callDIV(longToBytes32(chunk.getGDiff()), longToBytes32(64L)); - this.wcp.callLT(chunk.gas().orElseThrow(), longToBytes32(chunk.get63of64GDiff())); + this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); + if (!stpCall.outOfGasException()) { + this.mod.callDIV(longToBytes32(stpOperation.getGDiff()), longToBytes32(64L)); + this.wcp.callLT(stpCall.gas(), longToBytes32(stpOperation.get63of64GDiff())); } } } } - private StpChunk getCreateData(final MessageFrame frame) { - final Address to = getDeploymentAddress(frame); - final long gasRemaining = frame.getRemainingGas(); - final long gasMxp = getGasMxpCreate(frame); - final long gasPrelim = GasConstants.G_CREATE.cost() + gasMxp; - return new StpChunk( + private StpOperation stpOperationForCreate(StpCall stpCall) { + Hub hub = stpCall.hub(); + MessageFrame frame = hub.messageFrame(); + stpCall.gasActual(frame.getRemainingGas()); + stpCall.gas(EWord.ZERO); + stpCall.value(EWord.of(frame.getWorldUpdater().get(frame.getContractAddress()).getBalance())); + stpCall.exists(false); // irrelevant + stpCall.warm(false); // irrelevant + stpCall.upfrontGasCost(GasConstants.G_CREATE.cost() + stpCall.memoryExpansionGas()); + stpCall.outOfGasException(stpCall.gasActual() < stpCall.upfrontGasCost()); + final Address deploymentAddress = getDeploymentAddress(frame); + final long gasActual = frame.getRemainingGas(); + return new StpOperation( this.hub.opCode(), - gasRemaining, - gasPrelim, - gasRemaining < gasPrelim, - gasMxp, + gasActual, + upfrontGasCost, + gasActual < upfrontGasCost, + stpCall.memoryExpansionGas(), frame.getWorldUpdater().get(frame.getContractAddress()).getBalance(), - to, + deploymentAddress, Bytes32.leftPad(frame.getStackItem(0))); } - private StpChunk getCallData(final MessageFrame frame) { + private StpOperation stpOperationForCall(StpCall stpCall) { + MessageFrame frame = stpCall.hub().messageFrame(); final OpCode opcode = this.hub.opCode(); final long gasActual = frame.getRemainingGas(); final Bytes32 value = @@ -141,7 +157,7 @@ private StpChunk getCallData(final MessageFrame frame) { gasPrelim += GasConstants.G_NEW_ACCOUNT.cost(); } final boolean oogx = gasActual < gasPrelim; - return new StpChunk( + return new StpOperation( opcode, gasActual, gasPrelim, @@ -213,7 +229,7 @@ public void commit(List buffers) { final Trace trace = new Trace(buffers); int stamp = 0; - for (StpChunk chunk : chunks) { + for (StpOperation chunk : operations) { stamp++; chunk.trace(trace, stamp); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpChunk.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java similarity index 53% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpChunk.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java index 450aac6a06..6d714a04b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpChunk.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java @@ -26,84 +26,68 @@ import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.frame.MessageFrame; -@RequiredArgsConstructor @Accessors(fluent = true) @Getter -public final class StpChunk extends ModuleOperation { - private final OpCode opCode; - private final Long gasActual; - private final Long gasPrelim; - private final Boolean oogx; - private final Long gasMxp; - private final Wei balance; - private final Address to; - private final Bytes32 value; - private final Optional toExists; - private final Optional toWarm; - private final Optional gas; +public final class StpOperation extends ModuleOperation { + private final StpCall stpCall; - // Used by Create's instruction - public StpChunk( - OpCode opcode, - Long gasActual, - Long gasPrelim, - Boolean oogx, - Long gasMxp, - Wei balance, - Address to, - Bytes32 value) { - this( - opcode, - gasActual, - gasPrelim, - oogx, - gasMxp, - balance, - to, - value, - Optional.empty(), - Optional.empty(), - Optional.empty()); + public StpOperation(StpCall stpCall) { + this.stpCall = stpCall; } - // Used by Call's instruction - public StpChunk( - OpCode opcode, - Long gasActual, - Long gasPrelim, - Boolean oogx, - Long gasMxp, - Wei balance, - Address to, - Bytes32 value, - Boolean toExists, - Boolean toWarm, - Bytes32 gas) { - this( - opcode, - gasActual, - gasPrelim, - oogx, - gasMxp, - balance, - to, - value, - Optional.of(toExists), - Optional.of(toWarm), - Optional.of(gas)); + private boolean isCallType() { + return stpCall + .opCode() + .isAnyOf(OpCode.CALL, OpCode.CALLCODE, OpCode.DELEGATECALL, OpCode.STATICCALL); + } + + private boolean callCanTransferValue() { + return stpCall.opCode().isAnyOf(OpCode.CALL, OpCode.CALLCODE); + } + + private boolean isCall() { + return stpCall.opCode() == OpCode.CALL; + } + + private boolean isCallCode() { + return stpCall.opCode() == OpCode.CALLCODE; + } + + private boolean isDelegateCall() { + return stpCall.opCode() == OpCode.DELEGATECALL; + } + + private boolean isStaticCall() { + return stpCall.opCode() == OpCode.STATICCALL; + } + + private boolean isCreateType() { + return stpCall.opCode().isAnyOf(OpCode.CREATE, OpCode.CREATE2); + } + + private boolean isCreate() { + return stpCall.opCode() == OpCode.CREATE; + } + + private boolean isCreate2() { + return stpCall.opCode() == OpCode.CREATE2; } long getGDiff() { - Preconditions.checkArgument(!this.oogx()); - return this.gasActual() - this.gasPrelim(); + Preconditions.checkArgument(!stpCall.outOfGasException()); + return stpCall.gasActual() - stpCall.upfrontGasCost(); } long getGDiffOver64() { @@ -115,7 +99,7 @@ long get63of64GDiff() { } void trace(Trace trace, int stamp) { - if (this.opCode().isCreate()) { + if (stpCall.opCode().isCreate()) { this.traceCreate(trace, stamp); } else { this.traceCall(trace, stamp); @@ -124,37 +108,37 @@ void trace(Trace trace, int stamp) { private void traceCreate(Trace trace, int stamp) { final int ctMax = this.maxCt(); - final long gasOopkt = this.oogx() ? 0 : this.get63of64GDiff(); + final long gasOopkt = stpCall.outOfGasException() ? 0 : this.get63of64GDiff(); for (int ct = 0; ct <= ctMax; ct++) { trace .stamp(stamp) .ct(UnsignedByte.of(ct)) .ctMax(UnsignedByte.of(ctMax)) - .instruction(UnsignedByte.of(this.opCode().byteValue())) - .isCreate(this.opCode() == OpCode.CREATE) - .isCreate2(this.opCode() == OpCode.CREATE2) - .isCall(false) - .isCallcode(false) - .isDelegatecall(false) - .isStaticcall(false) - .gasHi(Bytes.EMPTY) - .gasLo(Bytes.EMPTY) - .valHi(this.value().slice(0, 16)) - .valLo(this.value().slice(16, 16)) - .exists(false) // TODO document this - .warm(false) // TODO document this - .outOfGasException(this.oogx()) - .gasActual(Bytes.ofUnsignedLong(this.gasActual())) - .gasMxp(Bytes.ofUnsignedLong(this.gasMxp())) - .gasUpfront(Bytes.ofUnsignedLong(this.gasPrelim())) + .instruction(UnsignedByte.of(stpCall.opCode().byteValue())) + .isCreate(isCreate()) + .isCreate2(isCreate2()) + .isCall(isCall()) + .isCallcode(isCallCode()) + .isDelegatecall(isDelegateCall()) + .isStaticcall(isStaticCall()) + // .gasHi(Bytes.EMPTY) + // .gasLo(Bytes.EMPTY) + .valHi(stpCall.value().slice(0, 16)) + .valLo(stpCall.value().slice(16, 16)) + // .exists(false) + // .warm(false) + .outOfGasException(stpCall.outOfGasException()) + .gasActual(Bytes.ofUnsignedLong(stpCall.gasActual())) + .gasMxp(Bytes.ofUnsignedLong(stpCall.memoryExpansionGas())) + .gasUpfront(Bytes.ofUnsignedLong(stpCall.upfrontGasCost())) .gasOutOfPocket(Bytes.ofUnsignedLong(gasOopkt)) - .gasStipend(Bytes.EMPTY) + .gasStipend(Bytes.ofUnsignedLong(stpCall.stipend())) .arg1Hi(Bytes.EMPTY); switch (ct) { case 0 -> trace - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) + .arg1Lo(Bytes.ofUnsignedLong(stpCall.gasActual())) .arg2Lo(Bytes.EMPTY) .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) .resLo(Bytes.EMPTY) // we REQUIRE that the currently available gas is nonnegative @@ -162,10 +146,10 @@ private void traceCreate(Trace trace, int stamp) { .modFlag(false) .validateRow(); case 1 -> trace - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) - .arg2Lo(Bytes.ofUnsignedLong(this.gasPrelim())) + .arg1Lo(Bytes.ofUnsignedLong(stpCall.gasActual())) + .arg2Lo(Bytes.ofUnsignedLong(stpCall.upfrontGasCost())) .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) - .resLo(Bytes.of(this.oogx() ? 1 : 0)) + .resLo(Bytes.of(stpCall.outOfGasException() ? 1 : 0)) .wcpFlag(true) .modFlag(false) .validateRow(); @@ -184,48 +168,35 @@ private void traceCreate(Trace trace, int stamp) { private void traceCall(Trace trace, int stamp) { final int ctMax = this.maxCt(); - final long gasStipend = - (!this.oogx() && callCanTransferValue(this.opCode()) && !this.value().isZero()) - ? GasConstants.G_CALL_STIPEND.cost() - : 0; - final Bytes gasOopkt = - this.oogx() - ? Bytes.EMPTY - : bigIntegerToBytes( - this.gas() - .orElseThrow() - .toUnsignedBigInteger() - .min(BigInteger.valueOf(get63of64GDiff()))); - for (int ct = 0; ct <= ctMax; ct++) { trace .stamp(stamp) .ct(UnsignedByte.of(ct)) .ctMax(UnsignedByte.of(ctMax)) - .instruction(UnsignedByte.of(this.opCode().byteValue())) - .isCreate(false) - .isCreate2(false) - .isCall(this.opCode() == OpCode.CALL) - .isCallcode(this.opCode() == OpCode.CALLCODE) - .isDelegatecall(this.opCode() == OpCode.DELEGATECALL) - .isStaticcall(this.opCode() == OpCode.STATICCALL) - .gasHi(this.gas().orElseThrow().slice(0, 16)) - .gasLo(this.gas().orElseThrow().slice(16)) - .valHi(this.value().slice(0, 16)) - .valLo(this.value().slice(16)) - .exists(this.toExists().orElseThrow()) - .warm(this.toWarm().orElseThrow()) - .outOfGasException(this.oogx()) - .gasActual(Bytes.ofUnsignedLong(this.gasActual())) - .gasMxp(Bytes.ofUnsignedLong(this.gasMxp())) - .gasUpfront(Bytes.ofUnsignedLong(this.gasPrelim())) - .gasOutOfPocket(gasOopkt) - .gasStipend(Bytes.ofUnsignedLong(gasStipend)); + .instruction(UnsignedByte.of(stpCall.opCode().byteValue())) + .isCreate(isCreate()) + .isCreate2(isCreate2()) + .isCall(isCall()) + .isCallcode(isCallCode()) + .isDelegatecall(isDelegateCall()) + .isStaticcall(isStaticCall()) + .gasHi(stpCall.gas().slice(0, 16)) + .gasLo(stpCall.gas().slice(16)) + .valHi(stpCall.value().slice(0, 16)) + .valLo(stpCall.value().slice(16)) + .exists(stpCall.exists()) + .warm(stpCall.warm()) + .outOfGasException(stpCall.outOfGasException()) + .gasActual(Bytes.ofUnsignedLong(stpCall.gasActual())) + .gasMxp(Bytes.ofUnsignedLong(stpCall.memoryExpansionGas())) + .gasUpfront(Bytes.ofUnsignedLong(stpCall.upfrontGasCost())) + .gasOutOfPocket(Bytes.ofUnsignedLong(stpCall.gasPaidOutOfPocket())) + .gasStipend(Bytes.ofUnsignedLong(stpCall.stipend())); switch (ct) { case 0 -> trace .arg1Hi(Bytes.EMPTY) - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) + .arg1Lo(Bytes.ofUnsignedLong(stpCall.gasActual())) .arg2Lo(Bytes.EMPTY) .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) .resLo(Bytes.EMPTY) // we REQUIRE that the currently available gas is nonnegative @@ -233,20 +204,20 @@ private void traceCall(Trace trace, int stamp) { .modFlag(false) .validateRow(); case 1 -> trace - .arg1Hi(this.value().slice(0, 16)) - .arg1Lo(this.value().slice(16, 16)) + .arg1Hi(stpCall.value().slice(0, 16)) + .arg1Lo(stpCall.value().slice(16, 16)) .arg2Lo(Bytes.EMPTY) .exogenousModuleInstruction(UnsignedByte.of(OpCode.ISZERO.byteValue())) - .resLo(Bytes.of(this.value().isZero() ? 1 : 0)) - .wcpFlag(callCanTransferValue(this.opCode())) + .resLo(Bytes.of(stpCall.value().isZero() ? 1 : 0)) + .wcpFlag(stpCall.opCode().callCanTransferValue()) .modFlag(false) .validateRow(); case 2 -> trace .arg1Hi(Bytes.EMPTY) - .arg1Lo(Bytes.ofUnsignedLong(this.gasActual())) - .arg2Lo(Bytes.ofUnsignedLong(this.gasPrelim())) + .arg1Lo(Bytes.ofUnsignedLong(stpCall.gasActual())) + .arg2Lo(Bytes.ofUnsignedLong(stpCall.upfrontGasCost())) .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) - .resLo(Bytes.of(this.oogx() ? 1 : 0)) + .resLo(Bytes.of(stpCall.outOfGasException() ? 1 : 0)) .wcpFlag(true) .modFlag(false) .validateRow(); @@ -261,14 +232,13 @@ private void traceCall(Trace trace, int stamp) { .modFlag(true) .validateRow(); case 4 -> trace - .arg1Hi(this.gas().orElseThrow().slice(0, 16)) - .arg1Lo(this.gas().orElseThrow().slice(16, 16)) + .arg1Hi(stpCall.gas().slice(0, 16)) + .arg1Lo(stpCall.gas().slice(16, 16)) .arg2Lo(Bytes.ofUnsignedLong(getGDiff() - getGDiffOver64())) .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) .resLo( Bytes.of( - this.gas() - .orElseThrow() + stpCall.gas() .toUnsignedBigInteger() .compareTo(BigInteger.valueOf(get63of64GDiff())) < 0 @@ -283,10 +253,10 @@ private void traceCall(Trace trace, int stamp) { } private int maxCt() { - if (this.oogx) { - return this.opCode.isCreate() ? 1 : 2; + if (stpCall.outOfGasException()) { + return stpCall.opCode().isCreate() ? 1 : 2; } else { - return this.opCode.isCreate() ? 2 : 4; + return stpCall.opCode().isCreate() ? 2 : 4; } } 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 08efa6fefc..cdb125e306 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 @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.opcode; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.types.UnsignedByte; /** Represents the entire set of opcodes that are required by the arithmetization process. */ @@ -236,11 +237,13 @@ public boolean isCall() { || this == OpCode.STATICCALL; } - public boolean callHasSixArgument() { + public boolean callMayNotTransferValue() { + Preconditions.checkArgument(isCall()); return this == OpCode.DELEGATECALL || this == OpCode.STATICCALL; } - public boolean callHasSevenArgument() { + public boolean callCanTransferValue() { + Preconditions.checkArgument(isCall()); return this == OpCode.CALL || this == OpCode.CALLCODE; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java index 1e8cd72156..30126e177d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java @@ -99,10 +99,10 @@ public static Address getCreate2Address(final MessageFrame frame) { public static Address getDeploymentAddress(final MessageFrame frame) { OpCode opcode = OpCode.of(frame.getCurrentOperation().getOpcode()); - if (!opcode.equals(OpCode.CREATE2) && !opcode.equals(OpCode.CREATE)) { - throw new IllegalArgumentException("Must be called only for CREATE/CREATE2 opcode"); + if (opcode.isAnyOf(OpCode.CREATE, OpCode.CREATE2)) { + return opcode.equals(OpCode.CREATE) ? getCreateAddress(frame) : getCreate2Address(frame); } - return opcode.equals(OpCode.CREATE) ? getCreateAddress(frame) : getCreate2Address(frame); + throw new IllegalArgumentException("Must be called only for CREATE/CREATE2 opcode"); } public static Address addressFromBytes(final Bytes input) { From 793a96c825a398eecbf89fc92c78d3510db99d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 26 Jun 2024 22:31:35 +0200 Subject: [PATCH 154/461] post merge --- .../module/hub/fragment/imc/ImcFragment.java | 2 +- .../module/hub/fragment/imc/call/StpCall.java | 8 --- .../linea/zktracer/module/stp/Stp.java | 25 +------- .../instructionprocessing/StpTests.java | 58 +++++++++++++++++++ gradle/corset.gradle | 4 +- 5 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 0ce7d7c613..fe6f7ac6a5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -140,7 +140,7 @@ public static ImcFragment forCall( // TODO: @Olivier get memory expansion gas long memoryExpansionGas = 0xdeadbeefL; - StpCall stpCall = new StpCall(hub.messageFrame(), memoryExpansionGas); + StpCall stpCall = new StpCall(hub, memoryExpansionGas); r.callStp(stpCall); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java index ad8eefb952..3d8a802da8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java @@ -84,10 +84,6 @@ public StpCall stpCallForCalls(Hub hub, long memoryExpansionGas) { } else { stpCall.upfrontGasCost += GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); } - // TODO: in the previous implementation (in Stp.java) - // ``toExists`` was only computed for CALLCODE (which is wrong) - // now it's for both CALL and CALLCODE. - // Check in tests if this is right. if (callWouldLeadToAccountCreation) { stpCall.upfrontGasCost += GasConstants.G_NEW_ACCOUNT.cost(); } @@ -114,13 +110,9 @@ private long computeGasPaidOutOfPocketForCalls() { } public StpCall stpCallForCreates(Hub hub, long memoryExpansionGas) { - // set up hub, memoryExpansionGas, opCode and gasActual; StpCall stpCall = new StpCall(hub, memoryExpansionGas); MessageFrame frame = hub.messageFrame(); - // TODO: in old Stp.java was given the balance - // rather than the value of the instruction; - // how did it not blow up in tests ? stpCall.gas = EWord.ZERO; // irrelevant stpCall.value = EWord.of(frame.getStackItem(0)); stpCall.exists = false; // irrelevant diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java index 211699e40a..a30b5cd8dc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java @@ -45,7 +45,7 @@ public class Stp implements Module { private final Mod mod; public void call(StpCall stpCall, MessageFrame messageFrame) { - this.operations.add(new StpOperation(stpCall, messageFrame)); + this.operations.add(new StpOperation(stpCall)); } @Override @@ -119,15 +119,7 @@ private StpOperation stpOperationForCreate(StpCall stpCall) { stpCall.outOfGasException(stpCall.gasActual() < stpCall.upfrontGasCost()); final Address deploymentAddress = getDeploymentAddress(frame); final long gasActual = frame.getRemainingGas(); - return new StpOperation( - this.hub.opCode(), - gasActual, - upfrontGasCost, - gasActual < upfrontGasCost, - stpCall.memoryExpansionGas(), - frame.getWorldUpdater().get(frame.getContractAddress()).getBalance(), - deploymentAddress, - Bytes32.leftPad(frame.getStackItem(0))); + return new StpOperation( stpCall); } private StpOperation stpOperationForCall(StpCall stpCall) { @@ -157,18 +149,7 @@ private StpOperation stpOperationForCall(StpCall stpCall) { gasPrelim += GasConstants.G_NEW_ACCOUNT.cost(); } final boolean oogx = gasActual < gasPrelim; - return new StpOperation( - opcode, - gasActual, - gasPrelim, - oogx, - gasMxp, - frame.getWorldUpdater().get(frame.getContractAddress()).getBalance(), - to, - value, - toExists, - toWarm, - Bytes32.leftPad(frame.getStackItem(0))); + return new StpOperation(stpCall); } static boolean callCanTransferValue(OpCode opCode) { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java new file mode 100644 index 0000000000..4f489801e8 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java @@ -0,0 +1,58 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.EvmExtension; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class StpTests { + + private void forceWarmRecipient(BytecodeCompiler bytecode, Address recipient, boolean forceWarmth) { + if (forceWarmth) { + bytecode.push(recipient) + .op(OpCode.BALANCE) + .op(OpCode.POP) + ; + } + } + + // private void appendCall(BytecodeCompiler bytecode, Address recipient, Wei value) { + // + // bytecode + // .push() // return at capacity + // .push() // return at offset + // .push() // call data size + // .push() // call data offset + // .push() // value + // .push() // address + // .push() // gas + // } + private void appendCallcode(BytecodeCompiler bytecode, Address recipient, Wei value) { + + } + private void appendDelegatecall(BytecodeCompiler bytecode, Address recipient) { + + } + private void appendStaticcall(BytecodeCompiler bytecode, Address recipient, Wei value) { + + } +} + + diff --git a/gradle/corset.gradle b/gradle/corset.gradle index 02b335b843..bf54bfbe5c 100644 --- a/gradle/corset.gradle +++ b/gradle/corset.gradle @@ -16,7 +16,7 @@ tasks.register('corsetExists') { doLast { def result = exec{ ignoreExitValue = true - commandLine "corset -V" + commandLine "corset", "-V" } if (result.getExitValue() != 0){ throw new GradleException('Corset not found, skipping corsetTests') @@ -25,7 +25,7 @@ tasks.register('corsetExists') { } tasks.register('buildZkevmBin', Exec) { - // dependsOn corsetExists +// dependsOn corsetExists workingDir "${project.rootDir}/zkevm-constraints/" commandLine 'make', 'zkevm.bin' From ef58ea8240b6adb6f25414decd06bbe7778760cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 30 Jun 2024 15:37:48 +0200 Subject: [PATCH 155/461] ras --- .../module/hub/fragment/imc/call/StpCall.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java index 3d8a802da8..a4b7710c4f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java @@ -64,38 +64,25 @@ public StpCall stpCallForCalls(Hub hub, long memoryExpansionGas) { MessageFrame frame = hub.messageFrame(); final boolean instructionCanTransferValue = stpCall.opCode.callCanTransferValue(); - final boolean isCALL = stpCall.opCode.equals(OpCode.CALL); final Address to = Words.toAddress(frame.getStackItem(1)); Account toAccount = frame.getWorldUpdater().getAccount(to); stpCall.gas = EWord.of(frame.getStackItem(0)); stpCall.value = (instructionCanTransferValue) ? EWord.of(frame.getStackItem(2)) : EWord.ZERO; stpCall.exists = toAccount != null ? !toAccount.isEmpty() : false; stpCall.warm = frame.isAddressWarm(to); - stpCall.upfrontGasCost = memoryExpansionGas; + final boolean isCALL = stpCall.opCode.equals(OpCode.CALL); final boolean nonzeroValueTransfer = !value.isZero(); - final boolean callWouldLeadToAccountCreation = - isCALL && nonzeroValueTransfer && !stpCall.exists; - if (nonzeroValueTransfer) { - stpCall.upfrontGasCost += GasConstants.G_CALL_VALUE.cost(); - } - if (stpCall.warm) { - stpCall.upfrontGasCost += GasConstants.G_WARM_ACCESS.cost(); - } else { - stpCall.upfrontGasCost += GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); - } - if (callWouldLeadToAccountCreation) { - stpCall.upfrontGasCost += GasConstants.G_NEW_ACCOUNT.cost(); - } + stpCall.upfrontGasCost = upfrontGasCostForCalls(isCALL, nonzeroValueTransfer); stpCall.outOfGasException = stpCall.gasActual < stpCall.upfrontGasCost; - stpCall.gasPaidOutOfPocket = stpCall.computeGasPaidOutOfPocketForCalls(); + stpCall.gasPaidOutOfPocket = stpCall.gasPaidOutOfPocketForCalls(); stpCall.stipend = !outOfGasException && nonzeroValueTransfer ? GasConstants.G_CALL_STIPEND.cost() : 0; return stpCall; } - private long computeGasPaidOutOfPocketForCalls() { + private long gasPaidOutOfPocketForCalls() { if (outOfGasException) { return gasPaidOutOfPocket = 0; } else { @@ -133,6 +120,20 @@ private long computeGasPaidOutOfPocketForCreates() { } } + private long upfrontGasCostForCalls(boolean isCALL, boolean nonzeroValueTransfer) { + + boolean toIsWarm = this.warm(); + long upfrontGasCost = this.memoryExpansionGas; + final boolean callWouldLeadToAccountCreation = + isCALL && nonzeroValueTransfer && !this.exists; + if (nonzeroValueTransfer) upfrontGasCost += GasConstants.G_CALL_VALUE.cost(); + if (toIsWarm) upfrontGasCost += GasConstants.G_WARM_ACCESS.cost(); + else upfrontGasCost += GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); + if (callWouldLeadToAccountCreation) upfrontGasCost += GasConstants.G_NEW_ACCOUNT.cost(); + + return upfrontGasCost; + } + @Override public Trace trace(Trace trace) { return trace From ecf4c3d636708f4db23ecb1a23aa1dddd895ee7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 30 Jun 2024 20:44:08 +0200 Subject: [PATCH 156/461] make it compile + spotless --- .../linea/zktracer/module/hub/Hub.java | 3 +- .../module/hub/fragment/imc/ImcFragment.java | 2 +- .../module/hub/fragment/imc/call/StpCall.java | 63 ++++--- .../module/hub/section/CreateSection.java | 31 ++-- .../linea/zktracer/module/stp/Stp.java | 165 +++--------------- .../zktracer/module/stp/StpOperation.java | 23 +-- 6 files changed, 79 insertions(+), 208 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 15054dcda0..efd917bffe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -197,7 +197,7 @@ public int lineCount() { private final TxnData txnData; // modules triggered by sub-fragments of the MISCELLANEOUS / IMC perspective - @Getter private final Stp stp = new Stp(this, wcp, mod); + @Getter private final Stp stp = new Stp(wcp, mod); @Getter private final Exp exp; @Getter private final Mmu mmu; @Getter private final Mxp mxp; @@ -1090,6 +1090,7 @@ void traceOperation(MessageFrame frame) { case CONTEXT -> this.addTraceSection( new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); + case LOG -> { new LogSection(this); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index fe6f7ac6a5..e43104a42f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -307,7 +307,7 @@ public ImcFragment callStp(StpCall f) { } else { stpIsSet = true; } - this.hub.stp().call(f, hub.messageFrame()); + this.hub.stp().call(f); this.moduleCalls.add(f); return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java index a4b7710c4f..8b8a8074e0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java @@ -56,30 +56,33 @@ public StpCall(Hub hub, long memoryExpansionGas) { this.opCode = hub.opCode(); this.gasActual = hub.messageFrame().getRemainingGas(); Preconditions.checkArgument(this.opCode.isCall() || this.opCode.isCreate()); + + if (this.opCode.isCall()) { + this.stpCallForCalls(hub); + } else { + this.stpCallForCreates(hub); + } } - public StpCall stpCallForCalls(Hub hub, long memoryExpansionGas) { - // set up hub, memoryExpansionGas, opCode and gasActual; - StpCall stpCall = new StpCall(hub, memoryExpansionGas); + public void stpCallForCalls(Hub hub) { MessageFrame frame = hub.messageFrame(); - final boolean instructionCanTransferValue = stpCall.opCode.callCanTransferValue(); + final boolean instructionCanTransferValue = this.opCode.callCanTransferValue(); final Address to = Words.toAddress(frame.getStackItem(1)); Account toAccount = frame.getWorldUpdater().getAccount(to); - stpCall.gas = EWord.of(frame.getStackItem(0)); - stpCall.value = (instructionCanTransferValue) ? EWord.of(frame.getStackItem(2)) : EWord.ZERO; - stpCall.exists = toAccount != null ? !toAccount.isEmpty() : false; - stpCall.warm = frame.isAddressWarm(to); + this.gas = EWord.of(frame.getStackItem(0)); + this.value = (instructionCanTransferValue) ? EWord.of(frame.getStackItem(2)) : EWord.ZERO; + this.exists = toAccount != null ? !toAccount.isEmpty() : false; + this.warm = frame.isAddressWarm(to); - final boolean isCALL = stpCall.opCode.equals(OpCode.CALL); + final boolean isCALL = this.opCode.equals(OpCode.CALL); final boolean nonzeroValueTransfer = !value.isZero(); - stpCall.upfrontGasCost = upfrontGasCostForCalls(isCALL, nonzeroValueTransfer); - stpCall.outOfGasException = stpCall.gasActual < stpCall.upfrontGasCost; - stpCall.gasPaidOutOfPocket = stpCall.gasPaidOutOfPocketForCalls(); - stpCall.stipend = !outOfGasException && nonzeroValueTransfer ? GasConstants.G_CALL_STIPEND.cost() : 0; - - return stpCall; + this.upfrontGasCost = upfrontGasCostForCalls(isCALL, nonzeroValueTransfer); + this.outOfGasException = this.gasActual < this.upfrontGasCost; + this.gasPaidOutOfPocket = this.gasPaidOutOfPocketForCalls(); + this.stipend = + !outOfGasException && nonzeroValueTransfer ? GasConstants.G_CALL_STIPEND.cost() : 0; } private long gasPaidOutOfPocketForCalls() { @@ -89,26 +92,23 @@ private long gasPaidOutOfPocketForCalls() { long gasMinusUpfront = gasActual - upfrontGasCost; long oneSixtyFourths = gasMinusUpfront >> 6; long maxGasAllowance = gasMinusUpfront - oneSixtyFourths; - return - gas().toUnsignedBigInteger().compareTo(BigInteger.valueOf(maxGasAllowance)) > 0 - ? maxGasAllowance - : gas.toLong(); + return gas().toUnsignedBigInteger().compareTo(BigInteger.valueOf(maxGasAllowance)) > 0 + ? maxGasAllowance + : gas.toLong(); } } - public StpCall stpCallForCreates(Hub hub, long memoryExpansionGas) { - StpCall stpCall = new StpCall(hub, memoryExpansionGas); + public void stpCallForCreates(Hub hub) { MessageFrame frame = hub.messageFrame(); - stpCall.gas = EWord.ZERO; // irrelevant - stpCall.value = EWord.of(frame.getStackItem(0)); - stpCall.exists = false; // irrelevant - stpCall.warm = false; // irrelevant - stpCall.upfrontGasCost = GasConstants.G_CREATE.cost() + stpCall.memoryExpansionGas; - stpCall.outOfGasException = stpCall.gasActual < stpCall.upfrontGasCost; - stpCall.gasPaidOutOfPocket = stpCall.computeGasPaidOutOfPocketForCreates(); - stpCall.stipend = 0; // irrelevant - return stpCall; + this.gas = EWord.ZERO; // irrelevant + this.value = EWord.of(frame.getStackItem(0)); + this.exists = false; // irrelevant + this.warm = false; // irrelevant + this.upfrontGasCost = GasConstants.G_CREATE.cost() + this.memoryExpansionGas; + this.outOfGasException = this.gasActual < this.upfrontGasCost; + this.gasPaidOutOfPocket = this.computeGasPaidOutOfPocketForCreates(); + this.stipend = 0; // irrelevant } private long computeGasPaidOutOfPocketForCreates() { @@ -124,8 +124,7 @@ private long upfrontGasCostForCalls(boolean isCALL, boolean nonzeroValueTransfer boolean toIsWarm = this.warm(); long upfrontGasCost = this.memoryExpansionGas; - final boolean callWouldLeadToAccountCreation = - isCALL && nonzeroValueTransfer && !this.exists; + final boolean callWouldLeadToAccountCreation = isCALL && nonzeroValueTransfer && !this.exists; if (nonzeroValueTransfer) upfrontGasCost += GasConstants.G_CALL_VALUE.cost(); if (toIsWarm) upfrontGasCost += GasConstants.G_WARM_ACCESS.cost(); else upfrontGasCost += GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 487c1eb7cc..6fe540cc1c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.hub.section; -import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; - import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.NextContextDefer; @@ -28,7 +26,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; @@ -37,7 +34,6 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.opcode.gas.projector.GasProjection; -import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -156,20 +152,19 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces projection.memoryExpansion() + projection.linearPerWord() + GasConstants.G_TX_CREATE.cost(); final ImcFragment commonImcFragment = - ImcFragment.empty(hub) - .callOob(new CreateOobCall()) - .callMxp(MxpCall.build(hub)) - .callStp( - new StpCall( - this.opCode.byteValue(), - EWord.of(this.initialGas), - EWord.ZERO, - false, - oldCreatedSnapshot.isWarm(), - this.exceptions.outOfGasException(), - upfrontCost, - allButOneSixtyFourth(this.initialGas - upfrontCost), - 0)); + ImcFragment.empty(hub).callOob(new CreateOobCall()).callMxp(MxpCall.build(hub)) + // .callStp( + // new StpCall( + // this.opCode.byteValue(), + // EWord.of(this.initialGas), + // EWord.ZERO, + // false, + // oldCreatedSnapshot.isWarm(), + // this.exceptions.outOfGasException(), + // upfrontCost, + // allButOneSixtyFourth(this.initialGas - upfrontCost), + // 0)) + ; this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); this.addFragmentsWithoutStack(scenarioFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java index a30b5cd8dc..4371d9181b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.stp; -import static java.lang.Long.max; -import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; import static net.consensys.linea.zktracer.types.Conversions.longToBytes32; import java.nio.MappedByteBuffer; @@ -26,26 +24,43 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; @RequiredArgsConstructor public class Stp implements Module { - private final Hub hub; + + private final StackedSet operations = new StackedSet<>(); + private final Wcp wcp; private final Mod mod; - public void call(StpCall stpCall, MessageFrame messageFrame) { - this.operations.add(new StpOperation(stpCall)); + public void call(StpCall stpCall) { + StpOperation stpOperation = new StpOperation(stpCall); + this.operations.add(stpOperation); + + if (stpCall.opCode().isCreate()) { + this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); + this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); + if (!stpCall.outOfGasException()) { + this.mod.callDIV(longToBytes32(stpOperation.getGDiff()), longToBytes32(64L)); + } + } + + if (stpCall.opCode().isCall()) { + this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); + if (callCanTransferValue(stpCall.opCode())) { + this.wcp.callISZERO(Bytes32.leftPad(stpCall.value())); + } + this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); + if (!stpCall.outOfGasException()) { + this.mod.callDIV(longToBytes32(stpOperation.getGDiff()), longToBytes32(64L)); + this.wcp.callLT(stpCall.gas(), longToBytes32(stpOperation.get63of64GDiff())); + } + } } @Override @@ -53,8 +68,6 @@ public String moduleKey() { return "STP"; } - private final StackedSet operations = new StackedSet<>(); - @Override public void enterTransaction() { this.operations.enter(); @@ -75,136 +88,10 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - @Override - public void tracePreOpcode(final MessageFrame frame) { - OpCode opCode = hub.opCode(); - - switch (opCode) { - case CREATE, CREATE2 -> { - final StpOperation stpOperation = stpOperationForCreate(frame); - StpCall stpCall = stpOperation.stpCall(); - this.operations.add(stpOperation); - this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); - this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); - if (!stpCall.outOfGasException()) { - this.mod.callDIV(longToBytes32(stpOperation.getGDiff()), longToBytes32(64L)); - } - } - case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { - final StpOperation stpOperation = stpOperationForCall(frame); - StpCall stpCall = stpOperation.stpCall(); - this.operations.add(stpOperation); - this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); - if (callCanTransferValue(stpCall.opCode())) { - this.wcp.callISZERO(Bytes32.leftPad(stpCall.value())); - } - this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); - if (!stpCall.outOfGasException()) { - this.mod.callDIV(longToBytes32(stpOperation.getGDiff()), longToBytes32(64L)); - this.wcp.callLT(stpCall.gas(), longToBytes32(stpOperation.get63of64GDiff())); - } - } - } - } - - private StpOperation stpOperationForCreate(StpCall stpCall) { - Hub hub = stpCall.hub(); - MessageFrame frame = hub.messageFrame(); - stpCall.gasActual(frame.getRemainingGas()); - stpCall.gas(EWord.ZERO); - stpCall.value(EWord.of(frame.getWorldUpdater().get(frame.getContractAddress()).getBalance())); - stpCall.exists(false); // irrelevant - stpCall.warm(false); // irrelevant - stpCall.upfrontGasCost(GasConstants.G_CREATE.cost() + stpCall.memoryExpansionGas()); - stpCall.outOfGasException(stpCall.gasActual() < stpCall.upfrontGasCost()); - final Address deploymentAddress = getDeploymentAddress(frame); - final long gasActual = frame.getRemainingGas(); - return new StpOperation( stpCall); - } - - private StpOperation stpOperationForCall(StpCall stpCall) { - MessageFrame frame = stpCall.hub().messageFrame(); - final OpCode opcode = this.hub.opCode(); - final long gasActual = frame.getRemainingGas(); - final Bytes32 value = - callCanTransferValue(opcode) ? Bytes32.leftPad(frame.getStackItem(2)) : Bytes32.ZERO; - final Address to = Words.toAddress(frame.getStackItem(1)); - final long gasMxp = getGasMxpCall(frame); - final boolean toWarm = frame.isAddressWarm(to); - final boolean toExists = - opcode == OpCode.CALLCODE - || (frame.getWorldUpdater().get(to) != null - && !frame.getWorldUpdater().get(to).isEmpty()); - - long gasPrelim = gasMxp; - if (!value.isZero() && callCanTransferValue(opcode)) { - gasPrelim += GasConstants.G_CALL_VALUE.cost(); - } - if (toWarm) { - gasPrelim += GasConstants.G_WARM_ACCESS.cost(); - } else { - gasPrelim += GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); - } - if (!toExists) { - gasPrelim += GasConstants.G_NEW_ACCOUNT.cost(); - } - final boolean oogx = gasActual < gasPrelim; - return new StpOperation(stpCall); - } - static boolean callCanTransferValue(OpCode opCode) { return (opCode == OpCode.CALL) || (opCode == OpCode.CALLCODE); } - // TODO get from Hub.GasProjector - private long getGasMxpCreate(final MessageFrame frame) { - long gasMxp = 0; - final long offset = Words.clampedToLong(frame.getStackItem(1)); - final long length = Words.clampedToLong(frame.getStackItem(2)); - final long currentMemorySizeInWords = frame.memoryWordSize(); - final long updatedMemorySizeInWords = frame.calculateMemoryExpansion(offset, length); - if (currentMemorySizeInWords < updatedMemorySizeInWords) { - // computing the "linear" portion of CREATE2 memory expansion cost - final long G_mem = GasConstants.G_MEMORY.cost(); - final long squareCurrent = (currentMemorySizeInWords * currentMemorySizeInWords) >> 9; - final long squareUpdated = (updatedMemorySizeInWords * updatedMemorySizeInWords) >> 9; - gasMxp += - G_mem * (updatedMemorySizeInWords - currentMemorySizeInWords) - + (squareUpdated - squareCurrent); - } - if (OpCode.of(frame.getCurrentOperation().getOpcode()) == OpCode.CREATE2) { - final long lengthInWords = (length + 31) >> 5; // ⌈ length / 32 ⌉ - gasMxp += lengthInWords * GasConstants.G_KECCAK_256_WORD.cost(); - } - return gasMxp; - } - - // TODO get from Hub.GasProjector - private long getGasMxpCall(final MessageFrame frame) { - long gasMxp = 0; - - final int offset = - callCanTransferValue(OpCode.of(frame.getCurrentOperation().getOpcode())) ? 1 : 0; - final long cdo = Words.clampedToLong(frame.getStackItem(2 + offset)); // call data offset - final long cds = Words.clampedToLong(frame.getStackItem(3 + offset)); // call data size - final long rdo = Words.clampedToLong(frame.getStackItem(4 + offset)); // return data offset - final long rdl = Words.clampedToLong(frame.getStackItem(5 + offset)); // return data size - - final long memSize = frame.memoryWordSize(); - final long memSizeCallData = frame.calculateMemoryExpansion(cdo, cds); - final long memSizeReturnData = frame.calculateMemoryExpansion(rdo, rdl); - final long maybeNewMemSize = max(memSizeReturnData, memSizeCallData); - - if (memSize < maybeNewMemSize) { - // computing the "linear" portion of CREATE2 memory expansion cost - final long G_mem = GasConstants.G_MEMORY.cost(); - final long squareCurrent = (memSize * memSize) >> 9; - final long squareUpdated = (maybeNewMemSize * maybeNewMemSize) >> 9; - gasMxp += G_mem * (maybeNewMemSize - memSize) + (squareUpdated - squareCurrent); - } - return gasMxp; - } - @Override public void commit(List buffers) { final Trace trace = new Trace(buffers); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java index 6d714a04b9..d8c0ac995c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java @@ -15,28 +15,16 @@ package net.consensys.linea.zktracer.module.stp; -import static net.consensys.linea.zktracer.module.stp.Stp.callCanTransferValue; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; - import java.math.BigInteger; -import java.util.Optional; import com.google.common.base.Preconditions; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; -import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.frame.MessageFrame; @Accessors(fluent = true) @Getter @@ -122,12 +110,12 @@ private void traceCreate(Trace trace, int stamp) { .isCallcode(isCallCode()) .isDelegatecall(isDelegateCall()) .isStaticcall(isStaticCall()) - // .gasHi(Bytes.EMPTY) - // .gasLo(Bytes.EMPTY) + // .gasHi(Bytes.EMPTY) // redundant + // .gasLo(Bytes.EMPTY) // redundant .valHi(stpCall.value().slice(0, 16)) .valLo(stpCall.value().slice(16, 16)) - // .exists(false) - // .warm(false) + // .exists(false) // redundant + // .warm(false) // redundant .outOfGasException(stpCall.outOfGasException()) .gasActual(Bytes.ofUnsignedLong(stpCall.gasActual())) .gasMxp(Bytes.ofUnsignedLong(stpCall.memoryExpansionGas())) @@ -238,7 +226,8 @@ private void traceCall(Trace trace, int stamp) { .exogenousModuleInstruction(UnsignedByte.of(OpCode.LT.byteValue())) .resLo( Bytes.of( - stpCall.gas() + stpCall + .gas() .toUnsignedBigInteger() .compareTo(BigInteger.valueOf(get63of64GDiff())) < 0 From 8be1e5651894054b139cce59a7d603c87b37c8f2 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 1 Jul 2024 12:25:39 +0530 Subject: [PATCH 157/461] ras --- .../linea/zktracer/module/hub/section/TraceSection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8047898220..5568ff0971 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 @@ -49,7 +49,7 @@ public abstract class TraceSection { /* A link to the next section */ @Setter public TraceSection nextSection = null; - /** Default creator for an empty section. Prefer the creator where we specify the max nb o rows */ + /** Default creator for an empty section. Prefer the creator where we specify the max nb of rows */ public TraceSection(Hub hub) { this.hub = hub; this.commonValues = new CommonFragmentValues(hub); From c15032249015d0f9919aed98f85490b7303a9d14 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 1 Jul 2024 16:15:47 +0200 Subject: [PATCH 158/461] feat(hub): implemented ExpSection --- .../consensys/linea/zktracer/module/hub/Hub.java | 3 +-- .../module/hub/fragment/imc/ImcFragment.java | 3 ++- .../zktracer/module/hub/section/ExpSection.java | 13 +++++++++---- .../zktracer/module/hub/section/TraceSection.java | 4 +++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c5c6bd670c..6b8580448a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1037,8 +1037,7 @@ void traceOperation(MessageFrame frame) { .addTraceSection(new StackOnlySection(this)); case MUL -> { if (this.opCode() == OpCode.EXP) { - this.addTraceSection( - new ExpSection(this, ImcFragment.forOpcode(this, this.messageFrame()))); + this.addTraceSection(new ExpSection(this)); } else { this.addTraceSection(new StackOnlySection(this)); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index e43104a42f..6efa03cbe1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -26,7 +26,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; @@ -172,9 +171,11 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { r.callMxp(MxpCall.build(hub)); } + /* TODO: this has been commented out since signals will die if (hub.pch().signals().exp()) { r.callExp(new ExplogExpCall()); } + */ if (hub.pch().signals().exp() && !hub.pch().exceptions().stackException()) { hub.exp().tracePreOpcode(frame); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java index 56309b8a4b..e689eb24c2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java @@ -16,11 +16,16 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; public class ExpSection extends TraceSection { - public ExpSection(Hub hub, TraceFragment... fragments) { - super(hub); - this.addFragmentsAndStack(hub, fragments); + public ExpSection(Hub hub) { + super(hub, (short) 3); + final ExpCall expCall = new ExplogExpCall(); + // TODO: should expCall be filled here? + final ImcFragment miscFragment = ImcFragment.empty(hub).callExp(expCall); + this.addFragmentsAndStack(hub, miscFragment); } } 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 5568ff0971..c5be730a38 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 @@ -49,7 +49,9 @@ public abstract class TraceSection { /* A link to the next section */ @Setter public TraceSection nextSection = null; - /** Default creator for an empty section. Prefer the creator where we specify the max nb of rows */ + /** + * Default creator for an empty section. Prefer the creator where we specify the max nb of rows + */ public TraceSection(Hub hub) { this.hub = hub; this.commonValues = new CommonFragmentValues(hub); From 6efdc5fb6938964aecd266cd654b9eb02c95b02e Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 1 Jul 2024 19:51:33 +0200 Subject: [PATCH 159/461] feat(hub): added exception for MUL instruction family handling --- .../consensys/linea/zktracer/module/hub/Hub.java | 15 +++++++++++---- .../zktracer/module/hub/section/ExpSection.java | 1 - 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6b8580448a..9c5b309b2b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1036,10 +1036,17 @@ void traceOperation(MessageFrame frame) { case ADD, MOD, SHF, BIN, WCP, EXT, BATCH, MACHINE_STATE, PUSH_POP, DUP, SWAP, INVALID -> this .addTraceSection(new StackOnlySection(this)); case MUL -> { - if (this.opCode() == OpCode.EXP) { - this.addTraceSection(new ExpSection(this)); - } else { - this.addTraceSection(new StackOnlySection(this)); + switch (this.opCode()) { + case OpCode.EXP -> { + this.addTraceSection(new ExpSection(this)); + } + case OpCode.MUL -> { + this.addTraceSection(new StackOnlySection(this)); + } + default -> { + throw new IllegalStateException( + String.format("opcode %s not part of the MUL instruction family", this.opCode())); + } } } case HALT -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java index e689eb24c2..c429ee9951 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java @@ -24,7 +24,6 @@ public class ExpSection extends TraceSection { public ExpSection(Hub hub) { super(hub, (short) 3); final ExpCall expCall = new ExplogExpCall(); - // TODO: should expCall be filled here? final ImcFragment miscFragment = ImcFragment.empty(hub).callExp(expCall); this.addFragmentsAndStack(hub, miscFragment); } From d6267e1b87b8cde3f5ede6d5a903f16d2b8fd6ee Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 2 Jul 2024 10:38:41 +0530 Subject: [PATCH 160/461] stackram inst wip --- .../linea/zktracer/module/hub/Hub.java | 23 +++--- .../zktracer/module/hub/section/StackRam.java | 72 ++++++++++--------- zkevm-constraints | 2 +- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 9c5b309b2b..86f965b4bf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1200,17 +1200,18 @@ void traceOperation(MessageFrame frame) { case TRANSACTION -> this.addTraceSection( new TransactionSection(this, TransactionFragment.prepare(this.txStack.current()))); case STACK_RAM -> { - switch (this.currentFrame().opCode()) { - case CALLDATALOAD -> { - final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); - - this.addTraceSection( - new StackRam(this, imcFragment, ContextFragment.readCurrentContextData(this))); - } - case MLOAD, MSTORE, MSTORE8 -> this.addTraceSection( - new StackRam(this, ImcFragment.forOpcode(this, frame))); - default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); - } + this.addTraceSection(new StackRam(this)); + // switch (this.currentFrame().opCode()) { + // case CALLDATALOAD -> { + // final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); +// + // this.addTraceSection( + // new StackRam(this, imcFragment, ContextFragment.readCurrentContextData(this))); + // } + // case MLOAD, MSTORE, MSTORE8 -> this.addTraceSection( + // new StackRam(this, ImcFragment.forOpcode(this, frame))); + // default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); + // } } case STORAGE -> { switch (this.currentFrame().opCode()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java index 79af1e5ed5..8cb4716dc6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java @@ -16,55 +16,63 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; +import net.consensys.linea.zktracer.opcode.OpCode; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class StackRam extends TraceSection { +public class StackRam extends TraceSection implements PostTransactionDefer { + final Bytes currentRam = Bytes.EMPTY; //TODO - public static void appendToTrace(Hub hub) { +public StackRam(Hub hub) { + super(hub, (short) (hub.opCode().equals(OpCode.CALLDATALOAD) ? 4 : 3)); + this.addStack(hub); - ImcFragment imcFragment = ImcFragment.empty(hub); + final ImcFragment imcFragment = ImcFragment.empty(hub); + switch (hub.opCode()) { + case MSTORE, MSTORE8, MLOAD -> { + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + } + case CALLDATALOAD -> { + OobCall oobCall = new CallDataLoadOobCall(); + imcFragment.callOob(oobCall); + } + } + + boolean triggerMmu = hub.pch().exceptions().none(); + + if (triggerMmu) { switch (hub.opCode()) { - case MSTORE, MSTORE8, MLOAD -> { - MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); + case MSTORE -> { + imcFragment.callMmu(MmuCall.mstore(hub)); + } + case MSTORE8 -> { + imcFragment.callMmu(MmuCall.mstore8(hub)); + } + case MLOAD -> { + imcFragment.callMmu(MmuCall.mload(hub)); } case CALLDATALOAD -> { - OobCall oobCall = new CallDataLoadOobCall(); - imcFragment.callOob(oobCall); + imcFragment.callMmu(MmuCall.callDataLoad(hub)); } - } - - boolean triggerMmu = hub.pch().exceptions().none(); - - if (triggerMmu) { - switch (hub.opCode()) { - case MSTORE -> { - imcFragment.callMmu(MmuCall.mstore(hub)); - } - case MSTORE8 -> { - imcFragment.callMmu(MmuCall.mstore8(hub)); - } - case MLOAD -> { - imcFragment.callMmu(MmuCall.mload(hub)); - } - case CALLDATALOAD -> { - imcFragment.callMmu(MmuCall.callDataLoad(hub)); - } - default -> { - throw new RuntimeException("Opcode not part of the stack ram family"); - } + default -> { + throw new RuntimeException("Opcode not part of the stack ram family"); } } } +} + + @Override + public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - public StackRam(Hub hub, TraceFragment... chunks) { - super(hub); - this.addFragmentsAndStack(hub, chunks); } } diff --git a/zkevm-constraints b/zkevm-constraints index 255677b629..b40be863df 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 255677b629dceaacffb053c79a4ee947c3a106d7 +Subproject commit b40be863dfccf4d445dee0c89e14718307afb1d7 From a59d38e8cc9f75910eaf2e7f152950267241aefa Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 2 Jul 2024 11:33:39 +0200 Subject: [PATCH 161/461] feat(hub): started restructuring COPY family instruction handling --- .../linea/zktracer/module/hub/Hub.java | 13 ++++-- .../hub/section/copy/CallDataCopySection.java | 27 ++++++++++++ .../CodeCopySection.java} | 7 +-- .../module/hub/section/copy/CopySection.java | 44 +++++++++++++++++++ .../hub/section/copy/ExtCodeCopySection.java | 27 ++++++++++++ .../section/copy/ReturnDataCopySection.java | 27 ++++++++++++ 6 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{CopySection.java => copy/CodeCopySection.java} (77%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index dacd2e2e22..4fdac44c7e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -17,7 +17,6 @@ import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.*; import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; -import static net.consensys.linea.zktracer.types.AddressUtils.addressFromBytes; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; @@ -57,6 +56,7 @@ import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; +import net.consensys.linea.zktracer.module.hub.section.copy.CopySection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -1152,14 +1152,15 @@ void traceOperation(MessageFrame frame) { this.addTraceSection(accountSection); } case COPY -> { + CopySection.appendToTrace(this); + + /* TraceSection copySection = new CopySection(this); - if (!this.opCode().equals(OpCode.RETURNDATACOPY)) { + if (!this.opCode().equals(OpCode.RETURNDATACOPY) && !this.opCode().equals(OpCode.CALLDATACOPY)) { final Bytes rawTargetAddress = switch (this.currentFrame().opCode()) { case CODECOPY -> this.currentFrame().byteCodeAddress(); case EXTCODECOPY -> frame.getStackItem(0); - case CALLDATACOPY -> addressFromBytes( - Bytes.fromHexString("0xdeadbeef")); // TODO: implement me please default -> throw new IllegalStateException( String.format("unexpected opcode %s", this.opCode())); }; @@ -1180,6 +1181,9 @@ void traceOperation(MessageFrame frame) { this.transients.conflation().deploymentInfo().number(targetAddress), this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + // TODO: this is deprecated, update it. Factories creates an account row (accountFragment) + // ImcFragment is for miscellaneaous rows + // ContextFragment DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this, 0); copySection.addFragment( @@ -1204,6 +1208,7 @@ void traceOperation(MessageFrame frame) { copySection.addFragment(ContextFragment.readCurrentContextData(this)); } this.addTraceSection(copySection); + */ } case TRANSACTION -> this.addTraceSection( new TransactionSection(this, TransactionFragment.prepare(this.txStack.current()))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java new file mode 100644 index 0000000000..8ce73f72ad --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -0,0 +1,27 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.copy; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class CallDataCopySection extends TraceSection { + public CallDataCopySection(Hub hub, TraceFragment... chunks) { + super(hub); + this.addFragmentsAndStack(hub, chunks); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java similarity index 77% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 88dd5ca6c4..0839bb0782 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -13,13 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section; +package net.consensys.linea.zktracer.module.hub.section.copy; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; -public class CopySection extends TraceSection { - public CopySection(Hub hub, TraceFragment... chunks) { +public class CodeCopySection extends TraceSection { + public CodeCopySection(Hub hub, TraceFragment... chunks) { super(hub); this.addFragmentsAndStack(hub, chunks); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java new file mode 100644 index 0000000000..0ee0e47642 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java @@ -0,0 +1,44 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.copy; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.opcode.OpCode; + +public class CopySection extends TraceSection { + + // TODO: this constructor is not really necessary + public CopySection(Hub hub) { + super(hub); + } + + /* + public CopySection(Hub hub, TraceFragment... chunks) { + super(hub); + this.addFragmentsAndStack(hub, chunks); + } + */ + + public static void appendToTrace(Hub hub) { + switch (hub.opCode()) { + case OpCode.CALLDATACOPY -> hub.addTraceSection(new CallDataCopySection(hub)); + case OpCode.RETURNDATACOPY -> hub.addTraceSection(new ReturnDataCopySection(hub)); + case OpCode.CODECOPY -> hub.addTraceSection(new CodeCopySection(hub)); + case OpCode.EXTCODECOPY -> hub.addTraceSection(new ExtCodeCopySection(hub)); + } + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java new file mode 100644 index 0000000000..dd848cacd7 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -0,0 +1,27 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.copy; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class ExtCodeCopySection extends TraceSection { + public ExtCodeCopySection(Hub hub, TraceFragment... chunks) { + super(hub); + this.addFragmentsAndStack(hub, chunks); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java new file mode 100644 index 0000000000..5b974f3d4b --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -0,0 +1,27 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.copy; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class ReturnDataCopySection extends TraceSection { + public ReturnDataCopySection(Hub hub, TraceFragment... chunks) { + super(hub); + this.addFragmentsAndStack(hub, chunks); + } +} From cbe0830f540deed45c5a2c5115e8734a9c3f1aea Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 2 Jul 2024 15:43:39 +0530 Subject: [PATCH 162/461] fix LOGX, defer MMU call for STACK_RAM inst --- .../linea/zktracer/module/hub/Hub.java | 19 ++- .../module/hub/fragment/imc/ImcFragment.java | 14 +-- .../module/hub/fragment/imc/call/MxpCall.java | 2 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 63 +--------- .../hub/section/CallDataLoadSection.java | 105 +++++++++++++++++ .../module/hub/section/LogSection.java | 9 +- .../zktracer/module/hub/section/StackRam.java | 76 ------------ .../module/hub/section/StackRamSection.java | 110 ++++++++++++++++++ .../zktracer/module/rlptxrcpt/LogTest.java | 6 +- zkevm-constraints | 2 +- 10 files changed, 240 insertions(+), 166 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index dacd2e2e22..28389049b6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1208,18 +1208,13 @@ void traceOperation(MessageFrame frame) { case TRANSACTION -> this.addTraceSection( new TransactionSection(this, TransactionFragment.prepare(this.txStack.current()))); case STACK_RAM -> { - this.addTraceSection(new StackRam(this)); - // switch (this.currentFrame().opCode()) { - // case CALLDATALOAD -> { - // final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); - // - // this.addTraceSection( - // new StackRam(this, imcFragment, ContextFragment.readCurrentContextData(this))); - // } - // case MLOAD, MSTORE, MSTORE8 -> this.addTraceSection( - // new StackRam(this, ImcFragment.forOpcode(this, frame))); - // default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); - // } + switch (this.currentFrame().opCode()) { + case CALLDATALOAD -> { + this.addTraceSection(new CallDataLoadSection(this)); + } + case MLOAD, MSTORE, MSTORE8 -> this.addTraceSection(new StackRamSection(this)); + default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); + } } case STORAGE -> { switch (this.currentFrame().opCode()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index d9796c97e0..f67b8eefb9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -28,7 +28,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; @@ -184,16 +183,17 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { if (hub.pch().signals().mmu()) { switch (hub.opCode()) { + // commented instruction are done elsewhere, everything should be deleted case SHA3 -> r.callMmu(MmuCall.sha3(hub)); - case CALLDATALOAD -> r.callMmu(MmuCall.callDataLoad(hub)); + // case CALLDATALOAD -> r.callMmu(MmuCall.callDataLoad(hub)); case CALLDATACOPY -> r.callMmu(MmuCall.callDataCopy(hub)); case CODECOPY -> r.callMmu(MmuCall.codeCopy(hub)); case EXTCODECOPY -> r.callMmu(MmuCall.extCodeCopy(hub)); case RETURNDATACOPY -> r.callMmu(MmuCall.returnDataCopy(hub)); - case MLOAD -> r.callMmu(MmuCall.mload(hub)); - case MSTORE -> r.callMmu(MmuCall.mstore(hub)); - case MSTORE8 -> r.callMmu(MmuCall.mstore8(hub)); - // case LOG0, LOG1, LOG2, LOG3, LOG4 -> r.callMmu(MmuCall.log(hub)); done elsewhere + // case MLOAD -> r.callMmu(MmuCall.mload(hub)); + // case MSTORE -> r.callMmu(MmuCall.mstore(hub)); + // case MSTORE8 -> r.callMmu(MmuCall.mstore8(hub)); + // case LOG0, LOG1, LOG2, LOG3, LOG4 -> r.callMmu(MmuCall.log(hub)); case CREATE -> r.callMmu(MmuCall.create(hub)); case RETURN -> r.callMmu( hub.currentFrame().isDeployment() @@ -209,7 +209,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { switch (hub.opCode()) { case JUMP -> r.callOob(new JumpOobCall()); case JUMPI -> r.callOob(new JumpiOobCall()); - case CALLDATALOAD -> r.callOob(new CallDataLoadOobCall()); + // case CALLDATALOAD -> r.callOob(new CallDataLoadOobCall()); case SSTORE -> r.callOob(new SstoreOobCall()); case CALL, CALLCODE -> { r.callOob(new CallOobCall()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index 5dd1d8a3b5..c037e61da7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -60,7 +60,7 @@ public Trace trace(Trace trace, State.TxState.Stamps stamps) { stamps.incrementMxpStamp(); return trace .pMiscMxpFlag(true) - .pMiscMxpInst(this.opCodeData.mnemonic().byteValue()) + .pMiscMxpInst(this.opCodeData.value()) .pMiscMxpDeploys(this.deploys) .pMiscMxpOffset1Hi(this.offset1.hi()) .pMiscMxpOffset1Lo(this.offset1.lo()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 2c9a3c0f2f..b3578c18e8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -34,7 +34,6 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MODEXP_DATA; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MODEXP_ZERO; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MSTORE; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MSTORE8; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_RAM_SANS_PADDING; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RIGHT_PADDED_WORD_EXTRACTION; @@ -61,7 +60,6 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import java.util.Arrays; import java.util.Optional; import com.google.common.base.Preconditions; @@ -177,33 +175,6 @@ public static MmuCall sha3(final Hub hub) { .setKec(); } - public static MmuCall callDataLoad(final Hub hub) { - final long callDataOffset = hub.currentFrame().callDataInfo().memorySpan().offset(); - final long callDataSize = hub.currentFrame().callDataInfo().memorySpan().length(); - - final long sourceOffset = Words.clampedToLong(hub.messageFrame().getStackItem(0)); - - if (sourceOffset >= callDataSize) { - return nop(); - } - - final EWord read = - EWord.of( - Bytes.wrap( - Arrays.copyOfRange( - hub.currentFrame().callDataInfo().data().toArray(), - (int) sourceOffset, - (int) (sourceOffset + WORD_SIZE)))); - - return new MmuCall(MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) - .sourceId(callDataContextNumber(hub)) - .sourceOffset(EWord.of(sourceOffset)) - .referenceOffset(callDataOffset) - .referenceSize(callDataSize) - .limb1(read.hi()) - .limb2(read.lo()); - } - public static MmuCall callDataCopy(final Hub hub) { final MemorySpan callDataSegment = hub.currentFrame().callDataInfo().memorySpan(); @@ -217,7 +188,7 @@ public static MmuCall callDataCopy(final Hub hub) { .referenceSize(callDataSegment.length()); } - private static int callDataContextNumber(final Hub hub) { + public static int callDataContextNumber(final Hub hub) { final CallFrame currentFrame = hub.callStack().current(); return currentFrame.isRoot() @@ -263,38 +234,6 @@ public static MmuCall returnDataCopy(final Hub hub) { .referenceSize(returnDataSegment.length()); } - public static MmuCall mload(final Hub hub) { - final long offset = Words.clampedToLong(hub.messageFrame().getStackItem(0)); - final EWord loadedValue = EWord.of(hub.messageFrame().shadowReadMemory(offset, WORD_SIZE)); - return new MmuCall(MMU_INST_MLOAD) - .sourceId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.of(offset)) - .limb1(loadedValue.hi()) - .limb2(loadedValue.lo()); - } - - public static MmuCall mstore(final Hub hub) { - final EWord storedValue = EWord.of(hub.messageFrame().getStackItem(1)); - return new MmuCall(MMU_INST_MSTORE) - .targetId(hub.currentFrame().contextNumber()) - .targetOffset(EWord.of(hub.messageFrame().getStackItem(0))) - .limb1(storedValue.hi()) - .limb2(storedValue.lo()); - } - - public static MmuCall mstore8(final Hub hub) { - final EWord storedValue = EWord.of(hub.messageFrame().getStackItem(1)); - return new MmuCall(MMU_INST_MSTORE8) - .targetId(hub.currentFrame().contextNumber()) - .targetOffset(EWord.of(hub.messageFrame().getStackItem(0))) - .limb1(storedValue.hi()) - .limb2(storedValue.lo()); - } - - // public static MmuCall log(final Hub hub) { - // return new LogX(hub); - // } - public static MmuCall create(final Hub hub) { return new Create(hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java new file mode 100644 index 0000000000..35c60f0d19 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -0,0 +1,105 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section; + +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RIGHT_PADDED_WORD_EXTRACTION; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; +import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readCurrentContextData; + +import java.util.Arrays; +import java.util.Optional; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.types.EWord; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class CallDataLoadSection extends TraceSection implements PostTransactionDefer { + final short exception; + final Bytes callDataRam; + final int currentContextNumber; + final long callDataCN; + final ImcFragment imcFragment; + final EWord sourceOffset; + + long callDataOffset = -1; + long callDataSize = -1; + + public CallDataLoadSection(Hub hub) { + super(hub, (short) (hub.opCode().equals(OpCode.CALLDATALOAD) ? 4 : 3)); + this.addStack(hub); + + this.exception = hub.pch().exceptions(); + this.currentContextNumber = hub.currentFrame().contextNumber(); + this.callDataSize = hub.currentFrame().callDataInfo().memorySpan().length(); + this.callDataOffset = hub.currentFrame().callDataInfo().memorySpan().offset(); + this.sourceOffset = (EWord) hub.currentFrame().frame().getStackItem(0); + this.callDataCN = hub.currentFrame().callDataInfo().callDataContextNumber(); + this.callDataRam = hub.currentFrame().callDataInfo().data(); + + this.imcFragment = ImcFragment.empty(hub); + + final OobCall oobCall = new CallDataLoadOobCall(); + imcFragment.callOob(oobCall); + + this.addFragment(imcFragment); + + final ContextFragment context = readCurrentContextData(hub); + this.addFragment(context); + + hub.defers().postTx(this); + } + + @Override + public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (Exceptions.none(exception)) { + + if (Words.clampedToLong(sourceOffset) >= callDataSize) { + return; + } + + final EWord read = + EWord.of( + Bytes.wrap( + Arrays.copyOfRange( + hub.currentFrame().callDataInfo().data().toArray(), + Words.clampedToInt(sourceOffset), + Words.clampedToInt(sourceOffset) + WORD_SIZE))); + + final MmuCall call = + new MmuCall(MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + .sourceId((int) callDataCN) + .sourceOffset(sourceOffset) + .referenceOffset(callDataOffset) + .referenceSize(callDataSize) + .limb1(read.hi()) + .limb2(read.lo()) + .sourceRamBytes(Optional.of(callDataRam)); + + imcFragment.callMmu(call); + } + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index c37f0bef11..726a58d0e0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -36,7 +36,6 @@ public class LogSection implements PostTransactionDefer { final boolean oogX; ImcFragment miscFragment; - MxpCall mxpSubFragment; LogInvocation logData; public LogSection(Hub hub) { @@ -57,8 +56,11 @@ public LogSection(Hub hub) { new LogCommonSection(hub, (short) 5, ContextFragment.readCurrentContextData(hub)); hub.addTraceSection(sectionPrequel); logData = new LogInvocation(hub); - mxpSubFragment = MxpCall.build(hub); - miscFragment = ImcFragment.empty(hub); // TODO: .callMxp(mxpSubFragment.get())); + + final MxpCall mxpCall = new MxpCall(hub); + miscFragment = ImcFragment.empty(hub).callMxp(mxpCall); + this.sectionPrequel.addFragment(miscFragment); + hub.defers().postTx(this); } @@ -73,7 +75,6 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces if (mmuTrigger) { miscFragment.callMmu(MmuCall.LogX(hub, this.logData)); } - this.sectionPrequel.addFragment(miscFragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java deleted file mode 100644 index 69c652f6e3..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRam.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class StackRam extends TraceSection implements PostTransactionDefer { - final Bytes currentRam = Bytes.EMPTY; // TODO - - public StackRam(Hub hub) { - super(hub, (short) (hub.opCode().equals(OpCode.CALLDATALOAD) ? 4 : 3)); - this.addStack(hub); - - final ImcFragment imcFragment = ImcFragment.empty(hub); - - switch (hub.opCode()) { - case MSTORE, MSTORE8, MLOAD -> { - MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); - } - case CALLDATALOAD -> { - OobCall oobCall = new CallDataLoadOobCall(); - imcFragment.callOob(oobCall); - } - } - - boolean triggerMmu = Exceptions.none(hub.pch().exceptions()); - - if (triggerMmu) { - switch (hub.opCode()) { - case MSTORE -> { - imcFragment.callMmu(MmuCall.mstore(hub)); - } - case MSTORE8 -> { - imcFragment.callMmu(MmuCall.mstore8(hub)); - } - case MLOAD -> { - imcFragment.callMmu(MmuCall.mload(hub)); - } - case CALLDATALOAD -> { - imcFragment.callMmu(MmuCall.callDataLoad(hub)); - } - default -> { - throw new RuntimeException("Opcode not part of the stack ram family"); - } - } - } - } - - @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java new file mode 100644 index 0000000000..1db4f2ccd7 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -0,0 +1,110 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section; + +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MLOAD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MSTORE; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MSTORE8; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; + +import java.util.Optional; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.types.EWord; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class StackRamSection extends TraceSection implements PostTransactionDefer { + final OpCode instruction; + final Bytes currentRam; + final int currentContextNumber; + final short exception; + final ImcFragment imcFragment; + final EWord offset; + final EWord value; + + public StackRamSection(Hub hub) { + super(hub, (short) (hub.opCode().equals(OpCode.CALLDATALOAD) ? 4 : 3)); + this.addStack(hub); + + this.instruction = hub.opCode(); + this.exception = hub.pch().exceptions(); + this.currentRam = + hub.currentFrame().frame().shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()); + this.currentContextNumber = hub.currentFrame().contextNumber(); + + this.imcFragment = ImcFragment.empty(hub); + this.offset = EWord.of(hub.currentFrame().frame().getStackItem(0)); + this.value = + instruction.equals(OpCode.MLOAD) + ? EWord.of(hub.messageFrame().shadowReadMemory(Words.clampedToLong(offset), WORD_SIZE)) + : EWord.of(hub.currentFrame().frame().getStackItem(1)); + + final MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + + this.addFragment(imcFragment); + + hub.defers().postTx(this); + } + + @Override + public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (Exceptions.none(exception)) { + switch (instruction) { + case MSTORE -> { + final MmuCall call = + new MmuCall(MMU_INST_MSTORE) + .targetId(currentContextNumber) + .targetOffset(offset) + .limb1(value.hi()) + .limb2(value.lo()) + .targetRamBytes(Optional.of(currentRam)); + + imcFragment.callMmu(call); + } + case MSTORE8 -> { + final MmuCall call = + new MmuCall(MMU_INST_MSTORE8) + .targetId(currentContextNumber) + .targetOffset(offset) + .limb1(value.hi()) + .limb2(value.lo()) + .targetRamBytes(Optional.of(currentRam)); + imcFragment.callMmu(call); + } + case MLOAD -> { + final MmuCall call = + new MmuCall(MMU_INST_MLOAD) + .sourceId(currentContextNumber) + .sourceOffset(offset) + .limb1(value.hi()) + .limb2(value.lo()) + .sourceRamBytes(Optional.of(currentRam)); + imcFragment.callMmu(call); + } + } + } + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java index cb4f83d54b..cbde941b45 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java @@ -39,9 +39,9 @@ void log2Test() { .push(33) // size .push(4) // offset .op(OpCode.LOG2) - // .push(1) - // .push(0) - // .op(OpCode.MSTORE) + .push(1) + .push(0) + .op(OpCode.MSTORE) .compile()) .run(); } diff --git a/zkevm-constraints b/zkevm-constraints index 60bde0031b..74f2885b2f 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 60bde0031b3db6e10b07f706a33b652d342bd37c +Subproject commit 74f2885b2f6fe31dba8f1b741668776add5451ee From 11876cb72f23d684a68ac14f5bec21f8aaeae3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 2 Jul 2024 13:39:19 +0200 Subject: [PATCH 163/461] EXTCODECOPY WARNING: The account undoing row is affected by #785 --- .../linea/zktracer/module/hub/Hub.java | 8 +- .../module/hub/fragment/StackFragment.java | 4 +- .../hub/fragment/common/CommonFragment.java | 4 +- .../module/hub/fragment/imc/call/MxpCall.java | 2 +- .../module/hub/section/CreateSection.java | 4 +- .../module/hub/section/JumpSection.java | 2 +- .../module/hub/section/LogSection.java | 4 +- .../module/hub/section/SloadSection.java | 2 +- .../module/hub/section/SstoreSection.java | 2 +- .../hub/section/copy/ExtCodeCopySection.java | 98 ++++++++++++++++++- .../module/hub/signals/Exceptions.java | 26 ++--- .../zktracer/module/hub/signals/Signals.java | 38 +++---- 12 files changed, 143 insertions(+), 51 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 9eba3de9a5..c69b986987 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -689,8 +689,8 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope final short exceptions = this.pch().exceptions(); - final boolean memoryExpansionException = Exceptions.outOfMemoryExpansion(exceptions); - final boolean outOfGasException = Exceptions.outOfGas(exceptions); + final boolean memoryExpansionException = Exceptions.memoryExpansionException(exceptions); + final boolean outOfGasException = Exceptions.outOfGasException(exceptions); final boolean unexceptional = Exceptions.none(exceptions); final boolean exceptional = Exceptions.any(exceptions); @@ -1294,13 +1294,13 @@ void traceOperation(MessageFrame frame) { ImcFragment.forCall(this, myAccount, calledAccount), ContextFragment.readContextDataByContextNumber( this, this.currentFrame().contextNumber()))); // TODO - } else if (Exceptions.outOfMemoryExpansion(this.pch().exceptions())) { + } else if (Exceptions.memoryExpansionException(this.pch().exceptions())) { this.addTraceSection( new FailedCallSection( this, ScenarioFragment.forCall(this, hasCode), ImcFragment.forCall(this, myAccount, calledAccount))); - } else if (Exceptions.outOfGas(this.pch().exceptions())) { + } else if (Exceptions.outOfGasException(this.pch().exceptions())) { this.addTraceSection( new FailedCallSection( this, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 1f16d0f477..68dcec9ab9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -295,8 +295,8 @@ public Trace trace(Trace trace) { .pStackOpcx(Exceptions.invalidCodePrefix(exceptions)) .pStackSux(Exceptions.stackUnderflow(exceptions)) .pStackSox(Exceptions.stackOverflow(exceptions)) - .pStackMxpx(Exceptions.outOfMemoryExpansion(exceptions)) - .pStackOogx(Exceptions.outOfGas(exceptions)) + .pStackMxpx(Exceptions.memoryExpansionException(exceptions)) + .pStackOogx(Exceptions.outOfGasException(exceptions)) .pStackRdcx(Exceptions.returnDataCopyFault(exceptions)) .pStackJumpx(Exceptions.jumpFault(exceptions)) .pStackStaticx(Exceptions.staticFault(exceptions)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java index 929342258e..e9649627f2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java @@ -113,7 +113,7 @@ static long computeGasCost(Hub hub, WorldView world) { switch (hub.opCodeData().instructionFamily()) { case ADD, MOD, SHF, BIN, WCP, EXT, BATCH, MACHINE_STATE, PUSH_POP, DUP, SWAP, INVALID -> { - if (Exceptions.outOfGas(hub.pch().exceptions()) + if (Exceptions.outOfGasException(hub.pch().exceptions()) || Exceptions.none(hub.pch().exceptions())) { return hub.opCode().getData().stackSettings().staticGas().cost(); } @@ -139,7 +139,7 @@ static long computeGasCost(Hub hub, WorldView world) { case RETURN, REVERT -> { Bytes offset = hub.messageFrame().getStackItem(0); Bytes size = hub.messageFrame().getStackItem(0); - return Exceptions.outOfMemoryExpansion(hub.pch().exceptions()) + return Exceptions.memoryExpansionException(hub.pch().exceptions()) ? 0 : ZkTracer.gasCalculator.memoryExpansionGasCost( hub.messageFrame(), offset.toLong(), size.toLong()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index c037e61da7..9b30e9a9d0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -49,7 +49,7 @@ public static MxpCall build(Hub hub) { } static boolean getMemoryExpansionException(Hub hub) { - return Exceptions.outOfMemoryExpansion(hub.pch().exceptions()); + return Exceptions.memoryExpansionException(hub.pch().exceptions()); } public final boolean type4InstructionMayTriggerNonTrivialOperation(Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 0487e59516..6d523350ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -173,11 +173,11 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces ImcFragment.empty(hub), ContextFragment.readCurrentContextData(hub), ContextFragment.executionProvidesEmptyReturnData(hub)); - } else if (Exceptions.outOfMemoryExpansion(this.exceptions)) { + } else if (Exceptions.memoryExpansionException(this.exceptions)) { this.addFragmentsWithoutStack( ImcFragment.empty(hub).callMxp(MxpCall.build(hub)), ContextFragment.executionProvidesEmptyReturnData(hub)); - } else if (Exceptions.outOfGas(this.exceptions)) { + } else if (Exceptions.outOfGasException(this.exceptions)) { this.addFragmentsWithoutStack( commonImcFragment, ContextFragment.executionProvidesEmptyReturnData(hub)); } else if (this.aborts.any()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index 00167fd41e..0881b7fe0f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -42,7 +42,7 @@ public static void appendToTrace(Hub hub, WorldView worldView) { hub.addTraceSection(currentSection); - if (Exceptions.outOfGas(hub.pch().exceptions())) { + if (Exceptions.outOfGasException(hub.pch().exceptions())) { return; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index 726a58d0e0..3d2163ad55 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -39,8 +39,8 @@ public class LogSection implements PostTransactionDefer { LogInvocation logData; public LogSection(Hub hub) { - this.mxpX = Exceptions.outOfMemoryExpansion(hub.pch().exceptions()); - this.oogX = Exceptions.outOfGas(hub.pch().exceptions()); + this.mxpX = Exceptions.memoryExpansionException(hub.pch().exceptions()); + this.oogX = Exceptions.outOfGasException(hub.pch().exceptions()); // Static Case if (hub.currentFrame().frame().isStatic()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 31cf0b1f05..28b992c4d8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -57,7 +57,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { sloadSection.addFragmentsAndStack(hub, readCurrentContext, miscFragmentForSload, doingSload); - final boolean outOfGasException = Exceptions.outOfGas(hub.pch().exceptions()); + final boolean outOfGasException = Exceptions.outOfGasException(hub.pch().exceptions()); final boolean contextWillRevert = hub.callStack().current().willRevert(); if (outOfGasException || contextWillRevert) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 16506d981d..f00417f95a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -52,7 +52,7 @@ public static void appendSectionTo(Hub hub, WorldView world) { final boolean staticContextException = Exceptions.staticFault(hub.pch().exceptions()); final boolean sstoreException = Exceptions.outOfSStore(hub.pch().exceptions()); - final boolean outOfGasException = Exceptions.outOfGas(hub.pch().exceptions()); + final boolean outOfGasException = Exceptions.outOfGasException(hub.pch().exceptions()); final boolean contextWillRevert = hub.callStack().current().willRevert(); final SstoreSection currentSection = new SstoreSection(hub, world); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index dd848cacd7..761bf7cfb7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -15,13 +15,105 @@ package net.consensys.linea.zktracer.module.hub.section.copy; +import com.slack.api.model.Message; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.frame.MessageFrame; + +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.none; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; public class ExtCodeCopySection extends TraceSection { - public ExtCodeCopySection(Hub hub, TraceFragment... chunks) { - super(hub); - this.addFragmentsAndStack(hub, chunks); + + public static void appendToTrace(Hub hub) { + + final ExtCodeCopySection extCodeCopySection = new ExtCodeCopySection(hub); + hub.addTraceSection(extCodeCopySection); + + ImcFragment imcFragment = ImcFragment.empty(hub); + extCodeCopySection.addFragmentsAndStack(hub, imcFragment); + + // triggerOob = false + // triggerMxp = true + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + + // The MXPX case + if (mxpCall.mxpx) { + // the last context row will be added automatically + return; + } + + final MessageFrame frame = hub.messageFrame(); + final Bytes rawTargetAddress = frame.getStackItem(0); + final Address targetAddress = Address.extract((Bytes32) rawTargetAddress); + final Account targetAccount = frame.getWorldUpdater().get(targetAddress); + + AccountSnapshot accountBefore = + AccountSnapshot.fromAccount( + targetAccount, + frame.isAddressWarm(targetAddress), + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + + DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + + final short exceptions = hub.pch().exceptions(); + + // The OOGX case + if (outOfGasException(exceptions)) { + // the last context row will be added automatically + AccountFragment accountReadingFragment = hub.factories() + .accountFragment() + .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); + + extCodeCopySection.addFragment(accountReadingFragment); + return; + } + + final boolean triggerMmu = none(exceptions) && mxpCall.isMayTriggerNonTrivialMmuOperation(); + if (triggerMmu) { + MmuCall mmuCall = MmuCall.extCodeCopy(hub); + imcFragment.callMmu(mmuCall); + } + + AccountSnapshot accountAfter = + AccountSnapshot.fromAccount( + targetAccount, + true, + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + + AccountFragment accountDoingFragment = hub.factories() + .accountFragment() + .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps); + + extCodeCopySection.addFragment(accountDoingFragment); + + // affected by issue #785 + if (hub.callStack().current().willRevert()) { + DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); + AccountFragment undoingAccountFragment = + hub.factories() + .accountFragment() + .make(accountAfter, accountBefore, undoingDomSubStamps); + extCodeCopySection.addFragment(undoingAccountFragment); + } } + + public ExtCodeCopySection(Hub hub) { super(hub); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java index 231153da36..a74dbf01e1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java @@ -35,8 +35,8 @@ private Exceptions() {} private static final short INVALID_OPCODE = 1; // unknown opcode private static final short STACK_UNDERFLOW = 2; // stack underflow private static final short STACK_OVERFLOW = 4; // stack overflow - private static final short OUT_OF_MEMORY_EXPANSION = 8; // tried to use memory too far away - private static final short OUT_OF_GAS = 16; // not enough gas for instruction + private static final short MEMORY_EXPANSION_EXCEPTION = 8; // tried to use memory too far away + private static final short OUT_OF_GAS_EXCEPTION = 16; // not enough gas for instruction private static final short RETURN_DATA_COPY_FAULT = 32; // trying to read past the RETURNDATA end private static final short JUMP_FAULT = 64; // jumping to an invalid destination private static final short STATIC_FAULT = @@ -82,12 +82,12 @@ public static boolean stackOverflow(final short bitmask) { return (bitmask & STACK_OVERFLOW) != 0; } - public static boolean outOfMemoryExpansion(final short bitmask) { - return (bitmask & OUT_OF_MEMORY_EXPANSION) != 0; + public static boolean memoryExpansionException(final short bitmask) { + return (bitmask & MEMORY_EXPANSION_EXCEPTION) != 0; } - public static boolean outOfGas(final short bitmask) { - return (bitmask & OUT_OF_GAS) != 0; + public static boolean outOfGasException(final short bitmask) { + return (bitmask & OUT_OF_GAS_EXCEPTION) != 0; } public static boolean returnDataCopyFault(final short bitmask) { @@ -257,10 +257,10 @@ public static short fromFrame(final Hub hub, final MessageFrame frame) { MSTORE, MSTORE8 -> { if (isMemoryExpansionFault(frame, opCode, gp)) { - return OUT_OF_MEMORY_EXPANSION; + return MEMORY_EXPANSION_EXCEPTION; } if (isOutOfGas(frame, opCode, gp)) { - return OUT_OF_GAS; + return OUT_OF_GAS_EXCEPTION; } } @@ -269,10 +269,10 @@ public static short fromFrame(final Hub hub, final MessageFrame frame) { return RETURN_DATA_COPY_FAULT; } if (isMemoryExpansionFault(frame, opCode, gp)) { - return OUT_OF_MEMORY_EXPANSION; + return MEMORY_EXPANSION_EXCEPTION; } if (isOutOfGas(frame, opCode, gp)) { - return OUT_OF_GAS; + return OUT_OF_GAS_EXCEPTION; } } @@ -280,7 +280,7 @@ public static short fromFrame(final Hub hub, final MessageFrame frame) { case JUMP, JUMPI -> { if (isOutOfGas(frame, opCode, gp)) { - return OUT_OF_GAS; + return OUT_OF_GAS_EXCEPTION; } if (isJumpFault(frame, opCode)) { return JUMP_FAULT; @@ -292,13 +292,13 @@ public static short fromFrame(final Hub hub, final MessageFrame frame) { return OUT_OF_SSTORE; } if (isOutOfGas(frame, opCode, gp)) { - return OUT_OF_GAS; + return OUT_OF_GAS_EXCEPTION; } } default -> { if (isOutOfGas(frame, opCode, gp)) { - return OUT_OF_GAS; + return OUT_OF_GAS_EXCEPTION; } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index e7f1e87c86..8dcffa4f01 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -143,22 +143,22 @@ public void prepare(MessageFrame frame, PlatformController platformController, H switch (opCode) { case CALLDATACOPY, CODECOPY -> { this.mxp = - Exceptions.outOfMemoryExpansion(ex) || Exceptions.outOfGas(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); } case RETURNDATACOPY -> { this.oob = Exceptions.none(ex) || Exceptions.returnDataCopyFault(ex); this.mxp = - Exceptions.none(ex) || Exceptions.outOfMemoryExpansion(ex) || Exceptions.outOfGas(ex); + Exceptions.none(ex) || Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); } case EXTCODECOPY -> { final boolean nonzeroSize = !frame.getStackItem(3).isZero(); this.mxp = - Exceptions.outOfMemoryExpansion(ex) || Exceptions.outOfGas(ex) || Exceptions.none(ex); - this.trm = Exceptions.outOfGas(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + this.trm = Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && nonzeroSize; final Address address = Words.toAddress(frame.getStackItem(0)); @@ -172,7 +172,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case LOG0, LOG1, LOG2, LOG3, LOG4 -> { this.mxp = - Exceptions.outOfMemoryExpansion(ex) || Exceptions.outOfGas(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame @@ -184,9 +184,9 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case CALL, DELEGATECALL, STATICCALL, CALLCODE -> { this.mxp = !Exceptions.staticFault(ex); - this.stp = Exceptions.outOfGas(ex) || Exceptions.none(ex); + this.stp = Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.oob = opCode.equals(OpCode.CALL) && Exceptions.staticFault(ex) || Exceptions.none(ex); - this.trm = Exceptions.outOfGas(ex) || Exceptions.none(ex); + this.trm = Exceptions.outOfGasException(ex) || Exceptions.none(ex); final boolean triggersAbortingCondition = Exceptions.none(ex) && this.platformController.abortingConditions().any(); @@ -219,7 +219,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H final boolean isCreate2 = opCode == OpCode.CREATE2; this.mxp = !Exceptions.staticFault(ex); - this.stp = Exceptions.outOfGas(ex) || Exceptions.none(ex); + this.stp = Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.oob = Exceptions.none(ex); this.rlpAddr = Exceptions.none(ex) && !triggersAbortingCondition; this.hashInfo = @@ -234,7 +234,7 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case REVERT -> { this.mxp = - Exceptions.outOfMemoryExpansion(ex) || Exceptions.outOfGas(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(1).isZero() @@ -247,8 +247,8 @@ public void prepare(MessageFrame frame, PlatformController platformController, H // WARN: Static part, other modules may be dynamically requested in the hub this.mxp = - Exceptions.outOfMemoryExpansion(ex) - || Exceptions.outOfGas(ex) + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) || Exceptions.invalidCodePrefix(ex) || Exceptions.none(ex); this.oob = isDeployment && (Exceptions.codeSizeOverflow(ex) || Exceptions.none(ex)); @@ -264,17 +264,17 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case EXP -> { this.exp = true; // TODO: use expCall instead - this.mul = !Exceptions.outOfGas(ex); + this.mul = !Exceptions.outOfGasException(ex); } // other opcodes - case ADD, SUB -> this.add = !Exceptions.outOfGas(ex); - case MUL -> this.mul = !Exceptions.outOfGas(ex); - case DIV, SDIV, MOD, SMOD -> this.mod = !Exceptions.outOfGas(ex); - case ADDMOD, MULMOD -> this.ext = !Exceptions.outOfGas(ex); - case LT, GT, SLT, SGT, EQ, ISZERO -> this.wcp = !Exceptions.outOfGas(ex); - case AND, OR, XOR, NOT, SIGNEXTEND, BYTE -> this.bin = !Exceptions.outOfGas(ex); - case SHL, SHR, SAR -> this.shf = !Exceptions.outOfGas(ex); + case ADD, SUB -> this.add = !Exceptions.outOfGasException(ex); + case MUL -> this.mul = !Exceptions.outOfGasException(ex); + case DIV, SDIV, MOD, SMOD -> this.mod = !Exceptions.outOfGasException(ex); + case ADDMOD, MULMOD -> this.ext = !Exceptions.outOfGasException(ex); + case LT, GT, SLT, SGT, EQ, ISZERO -> this.wcp = !Exceptions.outOfGasException(ex); + case AND, OR, XOR, NOT, SIGNEXTEND, BYTE -> this.bin = !Exceptions.outOfGasException(ex); + case SHL, SHR, SAR -> this.shf = !Exceptions.outOfGasException(ex); case SHA3 -> { this.mxp = true; this.hashInfo = Exceptions.none(ex) && !frame.getStackItem(1).isZero(); From 0b3c0fb7d35d7a0c9847b0713a3c45ff601f1a42 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 2 Jul 2024 14:37:28 +0200 Subject: [PATCH 164/461] feat(hub): implemented CodeCopySection --- .../hub/section/copy/CodeCopySection.java | 76 ++++++++++++++++++- .../hub/section/copy/ExtCodeCopySection.java | 49 ++++++------ .../zktracer/module/hub/signals/Signals.java | 20 +++-- 3 files changed, 112 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 0839bb0782..7ecc3e0138 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -15,13 +15,83 @@ package net.consensys.linea.zktracer.module.hub.section.copy; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.frame.MessageFrame; public class CodeCopySection extends TraceSection { - public CodeCopySection(Hub hub, TraceFragment... chunks) { + + public static void appendToTrace(Hub hub) { + final CodeCopySection codeCopySection = new CodeCopySection(hub); + hub.addTraceSection(codeCopySection); + + // Miscellaneous row + ImcFragment imcFragment = ImcFragment.empty(hub); + codeCopySection.addFragmentsAndStack(hub, imcFragment); + + // triggerOob = false + // triggerMxp = true + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + boolean xahoy = mxpCall.mxpx || outOfGasException(hub.pch().exceptions()); + final boolean triggerMmu = !xahoy && mxpCall.isMayTriggerNonTrivialMmuOperation(); + if (triggerMmu) { + MmuCall mmuCall = MmuCall.codeCopy(hub); + imcFragment.callMmu(mmuCall); + } + + // Context row + // TODO: use ContextFragment.readContextDataByContextNumber(hub, CN) + ContextFragment contextFragment = + xahoy + ? ContextFragment.executionProvidesEmptyReturnData(hub) + : ContextFragment.readCurrentContextData(hub); + codeCopySection.addFragment(contextFragment); + + // Account row + final MessageFrame frame = hub.messageFrame(); + final Bytes rawTargetAddress = frame.getStackItem(0); + final Address targetAddress = Address.extract((Bytes32) rawTargetAddress); + final Account targetAccount = frame.getWorldUpdater().get(targetAddress); + + AccountSnapshot accountBefore = + AccountSnapshot.fromAccount( + targetAccount, + frame.isAddressWarm(targetAddress), + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + + DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + + if (mxpCall.mxpx) { + AccountFragment accountReadingFragment = + hub.factories() + .accountFragment() + .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); + + codeCopySection.addFragment(accountReadingFragment); + return; + } + if (!xahoy) { + // ? + } + } + + public CodeCopySection(Hub hub) { super(hub); - this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 761bf7cfb7..3afd5c36b7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -15,12 +15,12 @@ package net.consensys.linea.zktracer.module.hub.section.copy; -import com.slack.api.model.Message; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.none; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; + import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -32,9 +32,6 @@ import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; -import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.none; -import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; - public class ExtCodeCopySection extends TraceSection { public static void appendToTrace(Hub hub) { @@ -62,21 +59,22 @@ public static void appendToTrace(Hub hub) { final Account targetAccount = frame.getWorldUpdater().get(targetAddress); AccountSnapshot accountBefore = - AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + AccountSnapshot.fromAccount( + targetAccount, + frame.isAddressWarm(targetAddress), + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); final short exceptions = hub.pch().exceptions(); // The OOGX case if (outOfGasException(exceptions)) { // the last context row will be added automatically - AccountFragment accountReadingFragment = hub.factories() + AccountFragment accountReadingFragment = + hub.factories() .accountFragment() .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); @@ -91,13 +89,14 @@ public static void appendToTrace(Hub hub) { } AccountSnapshot accountAfter = - AccountSnapshot.fromAccount( - targetAccount, - true, - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); - - AccountFragment accountDoingFragment = hub.factories() + AccountSnapshot.fromAccount( + targetAccount, + true, + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + + AccountFragment accountDoingFragment = + hub.factories() .accountFragment() .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps); @@ -106,14 +105,14 @@ public static void appendToTrace(Hub hub) { // affected by issue #785 if (hub.callStack().current().willRevert()) { DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); AccountFragment undoingAccountFragment = - hub.factories() - .accountFragment() - .make(accountAfter, accountBefore, undoingDomSubStamps); + hub.factories().accountFragment().make(accountAfter, accountBefore, undoingDomSubStamps); extCodeCopySection.addFragment(undoingAccountFragment); } } - public ExtCodeCopySection(Hub hub) { super(hub); } + public ExtCodeCopySection(Hub hub) { + super(hub); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index 8dcffa4f01..67ed7c46a2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -143,21 +143,27 @@ public void prepare(MessageFrame frame, PlatformController platformController, H switch (opCode) { case CALLDATACOPY, CODECOPY -> { this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); } case RETURNDATACOPY -> { this.oob = Exceptions.none(ex) || Exceptions.returnDataCopyFault(ex); this.mxp = - Exceptions.none(ex) || Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex); + Exceptions.none(ex) + || Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); } case EXTCODECOPY -> { final boolean nonzeroSize = !frame.getStackItem(3).isZero(); this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.trm = Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && nonzeroSize; @@ -172,7 +178,9 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case LOG0, LOG1, LOG2, LOG3, LOG4 -> { this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame @@ -234,7 +242,9 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case REVERT -> { this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(1).isZero() From da903c027273c2e22d48f318c2930ff682a3b0f5 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 2 Jul 2024 18:17:55 +0530 Subject: [PATCH 165/461] ras --- .../hub/section/{ContextLogSection.java => ContextSection.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{ContextLogSection.java => ContextSection.java} (100%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextLogSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java From fb41bec6417feddf0906372896cc081dccd3a9d7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 2 Jul 2024 18:19:43 +0530 Subject: [PATCH 166/461] merge remote --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/section/ContextSection.java | 10 ++-- .../module/hub/section/StackRamSection.java | 2 +- .../hub/section/copy/ExtCodeCopySection.java | 49 +++++++++---------- .../zktracer/module/hub/signals/Signals.java | 20 ++++++-- .../zktracer/runtime/callstack/CallStack.java | 4 +- 6 files changed, 49 insertions(+), 38 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c69b986987..d12f032874 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1103,7 +1103,7 @@ void traceOperation(MessageFrame frame) { } case CONTEXT -> this.addTraceSection( - new ContextLogSection(this, ContextFragment.readCurrentContextData(this))); + new ContextSection(this, ContextFragment.readCurrentContextData(this))); case LOG -> { new LogSection(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java index bf7787ea47..8ed79ff9cf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java @@ -16,11 +16,11 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -public class ContextLogSection extends TraceSection { - public ContextLogSection(Hub hub, TraceFragment... chunks) { - super(hub); - this.addFragmentsAndStack(hub, chunks); +public class ContextSection extends TraceSection { + public ContextSection(Hub hub, ContextFragment fragment) { + super(hub, (short) 3); + this.addFragmentsAndStack(hub, fragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index 1db4f2ccd7..b1e520a627 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -45,7 +45,7 @@ public class StackRamSection extends TraceSection implements PostTransactionDefe final EWord value; public StackRamSection(Hub hub) { - super(hub, (short) (hub.opCode().equals(OpCode.CALLDATALOAD) ? 4 : 3)); + super(hub, (short) 3); this.addStack(hub); this.instruction = hub.opCode(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 761bf7cfb7..3afd5c36b7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -15,12 +15,12 @@ package net.consensys.linea.zktracer.module.hub.section.copy; -import com.slack.api.model.Message; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.none; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; + import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -32,9 +32,6 @@ import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; -import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.none; -import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; - public class ExtCodeCopySection extends TraceSection { public static void appendToTrace(Hub hub) { @@ -62,21 +59,22 @@ public static void appendToTrace(Hub hub) { final Account targetAccount = frame.getWorldUpdater().get(targetAddress); AccountSnapshot accountBefore = - AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + AccountSnapshot.fromAccount( + targetAccount, + frame.isAddressWarm(targetAddress), + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); final short exceptions = hub.pch().exceptions(); // The OOGX case if (outOfGasException(exceptions)) { // the last context row will be added automatically - AccountFragment accountReadingFragment = hub.factories() + AccountFragment accountReadingFragment = + hub.factories() .accountFragment() .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); @@ -91,13 +89,14 @@ public static void appendToTrace(Hub hub) { } AccountSnapshot accountAfter = - AccountSnapshot.fromAccount( - targetAccount, - true, - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); - - AccountFragment accountDoingFragment = hub.factories() + AccountSnapshot.fromAccount( + targetAccount, + true, + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + + AccountFragment accountDoingFragment = + hub.factories() .accountFragment() .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps); @@ -106,14 +105,14 @@ public static void appendToTrace(Hub hub) { // affected by issue #785 if (hub.callStack().current().willRevert()) { DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); AccountFragment undoingAccountFragment = - hub.factories() - .accountFragment() - .make(accountAfter, accountBefore, undoingDomSubStamps); + hub.factories().accountFragment().make(accountAfter, accountBefore, undoingDomSubStamps); extCodeCopySection.addFragment(undoingAccountFragment); } } - public ExtCodeCopySection(Hub hub) { super(hub); } + public ExtCodeCopySection(Hub hub) { + super(hub); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index 8dcffa4f01..67ed7c46a2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -143,21 +143,27 @@ public void prepare(MessageFrame frame, PlatformController platformController, H switch (opCode) { case CALLDATACOPY, CODECOPY -> { this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); } case RETURNDATACOPY -> { this.oob = Exceptions.none(ex) || Exceptions.returnDataCopyFault(ex); this.mxp = - Exceptions.none(ex) || Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex); + Exceptions.none(ex) + || Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); } case EXTCODECOPY -> { final boolean nonzeroSize = !frame.getStackItem(3).isZero(); this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.trm = Exceptions.outOfGasException(ex) || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && nonzeroSize; @@ -172,7 +178,9 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case LOG0, LOG1, LOG2, LOG3, LOG4 -> { this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame @@ -234,7 +242,9 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case REVERT -> { this.mxp = - Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) || Exceptions.none(ex); + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); this.mmu = Exceptions.none(ex) && !frame.getStackItem(1).isZero() diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 9f6c74f971..2109bbdce3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -42,7 +42,9 @@ public final class CallStack { /** a never-pruned-tree of the {@link CallFrame} executed by the {@link Hub} */ private final List frames = - new ArrayList<>(50) { + new ArrayList<>( + 50) { // TODO: PERF as the List of TraceSection, we should have an estimate based on + // gasLimit on the nb of CallFrame a tx might have { add(CallFrame.EMPTY); } From 4a3193fd3215fe75663ca8d4660270dc1dc79fdf Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 2 Jul 2024 18:22:41 +0530 Subject: [PATCH 167/461] spotless --- .../zktracer/module/hub/section/copy/CodeCopySection.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 7ecc3e0138..61f16775b4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -79,9 +79,9 @@ public static void appendToTrace(Hub hub) { if (mxpCall.mxpx) { AccountFragment accountReadingFragment = - hub.factories() - .accountFragment() - .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); + hub.factories() + .accountFragment() + .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); codeCopySection.addFragment(accountReadingFragment); return; From 4e137d9cfb7f7f70fe4d37f10e9a30078159986c Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Tue, 2 Jul 2024 16:06:46 +0300 Subject: [PATCH 168/461] fix: add --stacktrace flag on tests stage in github actions --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 672bc8254d..2421f124f5 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -81,7 +81,7 @@ jobs: # echo $HOME >> $GITHUB_PATH - name: Run unit tests - run: ./gradlew :arithmetization:test + run: ./gradlew :arithmetization:test --stacktrace env: JAVA_OPTS: -Dorg.gradle.daemon=false CORSET_FLAGS: fields,expand,expand,expand From 5ab43be1b83070e980388f056246b00b0a7c8f54 Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Tue, 2 Jul 2024 17:00:20 +0300 Subject: [PATCH 169/461] fix: add missing EvmExtension @ExtendsWith annotations --- .../linea/continoustracing/ContinuousTracerTest.java | 2 ++ .../java/net/consensys/linea/zktracer/ZkTracerTest.java | 3 +++ .../linea/zktracer/module/rlpaddr/TestRlpAddress.java | 6 +++--- .../net/consensys/linea/zktracer/module/stp/StpTest.java | 3 --- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java index 88d09aa525..a1afa29711 100644 --- a/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java @@ -26,6 +26,7 @@ import net.consensys.linea.continoustracing.exception.TraceVerificationException; import net.consensys.linea.corset.CorsetValidator; import net.consensys.linea.zktracer.ZkTracer; +import net.consensys.linea.zktracer.testing.EvmExtension; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.plugin.data.BlockTraceResult; import org.hyperledger.besu.plugin.data.TransactionTraceResult; @@ -38,6 +39,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) +@ExtendWith(EvmExtension.class) public class ContinuousTracerTest { private static final Hash BLOCK_HASH = Hash.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000042"); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java index 1ac111f012..095877bfbb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java @@ -17,8 +17,11 @@ import static org.assertj.core.api.Assertions.assertThat; +import net.consensys.linea.zktracer.testing.EvmExtension; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(EvmExtension.class) public class ZkTracerTest { @Test diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index 4a78d48090..27e247b986 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -26,8 +26,8 @@ import java.util.Random; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.OpCodes; import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyAccount; import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import net.consensys.linea.zktracer.testing.ToyTransaction; @@ -42,7 +42,9 @@ import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(EvmExtension.class) public class TestRlpAddress { private static final int TEST_TX_COUNT = 30; private final Random rnd = new Random(666); @@ -50,8 +52,6 @@ public class TestRlpAddress { @Test @Disabled void test() { - OpCodes.load(); - ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); List txList = new ArrayList<>(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java index 52a9e13cd6..ee155d065f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java @@ -25,7 +25,6 @@ import java.util.Random; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.OpCodes; import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyAccount; @@ -52,7 +51,6 @@ public class StpTest { @Test void testCall() { - OpCodes.load(); ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); List txList = new ArrayList<>(); @@ -78,7 +76,6 @@ void testCall() { @Test void testCreate() { - OpCodes.load(); ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); List txList = new ArrayList<>(); From a06c37a075dfe3f652bff052635b73c2047a7098 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 2 Jul 2024 17:43:39 +0200 Subject: [PATCH 170/461] feat(hub): deferred MMU call in the context of CodeCopy --- .../hub/section/copy/CodeCopySection.java | 47 ++++++++++++------- .../module/hub/section/copy/CopySection.java | 8 ++-- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 61f16775b4..00e7342670 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -19,6 +19,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; @@ -29,29 +30,29 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class CodeCopySection extends TraceSection { +public class CodeCopySection implements PostTransactionDefer { + CodeCopyCommonSection sectionPrequel; + ImcFragment imcFragment; + boolean triggerMmu; - public static void appendToTrace(Hub hub) { - final CodeCopySection codeCopySection = new CodeCopySection(hub); - hub.addTraceSection(codeCopySection); + public CodeCopySection(Hub hub) { + this.sectionPrequel = new CodeCopyCommonSection(hub); + hub.addTraceSection(sectionPrequel); // Miscellaneous row - ImcFragment imcFragment = ImcFragment.empty(hub); - codeCopySection.addFragmentsAndStack(hub, imcFragment); + imcFragment = ImcFragment.empty(hub); + this.sectionPrequel.addFragmentsAndStack(hub, imcFragment); // triggerOob = false // triggerMxp = true MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); boolean xahoy = mxpCall.mxpx || outOfGasException(hub.pch().exceptions()); - final boolean triggerMmu = !xahoy && mxpCall.isMayTriggerNonTrivialMmuOperation(); - if (triggerMmu) { - MmuCall mmuCall = MmuCall.codeCopy(hub); - imcFragment.callMmu(mmuCall); - } // Context row // TODO: use ContextFragment.readContextDataByContextNumber(hub, CN) @@ -59,7 +60,7 @@ public static void appendToTrace(Hub hub) { xahoy ? ContextFragment.executionProvidesEmptyReturnData(hub) : ContextFragment.readCurrentContextData(hub); - codeCopySection.addFragment(contextFragment); + this.sectionPrequel.addFragment(contextFragment); // Account row final MessageFrame frame = hub.messageFrame(); @@ -83,15 +84,29 @@ public static void appendToTrace(Hub hub) { .accountFragment() .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); - codeCopySection.addFragment(accountReadingFragment); + this.sectionPrequel.addFragment(accountReadingFragment); return; } if (!xahoy) { - // ? + // TODO: ? } + + triggerMmu = !xahoy && mxpCall.isMayTriggerNonTrivialMmuOperation(); + hub.defers().postTx(this); } - public CodeCopySection(Hub hub) { - super(hub); + @Override + public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (triggerMmu) { + MmuCall mmuCall = MmuCall.codeCopy(hub); + imcFragment.callMmu(mmuCall); + } + } + + public static class CodeCopyCommonSection extends TraceSection { + public CodeCopyCommonSection(Hub hub) { + super(hub); + // TODO: do we need something else here? + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java index 0ee0e47642..c5e337e943 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java @@ -35,10 +35,10 @@ public CopySection(Hub hub, TraceFragment... chunks) { public static void appendToTrace(Hub hub) { switch (hub.opCode()) { - case OpCode.CALLDATACOPY -> hub.addTraceSection(new CallDataCopySection(hub)); - case OpCode.RETURNDATACOPY -> hub.addTraceSection(new ReturnDataCopySection(hub)); - case OpCode.CODECOPY -> hub.addTraceSection(new CodeCopySection(hub)); - case OpCode.EXTCODECOPY -> hub.addTraceSection(new ExtCodeCopySection(hub)); + case OpCode.CALLDATACOPY -> new CallDataCopySection(hub); + case OpCode.RETURNDATACOPY -> new ReturnDataCopySection(hub); + case OpCode.CODECOPY -> new CodeCopySection(hub); + case OpCode.EXTCODECOPY -> new ExtCodeCopySection(hub); } } } From 91432c96bc5d0e77eb65d62423dc19d681dcc2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 2 Jul 2024 15:20:56 +0200 Subject: [PATCH 171/461] RETURNDATACOPY stub --- .../zktracer/module/hub/section/copy/CopySection.java | 7 ------- .../module/hub/section/copy/ReturnDataCopySection.java | 6 ++---- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java index c5e337e943..77076cb182 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java @@ -26,13 +26,6 @@ public CopySection(Hub hub) { super(hub); } - /* - public CopySection(Hub hub, TraceFragment... chunks) { - super(hub); - this.addFragmentsAndStack(hub, chunks); - } - */ - public static void appendToTrace(Hub hub) { switch (hub.opCode()) { case OpCode.CALLDATACOPY -> new CallDataCopySection(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 5b974f3d4b..ad8499dbb8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -20,8 +20,6 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class ReturnDataCopySection extends TraceSection { - public ReturnDataCopySection(Hub hub, TraceFragment... chunks) { - super(hub); - this.addFragmentsAndStack(hub, chunks); - } + + public ReturnDataCopySection(Hub hub) { super(hub); } } From 5622eebf43f4dc2471e10fd9097f5fc83fbc8122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 3 Jul 2024 17:42:49 +0200 Subject: [PATCH 172/461] fix(defers): naming for defers: scheduling + resolving --- .../linea/zktracer/module/hub/Hub.java | 18 +- .../linea/zktracer/module/hub/TxTrace.java | 2 +- .../module/hub/defer/DeferRegistry.java | 167 +++++++++++++++--- .../module/hub/defer/NextContextDefer.java | 2 +- .../module/hub/defer/PostConflationDefer.java | 2 +- .../module/hub/defer/PostExecDefer.java | 2 +- .../module/hub/defer/PostRollbackDefer.java | 17 ++ .../hub/defer/PostTransactionDefer.java | 2 +- .../module/hub/defer/ReEnterContextDefer.java | 2 +- .../hub/fragment/TransactionFragment.java | 2 +- .../hub/fragment/account/AccountFragment.java | 6 +- .../fragment/scenario/ScenarioFragment.java | 4 +- .../hub/section/CallDataLoadSection.java | 4 +- .../module/hub/section/CreateSection.java | 16 +- .../module/hub/section/LogSection.java | 4 +- .../module/hub/section/StackRamSection.java | 4 +- .../section/TxFinalizationPostTxDefer.java | 2 +- .../hub/section/TxInitializationSection.java | 2 +- .../hub/section/TxSkippedSectionDefers.java | 2 +- .../hub/section/calls/NoCodeCallSection.java | 12 +- .../calls/SmartContractCallSection.java | 14 +- 21 files changed, 210 insertions(+), 76 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index d12f032874..b045fb84c3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -425,7 +425,7 @@ public void traceStartConflation(long blockCount) { public void traceEndConflation(final WorldView world) { this.romLex.determineCodeFragmentIndex(); this.txStack.setCodeFragmentIndex(this); - this.defers.runPostConflation(this, world); + this.defers.resolvePostConflation(this, world); for (Module m : this.modules) { m.traceEndConflation(world); @@ -453,14 +453,14 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { this.pch.reset(); this.state.enter(); this.txStack.enterTransaction(world, tx, transients.block()); - this.defers.postTx(this.state.currentTxTrace()); + this.defers.schedulePostTransaction(this.state.currentTxTrace()); this.enterTransaction(); if (!this.txStack.current().requiresEvmExecution()) { this.state.setProcessingPhase(TX_SKIP); this.state.stamps().incrementHubStamp(); - this.defers.postTx( + this.defers.schedulePostTransaction( new TxSkippedSectionDefers(world, this.txStack.current(), this.transients)); } else { if (this.txStack.current().requiresPrewarming()) { @@ -504,7 +504,7 @@ public void traceEndTransaction( this.state.stamps().incrementHubStamp(); } - this.defers.runPostTx(this, world, tx, isSuccessful); + this.defers.resolvePostTransaction(this, world, tx, isSuccessful); for (Module m : this.modules) { m.traceEndTx(txStack.current()); @@ -613,7 +613,7 @@ public void traceContextEnter(MessageFrame frame) { codeDeploymentNumber, isDeployment); - this.defers.runNextContext(this, frame); + this.defers.resolveWithNextContext(this, frame); for (Module m : this.modules) { m.traceContextEnter(frame); @@ -622,7 +622,7 @@ public void traceContextEnter(MessageFrame frame) { } public void traceContextReEnter(MessageFrame frame) { - this.defers.runReEntry(this, frame); + this.defers.resolveAtReEntry(this, frame); if (this.currentFrame().needsUnlatchingAtReEntry() != null) { this.unlatchStack(frame, this.currentFrame().needsUnlatchingAtReEntry()); this.currentFrame().needsUnlatchingAtReEntry(null); @@ -666,7 +666,7 @@ public void traceContextExit(MessageFrame frame) { this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); if (this.state.getProcessingPhase() != TX_SKIP) { this.state.setProcessingPhase(TX_FINAL); - this.defers.postTx(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); + this.defers.schedulePostTransaction(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); } } } @@ -721,7 +721,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.handleCreate(Words.toAddress(frame.getStackItem(0))); } - this.defers.runPostExec(this, frame, operationResult); + this.defers.resolvePostExecution(this, frame, operationResult); if (this.previousOperationWasCallToEcPrecompile) { this.ecData.getEcDataOperation().returnData(frame.getReturnData()); @@ -1152,7 +1152,7 @@ void traceOperation(MessageFrame frame) { this.addTraceSection(accountSection); } case COPY -> { - CopySection.appendToTrace(this); + CopySection.addTraceSection(this); /* TraceSection copySection = new CopySection(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 29436e0c68..1f7fd8cffa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -94,7 +94,7 @@ public long refundCounter() { } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} /** * Generate the final numeric trace from the accumulated information. diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index ad704e2416..6b0957e309 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -31,10 +31,10 @@ */ public class DeferRegistry { /** A list of actions deferred until the end of the current conflation execution */ - private final List conflationDefers = new ArrayList<>(); + private final List postConflationDefers = new ArrayList<>(); /** A list of actions deferred until the end of the current transaction */ - private final List txDefers = new ArrayList<>(); + private final List postTransactionDefers = new ArrayList<>(); /** A list of actions deferred until the end of the current opcode execution */ private final List postExecDefers = new ArrayList<>(); @@ -45,24 +45,128 @@ public class DeferRegistry { /** A list of actions deferred until the end of the current opcode execution */ private final List> contextReentry = new ArrayList<>(); + private final List>> rollbackDefers = new ArrayList<>(); + + /* + For every context X that is RESPONSIBLE for triggering a rollback i.e. + - executes the REVERT opcode or + - triggers an exceptional halting condition + should have an entry in the rollbackDefers sub-registry. + + < context_number_of_X, List < RollbackDefers > > + + this list should contain all the stuff that will be undone / make explicit + at the precise time where the context reverts. + + Note: we could have such a list for EVERY context, with that list being either + - empty if this context isn't responsible for a rollback + - nonempty and containing everything susceptible to be rolled back by itself o + an ancestor + + Choice + + A does a CALL + B is the callee context + B does a CALL + C is the callee context + C does a CREATE + D is the createe context + D is successful + D exits with exit code 1 (success) + C resumes execution + C fucks up + C now has to undo everything that happened in C and D + C exits with exit code 0 (failure) + B resumes execution + B is successful + B exits with exit code 1 (success) + A resumes execution + A does a CALL + E executes + E is successful + E exits with exit code 1 (success) + A resumes execution + A fucks up + A is responsible for undoing everything done by A, B and E + + for a context you would have the following information + - SUCCESS / FAILURE + - ALREADY_ROLLED_BACK + - better: in stead of saying: 'this context was already rolled back' and remembering + that decision we simply clear the corresponding list; and we always rollback everything + in the descendant contexts + + A does a CALL + enter B + B does a CALL + enter C + C success, exits with exits code 1 + B resumes + B succeeds + A resumes execution + A fucks up + A is responsible for reverting all its descendants (B and C) + + + Extra difficulty: + - nice stuff: + - nonces, warmth, deployments, ... get rolled back with any rollback + - balance transfers get rolled back with child failure + + A does a CREATE with value v + A's balance does bal_A -= v + A's nonce does nonce_A += 1 + B is the createe + B's balance does bal_B += v + B's nonce does nonce_B = 1 + B fucks up + B exits with exit code 0 + bal_A += v + bal_B -= v + nonces stay the same ! for A and B ... + A resumes execution + + if A is rolled back later then its nonce goes back to its initial value "n" + if A isn't rolled back later then its nonce remains at "n + 1" + + directDescendantSelfRevertRegistry + - everytime there is a CALL / CREATE we add 'it' (i.e. that operation) to that sub-registry + - every time a context comes to a halt we need to determine if it + exited with exit code 1 or 0 + - if the exit code is 0 we need to undo the balance transfer + + In other words we should have a LIST (not a tree) of such CALL's / CREATE's + We add items to it with every CALL / CREATE + Everytime we exit a context (special care has to be taken for EOA's / PRECOMPILE's) + we pop the top item of this list + and depending on whether or not the exit code is 1 / 0 we "resolve" that item. + if EXIT_CODE = 1 no resolution is required ( return; ) + if EXIT_CODE = 0 then the balance must be resolved; + - i.e. we need to resolve a CALL_SECTION or a CREATE_SECTION + + This means that + - CallSection must implement the DirectDescendantSelfRevertRegistry + - CreateSection must implement the DirectDescendantSelfRevertRegistry + */ + /** Schedule an action to be executed after the completion of the current opcode. */ - public void nextContext(NextContextDefer latch, int frameId) { - this.contextReentry.add(Pair.of(frameId, latch)); + public void scheduleForContextReEntry(NextContextDefer defer, int frameId) { + this.contextReentry.add(Pair.of(frameId, defer)); } /** Schedule an action to be executed after the completion of the current opcode. */ - public void postExec(PostExecDefer latch) { - this.postExecDefers.add(latch); + public void schedulePostExecution(PostExecDefer defer) { + this.postExecDefers.add(defer); } /** Schedule an action to be executed at the end of the current transaction. */ - public void postTx(PostTransactionDefer defer) { - this.txDefers.add(defer); + public void schedulePostTransaction(PostTransactionDefer defer) { + this.postTransactionDefers.add(defer); } /** Schedule an action to be executed at the end of the current transaction. */ - public void postConflation(PostConflationDefer defer) { - this.conflationDefers.add(defer); + public void schedulePostConflation(PostConflationDefer defer) { + this.postConflationDefers.add(defer); } /** Schedule an action to be executed at the re-entry in the current context. */ @@ -76,12 +180,13 @@ public void reEntry(ReEnterContextDefer defer) { * @param hub a {@link Hub} context * @param frame the new context {@link MessageFrame} */ - public void runNextContext(Hub hub, MessageFrame frame) { + public void resolveWithNextContext(Hub hub, MessageFrame frame) { for (Pair defer : this.contextReentry) { if (hub.currentFrame().parentFrame() == defer.getLeft()) { - defer.getRight().runNextContext(hub, frame); + defer.getRight().resolveWithNextContext(hub, frame); } } + // TODO: we clear everything ?!? not just the one that was just resolved ? this.contextReentry.clear(); } @@ -93,11 +198,11 @@ public void runNextContext(Hub hub, MessageFrame frame) { * @param tx the current {@link Transaction} */ // TODO: should use the TransactionProcessingMetadata - public void runPostTx(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { - for (PostTransactionDefer defer : this.txDefers) { - defer.runPostTx(hub, world, tx, isSuccessful); + public void resolvePostTransaction(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { + for (PostTransactionDefer defer : this.postTransactionDefers) { + defer.resolvePostTransaction(hub, world, tx, isSuccessful); } - this.txDefers.clear(); + this.postTransactionDefers.clear(); } /** @@ -105,11 +210,11 @@ public void runPostTx(Hub hub, WorldView world, Transaction tx, boolean isSucces * * @param hub the {@link Hub} context */ - public void runPostConflation(Hub hub, WorldView world) { - for (PostConflationDefer defer : this.conflationDefers) { - defer.runPostConflation(hub, world); + public void resolvePostConflation(Hub hub, WorldView world) { + for (PostConflationDefer defer : this.postConflationDefers) { + defer.resolvePostConflation(hub, world); } - this.conflationDefers.clear(); + this.postConflationDefers.clear(); } /** @@ -119,9 +224,9 @@ public void runPostConflation(Hub hub, WorldView world) { * @param frame the {@link MessageFrame} of the transaction * @param result the {@link Operation.OperationResult} of the transaction */ - public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult result) { + public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult result) { for (PostExecDefer defer : this.postExecDefers) { - defer.runPostExec(hub, frame, result); + defer.resolvePostExecution(hub, frame, result); } this.postExecDefers.clear(); } @@ -132,10 +237,22 @@ public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult r * @param hub the {@link Hub} context * @param frame the {@link MessageFrame} of the transaction */ - public void runReEntry(Hub hub, MessageFrame frame) { + public void resolveAtReEntry(Hub hub, MessageFrame frame) { for (ReEnterContextDefer defer : this.reEntryDefers) { - defer.runAtReEnter(hub, frame); + defer.resolveAtContextReEntry(hub, frame); } - this.postExecDefers.clear(); + // TODO: make sure this is correct; + // it used to be this.postExecDefers.clear() + // ... obvious mistake ? + this.reEntryDefers.clear(); + // TODO: how would us clearing the reentryDefers not + // fail in case you have e.g. A calls B calls C ? + // When we 're-enter' B after finishing with C wouldn't + // we try to resolve the re-entry business of A ? Which + // is too early ... ? + // Note: this is used for CREATE's, specifically for when + // deployment terminates and we re-enter the creator context ... + // But what if we have nested CREATE's ? + // A creates B, and during deployment B creates C ... ?! } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java index addd0a30eb..307abfa1bf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java @@ -19,5 +19,5 @@ import org.hyperledger.besu.evm.frame.MessageFrame; public interface NextContextDefer { - void runNextContext(Hub hub, MessageFrame frame); + void resolveWithNextContext(Hub hub, MessageFrame frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostConflationDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostConflationDefer.java index b6bef84ddc..18acb9f414 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostConflationDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostConflationDefer.java @@ -25,5 +25,5 @@ public interface PostConflationDefer { * * @param hub the {@link Hub} in which the {@link Transaction} took place */ - void runPostConflation(Hub hub, WorldView world); + void resolvePostConflation(Hub hub, WorldView world); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java index 1e034548b4..20837638c2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java @@ -20,5 +20,5 @@ import org.hyperledger.besu.evm.operation.Operation; public interface PostExecDefer { - void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult); + void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java new file mode 100644 index 0000000000..8c8c3901d6 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java @@ -0,0 +1,17 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.defer; +public interface PostRollbackDefer { +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostTransactionDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostTransactionDefer.java index a95f446d6d..22892be4fd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostTransactionDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostTransactionDefer.java @@ -31,5 +31,5 @@ public interface PostTransactionDefer { * @param state a view onto the current blockchain state * @param tx the {@link Transaction} that just executed */ - void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful); + void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java index 25f167c74a..b907c655be 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java @@ -19,5 +19,5 @@ import org.hyperledger.besu.evm.frame.MessageFrame; public interface ReEnterContextDefer { - void runAtReEnter(final Hub hub, final MessageFrame frame); + void resolveAtContextReEntry(final Hub hub, final MessageFrame frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index 4a44df5b4a..d663df077d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -87,5 +87,5 @@ public Trace trace(Trace trace) { } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index ab90f5e247..4438763553 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -96,7 +96,7 @@ public AccountFragment( this.addressToTrim = addressToTrim; this.domSubStampsSubFragment = domSubStampsSubFragment; - defers.postConflation(this); + defers.schedulePostConflation(this); } @Override @@ -158,10 +158,10 @@ public Trace trace(Trace trace) { } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} @Override - public void runPostConflation(Hub hub, WorldView world) { + public void resolvePostConflation(Hub hub, WorldView world) { this.deploymentNumberInfinity = hub.transients().conflation().deploymentInfo().number(this.oldState.address()); this.existsInfinity = world.get(this.oldState.address()) != null; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 847d7b2427..1a5d25907a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -97,7 +97,7 @@ public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { hub.pch().abortingConditions().any(), hub.pch().failureConditions().any(), Exceptions.invalidCodePrefix(hub.pch().exceptions())); - hub.defers().postTx(r); + hub.defers().schedulePostTransaction(r); return r; } @@ -224,7 +224,7 @@ private void fillPostCallInformation(final Hub hub) { } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { this.fillPostCallInformation(hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index 35c60f0d19..36ee711bb7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -70,11 +70,11 @@ public CallDataLoadSection(Hub hub) { final ContextFragment context = readCurrentContextData(hub); this.addFragment(context); - hub.defers().postTx(this); + hub.defers().schedulePostTransaction(this); } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (Exceptions.none(exception)) { if (Words.clampedToLong(sourceOffset) >= callDataSize) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 6d523350ab..95e80647d8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -90,13 +90,13 @@ public CreateSection( // Will be traced in one (and only one!) of these depending on the hubSuccess of // the operation - hub.defers().postExec(this); - hub.defers().nextContext(this, hub.currentFrame().id()); + hub.defers().schedulePostExecution(this); + hub.defers().scheduleForContextReEntry(this, hub.currentFrame().id()); hub.defers().reEntry(this); } @Override - public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { Address creatorAddress = oldCreatorSnapshot.address(); this.midCreatorSnapshot = AccountSnapshot.fromAccount( @@ -115,14 +115,14 @@ public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult o // Pre-emptively set new* snapshots in case we never enter the child frame. // Will be overwritten if we enter the child frame and runNextContext is explicitly called by // the defer registry. - this.runAtReEnter(hub, frame); + this.resolveAtContextReEntry(hub, frame); } @Override - public void runNextContext(Hub hub, MessageFrame frame) {} + public void resolveWithNextContext(Hub hub, MessageFrame frame) {} @Override - public void runAtReEnter(Hub hub, MessageFrame frame) { + public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { this.createSuccessful = !frame.getStackItem(0).isZero(); Address creatorAddress = oldCreatorSnapshot.address(); @@ -143,7 +143,7 @@ public void runAtReEnter(Hub hub, MessageFrame frame) { } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); final boolean creatorWillRevert = hub.callStack().getById(this.creatorContextId).hasReverted(); @@ -166,7 +166,7 @@ public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSucces // 0)) ; - this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); + this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); this.addFragmentsWithoutStack(scenarioFragment); if (Exceptions.staticFault(this.exceptions)) { this.addFragmentsWithoutStack( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index 3d2163ad55..4542df5c36 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -61,11 +61,11 @@ public LogSection(Hub hub) { miscFragment = ImcFragment.empty(hub).callMxp(mxpCall); this.sectionPrequel.addFragment(miscFragment); - hub.defers().postTx(this); + hub.defers().schedulePostTransaction(this); } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (!isStatic) { if (!this.logData.reverted()) { hub.state.stamps().incrementLogStamp(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index b1e520a627..eae04e6d21 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -66,11 +66,11 @@ public StackRamSection(Hub hub) { this.addFragment(imcFragment); - hub.defers().postTx(this); + hub.defers().schedulePostTransaction(this); } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (Exceptions.none(exception)) { switch (instruction) { case MSTORE -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java index 57c8f51ade..c6f68703de 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java @@ -69,7 +69,7 @@ public TxFinalizationPostTxDefer(Hub hub, WorldView world) { } @Override - public void runPostTx(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { final DeploymentInfo depInfo = hub.transients().conflation().deploymentInfo(); final Address fromAddress = fromAccountBeforeTxFinalization.address(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index e6a9e19086..922b63d2ae 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -89,7 +89,7 @@ public TxInitializationSection(Hub hub, WorldView world) { DomSubStampsSubFragment.standardDomSubStamps(hub, 1); final TransactionFragment txFragment = TransactionFragment.prepare(tx); - hub.defers().postTx(txFragment); + hub.defers().schedulePostTransaction(txFragment); final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java index cc7986ffd4..6cea3d9e5f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java @@ -76,7 +76,7 @@ public TxSkippedSectionDefers( } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final Address fromAddress = this.oldFromAccount.address(); final Address toAddress = this.oldToAccount.address(); final Address minerAddress = this.txMetadata.getCoinbase(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index 83c1622fba..4bf194b610 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -78,20 +78,20 @@ public NoCodeCallSection( hub, precompileInvocation, this.callerCallFrame.id(), this.calledCallFrameId); this.addStack(hub); - hub.defers().postExec(this); - hub.defers().postTx(this); + hub.defers().schedulePostExecution(this); + hub.defers().schedulePostTransaction(this); hub.defers().reEntry(this); } @Override - public void runAtReEnter(Hub hub, MessageFrame frame) { + public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { // The precompile lines will read the return data, so they need to be added after re-entry. this.maybePrecompileLines = this.precompileInvocation.map(p -> PrecompileLinesGenerator.generateFor(hub, p)); } @Override - public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { this.callSuccessful = !frame.getStackItem(0).isZero(); final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); @@ -113,10 +113,10 @@ public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult o } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); - this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); + this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); this.addFragmentsWithoutStack( this.scenarioFragment, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index cb629fcfc1..930c8c59f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -71,13 +71,13 @@ public SmartContractCallSection( this.addStack(hub); - hub.defers().postExec(this); - hub.defers().nextContext(this, hub.currentFrame().id()); - hub.defers().postTx(this); + hub.defers().schedulePostExecution(this); + hub.defers().scheduleForContextReEntry(this, hub.currentFrame().id()); + hub.defers().schedulePostTransaction(this); } @Override - public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); final Address calledAddress = preCallCalleeAccountSnapshot.address(); @@ -98,7 +98,7 @@ public void runPostExec(Hub hub, MessageFrame frame, Operation.OperationResult o } @Override - public void runNextContext(Hub hub, MessageFrame frame) { + public void resolveWithNextContext(Hub hub, MessageFrame frame) { final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); final Address calledAddress = preCallCalleeAccountSnapshot.address(); @@ -119,11 +119,11 @@ public void runNextContext(Hub hub, MessageFrame frame) { } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); final CallFrame calledCallFrame = hub.callStack().getById(this.calledCallFrameId); - this.scenarioFragment.runPostTx(hub, state, tx, isSuccessful); + this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); DomSubStampsSubFragment firstCallerDoingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 0); From 56ce2db761e4cbbb0948e08e69d364773bae0842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 3 Jul 2024 17:46:33 +0200 Subject: [PATCH 173/461] spotless --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 3 ++- .../net/consensys/linea/zktracer/module/hub/TxTrace.java | 3 ++- .../linea/zktracer/module/hub/defer/DeferRegistry.java | 3 ++- .../linea/zktracer/module/hub/defer/PostRollbackDefer.java | 4 ++-- .../zktracer/module/hub/fragment/TransactionFragment.java | 3 ++- .../module/hub/fragment/account/AccountFragment.java | 3 ++- .../module/hub/fragment/scenario/ScenarioFragment.java | 3 ++- .../zktracer/module/hub/section/CallDataLoadSection.java | 3 ++- .../linea/zktracer/module/hub/section/CreateSection.java | 6 ++++-- .../linea/zktracer/module/hub/section/LogSection.java | 3 ++- .../linea/zktracer/module/hub/section/StackRamSection.java | 3 ++- .../module/hub/section/TxFinalizationPostTxDefer.java | 3 ++- .../zktracer/module/hub/section/TxSkippedSectionDefers.java | 3 ++- .../module/hub/section/calls/NoCodeCallSection.java | 6 ++++-- .../module/hub/section/calls/SmartContractCallSection.java | 6 ++++-- .../module/hub/section/copy/ReturnDataCopySection.java | 5 +++-- 16 files changed, 39 insertions(+), 21 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index b045fb84c3..702e47f2e6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -666,7 +666,8 @@ public void traceContextExit(MessageFrame frame) { this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); if (this.state.getProcessingPhase() != TX_SKIP) { this.state.setProcessingPhase(TX_FINAL); - this.defers.schedulePostTransaction(new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); + this.defers.schedulePostTransaction( + new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 1f7fd8cffa..090df998fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -94,7 +94,8 @@ public long refundCounter() { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} /** * Generate the final numeric trace from the accumulated information. diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 6b0957e309..1d60fa65d8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -198,7 +198,8 @@ public void resolveWithNextContext(Hub hub, MessageFrame frame) { * @param tx the current {@link Transaction} */ // TODO: should use the TransactionProcessingMetadata - public void resolvePostTransaction(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { for (PostTransactionDefer defer : this.postTransactionDefers) { defer.resolvePostTransaction(hub, world, tx, isSuccessful); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java index 8c8c3901d6..576c0b08fa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java @@ -13,5 +13,5 @@ * SPDX-License-Identifier: Apache-2.0 */ package net.consensys.linea.zktracer.module.hub.defer; -public interface PostRollbackDefer { -} + +public interface PostRollbackDefer {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index d663df077d..d602dbcc1d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -87,5 +87,6 @@ public Trace trace(Trace trace) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 4438763553..a8b38fb9cf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -158,7 +158,8 @@ public Trace trace(Trace trace) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} @Override public void resolvePostConflation(Hub hub, WorldView world) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 1a5d25907a..92f48956ff 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -224,7 +224,8 @@ private void fillPostCallInformation(final Hub hub) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { this.fillPostCallInformation(hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index 36ee711bb7..1a917738e7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -74,7 +74,8 @@ public CallDataLoadSection(Hub hub) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (Exceptions.none(exception)) { if (Words.clampedToLong(sourceOffset) >= callDataSize) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 95e80647d8..408b57f6c0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -96,7 +96,8 @@ public CreateSection( } @Override - public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { Address creatorAddress = oldCreatorSnapshot.address(); this.midCreatorSnapshot = AccountSnapshot.fromAccount( @@ -143,7 +144,8 @@ public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); final boolean creatorWillRevert = hub.callStack().getById(this.creatorContextId).hasReverted(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index 4542df5c36..d47ff0a864 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -65,7 +65,8 @@ public LogSection(Hub hub) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (!isStatic) { if (!this.logData.reverted()) { hub.state.stamps().incrementLogStamp(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index eae04e6d21..f7b560c9be 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -70,7 +70,8 @@ public StackRamSection(Hub hub) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (Exceptions.none(exception)) { switch (instruction) { case MSTORE -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java index c6f68703de..8e36783ce4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java @@ -69,7 +69,8 @@ public TxFinalizationPostTxDefer(Hub hub, WorldView world) { } @Override - public void resolvePostTransaction(Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { final DeploymentInfo depInfo = hub.transients().conflation().deploymentInfo(); final Address fromAddress = fromAccountBeforeTxFinalization.address(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java index 6cea3d9e5f..5524dff3b6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java @@ -76,7 +76,8 @@ public TxSkippedSectionDefers( } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final Address fromAddress = this.oldFromAccount.address(); final Address toAddress = this.oldToAccount.address(); final Address minerAddress = this.txMetadata.getCoinbase(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index 4bf194b610..13d8d3956a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -91,7 +91,8 @@ public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { } @Override - public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { this.callSuccessful = !frame.getStackItem(0).isZero(); final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); @@ -113,7 +114,8 @@ public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.Operatio } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index 930c8c59f3..4de0f0d78c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -77,7 +77,8 @@ public SmartContractCallSection( } @Override - public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); final Address calledAddress = preCallCalleeAccountSnapshot.address(); @@ -119,7 +120,8 @@ public void resolveWithNextContext(Hub hub, MessageFrame frame) { } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); final CallFrame calledCallFrame = hub.callStack().getById(this.calledCallFrameId); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index ad8499dbb8..c72c09d4f9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -16,10 +16,11 @@ package net.consensys.linea.zktracer.module.hub.section.copy; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class ReturnDataCopySection extends TraceSection { - public ReturnDataCopySection(Hub hub) { super(hub); } + public ReturnDataCopySection(Hub hub) { + super(hub); + } } From 8e4eb8875b65ab1566b5c9aff7b75fbfed6bb922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 6 Jul 2024 12:38:22 +0200 Subject: [PATCH 174/461] feat(defers): post roll back defers (WIP) --- .../module/hub/defer/DeferRegistry.java | 134 ++++-------------- .../module/hub/defer/PostRollbackDefer.java | 7 +- .../zktracer/runtime/callstack/CallStack.java | 2 +- 3 files changed, 38 insertions(+), 105 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 1d60fa65d8..d7ce31996e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -16,13 +16,18 @@ package net.consensys.linea.zktracer.module.hub.defer; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.runtime.callstack.CallStack; import org.apache.commons.lang3.tuple.Pair; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; +import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.evm.worldstate.WorldView; /** @@ -45,109 +50,10 @@ public class DeferRegistry { /** A list of actions deferred until the end of the current opcode execution */ private final List> contextReentry = new ArrayList<>(); - private final List>> rollbackDefers = new ArrayList<>(); - - /* - For every context X that is RESPONSIBLE for triggering a rollback i.e. - - executes the REVERT opcode or - - triggers an exceptional halting condition - should have an entry in the rollbackDefers sub-registry. - - < context_number_of_X, List < RollbackDefers > > - - this list should contain all the stuff that will be undone / make explicit - at the precise time where the context reverts. - - Note: we could have such a list for EVERY context, with that list being either - - empty if this context isn't responsible for a rollback - - nonempty and containing everything susceptible to be rolled back by itself o - an ancestor - - Choice - - A does a CALL - B is the callee context - B does a CALL - C is the callee context - C does a CREATE - D is the createe context - D is successful - D exits with exit code 1 (success) - C resumes execution - C fucks up - C now has to undo everything that happened in C and D - C exits with exit code 0 (failure) - B resumes execution - B is successful - B exits with exit code 1 (success) - A resumes execution - A does a CALL - E executes - E is successful - E exits with exit code 1 (success) - A resumes execution - A fucks up - A is responsible for undoing everything done by A, B and E - - for a context you would have the following information - - SUCCESS / FAILURE - - ALREADY_ROLLED_BACK - - better: in stead of saying: 'this context was already rolled back' and remembering - that decision we simply clear the corresponding list; and we always rollback everything - in the descendant contexts - - A does a CALL - enter B - B does a CALL - enter C - C success, exits with exits code 1 - B resumes - B succeeds - A resumes execution - A fucks up - A is responsible for reverting all its descendants (B and C) - - - Extra difficulty: - - nice stuff: - - nonces, warmth, deployments, ... get rolled back with any rollback - - balance transfers get rolled back with child failure - - A does a CREATE with value v - A's balance does bal_A -= v - A's nonce does nonce_A += 1 - B is the createe - B's balance does bal_B += v - B's nonce does nonce_B = 1 - B fucks up - B exits with exit code 0 - bal_A += v - bal_B -= v - nonces stay the same ! for A and B ... - A resumes execution - - if A is rolled back later then its nonce goes back to its initial value "n" - if A isn't rolled back later then its nonce remains at "n + 1" - - directDescendantSelfRevertRegistry - - everytime there is a CALL / CREATE we add 'it' (i.e. that operation) to that sub-registry - - every time a context comes to a halt we need to determine if it - exited with exit code 1 or 0 - - if the exit code is 0 we need to undo the balance transfer - - In other words we should have a LIST (not a tree) of such CALL's / CREATE's - We add items to it with every CALL / CREATE - Everytime we exit a context (special care has to be taken for EOA's / PRECOMPILE's) - we pop the top item of this list - and depending on whether or not the exit code is 1 / 0 we "resolve" that item. - if EXIT_CODE = 1 no resolution is required ( return; ) - if EXIT_CODE = 0 then the balance must be resolved; - - i.e. we need to resolve a CALL_SECTION or a CREATE_SECTION - - This means that - - CallSection must implement the DirectDescendantSelfRevertRegistry - - CreateSection must implement the DirectDescendantSelfRevertRegistry - */ + /** A collection of actions whose execution is deferred to a hypothetical + * future rollback. This collection maps a context to all actions that + * would have to be done if that execution context were to be rolled back. */ + private final Map> rollbackDefers = new HashMap<>(); /** Schedule an action to be executed after the completion of the current opcode. */ public void scheduleForContextReEntry(NextContextDefer defer, int frameId) { @@ -256,4 +162,26 @@ public void resolveAtReEntry(Hub hub, MessageFrame frame) { // But what if we have nested CREATE's ? // A creates B, and during deployment B creates C ... ?! } + + /* + resolveAfterRollback should be invoked when precisely after a rollback + was acted upon in terms of rolling back modifications to + - state + - accrued state + but the caller (or creator), if present, hasn't resumed execution yet. + In particular the "current frame" is expected to be the frame responsible + for the rollback. + */ + public void resolvePostRollback(Hub hub, WorldState worldState, CallFrame frameToRollBack) { + int currentId = frameToRollBack.id(); + for (PostRollbackDefer defer: hub.defers().rollbackDefers.get(currentId)) { + defer.resolvePostRollback(hub, worldState); + } + hub.defers().rollbackDefers.get(currentId).clear(); + + CallStack callStack = hub.callStack(); + hub.currentFrame().childFrames().stream() + .map(callStack::getById) + .forEach(frame -> resolvePostRollback(hub, worldState, frame)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java index 576c0b08fa..25e1051e51 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java @@ -14,4 +14,9 @@ */ package net.consensys.linea.zktracer.module.hub.defer; -public interface PostRollbackDefer {} +import net.consensys.linea.zktracer.module.hub.Hub; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public interface PostRollbackDefer { + void resolvePostRollback(Hub hub, WorldView worldView); +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 2109bbdce3..8c3a33f30b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -41,7 +41,7 @@ public final class CallStack { static final int MAX_CALLSTACK_SIZE = 1024; /** a never-pruned-tree of the {@link CallFrame} executed by the {@link Hub} */ - private final List frames = + @Getter private final List frames = new ArrayList<>( 50) { // TODO: PERF as the List of TraceSection, we should have an estimate based on // gasLimit on the nb of CallFrame a tx might have From 99bef100d9dfe68f0544b8f57d3c7a0909b8976b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 8 Jul 2024 14:46:46 +0200 Subject: [PATCH 175/461] fix(ACC): various - extraction from Hub.java - integration with rollbackDefers --- .../linea/zktracer/module/hub/Hub.java | 48 +------- .../module/hub/defer/DeferRegistry.java | 50 ++++---- .../module/hub/defer/PostRollbackDefer.java | 11 +- .../module/hub/section/AccountSection.java | 107 +++++++++++++++++- .../zktracer/runtime/callstack/CallStack.java | 3 +- 5 files changed, 148 insertions(+), 71 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 702e47f2e6..47d1b745b1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -56,7 +56,6 @@ import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; -import net.consensys.linea.zktracer.module.hub.section.copy.CopySection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -640,8 +639,10 @@ public void traceContextExit(MessageFrame frame) { DeploymentExceptions contextExceptions = DeploymentExceptions.fromFrame(this.currentFrame(), frame); this.currentTraceSection().setContextExceptions(contextExceptions); + if (contextExceptions.any()) { this.callStack.revert(this.state.stamps().hub()); + this.defers.resolvePostRollback(this, frame, this.currentFrame()); } this.callStack.exit(); @@ -1110,52 +1111,13 @@ void traceOperation(MessageFrame frame) { new LogSection(this); } case ACCOUNT -> { - TraceSection accountSection = new AccountSection(this); - if (this.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { - accountSection.addFragment(ContextFragment.readCurrentContextData(this)); - } - - final Bytes rawTargetAddress = - switch (this.currentFrame().opCode()) { - case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); - default -> this.currentFrame().accountAddress(); - }; - final Address targetAddress = Words.toAddress(rawTargetAddress); - final Account targetAccount = frame.getWorldUpdater().get(targetAddress); - final AccountSnapshot accountBefore = - AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - final AccountSnapshot accountAfter = - AccountSnapshot.fromAccount( - targetAccount, - true, - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - final DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this, 0); - accountSection.addFragment( - this.factories - .accountFragment() - .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps)); - - if (this.currentFrame().willRevert()) { - final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); - accountSection.addFragment( - this.factories - .accountFragment() - .make(accountBefore, accountAfter, undoingDomSubStamps)); - } - - this.addTraceSection(accountSection); + final AccountSection accountSection = new AccountSection(this); + accountSection.appendToTrace(this); } case COPY -> { - CopySection.addTraceSection(this); /* + CopySection.addTraceSection(this); TraceSection copySection = new CopySection(this); if (!this.opCode().equals(OpCode.RETURNDATACOPY) && !this.opCode().equals(OpCode.CALLDATACOPY)) { final Bytes rawTargetAddress = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index d7ce31996e..44abbc66c1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -27,7 +27,6 @@ import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.WorldState; import org.hyperledger.besu.evm.worldstate.WorldView; /** @@ -50,10 +49,12 @@ public class DeferRegistry { /** A list of actions deferred until the end of the current opcode execution */ private final List> contextReentry = new ArrayList<>(); - /** A collection of actions whose execution is deferred to a hypothetical - * future rollback. This collection maps a context to all actions that - * would have to be done if that execution context were to be rolled back. */ - private final Map> rollbackDefers = new HashMap<>(); + /** + * A collection of actions whose execution is deferred to a hypothetical future rollback. This + * collection maps a context to all actions that would have to be done if that execution context + * were to be rolled back. + */ + private final Map> rollbackDefers = new HashMap<>(); /** Schedule an action to be executed after the completion of the current opcode. */ public void scheduleForContextReEntry(NextContextDefer defer, int frameId) { @@ -80,6 +81,10 @@ public void reEntry(ReEnterContextDefer defer) { this.reEntryDefers.add(defer); } + public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame) { + this.rollbackDefers.get(callFrame).add(defer); + } + /** * Trigger the execution of the actions deferred to the next context. * @@ -163,25 +168,28 @@ public void resolveAtReEntry(Hub hub, MessageFrame frame) { // A creates B, and during deployment B creates C ... ?! } - /* - resolveAfterRollback should be invoked when precisely after a rollback - was acted upon in terms of rolling back modifications to - - state - - accrued state - but the caller (or creator), if present, hasn't resumed execution yet. - In particular the "current frame" is expected to be the frame responsible - for the rollback. + /** + * Should be invoked when precisely after a rollback was acted upon in terms of rolling back + * modifications to WORLD STATE and ACCRUED STATE but the caller (or creator), if present, hasn't + * resumed execution yet, and if there isn't one because this is the root context of the + * transaction, we haven't entered the "transaction finalization phase." + * + *

Note that the "current messageFrame" is expected to STILL BE the messageFrame responsible + * for the rollback. */ - public void resolvePostRollback(Hub hub, WorldState worldState, CallFrame frameToRollBack) { - int currentId = frameToRollBack.id(); - for (PostRollbackDefer defer: hub.defers().rollbackDefers.get(currentId)) { - defer.resolvePostRollback(hub, worldState); + public void resolvePostRollback( + final Hub hub, final MessageFrame messageFrame, CallFrame currentCallFrame) { + + // roll back current context + for (PostRollbackDefer defer : hub.defers().rollbackDefers.get(currentCallFrame)) { + defer.resolvePostRollback(hub, messageFrame, currentCallFrame); } - hub.defers().rollbackDefers.get(currentId).clear(); + hub.defers().rollbackDefers.get(currentCallFrame).clear(); + // recursively roll back child call frames CallStack callStack = hub.callStack(); - hub.currentFrame().childFrames().stream() - .map(callStack::getById) - .forEach(frame -> resolvePostRollback(hub, worldState, frame)); + currentCallFrame.childFrames().stream() + .map(callStack::getById) + .forEach(childCallFrame -> resolvePostRollback(hub, messageFrame, childCallFrame)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java index 25e1051e51..ee0d1e718c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostRollbackDefer.java @@ -15,8 +15,15 @@ package net.consensys.linea.zktracer.module.hub.defer; import net.consensys.linea.zktracer.module.hub.Hub; -import org.hyperledger.besu.evm.worldstate.WorldView; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.hyperledger.besu.evm.frame.MessageFrame; + +// import org.hyperledger.besu.evm.worldstate.WorldView; public interface PostRollbackDefer { - void resolvePostRollback(Hub hub, WorldView worldView); + /** + * @param messageFrame access point to world state & accrued state + * @param callFrame reference to call frame whose actions are to be undone + */ + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 387b6f49f3..5ca291cd9c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -15,12 +15,111 @@ package net.consensys.linea.zktracer.module.hub.section; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; -public class AccountSection extends TraceSection { - public AccountSection(Hub hub, TraceFragment... chunks) { +public class AccountSection extends TraceSection implements PostRollbackDefer { + + final Bytes rawTargetAddress; + final Address targetAddress; + final boolean intialWarmth; + final AccountSnapshot accountSnapshotBefore; + final AccountSnapshot accountSnapshotAfter; + + public void appendToTrace(Hub hub) { + + hub.addTraceSection(this); + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + + if (hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { + this.addFragment(ContextFragment.readCurrentContextData(hub)); + } + + final DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + + AccountFragment doingAccountFragment = + hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE) + ? hub.factories().accountFragment().make(this.accountSnapshotBefore, this.accountSnapshotAfter, doingDomSubStamps) + : hub.factories().accountFragment().makeWithTrm(this.accountSnapshotBefore, this.accountSnapshotAfter, this.rawTargetAddress, doingDomSubStamps); + + this.addFragment(doingAccountFragment); + } + + public AccountSection(Hub hub) { super(hub); - this.addFragmentsAndStack(hub, chunks); + this.addFragmentsAndStack(hub); + + MessageFrame frame = hub.messageFrame(); + this.rawTargetAddress = + switch (hub.opCode()) { + case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); + case SELFBALANCE -> frame.getRecipientAddress(); + case CODESIZE -> frame.getContractAddress(); + default -> throw new RuntimeException("invalid opcode"); + }; + + this.targetAddress = Words.toAddress(this.rawTargetAddress); + this.intialWarmth = frame.isAddressWarm(targetAddress); + this.accountSnapshotBefore = + AccountSnapshot.fromAccount( + getTargetAccount(hub), + this.intialWarmth, + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + this.accountSnapshotAfter = + AccountSnapshot.fromAccount( + getTargetAccount(hub), + true, // QUESTION: is this true even if we revert with the instruction ? ANSWER: yes. + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + } + + private Account getTargetAccount(Hub hub) { + return hub.messageFrame().getWorldUpdater().get(targetAddress); + } + + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + + final DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); + + final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(targetAddress); + final boolean deploymentStatusAtRollback = hub.transients().conflation().deploymentInfo().isDeploying(targetAddress); + AccountSnapshot revertFrom = new AccountSnapshot( + this.accountSnapshotAfter.address(), + this.accountSnapshotAfter.nonce(), // TODO: this will blow up! + this.accountSnapshotAfter.balance(), + this.accountSnapshotAfter.isWarm(), + this.accountSnapshotAfter.code(), + deploymentNumberAtRollback, + deploymentStatusAtRollback + ); + + AccountSnapshot revertTo = new AccountSnapshot( + this.accountSnapshotBefore.address(), + this.accountSnapshotBefore.nonce(), // TODO: this will blow up! + this.accountSnapshotBefore.balance(), + this.accountSnapshotBefore.isWarm(), + this.accountSnapshotBefore.code(), + deploymentNumberAtRollback, + deploymentStatusAtRollback + ); + + this.addFragment( + hub.factories() + .accountFragment() + .make(revertFrom, revertTo, undoingDomSubStamps)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 8c3a33f30b..1ecf90cc3f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -41,7 +41,8 @@ public final class CallStack { static final int MAX_CALLSTACK_SIZE = 1024; /** a never-pruned-tree of the {@link CallFrame} executed by the {@link Hub} */ - @Getter private final List frames = + @Getter + private final List frames = new ArrayList<>( 50) { // TODO: PERF as the List of TraceSection, we should have an estimate based on // gasLimit on the nb of CallFrame a tx might have From b8ac3008cbdcf1e2d14b60afe31b13856b9fd64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 8 Jul 2024 17:43:02 +0200 Subject: [PATCH 176/461] fix(storage): compatible with postRollbackDefers --- .../linea/zktracer/module/hub/Hub.java | 6 +- .../module/hub/section/AccountSection.java | 78 ++++++----- .../module/hub/section/SloadSection.java | 126 ++++++++--------- .../module/hub/section/SstoreSection.java | 132 +++++++++--------- .../module/hub/signals/Exceptions.java | 22 +-- 5 files changed, 189 insertions(+), 175 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 47d1b745b1..7b4745a1a4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1187,10 +1187,12 @@ void traceOperation(MessageFrame frame) { case STORAGE -> { switch (this.currentFrame().opCode()) { case SSTORE -> { - SstoreSection.appendSectionTo(this, frame.getWorldUpdater()); + final SstoreSection sstoreSection = new SstoreSection(this, frame.getWorldUpdater()); + sstoreSection.populateSection(this, frame.getWorldUpdater()); } case SLOAD -> { - SloadSection.appendSectionTo(this, frame.getWorldUpdater()); + final SloadSection sloadSection = new SloadSection(this, frame.getWorldUpdater()); + sloadSection.populateSection(this, frame.getWorldUpdater()); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 5ca291cd9c..30abd9a22f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -47,12 +47,20 @@ public void appendToTrace(Hub hub) { } final DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); AccountFragment doingAccountFragment = - hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE) - ? hub.factories().accountFragment().make(this.accountSnapshotBefore, this.accountSnapshotAfter, doingDomSubStamps) - : hub.factories().accountFragment().makeWithTrm(this.accountSnapshotBefore, this.accountSnapshotAfter, this.rawTargetAddress, doingDomSubStamps); + hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE) + ? hub.factories() + .accountFragment() + .make(this.accountSnapshotBefore, this.accountSnapshotAfter, doingDomSubStamps) + : hub.factories() + .accountFragment() + .makeWithTrm( + this.accountSnapshotBefore, + this.accountSnapshotAfter, + this.rawTargetAddress, + doingDomSubStamps); this.addFragment(doingAccountFragment); } @@ -63,63 +71,67 @@ public AccountSection(Hub hub) { MessageFrame frame = hub.messageFrame(); this.rawTargetAddress = - switch (hub.opCode()) { - case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); - case SELFBALANCE -> frame.getRecipientAddress(); - case CODESIZE -> frame.getContractAddress(); - default -> throw new RuntimeException("invalid opcode"); - }; + switch (hub.opCode()) { + case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); + case SELFBALANCE -> frame.getRecipientAddress(); + case CODESIZE -> frame.getContractAddress(); + default -> throw new RuntimeException("invalid opcode"); + }; this.targetAddress = Words.toAddress(this.rawTargetAddress); this.intialWarmth = frame.isAddressWarm(targetAddress); this.accountSnapshotBefore = - AccountSnapshot.fromAccount( - getTargetAccount(hub), - this.intialWarmth, - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + AccountSnapshot.fromAccount( + getTargetAccount(hub), + this.intialWarmth, + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); this.accountSnapshotAfter = - AccountSnapshot.fromAccount( - getTargetAccount(hub), - true, // QUESTION: is this true even if we revert with the instruction ? ANSWER: yes. - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + AccountSnapshot.fromAccount( + getTargetAccount(hub), + true, // QUESTION: is this true even if we revert with the instruction ? ANSWER: yes. + hub.transients().conflation().deploymentInfo().number(targetAddress), + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); } private Account getTargetAccount(Hub hub) { return hub.messageFrame().getWorldUpdater().get(targetAddress); } + // TODO: make sure the resolvePostRollback method + // gets called before the final context row is + // added; simplest solution: have that final context + // row in a separate list. public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); - - final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(targetAddress); - final boolean deploymentStatusAtRollback = hub.transients().conflation().deploymentInfo().isDeploying(targetAddress); - AccountSnapshot revertFrom = new AccountSnapshot( + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); + + final int deploymentNumberAtRollback = + hub.transients().conflation().deploymentInfo().number(targetAddress); + final boolean deploymentStatusAtRollback = + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress); + AccountSnapshot revertFrom = + new AccountSnapshot( this.accountSnapshotAfter.address(), this.accountSnapshotAfter.nonce(), // TODO: this will blow up! this.accountSnapshotAfter.balance(), this.accountSnapshotAfter.isWarm(), this.accountSnapshotAfter.code(), deploymentNumberAtRollback, - deploymentStatusAtRollback - ); + deploymentStatusAtRollback); - AccountSnapshot revertTo = new AccountSnapshot( + AccountSnapshot revertTo = + new AccountSnapshot( this.accountSnapshotBefore.address(), this.accountSnapshotBefore.nonce(), // TODO: this will blow up! this.accountSnapshotBefore.balance(), this.accountSnapshotBefore.isWarm(), this.accountSnapshotBefore.code(), deploymentNumberAtRollback, - deploymentStatusAtRollback - ); + deploymentStatusAtRollback); this.addFragment( - hub.factories() - .accountFragment() - .make(revertFrom, revertTo, undoingDomSubStamps)); + hub.factories().accountFragment().make(revertFrom, revertTo, undoingDomSubStamps)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 28b992c4d8..b8b51bd75a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -17,102 +17,102 @@ import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; @Getter -public class SloadSection extends TraceSection { +public class SloadSection extends TraceSection implements PostRollbackDefer { + final Address address; + final int deploymentNumber; + final Bytes32 storageKey; + final boolean incomingWarmth; + final EWord valueOriginal; + final EWord valueCurrent; final WorldView world; + final short exceptions; - private SloadSection(Hub hub, WorldView world) { + public SloadSection(Hub hub, WorldView world) { super(hub); this.world = world; - } - - public static void appendSectionTo(Hub hub, WorldView world) { + this.address = hub.messageFrame().getRecipientAddress(); + this.deploymentNumber = hub.currentFrame().accountDeploymentNumber(); + this.storageKey = Bytes32.leftPad(hub.messageFrame().getStackItem(0)); + this.incomingWarmth = hub.messageFrame().getWarmedUpStorage().contains(address, storageKey); + this.valueOriginal = + EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); + this.valueCurrent = EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); + this.exceptions = hub.pch().exceptions(); - final SloadSection sloadSection = new SloadSection(hub, world); - hub.addTraceSection(sloadSection); + hub.addTraceSection(this); + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + } - final Address address = hub.messageFrame().getRecipientAddress(); - final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); - final Bytes32 storageKey = Bytes32.leftPad(hub.messageFrame().getStackItem(0)); - final EWord valueOriginal = - EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); - final EWord valueCurrent = - EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); + public void populateSection(Hub hub, WorldView world) { + // NOTE: SLOAD can only trigger + // - stackUnderflowException + // - outOfGasException + // in the present case we don't have a stack exception ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); ImcFragment miscFragmentForSload = ImcFragment.empty(hub); - StorageFragment doingSload = - doingSload(hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent); - - sloadSection.addFragmentsAndStack(hub, readCurrentContext, miscFragmentForSload, doingSload); - - final boolean outOfGasException = Exceptions.outOfGasException(hub.pch().exceptions()); - final boolean contextWillRevert = hub.callStack().current().willRevert(); - - if (outOfGasException || contextWillRevert) { - - final StorageFragment undoingSload = - undoingSload(hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent); + StorageFragment doingSload = doingSload(hub); - // TODO: make sure we trace a context when there is an exception - sloadSection.addFragment(undoingSload); - } + this.addFragmentsAndStack(hub, readCurrentContext, miscFragmentForSload, doingSload); } - private static StorageFragment doingSload( - Hub hub, - Address address, - int deploymentNumber, - Bytes32 storageKey, - EWord valueOriginal, - EWord valueCurrent) { - - final boolean incomingWarmth = - hub.messageFrame().getWarmedUpStorage().contains(address, storageKey); + private StorageFragment doingSload(Hub hub) { return new StorageFragment( hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), - valueOriginal, - valueCurrent, - valueCurrent, - incomingWarmth, + new State.StorageSlotIdentifier( + this.address, this.deploymentNumber, EWord.of(this.storageKey)), + this.valueOriginal, + this.valueCurrent, + this.valueCurrent, + this.incomingWarmth, true, DomSubStampsSubFragment.standardDomSubStamps(hub, 0), hub.state.firstAndLastStorageSlotOccurrences.size()); } - private static StorageFragment undoingSload( - Hub hub, - Address address, - int deploymentNumber, - Bytes32 storageKey, - EWord valueOriginal, - EWord valueCurrent) { + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - final boolean initiallyIncomingWarmth = - hub.messageFrame().getWarmedUpStorage().contains(address, storageKey); + if (!this.undoingRequired()) { + return; + } - return new StorageFragment( - hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), - valueOriginal, - valueCurrent, - valueCurrent, - true, - initiallyIncomingWarmth, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), - hub.state.firstAndLastStorageSlotOccurrences.size()); + final DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); + + final StorageFragment undoingSloadStorageFragment = + new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + this.address, this.deploymentNumber, EWord.of(this.storageKey)), + this.valueOriginal, + this.valueCurrent, + this.valueCurrent, + true, + this.incomingWarmth, + undoingDomSubStamps, + hub.state.firstAndLastStorageSlotOccurrences.size()); + + this.addFragment(undoingSloadStorageFragment); + } + + private boolean undoingRequired() { + return Exceptions.outOfGasException(this.exceptions) || Exceptions.none(this.exceptions); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index f00417f95a..fa4b221016 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -18,49 +18,57 @@ import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; @Getter -public class SstoreSection extends TraceSection { +public class SstoreSection extends TraceSection implements PostRollbackDefer { + final Address address; + final int deploymentNumber; + final Bytes32 storageKey; + final boolean incomingWarmth; + final EWord valueOriginal; + final EWord valueCurrent; + final EWord valueNext; final WorldView world; + final short exceptions; - private SstoreSection(Hub hub, WorldView world) { + public SstoreSection(Hub hub, WorldView world) { super(hub); this.world = world; - } - - public static void appendSectionTo(Hub hub, WorldView world) { - - final Address address = hub.messageFrame().getRecipientAddress(); - final int deploymentNumber = hub.currentFrame().codeDeploymentNumber(); - final Bytes32 storageKey = Bytes32.leftPad(hub.messageFrame().getStackItem(0)); - - final EWord valueOriginal = + this.address = hub.messageFrame().getRecipientAddress(); + this.deploymentNumber = hub.currentFrame().accountDeploymentNumber(); + this.storageKey = Bytes32.leftPad(hub.messageFrame().getStackItem(0)); + this.incomingWarmth = hub.messageFrame().getWarmedUpStorage().contains(address, storageKey); + this.valueOriginal = EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); - final EWord valueCurrent = - EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); - final EWord valueNext = EWord.of(hub.messageFrame().getStackItem(1)); + this.valueCurrent = EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); + this.valueNext = EWord.of(hub.messageFrame().getStackItem(1)); + this.exceptions = hub.pch().exceptions(); - final boolean staticContextException = Exceptions.staticFault(hub.pch().exceptions()); - final boolean sstoreException = Exceptions.outOfSStore(hub.pch().exceptions()); - final boolean outOfGasException = Exceptions.outOfGasException(hub.pch().exceptions()); - final boolean contextWillRevert = hub.callStack().current().willRevert(); + hub.addTraceSection(this); + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + } + + public void populateSection(Hub hub, WorldView world) { - final SstoreSection currentSection = new SstoreSection(hub, world); - hub.addTraceSection(currentSection); + final boolean staticContextException = Exceptions.staticFault(this.exceptions); + final boolean sstoreException = Exceptions.outOfSStore(this.exceptions); // CONTEXT fragment ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); - currentSection.addFragmentsAndStack(hub, readCurrentContext); + this.addFragmentsAndStack(hub, readCurrentContext); if (staticContextException) { return; @@ -68,67 +76,59 @@ public static void appendSectionTo(Hub hub, WorldView world) { // MISC fragment ImcFragment miscForSstore = ImcFragment.forOpcode(hub, hub.messageFrame()); - currentSection.addFragment(miscForSstore); + this.addFragment(miscForSstore); if (sstoreException) { return; } // STORAGE fragment (for doing) - StorageFragment doingSstore = - doingSstore( - hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); - - currentSection.addFragment(doingSstore); - - // STORAGE fragment (for undoing) - if (outOfGasException || contextWillRevert) { - StorageFragment undoingSstore = - undoingSstore( - hub, address, deploymentNumber, storageKey, valueOriginal, valueCurrent, valueNext); - currentSection.addFragment(undoingSstore); - } + StorageFragment doingSstore = this.doingSstore(hub); + this.addFragment(doingSstore); } - private static StorageFragment doingSstore( - Hub hub, - Address address, - int deploymentNumber, - Bytes32 storageKey, - EWord valueOriginal, - EWord valueCurrent, - EWord valueNext) { + private StorageFragment doingSstore(Hub hub) { return new StorageFragment( hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), - valueOriginal, - valueCurrent, - valueNext, - hub.messageFrame().getWarmedUpStorage().contains(address, storageKey), + new State.StorageSlotIdentifier( + this.address, this.deploymentNumber, EWord.of(this.storageKey)), + this.valueOriginal, + this.valueCurrent, + this.valueNext, + this.incomingWarmth, true, DomSubStampsSubFragment.standardDomSubStamps(hub, 0), hub.state.firstAndLastStorageSlotOccurrences.size()); } - private static StorageFragment undoingSstore( - Hub hub, - Address address, - int deploymentNumber, - Bytes32 storageKey, - EWord valueOriginal, - EWord valueCurrent, - EWord valueNext) { + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - return new StorageFragment( - hub.state, - new State.StorageSlotIdentifier(address, deploymentNumber, EWord.of(storageKey)), - valueOriginal, - valueNext, - valueCurrent, - true, - hub.messageFrame().getWarmedUpStorage().contains(address, storageKey), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1), - hub.state.firstAndLastStorageSlotOccurrences.size()); + if (!this.undoingRequired()) { + return; + } + + final DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); + + final StorageFragment undoingSstoreStorageFragment = + new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + this.address, this.deploymentNumber, EWord.of(this.storageKey)), + this.valueOriginal, + this.valueNext, + this.valueCurrent, + true, + this.incomingWarmth, + undoingDomSubStamps, + hub.state.firstAndLastStorageSlotOccurrences.size()); + + this.addFragment(undoingSstoreStorageFragment); + } + + private boolean undoingRequired() { + return Exceptions.outOfGasException(this.exceptions) || Exceptions.none(this.exceptions); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java index a74dbf01e1..b8a5afe2a5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java @@ -32,18 +32,18 @@ public class Exceptions { private Exceptions() {} public static final short NONE = 0; // no exceptions occurred - private static final short INVALID_OPCODE = 1; // unknown opcode - private static final short STACK_UNDERFLOW = 2; // stack underflow - private static final short STACK_OVERFLOW = 4; // stack overflow - private static final short MEMORY_EXPANSION_EXCEPTION = 8; // tried to use memory too far away - private static final short OUT_OF_GAS_EXCEPTION = 16; // not enough gas for instruction - private static final short RETURN_DATA_COPY_FAULT = 32; // trying to read past the RETURNDATA end - private static final short JUMP_FAULT = 64; // jumping to an invalid destination - private static final short STATIC_FAULT = + public static final short INVALID_OPCODE = 1; // unknown opcode + public static final short STACK_UNDERFLOW = 2; // stack underflow + public static final short STACK_OVERFLOW = 4; // stack overflow + public static final short MEMORY_EXPANSION_EXCEPTION = 8; // tried to use memory too far away + public static final short OUT_OF_GAS_EXCEPTION = 16; // not enough gas for instruction + public static final short RETURN_DATA_COPY_FAULT = 32; // trying to read past the RETURNDATA end + public static final short JUMP_FAULT = 64; // jumping to an invalid destination + public static final short STATIC_FAULT = 128; // trying to execute non-static instruction in a static context - private static final short OUT_OF_SSTORE = 256; // not enough gas to execute an SSTORE - private static final short INVALID_CODE_PREFIX = 512; - private static final short CODE_SIZE_OVERFLOW = 2048; + public static final short OUT_OF_SSTORE = 256; // not enough gas to execute an SSTORE + public static final short INVALID_CODE_PREFIX = 512; + public static final short CODE_SIZE_OVERFLOW = 2048; public static boolean stackException(final short bitmask) { return stackOverflow(bitmask) || stackUnderflow(bitmask); From 5e77dd11b7bf8b0e3daeaa3478e3603550d0bb3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 8 Jul 2024 22:19:21 +0200 Subject: [PATCH 177/461] ras - small STORAGE change - small JUMP(I) change --- .../linea/zktracer/module/hub/Hub.java | 35 ++++++------------- .../module/hub/section/JumpSection.java | 26 ++++---------- .../module/hub/section/SloadSection.java | 2 +- .../module/hub/section/SstoreSection.java | 2 +- 4 files changed, 19 insertions(+), 46 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 7b4745a1a4..406372df19 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1110,10 +1110,12 @@ void traceOperation(MessageFrame frame) { case LOG -> { new LogSection(this); } + case ACCOUNT -> { final AccountSection accountSection = new AccountSection(this); accountSection.appendToTrace(this); } + case COPY -> { /* @@ -1173,8 +1175,10 @@ void traceOperation(MessageFrame frame) { this.addTraceSection(copySection); */ } + case TRANSACTION -> this.addTraceSection( new TransactionSection(this, TransactionFragment.prepare(this.txStack.current()))); + case STACK_RAM -> { switch (this.currentFrame().opCode()) { case CALLDATALOAD -> { @@ -1184,19 +1188,21 @@ void traceOperation(MessageFrame frame) { default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); } } + case STORAGE -> { switch (this.currentFrame().opCode()) { case SSTORE -> { final SstoreSection sstoreSection = new SstoreSection(this, frame.getWorldUpdater()); - sstoreSection.populateSection(this, frame.getWorldUpdater()); + sstoreSection.populateSection(this); } case SLOAD -> { final SloadSection sloadSection = new SloadSection(this, frame.getWorldUpdater()); - sloadSection.populateSection(this, frame.getWorldUpdater()); + sloadSection.populateSection(this); } default -> throw new IllegalStateException("invalid operation in family STORAGE"); } } + case CREATE -> { final Address myAddress = this.currentFrame().accountAddress(); final Account myAccount = frame.getWorldUpdater().get(myAddress); @@ -1347,29 +1353,8 @@ void traceOperation(MessageFrame frame) { } case JUMP -> { - AccountSnapshot codeAccountSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(this.currentFrame().byteCodeAddress()), - true, - this.transients - .conflation() - .deploymentInfo() - .number(this.currentFrame().byteCodeAddress()), - this.currentFrame().isDeployment()); - - JumpSection jumpSection = - new JumpSection( - this, - ContextFragment.readCurrentContextData(this), - this.factories - .accountFragment() - .make( - codeAccountSnapshot, - codeAccountSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this, 0)), - ImcFragment.forOpcode(this, frame)); - - this.addTraceSection(jumpSection); + JumpSection jumpSection = new JumpSection(this); + jumpSection.populateSection(this); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index 0881b7fe0f..f9e6495466 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -25,7 +25,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; @@ -36,11 +35,10 @@ public class JumpSection extends TraceSection { - public static void appendToTrace(Hub hub, WorldView worldView) { - final JumpSection currentSection = new JumpSection(hub); - currentSection.addFragmentsAndStack(hub); // TODO strange to not give any fragments + public void populateSection(Hub hub) { - hub.addTraceSection(currentSection); + this.addFragmentsAndStack(hub); + hub.addTraceSection(this); if (Exceptions.outOfGasException(hub.pch().exceptions())) { return; @@ -54,7 +52,7 @@ public static void appendToTrace(Hub hub, WorldView worldView) { /////////////////// Address codeAddress = hub.messageFrame().getContractAddress(); AccountFragment.AccountFragmentFactory accountFragmentFactory = - new AccountFragment.AccountFragmentFactory(hub.defers()); + hub.factories().accountFragment(); DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); final int deploymentNumber = deploymentInfo.number(codeAddress); @@ -73,45 +71,35 @@ public static void appendToTrace(Hub hub, WorldView worldView) { // MISCELLANEOUS fragment ///////////////////////// ImcFragment miscellaneousRow = ImcFragment.empty(hub); - OobCall oobCall; boolean mustAttemptJump = false; switch (hub.opCode()) { case OpCode.JUMP -> { JumpOobCall jumpOobCall = new JumpOobCall(); miscellaneousRow.callOob(jumpOobCall); mustAttemptJump = jumpOobCall.isJumpMustBeAttempted(); - oobCall = jumpOobCall; } case OpCode.JUMPI -> { JumpiOobCall jumpiOobCall = new JumpiOobCall(); miscellaneousRow.callOob(jumpiOobCall); mustAttemptJump = jumpiOobCall.isJumpMustBeAttempted(); - oobCall = jumpiOobCall; } default -> throw new RuntimeException( hub.opCode().name() + " not part of the JUMP instruction family"); } - miscellaneousRow.callOob(oobCall); - // CONTEXT, ACCOUNT, MISCELLANEOUS ////////////////////////////////// - currentSection.addFragmentsWithoutStack( + this.addFragmentsWithoutStack( contextRowCurrentContext, accountRowCodeAccount, miscellaneousRow); // jump destination vetting /////////////////////////// if (mustAttemptJump) { - currentSection.triggerJumpDestinationVetting(hub); + this.triggerJumpDestinationVetting(hub); } } - private JumpSection(Hub hub) { - super(hub); - } - - public JumpSection(Hub hub, TraceFragment... chunks) { + public JumpSection(Hub hub) { super(hub); - this.addFragmentsAndStack(hub, chunks); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index b8b51bd75a..60cc6ea022 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -58,7 +58,7 @@ public SloadSection(Hub hub, WorldView world) { hub.defers().scheduleForPostRollback(this, hub.currentFrame()); } - public void populateSection(Hub hub, WorldView world) { + public void populateSection(Hub hub) { // NOTE: SLOAD can only trigger // - stackUnderflowException diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index fa4b221016..7dcd061804 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -61,7 +61,7 @@ public SstoreSection(Hub hub, WorldView world) { hub.defers().scheduleForPostRollback(this, hub.currentFrame()); } - public void populateSection(Hub hub, WorldView world) { + public void populateSection(Hub hub) { final boolean staticContextException = Exceptions.staticFault(this.exceptions); final boolean sstoreException = Exceptions.outOfSStore(this.exceptions); From 0b28187c096aaedc0eabf1a427bf5001768aa8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 8 Jul 2024 22:19:51 +0200 Subject: [PATCH 178/461] fix(copy): EXTCODECOPY revision + postRollbackDefers mechanism --- .../module/hub/section/copy/CopySection.java | 6 +- .../hub/section/copy/ExtCodeCopySection.java | 132 ++++++++++++------ 2 files changed, 97 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java index 77076cb182..6a6963a632 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java @@ -31,7 +31,11 @@ public static void appendToTrace(Hub hub) { case OpCode.CALLDATACOPY -> new CallDataCopySection(hub); case OpCode.RETURNDATACOPY -> new ReturnDataCopySection(hub); case OpCode.CODECOPY -> new CodeCopySection(hub); - case OpCode.EXTCODECOPY -> new ExtCodeCopySection(hub); + case OpCode.EXTCODECOPY -> { + ExtCodeCopySection extCodeCopySection = new ExtCodeCopySection(hub); + extCodeCopySection.populateSection(hub); + } + } } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 3afd5c36b7..000acc80d2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -18,101 +18,153 @@ import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.none; import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.types.Bytecode; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; -public class ExtCodeCopySection extends TraceSection { +public class ExtCodeCopySection extends TraceSection implements PostRollbackDefer { - public static void appendToTrace(Hub hub) { + final Bytes rawAddress; + final Address address; + final int incomingDeploymentNumber; + final boolean incomingDeploymentStatus; + final boolean incomingWarmth; + final short exceptions; - final ExtCodeCopySection extCodeCopySection = new ExtCodeCopySection(hub); - hub.addTraceSection(extCodeCopySection); + AccountSnapshot accountBefore; + AccountSnapshot accountAfter; + + public ExtCodeCopySection(Hub hub) { + super(hub); + + final MessageFrame frame = hub.messageFrame(); + this.rawAddress = frame.getStackItem(0); + this.address = Address.extract((Bytes32) this.rawAddress); + this.incomingDeploymentNumber = hub.transients().conflation().deploymentInfo().number(this.address); + this.incomingDeploymentStatus = hub.transients().conflation().deploymentInfo().isDeploying(this.address); + this.incomingWarmth = frame.isAddressWarm(this.address); + this.exceptions = hub.pch().exceptions(); + } + + public void populateSection(Hub hub) { + + hub.addTraceSection(this); ImcFragment imcFragment = ImcFragment.empty(hub); - extCodeCopySection.addFragmentsAndStack(hub, imcFragment); + this.addFragmentsAndStack(hub, imcFragment); // triggerOob = false // triggerMxp = true MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + // The MXPX case + //////////////// if (mxpCall.mxpx) { - // the last context row will be added automatically return; } final MessageFrame frame = hub.messageFrame(); - final Bytes rawTargetAddress = frame.getStackItem(0); - final Address targetAddress = Address.extract((Bytes32) rawTargetAddress); - final Account targetAccount = frame.getWorldUpdater().get(targetAddress); + final Account foreignAccount = frame.getWorldUpdater().get(this.address); - AccountSnapshot accountBefore = + this.accountBefore = AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + foreignAccount, + this.incomingWarmth, + this.incomingDeploymentNumber, + this.incomingDeploymentStatus); DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 0); - final short exceptions = hub.pch().exceptions(); - // The OOGX case - if (outOfGasException(exceptions)) { + //////////////// + if (outOfGasException(this.exceptions)) { // the last context row will be added automatically AccountFragment accountReadingFragment = hub.factories() .accountFragment() - .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); + .makeWithTrm(this.accountBefore, this.accountBefore, this.rawAddress, doingDomSubStamps); - extCodeCopySection.addFragment(accountReadingFragment); + this.addFragment(accountReadingFragment); return; } - final boolean triggerMmu = none(exceptions) && mxpCall.isMayTriggerNonTrivialMmuOperation(); + // The unexceptional case + ///////////////////////// + final boolean triggerMmu = none(this.exceptions) && mxpCall.isMayTriggerNonTrivialMmuOperation(); if (triggerMmu) { MmuCall mmuCall = MmuCall.extCodeCopy(hub); imcFragment.callMmu(mmuCall); } - AccountSnapshot accountAfter = + this.accountAfter = AccountSnapshot.fromAccount( - targetAccount, + foreignAccount, true, - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + this.incomingDeploymentNumber, + this.incomingDeploymentStatus); AccountFragment accountDoingFragment = - hub.factories() - .accountFragment() - .makeWithTrm(accountBefore, accountAfter, rawTargetAddress, doingDomSubStamps); - - extCodeCopySection.addFragment(accountDoingFragment); - - // affected by issue #785 - if (hub.callStack().current().willRevert()) { - DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); - AccountFragment undoingAccountFragment = - hub.factories().accountFragment().make(accountAfter, accountBefore, undoingDomSubStamps); - extCodeCopySection.addFragment(undoingAccountFragment); - } + hub.factories().accountFragment() + .makeWithTrm(this.accountBefore, this.accountAfter, this.rawAddress, doingDomSubStamps); + + this.addFragment(accountDoingFragment); + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); } - public ExtCodeCopySection(Hub hub) { - super(hub); + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + + Account revertFrom = messageFrame.getWorldUpdater().get(this.address); + final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(this.address); + final boolean deploymentStatusAtRollback = hub.transients().conflation().deploymentInfo().isDeploying(this.address); + + AccountSnapshot revertFromSnapshot = new AccountSnapshot( + this.address, + revertFrom.getNonce(), + revertFrom.getBalance(), + true, + new Bytecode(revertFrom.getCode().copy()), // stolen from AccountSnapshot.java + deploymentNumberAtRollback, + deploymentStatusAtRollback + ); + + AccountSnapshot revertToSnapshot = new AccountSnapshot( + this.address, + revertFrom.getNonce(), + revertFrom.getBalance(), + this.incomingWarmth, + new Bytecode(revertFrom.getCode().copy()), // stolen from AccountSnapshot.java + deploymentNumberAtRollback, + deploymentStatusAtRollback + ); + + + DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); + AccountFragment undoingAccountFragment = + hub.factories().accountFragment().make( + revertFromSnapshot, + revertToSnapshot, + undoingDomSubStamps); + + this.addFragment(undoingAccountFragment); } } From 546ad6bcedc367833f58488e5eaaff5f6132bd79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 9 Jul 2024 01:06:48 +0200 Subject: [PATCH 179/461] feat(copy): RETURNDATACOPY done ? --- .../linea/zktracer/module/hub/Hub.java | 60 +------------ .../module/hub/section/JumpSection.java | 2 - .../module/hub/section/copy/CopySection.java | 70 ++++++++++++++- .../hub/section/copy/ExtCodeCopySection.java | 86 ++++++++++--------- .../section/copy/ReturnDataCopySection.java | 49 +++++++++++ .../zktracer/module/mxp/MxpOperation.java | 4 +- 6 files changed, 163 insertions(+), 108 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 406372df19..369dbfe3a0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -56,6 +56,7 @@ import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; +import net.consensys.linea.zktracer.module.hub.section.copy.CopySection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -1117,63 +1118,8 @@ void traceOperation(MessageFrame frame) { } case COPY -> { - - /* - CopySection.addTraceSection(this); - TraceSection copySection = new CopySection(this); - if (!this.opCode().equals(OpCode.RETURNDATACOPY) && !this.opCode().equals(OpCode.CALLDATACOPY)) { - final Bytes rawTargetAddress = - switch (this.currentFrame().opCode()) { - case CODECOPY -> this.currentFrame().byteCodeAddress(); - case EXTCODECOPY -> frame.getStackItem(0); - default -> throw new IllegalStateException( - String.format("unexpected opcode %s", this.opCode())); - }; - final Address targetAddress = Words.toAddress(rawTargetAddress); - final Account targetAccount = frame.getWorldUpdater().get(targetAddress); - - AccountSnapshot accountBefore = - AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - - AccountSnapshot accountAfter = - AccountSnapshot.fromAccount( - targetAccount, - true, - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - - // TODO: this is deprecated, update it. Factories creates an account row (accountFragment) - // ImcFragment is for miscellaneaous rows - // ContextFragment - DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this, 0); - copySection.addFragment( - this.currentFrame().opCode() == OpCode.EXTCODECOPY - ? this.factories - .accountFragment() - .makeWithTrm( - accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps) - : this.factories - .accountFragment() - .make(accountBefore, accountAfter, doingDomSubStamps)); - - if (this.callStack.current().willRevert()) { - DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); - copySection.addFragment( - this.factories - .accountFragment() - .make(accountAfter, accountBefore, undoingDomSubStamps)); - } - } else { - copySection.addFragment(ContextFragment.readCurrentContextData(this)); - } - this.addTraceSection(copySection); - */ + final CopySection copySection = new CopySection(this); + copySection.populateSection(this); } case TRANSACTION -> this.addTraceSection( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index f9e6495466..a9dd0c3593 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -22,7 +22,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; @@ -31,7 +30,6 @@ import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.opcode.OpCode; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.worldstate.WorldView; public class JumpSection extends TraceSection { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java index 6a6963a632..9d0aadb3e8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java @@ -26,15 +26,77 @@ public CopySection(Hub hub) { super(hub); } - public static void appendToTrace(Hub hub) { + public void populateSection(Hub hub) { + + /* + CopySection.addTraceSection(this); + TraceSection copySection = new CopySection(this); + if (!this.opCode().equals(OpCode.RETURNDATACOPY) && !this.opCode().equals(OpCode.CALLDATACOPY)) { + final Bytes rawTargetAddress = + switch (this.currentFrame().opCode()) { + case CODECOPY -> this.currentFrame().byteCodeAddress(); + case EXTCODECOPY -> frame.getStackItem(0); + default -> throw new IllegalStateException( + String.format("unexpected opcode %s", this.opCode())); + }; + final Address targetAddress = Words.toAddress(rawTargetAddress); + final Account targetAccount = frame.getWorldUpdater().get(targetAddress); + + AccountSnapshot accountBefore = + AccountSnapshot.fromAccount( + targetAccount, + frame.isAddressWarm(targetAddress), + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + + AccountSnapshot accountAfter = + AccountSnapshot.fromAccount( + targetAccount, + true, + this.transients.conflation().deploymentInfo().number(targetAddress), + this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); + + // TODO: this is deprecated, update it. Factories creates an account row (accountFragment) + // ImcFragment is for miscellaneaous rows + // ContextFragment + DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this, 0); + copySection.addFragment( + this.currentFrame().opCode() == OpCode.EXTCODECOPY + ? this.factories + .accountFragment() + .makeWithTrm( + accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps) + : this.factories + .accountFragment() + .make(accountBefore, accountAfter, doingDomSubStamps)); + + if (this.callStack.current().willRevert()) { + DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); + copySection.addFragment( + this.factories + .accountFragment() + .make(accountAfter, accountBefore, undoingDomSubStamps)); + } + } else { + copySection.addFragment(ContextFragment.readCurrentContextData(this)); + } + this.addTraceSection(copySection); + */ + switch (hub.opCode()) { case OpCode.CALLDATACOPY -> new CallDataCopySection(hub); - case OpCode.RETURNDATACOPY -> new ReturnDataCopySection(hub); + case OpCode.RETURNDATACOPY -> { + ReturnDataCopySection returnDataCopySection = new ReturnDataCopySection(hub); + hub.addTraceSection(returnDataCopySection); + returnDataCopySection.populateSection(hub); + } case OpCode.CODECOPY -> new CodeCopySection(hub); case OpCode.EXTCODECOPY -> { ExtCodeCopySection extCodeCopySection = new ExtCodeCopySection(hub); - extCodeCopySection.populateSection(hub); - } + hub.addTraceSection(extCodeCopySection); + extCodeCopySection.populate(hub); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 000acc80d2..8ccbe81909 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -30,7 +30,6 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.Bytecode; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; @@ -51,19 +50,18 @@ public class ExtCodeCopySection extends TraceSection implements PostRollbackDefe public ExtCodeCopySection(Hub hub) { super(hub); - final MessageFrame frame = hub.messageFrame(); this.rawAddress = frame.getStackItem(0); this.address = Address.extract((Bytes32) this.rawAddress); - this.incomingDeploymentNumber = hub.transients().conflation().deploymentInfo().number(this.address); - this.incomingDeploymentStatus = hub.transients().conflation().deploymentInfo().isDeploying(this.address); + this.incomingDeploymentNumber = + hub.transients().conflation().deploymentInfo().number(this.address); + this.incomingDeploymentStatus = + hub.transients().conflation().deploymentInfo().isDeploying(this.address); this.incomingWarmth = frame.isAddressWarm(this.address); this.exceptions = hub.pch().exceptions(); } - public void populateSection(Hub hub) { - - hub.addTraceSection(this); + public void populate(Hub hub) { ImcFragment imcFragment = ImcFragment.empty(hub); this.addFragmentsAndStack(hub, imcFragment); @@ -73,7 +71,8 @@ public void populateSection(Hub hub) { MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + Preconditions.checkArgument( + mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); // The MXPX case //////////////// @@ -101,7 +100,8 @@ public void populateSection(Hub hub) { AccountFragment accountReadingFragment = hub.factories() .accountFragment() - .makeWithTrm(this.accountBefore, this.accountBefore, this.rawAddress, doingDomSubStamps); + .makeWithTrm( + this.accountBefore, this.accountBefore, this.rawAddress, doingDomSubStamps); this.addFragment(accountReadingFragment); return; @@ -109,7 +109,8 @@ public void populateSection(Hub hub) { // The unexceptional case ///////////////////////// - final boolean triggerMmu = none(this.exceptions) && mxpCall.isMayTriggerNonTrivialMmuOperation(); + final boolean triggerMmu = + none(this.exceptions) && mxpCall.isMayTriggerNonTrivialMmuOperation(); if (triggerMmu) { MmuCall mmuCall = MmuCall.extCodeCopy(hub); imcFragment.callMmu(mmuCall); @@ -117,53 +118,54 @@ public void populateSection(Hub hub) { this.accountAfter = AccountSnapshot.fromAccount( - foreignAccount, - true, - this.incomingDeploymentNumber, - this.incomingDeploymentStatus); + foreignAccount, true, this.incomingDeploymentNumber, this.incomingDeploymentStatus); AccountFragment accountDoingFragment = - hub.factories().accountFragment() + hub.factories() + .accountFragment() .makeWithTrm(this.accountBefore, this.accountAfter, this.rawAddress, doingDomSubStamps); this.addFragment(accountDoingFragment); + + // an EXTCODECOPY section is only scheduled + // for rollback if it is unexceptional hub.defers().scheduleForPostRollback(this, hub.currentFrame()); } @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - Account revertFrom = messageFrame.getWorldUpdater().get(this.address); - final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(this.address); - final boolean deploymentStatusAtRollback = hub.transients().conflation().deploymentInfo().isDeploying(this.address); - - AccountSnapshot revertFromSnapshot = new AccountSnapshot( - this.address, - revertFrom.getNonce(), - revertFrom.getBalance(), - true, - new Bytecode(revertFrom.getCode().copy()), // stolen from AccountSnapshot.java + final int deploymentNumberAtRollback = + hub.transients().conflation().deploymentInfo().number(this.address); + final boolean deploymentStatusAtRollback = + hub.transients().conflation().deploymentInfo().isDeploying(this.address); + + AccountSnapshot revertFromSnapshot = + new AccountSnapshot( + this.accountAfter.address(), + this.accountAfter.nonce(), + this.accountAfter.balance(), + this.accountAfter.isWarm(), + this.accountAfter.code(), deploymentNumberAtRollback, - deploymentStatusAtRollback - ); - - AccountSnapshot revertToSnapshot = new AccountSnapshot( - this.address, - revertFrom.getNonce(), - revertFrom.getBalance(), - this.incomingWarmth, - new Bytecode(revertFrom.getCode().copy()), // stolen from AccountSnapshot.java + deploymentStatusAtRollback); + + AccountSnapshot revertToSnapshot = + new AccountSnapshot( + this.accountBefore.address(), + this.accountBefore.nonce(), + this.accountBefore.balance(), + this.accountBefore.isWarm(), + this.accountBefore.code(), deploymentNumberAtRollback, - deploymentStatusAtRollback - ); - + deploymentStatusAtRollback); - DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); + DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); AccountFragment undoingAccountFragment = - hub.factories().accountFragment().make( - revertFromSnapshot, - revertToSnapshot, - undoingDomSubStamps); + hub.factories() + .accountFragment() + .make(revertFromSnapshot, revertToSnapshot, undoingDomSubStamps); this.addFragment(undoingAccountFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index c72c09d4f9..38bff6a5fb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -15,12 +15,61 @@ package net.consensys.linea.zktracer.module.hub.section.copy; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; public class ReturnDataCopySection extends TraceSection { + final short exceptions; + public ReturnDataCopySection(Hub hub) { super(hub); + this.exceptions = hub.pch().exceptions(); + } + + public void populateSection(Hub hub) { + + ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + this.addFragmentsAndStack(hub, currentContext); + + ImcFragment imcFragment = ImcFragment.empty(hub); + this.addFragment(imcFragment); + + ReturnDataCopyOobCall oobCall = new ReturnDataCopyOobCall(); + imcFragment.callOob(oobCall); + + final boolean returnDataCopyException = oobCall.isRdcx(); + Preconditions.checkArgument( + returnDataCopyException == Exceptions.returnDataCopyFault(this.exceptions)); + + if (returnDataCopyException) { + return; + } + + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + + final boolean memoryExpansionException = mxpCall.mxpx; + Preconditions.checkArgument( + memoryExpansionException == Exceptions.memoryExpansionException(this.exceptions)); + + // if MXPX ∨ OOGX + if (Exceptions.any(this.exceptions)) { + return; + } + + // beyond this point unexceptional + final boolean triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; + if (triggerMmu) { + MmuCall mmuCall = MmuCall.returnDataCopy(hub); + imcFragment.callMmu(mmuCall); + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java index ee80186b2b..f35d246d54 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java @@ -89,17 +89,15 @@ public class MxpOperation extends ModuleOperation { private long linCost = 0; public MxpOperation(final MxpCall mxpCall) { - this.mxpCall = mxpCall; final Hub hub = mxpCall.hub; - final MessageFrame frame = hub.messageFrame(); + this.mxpCall = mxpCall; this.mxpCall.setOpCodeData(hub.opCodeData()); this.mxpCall.setDeploys( mxpCall.getOpCodeData().mnemonic() == OpCode.RETURN & hub.currentFrame().isDeployment()); this.mxpCall.setMemorySizeInWords(frame.memoryWordSize()); - this.wordsNew = frame.memoryWordSize(); // will (may) be updated later this.cMem = memoryCost(frame.memoryWordSize()); this.cMemNew = memoryCost(frame.memoryWordSize()); // will (may) be updated later From 0e2112e77033212e092e40e4224a8b127fcea8d7 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 9 Jul 2024 14:11:53 +0200 Subject: [PATCH 180/461] fix(hub): respected interface for CodeCopySection --- .../zktracer/module/hub/section/copy/CodeCopySection.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 00e7342670..2632c7026f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -92,11 +92,12 @@ public CodeCopySection(Hub hub) { } triggerMmu = !xahoy && mxpCall.isMayTriggerNonTrivialMmuOperation(); - hub.defers().postTx(this); + hub.defers().resolvePostTransaction(hub, null, null, true); // TODO: pass the right parameters } @Override - public void runPostTx(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (triggerMmu) { MmuCall mmuCall = MmuCall.codeCopy(hub); imcFragment.callMmu(mmuCall); From 983cddb9df3db6c3010734cabd8e4f6c0250fbbc Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 9 Jul 2024 15:24:39 +0200 Subject: [PATCH 181/461] fix(oob): issue with preconditions check 16 bytes inputs --- .../zktracer/module/oob/OobOperation.java | 99 ++++++++----------- 1 file changed, 40 insertions(+), 59 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 038f203d9a..bb80fb7a95 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -75,6 +75,7 @@ import java.math.BigInteger; import java.math.RoundingMode; +import com.google.common.base.Preconditions; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -611,15 +612,12 @@ private void populateColumns(final MessageFrame frame) { // Constraint systems for populating lookups private void callToADD( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - // TODO: reactivate preconditions and remove conditional initialization - // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = - arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); - final EWord arg2 = - arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); + Preconditions.checkArgument(arg1Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg1Lo.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Lo.bitLength() / 8 <= 16); + final EWord arg1 = EWord.of(arg1Hi, arg1Lo); + final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = true; modFlag[k] = false; wcpFlag[k] = false; @@ -637,15 +635,12 @@ private void callToADD( private BigInteger callToDIV( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - // TODO: reactivate preconditions and remove conditional initialization - // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = - arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); - final EWord arg2 = - arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); + Preconditions.checkArgument(arg1Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg1Lo.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Lo.bitLength() / 8 <= 16); + final EWord arg1 = EWord.of(arg1Hi, arg1Lo); + final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; modFlag[k] = true; wcpFlag[k] = false; @@ -660,15 +655,12 @@ private BigInteger callToDIV( private BigInteger callToMOD( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - // TODO: reactivate preconditions and remove conditional initialization - // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = - arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); - final EWord arg2 = - arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); + Preconditions.checkArgument(arg1Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg1Lo.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Lo.bitLength() / 8 <= 16); + final EWord arg1 = EWord.of(arg1Hi, arg1Lo); + final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; modFlag[k] = true; wcpFlag[k] = false; @@ -683,15 +675,12 @@ private BigInteger callToMOD( private boolean callToLT( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - // TODO: reactivate preconditions and remove conditional initialization - // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = - arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); - final EWord arg2 = - arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); + Preconditions.checkArgument(arg1Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg1Lo.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Lo.bitLength() / 8 <= 16); + final EWord arg1 = EWord.of(arg1Hi, arg1Lo); + final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; @@ -707,15 +696,12 @@ private boolean callToLT( private boolean callToGT( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - // TODO: reactivate preconditions and remove conditional initialization - // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = - arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); - final EWord arg2 = - arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); + Preconditions.checkArgument(arg1Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg1Lo.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Lo.bitLength() / 8 <= 16); + final EWord arg1 = EWord.of(arg1Hi, arg1Lo); + final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; @@ -730,11 +716,9 @@ private boolean callToGT( } private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInteger arg1Lo) { - // TODO: reactivate preconditions and remove conditional initialization - // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - final EWord arg1 = - arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); + Preconditions.checkArgument(arg1Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg1Lo.bitLength() / 8 <= 16); + final EWord arg1 = EWord.of(arg1Hi, arg1Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; @@ -750,15 +734,12 @@ private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInte private boolean callToEQ( int k, BigInteger arg1Hi, BigInteger arg1Lo, BigInteger arg2Hi, BigInteger arg2Lo) { - // TODO: reactivate preconditions and remove conditional initialization - // Preconditions.checkArgument(arg1Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg1Lo.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Hi.toByteArray().length <= 16); - // Preconditions.checkArgument(arg2Lo.toByteArray().length <= 16); - final EWord arg1 = - arg1Lo.toByteArray().length <= 16 ? EWord.of(arg1Hi, arg1Lo) : EWord.of(arg1Lo); - final EWord arg2 = - arg2Lo.toByteArray().length <= 16 ? EWord.of(arg2Hi, arg2Lo) : EWord.of(arg2Lo); + Preconditions.checkArgument(arg1Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg1Lo.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Hi.bitLength() / 8 <= 16); + Preconditions.checkArgument(arg2Lo.bitLength() / 8 <= 16); + final EWord arg1 = EWord.of(arg1Hi, arg1Lo); + final EWord arg2 = EWord.of(arg2Hi, arg2Lo); addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; From 0f744d4e6f3f10e5c770a4693f760f9cf115fc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 9 Jul 2024 15:52:05 +0200 Subject: [PATCH 182/461] feat(copy): CALLDATACOPY + small fixes --- .../linea/zktracer/module/hub/Hub.java | 12 +- .../hub/fragment/account/AccountFragment.java | 22 ++-- .../module/hub/section/TraceSection.java | 4 +- .../hub/section/copy/CallDataCopySection.java | 66 ++++++++++- .../hub/section/copy/CodeCopySection.java | 2 +- .../module/hub/section/copy/CopySection.java | 103 ------------------ .../hub/section/copy/ExtCodeCopySection.java | 14 ++- .../section/copy/ReturnDataCopySection.java | 8 +- 8 files changed, 102 insertions(+), 129 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 369dbfe3a0..645a017c7e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -56,7 +56,7 @@ import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; -import net.consensys.linea.zktracer.module.hub.section.copy.CopySection; +import net.consensys.linea.zktracer.module.hub.section.copy.*; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.Transients; @@ -1118,8 +1118,14 @@ void traceOperation(MessageFrame frame) { } case COPY -> { - final CopySection copySection = new CopySection(this); - copySection.populateSection(this); + switch (this.opCode()) { + case OpCode.CALLDATACOPY -> new CallDataCopySection(this); + case OpCode.RETURNDATACOPY -> new ReturnDataCopySection(this); + case OpCode.CODECOPY -> new CodeCopySection(this); + case OpCode.EXTCODECOPY -> new ExtCodeCopySection(this); + default -> throw new RuntimeException( + "Invalid instruction: " + this.opCode().toString() + " not in the COPY family"); + } } case TRANSACTION -> this.addTraceSection( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index a8b38fb9cf..69473f8d62 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -44,6 +44,17 @@ public final class AccountFragment implements TraceFragment, PostTransactionDefer, PostConflationDefer { + private final AccountSnapshot oldState; + private final AccountSnapshot newState; + @Setter private int deploymentNumberInfinity = 0; // retconned on conflation end + private final int deploymentNumber; + private final boolean isDeployment; + @Setter private boolean existsInfinity = false; // retconned on conflation end + @Setter private boolean requiresRomlex; + private int codeFragmentIndex; + private final Optional addressToTrim; + private final DomSubStampsSubFragment domSubStampsSubFragment; + /** * {@link AccountFragment} creation requires access to a {@link DeferRegistry} for post-conflation * data gathering, which is provided by this factory. @@ -70,17 +81,6 @@ public AccountFragment makeWithTrm( } } - private final AccountSnapshot oldState; - private final AccountSnapshot newState; - @Setter private int deploymentNumberInfinity = 0; // retconned on conflation end - private final int deploymentNumber; - private final boolean isDeployment; - @Setter private boolean existsInfinity = false; // retconned on conflation end - private int codeFragmentIndex; - @Setter private boolean requiresRomlex; - private final Optional addressToTrim; - private final DomSubStampsSubFragment domSubStampsSubFragment; - public AccountFragment( final DeferRegistry defers, AccountSnapshot oldState, 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 e3a8886b05..d48c869040 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 @@ -61,10 +61,10 @@ public TraceSection(Hub hub) { } /** Default creator specifying the max number of rows the section can contain. */ - public TraceSection(final Hub hub, final short maxNbOfLines) { + public TraceSection(final Hub hub, final short maxNumberOfLines) { this.hub = hub; this.commonValues = new CommonFragmentValues(hub); - this.fragments = new ArrayList<>(maxNbOfLines); + this.fragments = new ArrayList<>(maxNumberOfLines); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index 8ce73f72ad..93e611c771 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -15,13 +15,71 @@ package net.consensys.linea.zktracer.module.hub.section.copy; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; public class CallDataCopySection extends TraceSection { - public CallDataCopySection(Hub hub, TraceFragment... chunks) { - super(hub); - this.addFragmentsAndStack(hub, chunks); + + final short exceptions; + + public CallDataCopySection(Hub hub) { + // 3 = 1 + 2 + super(hub, (short) 3); + this.exceptions = hub.pch().exceptions(); + + hub.addTraceSection(this); + this.populate(hub); + } + + public void populate(Hub hub) { + + ImcFragment imcFragment = ImcFragment.empty(hub); + this.addFragmentsAndStack(hub, imcFragment); + + // triggerOob = false + // triggerMxp = true + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + + Preconditions.checkArgument( + mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + + // the only allowable exceptions are + // - memoryExpansionException (MXPX) + // - outOfGasException OOGX + //////////////////////////////////// + + // The MXPX case + //////////////// + if (mxpCall.mxpx) { + return; + } + + // The OOGX case + //////////////// + if (Exceptions.any(exceptions)) { + Preconditions.checkArgument(this.exceptions == Exceptions.OUT_OF_GAS_EXCEPTION); + return; + } + + // The unexceptional case + ///////////////////////// + + ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + this.addFragment(currentContext); + + final boolean triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; + if (!triggerMmu) { + return; + } + + MmuCall mmuCall = MmuCall.callDataCopy(hub); + imcFragment.callMmu(mmuCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 2632c7026f..a193621ed4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -92,7 +92,7 @@ public CodeCopySection(Hub hub) { } triggerMmu = !xahoy && mxpCall.isMayTriggerNonTrivialMmuOperation(); - hub.defers().resolvePostTransaction(hub, null, null, true); // TODO: pass the right parameters + hub.defers().schedulePostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java deleted file mode 100644 index 9d0aadb3e8..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CopySection.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.copy; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import net.consensys.linea.zktracer.opcode.OpCode; - -public class CopySection extends TraceSection { - - // TODO: this constructor is not really necessary - public CopySection(Hub hub) { - super(hub); - } - - public void populateSection(Hub hub) { - - /* - CopySection.addTraceSection(this); - TraceSection copySection = new CopySection(this); - if (!this.opCode().equals(OpCode.RETURNDATACOPY) && !this.opCode().equals(OpCode.CALLDATACOPY)) { - final Bytes rawTargetAddress = - switch (this.currentFrame().opCode()) { - case CODECOPY -> this.currentFrame().byteCodeAddress(); - case EXTCODECOPY -> frame.getStackItem(0); - default -> throw new IllegalStateException( - String.format("unexpected opcode %s", this.opCode())); - }; - final Address targetAddress = Words.toAddress(rawTargetAddress); - final Account targetAccount = frame.getWorldUpdater().get(targetAddress); - - AccountSnapshot accountBefore = - AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - - AccountSnapshot accountAfter = - AccountSnapshot.fromAccount( - targetAccount, - true, - this.transients.conflation().deploymentInfo().number(targetAddress), - this.transients.conflation().deploymentInfo().isDeploying(targetAddress)); - - // TODO: this is deprecated, update it. Factories creates an account row (accountFragment) - // ImcFragment is for miscellaneaous rows - // ContextFragment - DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this, 0); - copySection.addFragment( - this.currentFrame().opCode() == OpCode.EXTCODECOPY - ? this.factories - .accountFragment() - .makeWithTrm( - accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps) - : this.factories - .accountFragment() - .make(accountBefore, accountAfter, doingDomSubStamps)); - - if (this.callStack.current().willRevert()) { - DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this, 0); - copySection.addFragment( - this.factories - .accountFragment() - .make(accountAfter, accountBefore, undoingDomSubStamps)); - } - } else { - copySection.addFragment(ContextFragment.readCurrentContextData(this)); - } - this.addTraceSection(copySection); - */ - - switch (hub.opCode()) { - case OpCode.CALLDATACOPY -> new CallDataCopySection(hub); - case OpCode.RETURNDATACOPY -> { - ReturnDataCopySection returnDataCopySection = new ReturnDataCopySection(hub); - hub.addTraceSection(returnDataCopySection); - returnDataCopySection.populateSection(hub); - } - case OpCode.CODECOPY -> new CodeCopySection(hub); - case OpCode.EXTCODECOPY -> { - ExtCodeCopySection extCodeCopySection = new ExtCodeCopySection(hub); - hub.addTraceSection(extCodeCopySection); - extCodeCopySection.populate(hub); - } - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 8ccbe81909..bf96c371de 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -49,7 +49,8 @@ public class ExtCodeCopySection extends TraceSection implements PostRollbackDefe AccountSnapshot accountAfter; public ExtCodeCopySection(Hub hub) { - super(hub); + // 4 = 1 + 3 + super(hub, (short) 4); final MessageFrame frame = hub.messageFrame(); this.rawAddress = frame.getStackItem(0); this.address = Address.extract((Bytes32) this.rawAddress); @@ -59,6 +60,9 @@ public ExtCodeCopySection(Hub hub) { hub.transients().conflation().deploymentInfo().isDeploying(this.address); this.incomingWarmth = frame.isAddressWarm(this.address); this.exceptions = hub.pch().exceptions(); + + this.populate(hub); + hub.addTraceSection(this); } public void populate(Hub hub) { @@ -110,12 +114,16 @@ public void populate(Hub hub) { // The unexceptional case ///////////////////////// final boolean triggerMmu = - none(this.exceptions) && mxpCall.isMayTriggerNonTrivialMmuOperation(); + none(this.exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { MmuCall mmuCall = MmuCall.extCodeCopy(hub); imcFragment.callMmu(mmuCall); } + // TODO: make sure that hasCode returns false during deployments + // in particular: write tests for that scenario + final boolean triggerCfi = triggerMmu && foreignAccount.hasCode(); + this.accountAfter = AccountSnapshot.fromAccount( foreignAccount, true, this.incomingDeploymentNumber, this.incomingDeploymentStatus); @@ -124,7 +132,7 @@ public void populate(Hub hub) { hub.factories() .accountFragment() .makeWithTrm(this.accountBefore, this.accountAfter, this.rawAddress, doingDomSubStamps); - + accountDoingFragment.requiresRomlex(triggerCfi); this.addFragment(accountDoingFragment); // an EXTCODECOPY section is only scheduled diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 38bff6a5fb..45209427e9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -30,11 +30,15 @@ public class ReturnDataCopySection extends TraceSection { final short exceptions; public ReturnDataCopySection(Hub hub) { - super(hub); + // 4 = 1 + 3 + super(hub, (short) 4); this.exceptions = hub.pch().exceptions(); + + this.populate(hub); + hub.addTraceSection(this); } - public void populateSection(Hub hub) { + public void populate(Hub hub) { ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); this.addFragmentsAndStack(hub, currentContext); From 45ae0208aedff00b8bdb7e51c062b0b72b8ac738 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 9 Jul 2024 17:05:16 +0200 Subject: [PATCH 183/461] fix(hub): CODECOPY --- .../linea/zktracer/module/hub/Hub.java | 4 +- .../module/hub/defer/DeferRegistry.java | 9 +- .../hub/section/copy/CallDataCopySection.java | 2 +- .../hub/section/copy/CodeCopySection.java | 96 ++++++++++--------- .../hub/section/copy/ExtCodeCopySection.java | 3 +- 5 files changed, 65 insertions(+), 49 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 645a017c7e..71b2ad6e6c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1310,7 +1310,9 @@ void traceOperation(MessageFrame frame) { } } - // In all cases, add a context fragment if an exception occurred + // NOTE: whenever there is an exception, a context row is added at the end to update the + // caller context with empty return data + //////////////////////////////////////////////////////////////////////////////////////// if (Exceptions.any(this.pch().exceptions())) { this.currentTraceSection() .addFragment(ContextFragment.executionProvidesEmptyReturnData(this)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 44abbc66c1..e2ab64142e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -33,7 +33,9 @@ * Stores different categories of actions whose execution must be deferred later in the normal * transaction execution process. */ -public class DeferRegistry { +// TODO: fix naming and implement the missing interfaces +public class DeferRegistry + implements PostExecDefer, PostRollbackDefer, PostTransactionDefer, PostConflationDefer { /** A list of actions deferred until the end of the current conflation execution */ private final List postConflationDefers = new ArrayList<>(); @@ -109,6 +111,7 @@ public void resolveWithNextContext(Hub hub, MessageFrame frame) { * @param tx the current {@link Transaction} */ // TODO: should use the TransactionProcessingMetadata + @Override public void resolvePostTransaction( Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { for (PostTransactionDefer defer : this.postTransactionDefers) { @@ -122,6 +125,7 @@ public void resolvePostTransaction( * * @param hub the {@link Hub} context */ + @Override public void resolvePostConflation(Hub hub, WorldView world) { for (PostConflationDefer defer : this.postConflationDefers) { defer.resolvePostConflation(hub, world); @@ -136,6 +140,7 @@ public void resolvePostConflation(Hub hub, WorldView world) { * @param frame the {@link MessageFrame} of the transaction * @param result the {@link Operation.OperationResult} of the transaction */ + @Override public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult result) { for (PostExecDefer defer : this.postExecDefers) { defer.resolvePostExecution(hub, frame, result); @@ -149,6 +154,7 @@ public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.Operatio * @param hub the {@link Hub} context * @param frame the {@link MessageFrame} of the transaction */ + // (ReEnterContextDefer?) public void resolveAtReEntry(Hub hub, MessageFrame frame) { for (ReEnterContextDefer defer : this.reEntryDefers) { defer.resolveAtContextReEntry(hub, frame); @@ -177,6 +183,7 @@ public void resolveAtReEntry(Hub hub, MessageFrame frame) { *

Note that the "current messageFrame" is expected to STILL BE the messageFrame responsible * for the rollback. */ + @Override public void resolvePostRollback( final Hub hub, final MessageFrame messageFrame, CallFrame currentCallFrame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index 93e611c771..45a0e2916a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -48,7 +48,7 @@ public void populate(Hub hub) { imcFragment.callMxp(mxpCall); Preconditions.checkArgument( - mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); // the only allowable exceptions are // - memoryExpansionException (MXPX) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index a193621ed4..3c2b13a128 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -15,8 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section.copy; -import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; - +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; @@ -27,71 +26,87 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; -public class CodeCopySection implements PostTransactionDefer { - CodeCopyCommonSection sectionPrequel; +public class CodeCopySection extends TraceSection implements PostTransactionDefer { ImcFragment imcFragment; boolean triggerMmu; + final short exceptions; public CodeCopySection(Hub hub) { - this.sectionPrequel = new CodeCopyCommonSection(hub); - hub.addTraceSection(sectionPrequel); + // 4 = 1 (stack row) + 3 (up to 3 non-stack rows) + super(hub, (short) 4); + this.exceptions = hub.pch().exceptions(); + this.populate(hub); + hub.addTraceSection(this); + } + public void populate(Hub hub) { // Miscellaneous row imcFragment = ImcFragment.empty(hub); - this.sectionPrequel.addFragmentsAndStack(hub, imcFragment); + this.addFragmentsAndStack(hub, imcFragment); // triggerOob = false // triggerMxp = true MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - boolean xahoy = mxpCall.mxpx || outOfGasException(hub.pch().exceptions()); + boolean mxpx = mxpCall.mxpx; + Preconditions.checkArgument(mxpx == Exceptions.memoryExpansionException(exceptions)); + + // The MXPX case + //////////////// + if (mxpx) { + return; + } + + boolean xahoy = Exceptions.any(exceptions); + Preconditions.checkArgument(xahoy == (exceptions == Exceptions.OUT_OF_GAS_EXCEPTION)); + + // The OOGX case + //////////////// + if (Exceptions.any(exceptions)) { + return; + } + + // Beyond this point we are in the xahoy = false case // Context row - // TODO: use ContextFragment.readContextDataByContextNumber(hub, CN) - ContextFragment contextFragment = - xahoy - ? ContextFragment.executionProvidesEmptyReturnData(hub) - : ContextFragment.readCurrentContextData(hub); - this.sectionPrequel.addFragment(contextFragment); + ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); + this.addFragment(contextFragment); // Account row final MessageFrame frame = hub.messageFrame(); - final Bytes rawTargetAddress = frame.getStackItem(0); - final Address targetAddress = Address.extract((Bytes32) rawTargetAddress); - final Account targetAccount = frame.getWorldUpdater().get(targetAddress); + final Address codeAddress = frame.getContractAddress(); + final Account codeAccount = frame.getWorldUpdater().get(codeAddress); + + boolean warmth = frame.isAddressWarm(codeAddress); + Preconditions.checkArgument(warmth); - AccountSnapshot accountBefore = + AccountSnapshot codeAccountSnapshot = AccountSnapshot.fromAccount( - targetAccount, - frame.isAddressWarm(targetAddress), - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); + codeAccount, + warmth, + hub.transients().conflation().deploymentInfo().number(codeAddress), + hub.transients().conflation().deploymentInfo().isDeploying(codeAddress)); DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(hub, 0); // Specifics for CODECOPY - if (mxpCall.mxpx) { - AccountFragment accountReadingFragment = - hub.factories() - .accountFragment() - .makeWithTrm(accountBefore, accountBefore, rawTargetAddress, doingDomSubStamps); + AccountFragment accountReadingFragment = + hub.factories() + .accountFragment() + .make(codeAccountSnapshot, codeAccountSnapshot, doingDomSubStamps); - this.sectionPrequel.addFragment(accountReadingFragment); - return; - } - if (!xahoy) { - // TODO: ? - } + accountReadingFragment.requiresRomlex(true); - triggerMmu = !xahoy && mxpCall.isMayTriggerNonTrivialMmuOperation(); + this.addFragment(accountReadingFragment); + + triggerMmu = mxpCall.isMayTriggerNonTrivialMmuOperation(); hub.defers().schedulePostTransaction(this); } @@ -103,11 +118,4 @@ public void resolvePostTransaction( imcFragment.callMmu(mmuCall); } } - - public static class CodeCopyCommonSection extends TraceSection { - public CodeCopyCommonSection(Hub hub) { - super(hub); - // TODO: do we need something else here? - } - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index bf96c371de..c44ad406e5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -113,8 +113,7 @@ public void populate(Hub hub) { // The unexceptional case ///////////////////////// - final boolean triggerMmu = - none(this.exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; + final boolean triggerMmu = none(this.exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { MmuCall mmuCall = MmuCall.extCodeCopy(hub); imcFragment.callMmu(mmuCall); From 8f7330ea500e619755f322e49980d93732f1ca4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 9 Jul 2024 23:27:58 +0200 Subject: [PATCH 184/461] fix(hub): canonical AccountSnapshot method + CallFrame fixes - the canonical AccountSnapshot method replaces 'fromWorld' and incorporates missing elements - the CallFrame now correctly tracks - getsReverted - selfReverts - revertStamp --- .../zktracer/module/hub/AccountSnapshot.java | 22 ++++++++--- .../linea/zktracer/module/hub/Hub.java | 14 +++---- .../hub/fragment/DomSubStampsSubFragment.java | 4 +- .../hub/fragment/account/AccountFragment.java | 2 +- .../hub/fragment/common/CommonFragment.java | 2 +- .../module/hub/section/JumpSection.java | 25 ++++++------ .../zktracer/runtime/callstack/CallFrame.java | 38 ++++++++----------- .../types/TransactionProcessingMetadata.java | 4 +- 8 files changed, 60 insertions(+), 51 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 97f59a5d61..cbd8d4f447 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -26,7 +26,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.worldstate.WorldView; @AllArgsConstructor @Getter @@ -42,6 +41,18 @@ public class AccountSnapshot { private int deploymentNumber; private boolean deploymentStatus; + public static AccountSnapshot canonical(Hub hub, Address address) { + final Account account = hub.messageFrame().getWorldUpdater().getAccount(address); + return new AccountSnapshot( + address, + account.getNonce(), + account.getBalance(), + hub.messageFrame().isAddressWarm(address), + new Bytecode(account.getCode()), + hub.transients.conflation().deploymentInfo().number(address), + hub.transients.conflation().deploymentInfo().isDeploying(address)); + } + public AccountSnapshot decrementBalance(Wei quantity) { Preconditions.checkState( this.balance.greaterOrEqualThan(quantity), @@ -55,10 +66,11 @@ public AccountSnapshot incrementBalance(Wei quantity) { return this; } - public static AccountSnapshot fromWorld(WorldView world, Address address) { - final Account account = world.get(address); - return fromAccount(account, true, 0, false); // TODO: implement warm, depNumber and Status - } + // Deprecated ? + // public static AccountSnapshot fromWorld(WorldView world, Address address) { + // final Account account = world.get(address); + // return fromAccount(account, true, 0, false); // TODO: implement warm, depNumber and Status + // } public static AccountSnapshot fromAccount( Account account, boolean isWarm, int deploymentNumber, boolean deploymentStatus) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 71b2ad6e6c..c82724a7c2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -493,6 +493,7 @@ public void traceEndTransaction( this.txStack .current() .completeLineaTransaction( + this, world, isSuccessful, this.state.stamps().hub(), @@ -1304,15 +1305,14 @@ void traceOperation(MessageFrame frame) { } } - case JUMP -> { - JumpSection jumpSection = new JumpSection(this); - jumpSection.populateSection(this); - } + case JUMP -> new JumpSection(this); } - // NOTE: whenever there is an exception, a context row is added at the end to update the - // caller context with empty return data - //////////////////////////////////////////////////////////////////////////////////////// + // NOTE: whenever there is an exception, a context row + // is added at the end of the section; its purpose is + // to update the caller / creator context with empty + // return data. + /////////////////////////////////////////////////////// if (Exceptions.any(this.pch().exceptions())) { this.currentTraceSection() .addFragment(ContextFragment.executionProvidesEmptyReturnData(this)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java index 7d98e9c65a..6d771090d9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java @@ -50,7 +50,7 @@ public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( hub.stamp(), 0, subOffset, - hub.callStack().current().getsRevertedAt(), + hub.callStack().current().revertStamp(), 0, 0); } @@ -58,7 +58,7 @@ public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( public static DomSubStampsSubFragment revertsWithChildDomSubStamps( final Hub hub, final CallFrame child, final int subOffset) { return new DomSubStampsSubFragment( - DomSubType.REVERTS_WITH_CHILD, hub.stamp(), 0, subOffset, 0, child.getsRevertedAt(), 0); + DomSubType.REVERTS_WITH_CHILD, hub.stamp(), 0, subOffset, 0, child.revertStamp(), 0); } public static DomSubStampsSubFragment selfdestructDomSubStamps(final Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 69473f8d62..1d2a8fed9d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -135,7 +135,7 @@ public Trace trace(Trace trace) { || !newState.balance().isZero()) .pAccountWarmth(oldState.isWarm()) .pAccountWarmthNew(newState.isWarm()) - .pAccountMarkedForSelfdestruct(false) // TODO: + .pAccountMarkedForSelfdestruct(false) // TODO .pAccountMarkedForSelfdestructNew(false) // TODO .pAccountDeploymentNumber(oldState.deploymentNumber()) .pAccountDeploymentNumberNew(newState.deploymentNumber()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java index e9649627f2..ffe7218335 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java @@ -90,7 +90,7 @@ public Trace trace(Trace trace) { .contextWillRevert(frame.willRevert()) .contextGetsReverted(frame.getsReverted()) .contextSelfReverts(frame.selfReverts()) - .contextRevertStamp(commonFragmentValues.cnRevertStamp) + .contextRevertStamp(frame.revertStamp()) .codeFragmentIndex(commonFragmentValues.codeFragmentIndex) .programCounter(commonFragmentValues.pc) .programCounterNew(commonFragmentValues.pcNew) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index a9dd0c3593..207aacc5f5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section; -import static net.consensys.linea.zktracer.module.hub.AccountSnapshot.fromAddress; +import static net.consensys.linea.zktracer.module.hub.AccountSnapshot.*; import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; @@ -33,10 +33,17 @@ public class JumpSection extends TraceSection { + public JumpSection(Hub hub) { + // 5 = 1 + 4 + // There are up to 4 NSR's + super(hub, (short) 5); + this.populateSection(hub); + hub.addTraceSection(this); + } + public void populateSection(Hub hub) { this.addFragmentsAndStack(hub); - hub.addTraceSection(this); if (Exceptions.outOfGasException(hub.pch().exceptions())) { return; @@ -49,8 +56,6 @@ public void populateSection(Hub hub) { // ACCOUNT fragment /////////////////// Address codeAddress = hub.messageFrame().getContractAddress(); - AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); final int deploymentNumber = deploymentInfo.number(codeAddress); @@ -59,12 +64,12 @@ public void populateSection(Hub hub) { final boolean warmth = hub.messageFrame().isAddressWarm(codeAddress); Preconditions.checkArgument(warmth); - AccountSnapshot codeAccount = - fromAddress(codeAddress, warmth, deploymentNumber, deploymentStatus); + AccountSnapshot codeAccount = canonical(hub, codeAddress); AccountFragment accountRowCodeAccount = - accountFragmentFactory.make( - codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + hub.factories() + .accountFragment() + .make(codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); // MISCELLANEOUS fragment ///////////////////////// @@ -96,8 +101,4 @@ public void populateSection(Hub hub) { this.triggerJumpDestinationVetting(hub); } } - - public JumpSection(Hub hub) { - super(hub); - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 8b7780c332..343410995c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -140,8 +140,9 @@ public int getCodeFragmentIndex(Hub hub) { /** the latest child context to have been called from this frame */ @Getter @Setter private int returnDataContextNumber = 0; - @Getter @Setter private int selfRevertsAt = 0; - @Getter @Setter private int getsRevertedAt = 0; + @Getter @Setter private boolean selfReverts = false; + @Getter @Setter private boolean getsReverted = false; + @Getter @Setter private int revertStamp = 0; /** this frame {@link Stack}. */ @Getter private final Stack stack = new Stack(); @@ -300,30 +301,23 @@ public ContractMetadata metadata() { this.byteCodeAddress, this.codeDeploymentNumber, this.isDeployment); } - private void revertChildren(CallStack callStack, int stamp) { - if (this.getsRevertedAt == 0) { - this.getsRevertedAt = stamp; + private void revertChildren(CallStack callStack, int parentRevertStamp) { this.childFrames.stream() .map(callStack::getById) - .forEach(frame -> frame.revertChildren(callStack, stamp)); - } + .forEach(frame -> { + frame.getsReverted = true; + if (!frame.selfReverts) { frame.revertStamp = parentRevertStamp; } + frame.revertChildren(callStack, parentRevertStamp); + }); } - public void revert(CallStack callStack, int stamp) { - if (this.selfRevertsAt == 0) { - this.selfRevertsAt = stamp; - this.revertChildren(callStack, stamp); - } else if (stamp != this.selfRevertsAt) { - throw new IllegalStateException("a context can not self-reverse twice"); + public void revert(CallStack callStack, int revertStamp) { + if (this.selfReverts) { + throw new IllegalStateException("a context can not self-revert twice"); } - } - - public boolean selfReverts() { - return this.selfRevertsAt > 0; - } - - public boolean getsReverted() { - return this.getsRevertedAt > 0; + this.selfReverts = true; + this.revertStamp = revertStamp; + this.revertChildren(callStack, revertStamp); } public boolean willRevert() { @@ -331,7 +325,7 @@ public boolean willRevert() { } public boolean hasReverted() { - return (this.selfRevertsAt > 0) || (this.getsRevertedAt > 0); + return this.selfReverts || this.getsReverted; } public void frame(MessageFrame frame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index b4da6f30b9..22001de1a2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -29,6 +29,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; @@ -160,6 +161,7 @@ public void setPreFinalisationValues( } public void completeLineaTransaction( + Hub hub, WorldView world, final boolean statusCode, final int hubStampTransactionEnd, @@ -171,7 +173,7 @@ public void completeLineaTransaction( (hubPhase == TX_SKIP) ? hubStampTransactionEnd : hubStampTransactionEnd + 1; this.logs = logs; for (Address address : selfDestructs) { - this.destructedAccountsSnapshot.add(AccountSnapshot.fromWorld(world, address)); + this.destructedAccountsSnapshot.add(AccountSnapshot.canonical(hub, address)); } } From 7e334273bcd4d74da0d0b48cfb174408aeb2aa43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 9 Jul 2024 23:48:38 +0200 Subject: [PATCH 185/461] fix(hub): final context row for exceptional opcodes now drawn only once --- .../consensys/linea/zktracer/module/hub/Hub.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c82724a7c2..9e744a3800 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -699,7 +699,11 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope final boolean exceptional = Exceptions.any(exceptions); /* TODO: Might be dangerous : in some cases, we add fragments at the end of the transaction, we need an other mechanism ... */ - // adds the final context row to reset the caller's return data + // NOTE: whenever there is an exception, a context row + // is added at the end of the section; its purpose is + // to update the caller / creator context with empty + // return data. + ////////////////////////////////////////////////////// if (exceptional) { this.currentTraceSection() .addFragmentsWithoutStack(ContextFragment.executionProvidesEmptyReturnData(this)); @@ -1307,16 +1311,6 @@ void traceOperation(MessageFrame frame) { case JUMP -> new JumpSection(this); } - - // NOTE: whenever there is an exception, a context row - // is added at the end of the section; its purpose is - // to update the caller / creator context with empty - // return data. - /////////////////////////////////////////////////////// - if (Exceptions.any(this.pch().exceptions())) { - this.currentTraceSection() - .addFragment(ContextFragment.executionProvidesEmptyReturnData(this)); - } } public TraceSection getCurrentSection() { From 39206fa46be57814b6536eb74103ada11a513394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 10 Jul 2024 11:15:14 +0200 Subject: [PATCH 186/461] spotless --- .../zktracer/runtime/callstack/CallFrame.java | 17 ++++++++++------- .../instructionprocessing/JumpTests.java | 14 ++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 343410995c..4bdf99f4ff 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -302,13 +302,16 @@ public ContractMetadata metadata() { } private void revertChildren(CallStack callStack, int parentRevertStamp) { - this.childFrames.stream() - .map(callStack::getById) - .forEach(frame -> { - frame.getsReverted = true; - if (!frame.selfReverts) { frame.revertStamp = parentRevertStamp; } - frame.revertChildren(callStack, parentRevertStamp); - }); + this.childFrames.stream() + .map(callStack::getById) + .forEach( + frame -> { + frame.getsReverted = true; + if (!frame.selfReverts) { + frame.revertStamp = parentRevertStamp; + } + frame.revertChildren(callStack, parentRevertStamp); + }); } public void revert(CallStack callStack, int revertStamp) { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index 452b9ba7aa..c62c64895a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -25,11 +25,13 @@ @ExtendWith(EvmExtension.class) public class JumpTests { - /** - * NOTE: the bytecode we propose will at time use the following offsets (unless the initial push - * is large!) bytecode: PUSHX pcNew // offsets: 0, 1 JUMP // offset: 2 INVALID // offset: 3 - * JUMPDEST // offset: 4 PUSH1 0x5b // offsets: 5, 6 <- 0x5b is the byte value of JUMPDEST - */ + // NOTE: the bytecode we propose will at time use the following offsets (unless the initial push + // is large!) bytecode: + // - PUSHX pcNew // offsets: 0, 1 + // - JUMP // offset: 2 + // - INVALID // offset: 3 + // - JUMPDEST // offset: 4 + // - PUSH1 0x5b // offsets: 5, 6 <- 0x5b is the byte value of JUMPDEST Bytes testCodeForJumpScenario(String pcNew) { return BytecodeCompiler.newProgram() .push(pcNew) @@ -52,7 +54,7 @@ void jumpOntoInvalidTest() { @Test void jumpOntoJumpDestByteOwnedBySomePush() { - BytecodeRunner.of(testCodeForJumpScenario("5")).run(); + BytecodeRunner.of(testCodeForJumpScenario("6")).run(); } @Test From d0eecae420f1f763f7c93943344ce5bfa5c1c5f2 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 12:42:03 +0200 Subject: [PATCH 187/461] feat(hub): parametrized jump tests and added jumpi tests --- .../instructionprocessing/JumpTests.java | 80 +++++++------------ .../instructionprocessing/JumpiTests.java | 78 ++++++++++++++++++ 2 files changed, 107 insertions(+), 51 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index c62c64895a..601d4cf012 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -14,13 +14,16 @@ */ package net.consensys.linea.zktracer.instructionprocessing; +import java.util.stream.Stream; + import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; import net.consensys.linea.zktracer.testing.EvmExtension; -import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; @ExtendWith(EvmExtension.class) public class JumpTests { @@ -32,56 +35,31 @@ public class JumpTests { // - INVALID // offset: 3 // - JUMPDEST // offset: 4 // - PUSH1 0x5b // offsets: 5, 6 <- 0x5b is the byte value of JUMPDEST - Bytes testCodeForJumpScenario(String pcNew) { - return BytecodeCompiler.newProgram() - .push(pcNew) - .op(OpCode.JUMP) - .op(OpCode.INVALID) - .op(OpCode.JUMPDEST) - .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST - .compile(); - } - - @Test - void jumpOntoJumpDestTest() { - BytecodeRunner.of(testCodeForJumpScenario("4")).run(); - } - - @Test - void jumpOntoInvalidTest() { - BytecodeRunner.of(testCodeForJumpScenario("3")).run(); - } - - @Test - void jumpOntoJumpDestByteOwnedBySomePush() { - BytecodeRunner.of(testCodeForJumpScenario("6")).run(); - } - - @Test - void jumpOutOfBoundsSmall() { - BytecodeRunner.of(testCodeForJumpScenario("0xff")).run(); - } - - @Test - void jumpOutOfBoundsMaxUint128() { - BytecodeRunner.of(testCodeForJumpScenario("0xffffffffffffffffffffffffffffffff")).run(); - } - - @Test - void jumpOutOfBoundsTwoToThe128() { - BytecodeRunner.of(testCodeForJumpScenario("0x0100000000000000000000000000000000")).run(); - } - - @Test - void jumpOutOfBoundsTwoToThe128Plus4() { - BytecodeRunner.of(testCodeForJumpScenario("0x0100000000000000000000000000000004")).run(); - } - - @Test - void jumpOutOfBoundsMaxUint256() { + @ParameterizedTest + @MethodSource("provideJumpScenario") + void testCodeForJumpScenario(String description, String pcNew) { BytecodeRunner.of( - testCodeForJumpScenario( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + BytecodeCompiler.newProgram() + .push(pcNew) + .op(OpCode.JUMP) + .op(OpCode.INVALID) + .op(OpCode.JUMPDEST) + .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST + .compile()) .run(); } + + private static Stream provideJumpScenario() { + return Stream.of( + Arguments.of("jumpOntoJumpDestTest", "4"), + Arguments.of("jumpOntoInvalidTest", "3"), + Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), + Arguments.of("jumpOutOfBoundsSmall", "0xff"), + Arguments.of("jumpOutOfBoundsMaxUint128", "0xffffffffffffffffffffffffffffffff"), + Arguments.of("jumpOutOfBoundsTwoToThe128", "0x0100000000000000000000000000000000"), + Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0x0100000000000000000000000000000004"), + Arguments.of( + "jumpOutOfBoundsMaxUint256", + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java new file mode 100644 index 0000000000..62e33b21ce --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -0,0 +1,78 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import java.util.stream.Stream; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import net.consensys.linea.zktracer.testing.EvmExtension; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +@ExtendWith(EvmExtension.class) +public class JumpiTests { + + // NOTE: the bytecode we propose will at time use the following offsets (unless the initial push + // is large!) bytecode: + // - PUSH1 b // 0, 1 + // - PUSHX pcNew // offsets: 2, 3 + // - JUMP // offset: 4 + // - INVALID // offset: 5 + // - JUMPDEST // offset: 6 + // - PUSH1 0x5b // offsets: 7, 8 <- 0x5b is the byte value of JUMPDEST + @ParameterizedTest + @MethodSource("provideJumpiScenario") + void testCodeForJumpiScenario(String description, boolean jumpiCondition, String pcNew) { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push(jumpiCondition ? 1 : 0) + .push(pcNew) + .op(OpCode.JUMP) + .op(OpCode.INVALID) + .op(OpCode.JUMPDEST) + .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST + .compile()) + .run(); + } + + private static Stream provideJumpiScenario() { + return Stream.concat( + provideJumpiScenarioForJumpiCondition(true), provideJumpiScenarioForJumpiCondition(false)); + } + + private static Stream provideJumpiScenarioForJumpiCondition(boolean jumpiCondition) { + return Stream.of( + Arguments.of("jumpOntoJumpDestTest", jumpiCondition, "6"), + Arguments.of("jumpOntoInvalidTest", jumpiCondition, "5"), + Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", jumpiCondition, "8"), + Arguments.of("jumpOutOfBoundsSmall", jumpiCondition, "0xff"), + Arguments.of( + "jumpOutOfBoundsMaxUint128", jumpiCondition, "0xffffffffffffffffffffffffffffffff"), + Arguments.of( + "jumpOutOfBoundsTwoToThe128", jumpiCondition, "0x0100000000000000000000000000000000"), + Arguments.of( + "jumpOutOfBoundsTwoToThe128Plus4", + jumpiCondition, + "0x0100000000000000000000000000000004"), + Arguments.of( + "jumpOutOfBoundsMaxUint256", + jumpiCondition, + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + } +} From 5ea6fd9098b47c8f1b4240dc8bfedf3e4fd3bc81 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 12:53:42 +0200 Subject: [PATCH 188/461] feat(hub): added comment to jump tests --- .../instructionprocessing/JumpTests.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index 601d4cf012..cce176b7e2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -51,15 +51,19 @@ void testCodeForJumpScenario(String description, String pcNew) { private static Stream provideJumpScenario() { return Stream.of( - Arguments.of("jumpOntoJumpDestTest", "4"), - Arguments.of("jumpOntoInvalidTest", "3"), - Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), - Arguments.of("jumpOutOfBoundsSmall", "0xff"), - Arguments.of("jumpOutOfBoundsMaxUint128", "0xffffffffffffffffffffffffffffffff"), - Arguments.of("jumpOutOfBoundsTwoToThe128", "0x0100000000000000000000000000000000"), - Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0x0100000000000000000000000000000004"), - Arguments.of( - "jumpOutOfBoundsMaxUint256", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + Arguments.of("jumpOntoJumpDestTest", "4"), + Arguments.of("jumpOntoInvalidTest", "3"), + Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), + Arguments.of("jumpOutOfBoundsSmall", "0xff"), + Arguments.of("jumpOutOfBoundsMaxUint128", "0xffffffffffffffffffffffffffffffff"), + Arguments.of("jumpOutOfBoundsTwoToThe128", "0x0100000000000000000000000000000000"), + Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0x0100000000000000000000000000000004"), + Arguments.of( + "jumpOutOfBoundsMaxUint256", + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + /* + In order to run a specific test case (for example, the first one) use the following: + .filter(arguments -> "jumpOntoJumpDestTest".equals(arguments.get()[0])); + */ } } From 075057cae9897a45bfbea2c63ce039f687add39c Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 14:32:40 +0200 Subject: [PATCH 189/461] feat(hub): tested more jumpiConditions for JUMPI --- .../instructionprocessing/JumpiTests.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index 62e33b21ce..6e56ba39fb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -14,6 +14,8 @@ */ package net.consensys.linea.zktracer.instructionprocessing; +import java.util.ArrayList; +import java.util.List; import java.util.stream.Stream; import net.consensys.linea.zktracer.opcode.OpCode; @@ -28,7 +30,7 @@ @ExtendWith(EvmExtension.class) public class JumpiTests { - // NOTE: the bytecode we propose will at time use the following offsets (unless the initial push + // NOTE: the bytecode we propose will at time use the following offsets (unless one of the two initial push // is large!) bytecode: // - PUSH1 b // 0, 1 // - PUSHX pcNew // offsets: 2, 3 @@ -38,10 +40,10 @@ public class JumpiTests { // - PUSH1 0x5b // offsets: 7, 8 <- 0x5b is the byte value of JUMPDEST @ParameterizedTest @MethodSource("provideJumpiScenario") - void testCodeForJumpiScenario(String description, boolean jumpiCondition, String pcNew) { + void testCodeForJumpiScenario(String description, String jumpiCondition, String pcNew) { BytecodeRunner.of( BytecodeCompiler.newProgram() - .push(jumpiCondition ? 1 : 0) + .push(jumpiCondition) .push(pcNew) .op(OpCode.JUMP) .op(OpCode.INVALID) @@ -52,12 +54,16 @@ void testCodeForJumpiScenario(String description, boolean jumpiCondition, String } private static Stream provideJumpiScenario() { - return Stream.concat( - provideJumpiScenarioForJumpiCondition(true), provideJumpiScenarioForJumpiCondition(false)); + List jumpiScenarios = new ArrayList<>(); + List jumpiConditions = List.of("0", "1", "0xdeadbeefdeadcafedeadceefdeadcafe", "0xffffffffffffffffffffffffffffffff", "0x0100000000000000000000000000000001", "0xcafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + for (String jumpiCondition: jumpiConditions) { + jumpiScenarios.addAll(provideJumpiScenarioForJumpiCondition(jumpiCondition)); + } + return jumpiScenarios.stream(); } - private static Stream provideJumpiScenarioForJumpiCondition(boolean jumpiCondition) { - return Stream.of( + private static List provideJumpiScenarioForJumpiCondition(String jumpiCondition) { + return List.of( Arguments.of("jumpOntoJumpDestTest", jumpiCondition, "6"), Arguments.of("jumpOntoInvalidTest", jumpiCondition, "5"), Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", jumpiCondition, "8"), From e794432d3649c4099223d7194c5e85a0bbd08d7b Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 14:35:43 +0200 Subject: [PATCH 190/461] fix(hub): typo --- .../linea/zktracer/instructionprocessing/JumpiTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index 6e56ba39fb..f359112654 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -55,7 +55,7 @@ void testCodeForJumpiScenario(String description, String jumpiCondition, String private static Stream provideJumpiScenario() { List jumpiScenarios = new ArrayList<>(); - List jumpiConditions = List.of("0", "1", "0xdeadbeefdeadcafedeadceefdeadcafe", "0xffffffffffffffffffffffffffffffff", "0x0100000000000000000000000000000001", "0xcafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + List jumpiConditions = List.of("0", "1", "0xdeadbeefdeadcafedeadbeefdeadcafe", "0xffffffffffffffffffffffffffffffff", "0x0100000000000000000000000000000001", "0xcafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); for (String jumpiCondition: jumpiConditions) { jumpiScenarios.addAll(provideJumpiScenarioForJumpiCondition(jumpiCondition)); } From 00aa704cfe9950e56e5848182cb8ed08e6301c2b Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 14:54:54 +0200 Subject: [PATCH 191/461] fix(hub): spotless --- .../instructionprocessing/JumpTests.java | 28 +++++++++---------- .../instructionprocessing/JumpiTests.java | 15 ++++++++-- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index cce176b7e2..0b6b5e51ce 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -51,19 +51,19 @@ void testCodeForJumpScenario(String description, String pcNew) { private static Stream provideJumpScenario() { return Stream.of( - Arguments.of("jumpOntoJumpDestTest", "4"), - Arguments.of("jumpOntoInvalidTest", "3"), - Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), - Arguments.of("jumpOutOfBoundsSmall", "0xff"), - Arguments.of("jumpOutOfBoundsMaxUint128", "0xffffffffffffffffffffffffffffffff"), - Arguments.of("jumpOutOfBoundsTwoToThe128", "0x0100000000000000000000000000000000"), - Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0x0100000000000000000000000000000004"), - Arguments.of( - "jumpOutOfBoundsMaxUint256", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); - /* - In order to run a specific test case (for example, the first one) use the following: - .filter(arguments -> "jumpOntoJumpDestTest".equals(arguments.get()[0])); - */ + Arguments.of("jumpOntoJumpDestTest", "4"), + Arguments.of("jumpOntoInvalidTest", "3"), + Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), + Arguments.of("jumpOutOfBoundsSmall", "0xff"), + Arguments.of("jumpOutOfBoundsMaxUint128", "0xffffffffffffffffffffffffffffffff"), + Arguments.of("jumpOutOfBoundsTwoToThe128", "0x0100000000000000000000000000000000"), + Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0x0100000000000000000000000000000004"), + Arguments.of( + "jumpOutOfBoundsMaxUint256", + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + /* + In order to run a specific test case (for example, the first one) use the following: + .filter(arguments -> "jumpOntoJumpDestTest".equals(arguments.get()[0])); + */ } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index f359112654..66ce65540d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -30,7 +30,8 @@ @ExtendWith(EvmExtension.class) public class JumpiTests { - // NOTE: the bytecode we propose will at time use the following offsets (unless one of the two initial push + // NOTE: the bytecode we propose will at time use the following offsets (unless one of the two + // initial push // is large!) bytecode: // - PUSH1 b // 0, 1 // - PUSHX pcNew // offsets: 2, 3 @@ -55,8 +56,16 @@ void testCodeForJumpiScenario(String description, String jumpiCondition, String private static Stream provideJumpiScenario() { List jumpiScenarios = new ArrayList<>(); - List jumpiConditions = List.of("0", "1", "0xdeadbeefdeadcafedeadbeefdeadcafe", "0xffffffffffffffffffffffffffffffff", "0x0100000000000000000000000000000001", "0xcafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - for (String jumpiCondition: jumpiConditions) { + List jumpiConditions = + List.of( + "0", + "1", + "0xdeadbeefdeadcafedeadbeefdeadcafe", + "0xffffffffffffffffffffffffffffffff", + "0x0100000000000000000000000000000001", + "0xcafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + for (String jumpiCondition : jumpiConditions) { jumpiScenarios.addAll(provideJumpiScenarioForJumpiCondition(jumpiCondition)); } return jumpiScenarios.stream(); From 7433e8e9457ed951392f2103992462e9613fcdb9 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 16:28:17 +0200 Subject: [PATCH 192/461] fix(hub): jump and jumpi tests push of hex input as string --- .../instructionprocessing/JumpTests.java | 19 ++++++++++++++----- .../instructionprocessing/JumpiTests.java | 12 ++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index 0b6b5e51ce..f9235b69db 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -35,9 +35,18 @@ public class JumpTests { // - INVALID // offset: 3 // - JUMPDEST // offset: 4 // - PUSH1 0x5b // offsets: 5, 6 <- 0x5b is the byte value of JUMPDEST + + // NOTE: in general the offsets are the following: + // - PUSHX pcNew // offsets: 0, 1 ... pcNewByteSize + // - JUMP // offset: pcNewByteSize + 1 + // - INVALID // offset: pcNewByteSize + 2 + // - JUMPDEST // offset: pcNewByteSize + 3 + // - PUSH1 0x5b // offsets: pcNewByteSize + 4, pcNewByteSize + 5 <- 0x5b is the byte value of + // JUMPDEST @ParameterizedTest @MethodSource("provideJumpScenario") void testCodeForJumpScenario(String description, String pcNew) { + // int pcNewByteSize = (int) Math.ceil((double) new BigInteger(pcNew, 16).bitLength() / 8); BytecodeRunner.of( BytecodeCompiler.newProgram() .push(pcNew) @@ -54,13 +63,13 @@ private static Stream provideJumpScenario() { Arguments.of("jumpOntoJumpDestTest", "4"), Arguments.of("jumpOntoInvalidTest", "3"), Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), - Arguments.of("jumpOutOfBoundsSmall", "0xff"), - Arguments.of("jumpOutOfBoundsMaxUint128", "0xffffffffffffffffffffffffffffffff"), - Arguments.of("jumpOutOfBoundsTwoToThe128", "0x0100000000000000000000000000000000"), - Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0x0100000000000000000000000000000004"), + Arguments.of("jumpOutOfBoundsSmall", "ff"), + Arguments.of("jumpOutOfBoundsMaxUint128", "ffffffffffffffffffffffffffffffff"), + Arguments.of("jumpOutOfBoundsTwoToThe128", "0100000000000000000000000000000000"), + Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0100000000000000000000000000000004"), Arguments.of( "jumpOutOfBoundsMaxUint256", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); /* In order to run a specific test case (for example, the first one) use the following: .filter(arguments -> "jumpOntoJumpDestTest".equals(arguments.get()[0])); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index 66ce65540d..9d97709d8e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -35,7 +35,7 @@ public class JumpiTests { // is large!) bytecode: // - PUSH1 b // 0, 1 // - PUSHX pcNew // offsets: 2, 3 - // - JUMP // offset: 4 + // - JUMPI // offset: 4 // - INVALID // offset: 5 // - JUMPDEST // offset: 6 // - PUSH1 0x5b // offsets: 7, 8 <- 0x5b is the byte value of JUMPDEST @@ -76,18 +76,18 @@ private static List provideJumpiScenarioForJumpiCondition(String jump Arguments.of("jumpOntoJumpDestTest", jumpiCondition, "6"), Arguments.of("jumpOntoInvalidTest", jumpiCondition, "5"), Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", jumpiCondition, "8"), - Arguments.of("jumpOutOfBoundsSmall", jumpiCondition, "0xff"), + Arguments.of("jumpOutOfBoundsSmall", jumpiCondition, "ff"), Arguments.of( - "jumpOutOfBoundsMaxUint128", jumpiCondition, "0xffffffffffffffffffffffffffffffff"), + "jumpOutOfBoundsMaxUint128", jumpiCondition, "ffffffffffffffffffffffffffffffff"), Arguments.of( - "jumpOutOfBoundsTwoToThe128", jumpiCondition, "0x0100000000000000000000000000000000"), + "jumpOutOfBoundsTwoToThe128", jumpiCondition, "0100000000000000000000000000000000"), Arguments.of( "jumpOutOfBoundsTwoToThe128Plus4", jumpiCondition, - "0x0100000000000000000000000000000004"), + "0100000000000000000000000000000004"), Arguments.of( "jumpOutOfBoundsMaxUint256", jumpiCondition, - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); } } From a026e2b642bb870364a923d3a26f34aed46e54dc Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 17:53:08 +0200 Subject: [PATCH 193/461] feat(hub): fixed JUMPI test adding jumpiConditionByteOffset to pcNew --- .../consensys/linea/zktracer/types/Utils.java | 15 ++++ .../instructionprocessing/JumpTests.java | 13 +--- .../instructionprocessing/JumpiTests.java | 71 +++++++++++++------ 3 files changed, 66 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java index 54a184640c..acce64677e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.types; +import java.math.BigInteger; import java.util.ArrayList; import com.google.common.base.Preconditions; @@ -83,4 +84,18 @@ public static BitDecOutput bitDecomposition(int input, int nbStep) { } return output; } + + /** + * Adds an offset to a hexadecimal string representation of a number. This method takes a + * hexadecimal string and an integer offset, adds the offset to the number represented by the + * hexadecimal string, and returns the result as a hexadecimal string. + * + * @param offset The integer offset to add to the number represented by the hexadecimal string. + * @param hexString The hexadecimal string representation of the number to which the offset will + * be added. + * @return A hexadecimal string representing the sum of the original number and the offset. + */ + public static String addOffsetToHexString(int offset, String hexString) { + return new BigInteger(hexString, 16).add(BigInteger.valueOf(offset)).toString(16); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index f9235b69db..0c0e257b23 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -28,25 +28,16 @@ @ExtendWith(EvmExtension.class) public class JumpTests { - // NOTE: the bytecode we propose will at time use the following offsets (unless the initial push - // is large!) bytecode: + // NOTE: the bytecode we propose will at time use the following offsets (unless pcNew is large) + // bytecode: // - PUSHX pcNew // offsets: 0, 1 // - JUMP // offset: 2 // - INVALID // offset: 3 // - JUMPDEST // offset: 4 // - PUSH1 0x5b // offsets: 5, 6 <- 0x5b is the byte value of JUMPDEST - - // NOTE: in general the offsets are the following: - // - PUSHX pcNew // offsets: 0, 1 ... pcNewByteSize - // - JUMP // offset: pcNewByteSize + 1 - // - INVALID // offset: pcNewByteSize + 2 - // - JUMPDEST // offset: pcNewByteSize + 3 - // - PUSH1 0x5b // offsets: pcNewByteSize + 4, pcNewByteSize + 5 <- 0x5b is the byte value of - // JUMPDEST @ParameterizedTest @MethodSource("provideJumpScenario") void testCodeForJumpScenario(String description, String pcNew) { - // int pcNewByteSize = (int) Math.ceil((double) new BigInteger(pcNew, 16).bitLength() / 8); BytecodeRunner.of( BytecodeCompiler.newProgram() .push(pcNew) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index 9d97709d8e..8baf3c9ead 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -14,6 +14,9 @@ */ package net.consensys.linea.zktracer.instructionprocessing; +import static net.consensys.linea.zktracer.types.Utils.addOffsetToHexString; + +import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -30,15 +33,15 @@ @ExtendWith(EvmExtension.class) public class JumpiTests { - // NOTE: the bytecode we propose will at time use the following offsets (unless one of the two - // initial push - // is large!) bytecode: - // - PUSH1 b // 0, 1 - // - PUSHX pcNew // offsets: 2, 3 - // - JUMPI // offset: 4 - // - INVALID // offset: 5 - // - JUMPDEST // offset: 6 - // - PUSH1 0x5b // offsets: 7, 8 <- 0x5b is the byte value of JUMPDEST + // NOTE: the bytecode we propose will at time use the following offsets (unless pcNew is large) + // bytecode: + // - PUSH1 b // 0, 1, ..., jumpiConditionByteOffset + 1 + // - PUSHX pcNew // offsets: jumpiConditionByteOffset + 2, jumpiConditionByteOffset + 3 + // - JUMPI // offset: jumpiConditionByteOffset + 4 + // - INVALID // offset: jumpiConditionByteOffset + 5 + // - JUMPDEST // offset: jumpiConditionByteOffset + 6 + // - PUSH1 0x5b // offsets: jumpiConditionByteOffset + 7, jumpiConditionByteOffset + 8 <- 0x5b is + // byte value of JUMPDEST @ParameterizedTest @MethodSource("provideJumpiScenario") void testCodeForJumpiScenario(String description, String jumpiCondition, String pcNew) { @@ -60,11 +63,11 @@ private static Stream provideJumpiScenario() { List.of( "0", "1", - "0xdeadbeefdeadcafedeadbeefdeadcafe", - "0xffffffffffffffffffffffffffffffff", - "0x0100000000000000000000000000000001", - "0xcafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + "deadbeefdeadcafedeadbeefdeadcafe", + "ffffffffffffffffffffffffffffffff", + "0100000000000000000000000000000001", + "cafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); for (String jumpiCondition : jumpiConditions) { jumpiScenarios.addAll(provideJumpiScenarioForJumpiCondition(jumpiCondition)); } @@ -72,22 +75,46 @@ private static Stream provideJumpiScenario() { } private static List provideJumpiScenarioForJumpiCondition(String jumpiCondition) { + int jumpiConditionByteSize = + jumpiCondition.equals("0") + ? 1 + : (int) Math.ceil((double) new BigInteger(jumpiCondition, 16).bitLength() / 8); + int jumpiConditionByteOffset = jumpiConditionByteSize - 1; return List.of( - Arguments.of("jumpOntoJumpDestTest", jumpiCondition, "6"), - Arguments.of("jumpOntoInvalidTest", jumpiCondition, "5"), - Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", jumpiCondition, "8"), - Arguments.of("jumpOutOfBoundsSmall", jumpiCondition, "ff"), Arguments.of( - "jumpOutOfBoundsMaxUint128", jumpiCondition, "ffffffffffffffffffffffffffffffff"), + "jumpOntoJumpDestTest", + jumpiCondition, + addOffsetToHexString(jumpiConditionByteOffset, "6")), + Arguments.of( + "jumpOntoInvalidTest", + jumpiCondition, + addOffsetToHexString(jumpiConditionByteOffset, "5")), + Arguments.of( + "jumpOntoJumpDestByteOwnedBySomePush", + jumpiCondition, + addOffsetToHexString(jumpiConditionByteOffset, "8")), + // NOTE: in the cases below we add Arguments.of( - "jumpOutOfBoundsTwoToThe128", jumpiCondition, "0100000000000000000000000000000000"), + "jumpOutOfBoundsSmall", + jumpiCondition, + addOffsetToHexString(jumpiConditionByteOffset, "ff")), + Arguments.of( + "jumpOutOfBoundsMaxUint128", + jumpiCondition, + addOffsetToHexString(jumpiConditionByteOffset, "ffffffffffffffffffffffffffffffff")), + Arguments.of( + "jumpOutOfBoundsTwoToThe128", + jumpiCondition, + addOffsetToHexString(jumpiConditionByteOffset, "0100000000000000000000000000000000")), Arguments.of( "jumpOutOfBoundsTwoToThe128Plus4", jumpiCondition, - "0100000000000000000000000000000004"), + addOffsetToHexString(jumpiConditionByteOffset, "0100000000000000000000000000000004")), Arguments.of( "jumpOutOfBoundsMaxUint256", jumpiCondition, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + addOffsetToHexString( + jumpiConditionByteOffset, + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); } } From 337926e5c39fcd972d96b56826083e110ac93938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 10 Jul 2024 20:22:53 +0200 Subject: [PATCH 194/461] fix(instructio-decoder): fixed instruction family filling for MACHINE_STATE + ras twoLinesInstruction --> twoLineInstruction --- .../module/hub/section/StackOnlySection.java | 2 +- .../module/hub/section/TraceSection.java | 2 +- .../InstructionDecoder.java | 4 +-- .../linea/zktracer/opcode/OpCodes.java | 4 +-- .../zktracer/opcode/stack/StackSettings.java | 4 +-- .../linea/zktracer/runtime/stack/Stack.java | 2 +- .../instructionprocessing/JumpTests.java | 8 ++--- .../instructionprocessing/JumpiTests.java | 29 ++++++++++--------- 8 files changed, 29 insertions(+), 26 deletions(-) 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 48eee57d3c..9e80969285 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().twoLinesInstruction() ? 2 : 1)); + super(hub, (short) (hub.opCode().getData().stackSettings().twoLineInstruction() ? 2 : 1)); 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 d48c869040..f947e4c97c 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 @@ -155,7 +155,7 @@ public void setContextExceptions(DeploymentExceptions contEx) { private List makeStackFragments(final Hub hub, CallFrame f) { final List r = new ArrayList<>(2); if (f.pending().lines().isEmpty()) { - for (int i = 0; i < (f.opCodeData().stackSettings().twoLinesInstruction() ? 2 : 1); i++) { + for (int i = 0; i < (f.opCodeData().stackSettings().twoLineInstruction() ? 2 : 1); i++) { r.add( StackFragment.prepare( hub, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java index cc00aa5641..ca4777e262 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java @@ -47,7 +47,7 @@ private static void traceFamily(OpCodeData op, Trace trace) { .familyStackRam(op.instructionFamily() == InstructionFamily.STACK_RAM) .familyStorage(op.instructionFamily() == InstructionFamily.STORAGE) .familyJump(op.instructionFamily() == InstructionFamily.JUMP) - .familyMachineState(op.instructionFamily() == InstructionFamily.JUMP) + .familyMachineState(op.instructionFamily() == InstructionFamily.MACHINE_STATE) .familyPushPop(op.instructionFamily() == InstructionFamily.PUSH_POP) .familyDup(op.instructionFamily() == InstructionFamily.DUP) .familySwap(op.instructionFamily() == InstructionFamily.SWAP) @@ -65,7 +65,7 @@ private static void traceStackSettings(OpCodeData op, Trace trace) { .nbAdded(UnsignedByte.of(op.stackSettings().nbAdded())) .nbRemoved(UnsignedByte.of(op.stackSettings().nbRemoved())) .staticGas(op.stackSettings().staticGas().cost()) - .twoLineInstruction(op.stackSettings().twoLinesInstruction()) + .twoLineInstruction(op.stackSettings().twoLineInstruction()) .staticFlag(op.stackSettings().forbiddenInStatic()) .flag1(op.stackSettings().flag1()) .flag2(op.stackSettings().flag2()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java index 2b293bfb6f..5cad4ab02c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java @@ -58,8 +58,8 @@ public static void load() { /** * Get opcode metadata per opcode long value. * - * @param value opcode long value. - * @return an instance of {@link OpCodeData} corresponding to the numeric (long) value. + * @param value opcode value. + * @return an instance of {@link OpCodeData} corresponding to the numeric value. */ public static OpCodeData of(final int value) { if (value < 0 || value > 255) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/StackSettings.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/StackSettings.java index fb1de90445..7ae813853b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/StackSettings.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/stack/StackSettings.java @@ -26,7 +26,7 @@ * @param nbAdded the number of elements this operation adds on the stack * @param nbRemoved the number of elements this operation pops from the stack * @param staticGas the static part of the gas consumed by this operation - * @param twoLinesInstruction whether this operation fills one or two stack lines + * @param twoLineInstruction whether this operation fills one or two stack lines * @param forbiddenInStatic whether this instruction is forbidden in a static context * @param addressTrimmingInstruction whether this instruction triggers addres trimming * @param oobFlag whether this instruction may trigger an OoB exception @@ -42,7 +42,7 @@ public record StackSettings( int nbAdded, int nbRemoved, GasConstants staticGas, - boolean twoLinesInstruction, + boolean twoLineInstruction, boolean forbiddenInStatic, boolean addressTrimmingInstruction, boolean oobFlag, 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 1cf5137b22..f0d78c0eb6 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 @@ -402,7 +402,7 @@ public void processInstruction(final Hub hub, MessageFrame frame, int stackStamp if (this.status.isFailure()) { this.heightNew = 0; - if (this.currentOpcodeData.stackSettings().twoLinesInstruction()) { + if (this.currentOpcodeData.stackSettings().twoLineInstruction()) { this.stamp += callFrame.pending().addEmptyLines(2); } else { this.stamp += callFrame.pending().addEmptyLines(1); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index 0c0e257b23..8c02ec5de6 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -51,11 +51,11 @@ void testCodeForJumpScenario(String description, String pcNew) { private static Stream provideJumpScenario() { return Stream.of( - Arguments.of("jumpOntoJumpDestTest", "4"), - Arguments.of("jumpOntoInvalidTest", "3"), - Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), + Arguments.of("jumpOntoValidJumpDestination", "4"), + Arguments.of("jumpOntoINVALID", "3"), + Arguments.of("jumpOntoPushByteEqualToJUMPDEST", "6"), Arguments.of("jumpOutOfBoundsSmall", "ff"), - Arguments.of("jumpOutOfBoundsMaxUint128", "ffffffffffffffffffffffffffffffff"), + Arguments.of("jumpOutOfBoundsMaxUint128", "ffffffffffffffffffffffffffffffff"), Arguments.of("jumpOutOfBoundsTwoToThe128", "0100000000000000000000000000000000"), Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0100000000000000000000000000000004"), Arguments.of( diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index 8baf3c9ead..48ec385d62 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -63,11 +63,14 @@ private static Stream provideJumpiScenario() { List.of( "0", "1", - "deadbeefdeadcafedeadbeefdeadcafe", - "ffffffffffffffffffffffffffffffff", - "0100000000000000000000000000000001", - "cafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); + "1a30", // very small random integer + "deadbeefdeadcafedeadbeefdeadcafe", // some random Bytes16 + "ffffffffffffffffffffffffffffffff", // max Bytes16 (hi = 0x00) + "0100000000000000000000000000000000", // 256 ^16 (hi = 0x01, lo = 0x00) + "0100000000000000000000000000000001", // 256 ^16 + 1 (hi = 0x01, lo = 0x01) + "cafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", // some random Bytes32 + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" // max Bytes32 + ); for (String jumpiCondition : jumpiConditions) { jumpiScenarios.addAll(provideJumpiScenarioForJumpiCondition(jumpiCondition)); } @@ -82,36 +85,36 @@ private static List provideJumpiScenarioForJumpiCondition(String jump int jumpiConditionByteOffset = jumpiConditionByteSize - 1; return List.of( Arguments.of( - "jumpOntoJumpDestTest", + "jumpiOntoJumpDestTest", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "6")), Arguments.of( - "jumpOntoInvalidTest", + "jumpiOntoInvalidTest", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "5")), Arguments.of( - "jumpOntoJumpDestByteOwnedBySomePush", + "jumpiOntoJumpDestByteOwnedBySomePush", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "8")), // NOTE: in the cases below we add Arguments.of( - "jumpOutOfBoundsSmall", + "jumpiOutOfBoundsSmall", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "ff")), Arguments.of( - "jumpOutOfBoundsMaxUint128", + "jumpiOutOfBoundsMaxUint128", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "ffffffffffffffffffffffffffffffff")), Arguments.of( - "jumpOutOfBoundsTwoToThe128", + "jumpiOutOfBoundsTwoToThe128", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "0100000000000000000000000000000000")), Arguments.of( - "jumpOutOfBoundsTwoToThe128Plus4", + "jumpiOutOfBoundsTwoToThe128Plus4", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "0100000000000000000000000000000004")), Arguments.of( - "jumpOutOfBoundsMaxUint256", + "jumpiOutOfBoundsMaxUint256", jumpiCondition, addOffsetToHexString( jumpiConditionByteOffset, From d202118b491a3888e35deb7c4e3056b72f1e03b9 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 22:39:01 +0200 Subject: [PATCH 195/461] fix(hub): naming of tests for JUMP and JUMPI and spotless --- .../linea/zktracer/instructionprocessing/JumpTests.java | 4 ++-- .../linea/zktracer/instructionprocessing/JumpiTests.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index 8c02ec5de6..efb2cc0d57 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -53,9 +53,9 @@ private static Stream provideJumpScenario() { return Stream.of( Arguments.of("jumpOntoValidJumpDestination", "4"), Arguments.of("jumpOntoINVALID", "3"), - Arguments.of("jumpOntoPushByteEqualToJUMPDEST", "6"), + Arguments.of("jumpOntoJumpDestByteOwnedBySomePush", "6"), Arguments.of("jumpOutOfBoundsSmall", "ff"), - Arguments.of("jumpOutOfBoundsMaxUint128", "ffffffffffffffffffffffffffffffff"), + Arguments.of("jumpOutOfBoundsMaxUint128", "ffffffffffffffffffffffffffffffff"), Arguments.of("jumpOutOfBoundsTwoToThe128", "0100000000000000000000000000000000"), Arguments.of("jumpOutOfBoundsTwoToThe128Plus4", "0100000000000000000000000000000004"), Arguments.of( diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index 48ec385d62..267d49ca61 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -68,9 +68,10 @@ private static Stream provideJumpiScenario() { "ffffffffffffffffffffffffffffffff", // max Bytes16 (hi = 0x00) "0100000000000000000000000000000000", // 256 ^16 (hi = 0x01, lo = 0x00) "0100000000000000000000000000000001", // 256 ^16 + 1 (hi = 0x01, lo = 0x01) - "cafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", // some random Bytes32 + "cafefeedcafebabecafefeedcafebabecafefeedcafebabecafefeedcafebabe", // some random + // Bytes32 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" // max Bytes32 - ); + ); for (String jumpiCondition : jumpiConditions) { jumpiScenarios.addAll(provideJumpiScenarioForJumpiCondition(jumpiCondition)); } @@ -85,11 +86,11 @@ private static List provideJumpiScenarioForJumpiCondition(String jump int jumpiConditionByteOffset = jumpiConditionByteSize - 1; return List.of( Arguments.of( - "jumpiOntoJumpDestTest", + "jumpiOntoValidJumpDestination", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "6")), Arguments.of( - "jumpiOntoInvalidTest", + "jumpiOntoINVALID", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "5")), Arguments.of( From 5540162837cb99a4d819dfb1fd323ddcd72fabfe Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 10 Jul 2024 23:09:07 +0200 Subject: [PATCH 196/461] fix(jump and jumpi tests): renaming --- .../linea/zktracer/instructionprocessing/JumpTests.java | 2 +- .../linea/zktracer/instructionprocessing/JumpiTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index efb2cc0d57..bb97f762d6 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -37,7 +37,7 @@ public class JumpTests { // - PUSH1 0x5b // offsets: 5, 6 <- 0x5b is the byte value of JUMPDEST @ParameterizedTest @MethodSource("provideJumpScenario") - void testCodeForJumpScenario(String description, String pcNew) { + void jumpScenarioTest(String description, String pcNew) { BytecodeRunner.of( BytecodeCompiler.newProgram() .push(pcNew) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index 267d49ca61..e632f3368d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -44,7 +44,7 @@ public class JumpiTests { // byte value of JUMPDEST @ParameterizedTest @MethodSource("provideJumpiScenario") - void testCodeForJumpiScenario(String description, String jumpiCondition, String pcNew) { + void jumpiScenarioTest(String description, String jumpiCondition, String pcNew) { BytecodeRunner.of( BytecodeCompiler.newProgram() .push(jumpiCondition) From 505c761ea70c5ba8a2803b2ff10f4feb58e05023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 10 Jul 2024 23:09:52 +0200 Subject: [PATCH 197/461] fix(constants): removed most GasConstants.java references + fixed G_JUMP_DEST the opcodes.toml still references those values TODO: use GlobalConstants.java constants instead --- .../zktracer/module/exp/ExpOperation.java | 4 ++-- .../module/hub/fragment/imc/ImcFragment.java | 4 ++-- .../module/hub/fragment/imc/call/StpCall.java | 14 ++++++------ .../module/hub/section/CreateSection.java | 6 +++-- .../module/hub/signals/Exceptions.java | 5 +++-- .../module/hub/transients/Operation.java | 4 ++-- .../hub/transients/OperationAncillaries.java | 4 ++-- .../zktracer/module/mxp/MxpOperation.java | 4 ++-- .../zktracer/opcode/gas/GasConstants.java | 5 +++-- .../zktracer/opcode/gas/projector/Call.java | 12 +++++----- .../zktracer/opcode/gas/projector/Create.java | 4 ++-- .../opcode/gas/projector/Create2.java | 6 ++--- .../opcode/gas/projector/DataCopy.java | 4 ++-- .../zktracer/opcode/gas/projector/Exp.java | 6 ++--- .../opcode/gas/projector/ExtCodeCopy.java | 4 ++-- .../zktracer/opcode/gas/projector/Log.java | 14 ++++++------ .../zktracer/opcode/gas/projector/Return.java | 4 ++-- .../zktracer/opcode/gas/projector/SLoad.java | 6 ++--- .../zktracer/opcode/gas/projector/SStore.java | 20 +++++++++-------- .../opcode/gas/projector/SelfDestruct.java | 10 ++++----- .../zktracer/opcode/gas/projector/Sha3.java | 6 ++--- .../src/main/resources/opcodes.yml | 22 +++++++++---------- 22 files changed, 87 insertions(+), 81 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index 4913547514..4df1ad92f5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -28,7 +28,6 @@ import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_CMPTN_MODEXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_PRPRC_EXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.MAX_CT_PRPRC_MODEXP_LOG; -import static net.consensys.linea.zktracer.opcode.gas.GasConstants.G_EXP_BYTE; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Utils.leftPadTo; @@ -39,6 +38,7 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import net.consensys.linea.zktracer.container.ModuleOperation; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; @@ -89,7 +89,7 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { // Extract inputs EWord exponent = EWord.of(hub.messageFrame().getStackItem(1)); - long dynCost = (long) G_EXP_BYTE.cost() * exponent.byteLength(); + long dynCost = (long) GlobalConstants.GAS_CONST_G_EXP_BYTE * exponent.byteLength(); // Fill expCall explogExpCall.setExponent(exponent); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index f67b8eefb9..2331fc5d52 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Optional; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; @@ -36,7 +37,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -134,7 +134,7 @@ public static ImcFragment forCall( value = EWord.of(hub.messageFrame().getStackItem(2)); } - final long stipend = value.isZero() ? 0 : GasConstants.G_CALL_STIPEND.cost(); + final long stipend = value.isZero() ? 0 : GlobalConstants.GAS_CONST_G_CALL_STIPEND; final long upfrontCost = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()).total(); // TODO: @Olivier get memory expansion gas diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java index 8b8a8074e0..70ec35e2b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java @@ -21,11 +21,11 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; @@ -82,7 +82,7 @@ public void stpCallForCalls(Hub hub) { this.outOfGasException = this.gasActual < this.upfrontGasCost; this.gasPaidOutOfPocket = this.gasPaidOutOfPocketForCalls(); this.stipend = - !outOfGasException && nonzeroValueTransfer ? GasConstants.G_CALL_STIPEND.cost() : 0; + !outOfGasException && nonzeroValueTransfer ? GlobalConstants.GAS_CONST_G_CALL_STIPEND : 0; } private long gasPaidOutOfPocketForCalls() { @@ -105,7 +105,7 @@ public void stpCallForCreates(Hub hub) { this.value = EWord.of(frame.getStackItem(0)); this.exists = false; // irrelevant this.warm = false; // irrelevant - this.upfrontGasCost = GasConstants.G_CREATE.cost() + this.memoryExpansionGas; + this.upfrontGasCost = GlobalConstants.GAS_CONST_G_CREATE + this.memoryExpansionGas; this.outOfGasException = this.gasActual < this.upfrontGasCost; this.gasPaidOutOfPocket = this.computeGasPaidOutOfPocketForCreates(); this.stipend = 0; // irrelevant @@ -125,10 +125,10 @@ private long upfrontGasCostForCalls(boolean isCALL, boolean nonzeroValueTransfer boolean toIsWarm = this.warm(); long upfrontGasCost = this.memoryExpansionGas; final boolean callWouldLeadToAccountCreation = isCALL && nonzeroValueTransfer && !this.exists; - if (nonzeroValueTransfer) upfrontGasCost += GasConstants.G_CALL_VALUE.cost(); - if (toIsWarm) upfrontGasCost += GasConstants.G_WARM_ACCESS.cost(); - else upfrontGasCost += GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); - if (callWouldLeadToAccountCreation) upfrontGasCost += GasConstants.G_NEW_ACCOUNT.cost(); + if (nonzeroValueTransfer) upfrontGasCost += GlobalConstants.GAS_CONST_G_CALL_VALUE; + if (toIsWarm) upfrontGasCost += GlobalConstants.GAS_CONST_G_WARM_ACCESS; + else upfrontGasCost += GlobalConstants.GAS_CONST_G_COLD_ACCOUNT_ACCESS; + if (callWouldLeadToAccountCreation) upfrontGasCost += GlobalConstants.GAS_CONST_G_NEW_ACCOUNT; return upfrontGasCost; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 408b57f6c0..f1f3e3977e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.NextContextDefer; @@ -32,7 +33,6 @@ import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.opcode.gas.projector.GasProjection; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; @@ -151,7 +151,9 @@ public void resolvePostTransaction( final boolean creatorWillRevert = hub.callStack().getById(this.creatorContextId).hasReverted(); final GasProjection projection = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()); final long upfrontCost = - projection.memoryExpansion() + projection.linearPerWord() + GasConstants.G_TX_CREATE.cost(); + projection.memoryExpansion() + + projection.linearPerWord() + + GlobalConstants.GAS_CONST_G_TX_CREATE; final ImcFragment commonImcFragment = ImcFragment.empty(hub).callOob(new CreateOobCall()).callMxp(MxpCall.build(hub)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java index b8a5afe2a5..8ff5cbbe67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Exceptions.java @@ -18,10 +18,10 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EIP_3541_MARKER; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MAX_CODE_SIZE; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.opcode.gas.projector.GasProjector; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -185,7 +185,8 @@ private static boolean isStaticFault(final MessageFrame frame, OpCodeData opCode } private static boolean isOutOfSStore(MessageFrame frame, OpCode opCode) { - return opCode == OpCode.SSTORE && frame.getRemainingGas() <= GasConstants.G_CALL_STIPEND.cost(); + return opCode == OpCode.SSTORE + && frame.getRemainingGas() <= GlobalConstants.GAS_CONST_G_CALL_STIPEND; } private static boolean isInvalidCodePrefix(MessageFrame frame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java index 96618f0e77..5f30845f28 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java @@ -18,9 +18,9 @@ import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; @@ -47,7 +47,7 @@ public long gasAllowanceForCall() { if (opCode == OpCode.CALL || opCode == OpCode.CALLCODE) { value = EWord.of(hub.messageFrame().getStackItem(2)); } - final long stipend = value.isZero() ? 0 : GasConstants.G_CALL_STIPEND.cost(); + final long stipend = value.isZero() ? 0 : GlobalConstants.GAS_CONST_G_CALL_STIPEND; final long upfrontCost = Hub.GAS_PROJECTOR.of(hub.messageFrame(), opCode).total(); return stipend + Math.max( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index 3d23b0cd61..b9d3f65759 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -21,9 +21,9 @@ import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; @@ -66,7 +66,7 @@ public long gasAllowanceForCall() { if (opCode == OpCode.CALL || opCode == OpCode.CALLCODE) { value = EWord.of(hub.messageFrame().getStackItem(2)); } - final long stipend = value.isZero() ? 0 : GasConstants.G_CALL_STIPEND.cost(); + final long stipend = value.isZero() ? 0 : GlobalConstants.GAS_CONST_G_CALL_STIPEND; final long upfrontCost = Hub.GAS_PROJECTOR.of(hub.messageFrame(), opCode).total(); return stipend + Math.max( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java index f35d246d54..ba69fa4592 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java @@ -29,13 +29,13 @@ import com.google.common.base.Preconditions; import lombok.Getter; import net.consensys.linea.zktracer.container.ModuleOperation; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.transients.OperationAncillaries; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; import net.consensys.linea.zktracer.opcode.gas.BillingRate; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import net.consensys.linea.zktracer.opcode.gas.MxpType; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; @@ -299,7 +299,7 @@ private static long memoryCost(final long length) { ? clampedMultiply(length / 512, length) : lengthSquare / 512; - return clampedAdd(clampedMultiply(GasConstants.G_MEMORY.cost(), length), base); + return clampedAdd(clampedMultiply(GlobalConstants.GAS_CONST_G_MEMORY, length), base); } private long getLinCost(OpCodeData opCodeData, long sizeInBytes) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java index 20c9d357a0..dcd3fe974f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java @@ -23,7 +23,7 @@ @RequiredArgsConstructor public enum GasConstants { G_ZERO(0), - G_JUMP_DEST(0), + G_JUMP_DEST(1), G_BASE(2), G_VERY_LOW(3), G_LOW(5), @@ -65,7 +65,8 @@ public enum GasConstants { // below are markers for gas that is computed in other modules // that is: hub, memory expansion, stipend, precompile info S_MXP(0), - S_CALL(0), // computing the cost of a CALL requires HUB data (warmth, account existence, ...), MXP + S_CALL(0), + // computing the cost of a CALL requires HUB data (warmth, account existence, ...), MXP // data for memory expansion, STP data for gas stipend <- made it its own type S_HUB(0), S_STP(0), diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java index 8140820980..f7235dae10 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java @@ -18,7 +18,7 @@ import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.types.MemorySpan; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; @@ -73,9 +73,9 @@ public long accountAccess() { } if (frame.isAddressWarm(to) || isPrecompile(to)) { - return GasConstants.G_WARM_ACCESS.cost(); + return GlobalConstants.GAS_CONST_G_WARM_ACCESS; } else { - return GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); + return GlobalConstants.GAS_CONST_G_COLD_ACCOUNT_ACCESS; } } @@ -86,7 +86,7 @@ public long accountCreation() { } if ((recipient == null || recipient.isEmpty()) && !value.isZero()) { - return GasConstants.G_NEW_ACCOUNT.cost(); + return GlobalConstants.GAS_CONST_G_NEW_ACCOUNT; } else { return 0L; } @@ -101,7 +101,7 @@ public long transferValue() { if (value.isZero()) { return 0L; } else { - return GasConstants.G_CALL_VALUE.cost(); + return GlobalConstants.GAS_CONST_G_CALL_VALUE; } } @@ -128,6 +128,6 @@ public long extraStipend() { return 0; } - return GasConstants.G_CALL_STIPEND.cost(); + return GlobalConstants.GAS_CONST_G_CALL_STIPEND; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create.java index 367d923549..685ea1fe54 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create.java @@ -17,7 +17,7 @@ import static org.hyperledger.besu.evm.internal.Words.clampedToLong; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -36,7 +36,7 @@ public Create(MessageFrame frame) { @Override public long staticGas() { - return GasConstants.G_CREATE.cost(); + return GlobalConstants.GAS_CONST_G_CREATE; } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create2.java index 38ea7e3ccd..5cca7a1120 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Create2.java @@ -17,7 +17,7 @@ import static org.hyperledger.besu.evm.internal.Words.clampedToLong; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -36,7 +36,7 @@ public Create2(MessageFrame frame) { @Override public long staticGas() { - return GasConstants.G_CREATE.cost(); + return GlobalConstants.GAS_CONST_G_CREATE; } @Override @@ -51,7 +51,7 @@ public long largestOffset() { @Override public long linearPerWord() { - return linearCost(GasConstants.G_KECCAK_256_WORD.cost(), initCodeLength, 32); + return linearCost(GlobalConstants.GAS_CONST_G_KECCAK_256_WORD, initCodeLength, 32); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/DataCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/DataCopy.java index dff743a59f..513f8b851c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/DataCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/DataCopy.java @@ -18,8 +18,8 @@ import static org.hyperledger.besu.evm.internal.Words.clampedToLong; import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -53,7 +53,7 @@ public long memoryExpansion() { @Override public long linearPerWord() { - return linearCost(GasConstants.G_COPY.cost(), this.len, 32); + return linearCost(GlobalConstants.GAS_CONST_G_COPY, this.len, 32); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Exp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Exp.java index 077b0f8eae..38be61b694 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Exp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Exp.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.opcode.gas.projector; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.evm.frame.MessageFrame; public final class Exp extends GasProjection { @@ -30,11 +30,11 @@ public Exp(MessageFrame frame) { @Override public long staticGas() { - return GasConstants.G_EXP.cost(); + return GlobalConstants.GAS_CONST_G_EXP; } @Override public long expGas() { - return linearCost(GasConstants.G_EXP_BYTE.cost(), this.exponentByteSize, 1); + return linearCost(GlobalConstants.GAS_CONST_G_EXP_BYTE, this.exponentByteSize, 1); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/ExtCodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/ExtCodeCopy.java index 52ff679d9a..03d0b90efa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/ExtCodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/ExtCodeCopy.java @@ -17,7 +17,7 @@ import static org.hyperledger.besu.evm.internal.Words.clampedToLong; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -61,6 +61,6 @@ public long accountAccess() { @Override public long linearPerWord() { - return linearCost(GasConstants.G_COPY.cost(), this.bitSize, 32); + return linearCost(GlobalConstants.GAS_CONST_G_COPY, this.bitSize, 32); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Log.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Log.java index b0107c131b..3ba67c909d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Log.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Log.java @@ -17,7 +17,7 @@ import static org.hyperledger.besu.evm.internal.Words.clampedToLong; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -40,19 +40,19 @@ public Log(MessageFrame frame, int numTopics) { public long staticGas() { switch (numTopics) { case 0 -> { - return GasConstants.G_LOG_0.cost(); + return GlobalConstants.GAS_CONST_G_LOG; } case 1 -> { - return GasConstants.G_LOG_1.cost(); + return GlobalConstants.GAS_CONST_G_LOG + GlobalConstants.GAS_CONST_G_LOG_TOPIC; } case 2 -> { - return GasConstants.G_LOG_2.cost(); + return GlobalConstants.GAS_CONST_G_LOG + 2 * GlobalConstants.GAS_CONST_G_LOG_TOPIC; } case 3 -> { - return GasConstants.G_LOG_3.cost(); + return GlobalConstants.GAS_CONST_G_LOG + 3 * GlobalConstants.GAS_CONST_G_LOG_TOPIC; } case 4 -> { - return GasConstants.G_LOG_4.cost(); + return GlobalConstants.GAS_CONST_G_LOG + 4 * GlobalConstants.GAS_CONST_G_LOG_TOPIC; } default -> throw new IllegalStateException("Unexpected value: " + numTopics); } @@ -70,6 +70,6 @@ public long largestOffset() { @Override public long linearPerByte() { - return linearCost(GasConstants.G_LOG_DATA.cost(), size, 1); + return linearCost(GlobalConstants.GAS_CONST_G_LOG_DATA, size, 1); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Return.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Return.java index 4c554ca659..18c70c31db 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Return.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Return.java @@ -17,7 +17,7 @@ import static org.hyperledger.besu.evm.internal.Words.clampedToLong; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -49,7 +49,7 @@ public long deploymentCost() { if (this.size > 24_576) { return 0L; } else { - return GasConstants.G_CODE_DEPOSIT.cost() * this.size; + return GlobalConstants.GAS_CONST_G_CODE_DEPOSIT * this.size; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SLoad.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SLoad.java index db7da82f30..9dbb4a6a12 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SLoad.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SLoad.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.opcode.gas.projector; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -36,9 +36,9 @@ public long storageWarmth() { return 0; } else { if (frame.getWarmedUpStorage().contains(frame.getRecipientAddress(), key)) { - return GasConstants.G_WARM_ACCESS.cost(); + return GlobalConstants.GAS_CONST_G_WARM_ACCESS; } else { - return GasConstants.G_COLD_S_LOAD.cost(); + return GlobalConstants.GAS_CONST_G_COLD_SLOAD; } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SStore.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SStore.java index dd42700c75..039c329a02 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SStore.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SStore.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.opcode.gas.projector; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -47,16 +47,18 @@ public long storageWarmth() { if (frame.getWarmedUpStorage().contains(frame.getRecipientAddress(), key)) { return 0L; } else { - return GasConstants.G_COLD_S_LOAD.cost(); + return GlobalConstants.GAS_CONST_G_COLD_SLOAD; } } @Override public long sStoreValue() { if (newValue.equals(currentValue) || !originalValue.equals(currentValue)) { - return GasConstants.G_WARM_ACCESS.cost(); + return GlobalConstants.GAS_CONST_G_WARM_ACCESS; } else { - return originalValue.isZero() ? GasConstants.G_S_SET.cost() : GasConstants.G_S_RESET.cost(); + return originalValue.isZero() + ? GlobalConstants.GAS_CONST_G_SSET + : GlobalConstants.GAS_CONST_G_SRESET; } } @@ -64,23 +66,23 @@ public long sStoreValue() { public long refund() { long rDirtyClear = 0; if (!originalValue.isZero() && currentValue.isZero()) { - rDirtyClear = -GasConstants.R_S_CLEAR.cost(); + rDirtyClear = -GlobalConstants.REFUND_CONST_R_SCLEAR; } if (!originalValue.isZero() && newValue.isZero()) { - rDirtyClear = GasConstants.R_S_CLEAR.cost(); + rDirtyClear = GlobalConstants.REFUND_CONST_R_SCLEAR; } long rDirtyReset = 0; if (originalValue.equals(newValue) && originalValue.isZero()) { - rDirtyReset = GasConstants.G_S_SET.cost() - GasConstants.G_WARM_ACCESS.cost(); + rDirtyReset = GlobalConstants.GAS_CONST_G_SSET - GlobalConstants.GAS_CONST_G_WARM_ACCESS; } if (originalValue.equals(newValue) && !originalValue.isZero()) { - rDirtyReset = GasConstants.G_S_RESET.cost() - GasConstants.G_WARM_ACCESS.cost(); + rDirtyReset = GlobalConstants.GAS_CONST_G_SRESET - GlobalConstants.GAS_CONST_G_WARM_ACCESS; } long r = 0; if (!currentValue.equals(newValue) && currentValue.equals(originalValue) && newValue.isZero()) { - r = GasConstants.R_S_CLEAR.cost(); + r = GlobalConstants.REFUND_CONST_R_SCLEAR; } if (!currentValue.equals(newValue) && !currentValue.equals(originalValue)) { r = rDirtyClear + rDirtyReset; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SelfDestruct.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SelfDestruct.java index 3acd7b0ea3..d7d25a5751 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SelfDestruct.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/SelfDestruct.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.opcode.gas.projector; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; @@ -39,7 +39,7 @@ boolean isInvalid() { @Override public long staticGas() { - return GasConstants.G_SELF_DESTRUCT.cost(); + return GlobalConstants.GAS_CONST_G_SELFDESTRUCT; } @Override @@ -51,7 +51,7 @@ public long accountAccess() { if (frame.isAddressWarm(this.beneficiaryAddress)) { return 0L; } else { - return GasConstants.G_COLD_ACCOUNT_ACCESS.cost(); + return GlobalConstants.GAS_CONST_G_COLD_ACCOUNT_ACCESS; } } @@ -66,7 +66,7 @@ public long accountCreation() { final Wei balance = frame.getWorldUpdater().get(me).getBalance(); if ((beneficiaryAccount == null || beneficiaryAccount.isEmpty()) && !balance.isZero()) { - return GasConstants.G_NEW_ACCOUNT.cost(); + return GlobalConstants.GAS_CONST_G_NEW_ACCOUNT; } else { return 0L; } @@ -74,6 +74,6 @@ public long accountCreation() { @Override public long refund() { - return GasConstants.R_SELF_DESTRUCT.cost(); + return GlobalConstants.REFUND_CONST_R_SELFDESTRUCT; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Sha3.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Sha3.java index 71c4bbaba5..3a50864b2a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Sha3.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Sha3.java @@ -18,7 +18,7 @@ import static org.hyperledger.besu.evm.internal.Words.clampedAdd; import static org.hyperledger.besu.evm.internal.Words.clampedToLong; -import net.consensys.linea.zktracer.opcode.gas.GasConstants; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import org.hyperledger.besu.evm.frame.MessageFrame; public final class Sha3 extends GasProjection { @@ -36,7 +36,7 @@ public Sha3(MessageFrame frame) { @Override public long staticGas() { - return GasConstants.G_KECCAK_256.cost(); + return GlobalConstants.GAS_CONST_G_KECCAK_256; } @Override @@ -51,7 +51,7 @@ public long largestOffset() { @Override public long linearPerWord() { - return linearCost(GasConstants.G_KECCAK_256_WORD.cost(), this.length, 32); + return linearCost(GlobalConstants.GAS_CONST_G_KECCAK_256_WORD, this.length, 32); } @Override diff --git a/arithmetization/src/main/resources/opcodes.yml b/arithmetization/src/main/resources/opcodes.yml index a20eb291bd..decd4087a5 100644 --- a/arithmetization/src/main/resources/opcodes.yml +++ b/arithmetization/src/main/resources/opcodes.yml @@ -1419,7 +1419,7 @@ opcodes: nbAdded: 0 nbRemoved: 2 staticGas: G_LOG_0 - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true billing: byByte: @@ -1435,7 +1435,7 @@ opcodes: nbAdded: 0 nbRemoved: 3 staticGas: G_LOG_1 - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true flag1: true billing: @@ -1452,7 +1452,7 @@ opcodes: nbAdded: 0 nbRemoved: 4 staticGas: G_LOG_2 - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true flag2: true billing: @@ -1469,7 +1469,7 @@ opcodes: nbAdded: 0 nbRemoved: 5 staticGas: G_LOG_3 - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true flag3: true billing: @@ -1486,7 +1486,7 @@ opcodes: nbAdded: 0 nbRemoved: 6 staticGas: G_LOG_4 - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true flag4: true billing: @@ -1503,7 +1503,7 @@ opcodes: nbAdded: 1 nbRemoved: 3 staticGas: G_CREATE - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true flag1: true billing: @@ -1520,7 +1520,7 @@ opcodes: nbAdded: 1 nbRemoved: 7 staticGas: S_CALL - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true flag1: true billing: @@ -1536,7 +1536,7 @@ opcodes: nbAdded: 1 nbRemoved: 7 staticGas: S_CALL - twoLinesInstruction: true + twoLineInstruction: true flag2: true billing: byMxp: @@ -1566,7 +1566,7 @@ opcodes: nbAdded: 1 nbRemoved: 6 staticGas: S_CALL - twoLinesInstruction: true + twoLineInstruction: true flag3: true billing: byMxp: @@ -1581,7 +1581,7 @@ opcodes: nbAdded: 1 nbRemoved: 4 staticGas: G_CREATE - twoLinesInstruction: true + twoLineInstruction: true forbiddenInStatic: true flag2: true billing: @@ -1598,7 +1598,7 @@ opcodes: nbAdded: 1 nbRemoved: 6 staticGas: S_CALL - twoLinesInstruction: true + twoLineInstruction: true flag4: true billing: byMxp: From 0055e576f620af90f6cd11d2641e24df8cbd04bc Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 11 Jul 2024 00:24:32 +0200 Subject: [PATCH 198/461] fix(common fragment): various columns now vanish outside the execution phase --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../hub/fragment/common/CommonFragment.java | 15 +++++------ .../instructionprocessing/JumpTests.java | 22 +++++++++------- .../instructionprocessing/JumpiTests.java | 26 ++++++++++--------- zkevm-constraints | 2 +- 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 9e744a3800..29bd773576 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -721,7 +721,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope unexceptional ? currentSection.commonValues.gasActual - gasCost : 0); } else { currentSection.commonValues.gasCost( - 0xdeadbeefL); // TODO: fill with correct values --- likely 0 + 0); // TODO: fill with correct values --- make sure this works in all cases currentSection.commonValues.gasNext(0); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java index ffe7218335..b8444e6602 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java @@ -65,7 +65,7 @@ public boolean txReverts() { public Trace trace(Trace trace) { final CallFrame frame = commonFragmentValues.callFrame; final TransactionProcessingMetadata tx = commonFragmentValues.txMetadata; - + final boolean isExec = commonFragmentValues.hubProcessingPhase == TX_EXEC; return trace .absoluteTransactionNumber(tx.getAbsoluteTransactionNumber()) .batchNumber(tx.getRelativeBlockNumber()) @@ -77,20 +77,19 @@ public Trace trace(Trace trace) { .hubStamp(commonFragmentValues.hubStamp) .hubStampTransactionEnd(tx.getHubStampTransactionEnd()) .contextMayChange(commonFragmentValues.contextMayChange) - .exceptionAhoy(commonFragmentValues.exceptionAhoy) + .exceptionAhoy(commonFragmentValues.exceptionAhoy && isExec) .logInfoStamp(commonFragmentValues.logStamp) .mmuStamp(commonFragmentValues.stamps.mmu()) .mxpStamp(commonFragmentValues.stamps.mxp()) // nontrivial dom / sub are traced in storage or account fragments only - .contextNumber( - commonFragmentValues.hubProcessingPhase == TX_EXEC ? frame.contextNumber() : 0) + .contextNumber(isExec ? frame.contextNumber() : 0) .contextNumberNew(commonFragmentValues.contextNumberNew) .callerContextNumber( commonFragmentValues.callStack.getById(frame.parentFrame()).contextNumber()) - .contextWillRevert(frame.willRevert()) - .contextGetsReverted(frame.getsReverted()) - .contextSelfReverts(frame.selfReverts()) - .contextRevertStamp(frame.revertStamp()) + .contextWillRevert(frame.willRevert() && isExec) + .contextGetsReverted(frame.getsReverted() && isExec) + .contextSelfReverts(frame.selfReverts() && isExec) + .contextRevertStamp(isExec ? frame.revertStamp() : 0) .codeFragmentIndex(commonFragmentValues.codeFragmentIndex) .programCounter(commonFragmentValues.pc) .programCounterNew(commonFragmentValues.pcNew) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java index bb97f762d6..55d18ea084 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java @@ -20,6 +20,7 @@ import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; import net.consensys.linea.zktracer.testing.EvmExtension; +import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -38,15 +39,16 @@ public class JumpTests { @ParameterizedTest @MethodSource("provideJumpScenario") void jumpScenarioTest(String description, String pcNew) { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(pcNew) - .op(OpCode.JUMP) - .op(OpCode.INVALID) - .op(OpCode.JUMPDEST) - .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST - .compile()) - .run(); + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(pcNew) + .op(OpCode.JUMP) + .op(OpCode.INVALID) + .op(OpCode.JUMPDEST) + .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST + .compile(); + System.out.println(bytecode.toHexString()); + BytecodeRunner.of(bytecode).run(); } private static Stream provideJumpScenario() { @@ -63,7 +65,7 @@ private static Stream provideJumpScenario() { "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); /* In order to run a specific test case (for example, the first one) use the following: - .filter(arguments -> "jumpOntoJumpDestTest".equals(arguments.get()[0])); + .filter(arguments -> "jumpOntoValidJumpDestination".equals(arguments.get()[0])); */ } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java index e632f3368d..40274448f6 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java @@ -25,6 +25,7 @@ import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; import net.consensys.linea.zktracer.testing.EvmExtension; +import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -45,16 +46,17 @@ public class JumpiTests { @ParameterizedTest @MethodSource("provideJumpiScenario") void jumpiScenarioTest(String description, String jumpiCondition, String pcNew) { - BytecodeRunner.of( - BytecodeCompiler.newProgram() - .push(jumpiCondition) - .push(pcNew) - .op(OpCode.JUMP) - .op(OpCode.INVALID) - .op(OpCode.JUMPDEST) - .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST - .compile()) - .run(); + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(jumpiCondition) + .push(pcNew) + .op(OpCode.JUMP) + .op(OpCode.INVALID) + .op(OpCode.JUMPDEST) + .push(OpCode.JUMPDEST.byteValue()) // false JUMPDEST + .compile(); + System.out.println(bytecode.toHexString()); + BytecodeRunner.of(bytecode).run(); } private static Stream provideJumpiScenario() { @@ -79,11 +81,11 @@ private static Stream provideJumpiScenario() { } private static List provideJumpiScenarioForJumpiCondition(String jumpiCondition) { - int jumpiConditionByteSize = + final int jumpiConditionByteSize = jumpiCondition.equals("0") ? 1 : (int) Math.ceil((double) new BigInteger(jumpiCondition, 16).bitLength() / 8); - int jumpiConditionByteOffset = jumpiConditionByteSize - 1; + final int jumpiConditionByteOffset = jumpiConditionByteSize - 1; return List.of( Arguments.of( "jumpiOntoValidJumpDestination", diff --git a/zkevm-constraints b/zkevm-constraints index 74f2885b2f..29b10da4cd 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 74f2885b2f6fe31dba8f1b741668776add5451ee +Subproject commit 29b10da4cd96cfbe8bf12d84020fb4df177021db From 2114c96cf685eba9419b992583348d7845e3f200 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 11 Jul 2024 12:29:30 +0200 Subject: [PATCH 199/461] feat(jump and jumpi tests): renaming and added skeleton of JumpDestinationVettingTest --- .../JumpDestinationVettingTest.java | 26 +++++++++++++++++++ .../{JumpTests.java => JumpTest.java} | 2 +- .../{JumpiTests.java => JumpiTest.java} | 3 +-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java rename arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/{JumpTests.java => JumpTest.java} (99%) rename arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/{JumpiTests.java => JumpiTest.java} (98%) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java new file mode 100644 index 0000000000..4bf3e40be0 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java @@ -0,0 +1,26 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import net.consensys.linea.zktracer.testing.EvmExtension; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class JumpDestinationVettingTest { + + // @ParameterizedTest + // @MethodSource("methodSource") + void jumpDestinationVettingTest() {} +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTest.java similarity index 99% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTest.java index 55d18ea084..a419a23a7b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTest.java @@ -27,7 +27,7 @@ import org.junit.jupiter.params.provider.MethodSource; @ExtendWith(EvmExtension.class) -public class JumpTests { +public class JumpTest { // NOTE: the bytecode we propose will at time use the following offsets (unless pcNew is large) // bytecode: diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java similarity index 98% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java index 40274448f6..221c1f2f48 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java @@ -32,7 +32,7 @@ import org.junit.jupiter.params.provider.MethodSource; @ExtendWith(EvmExtension.class) -public class JumpiTests { +public class JumpiTest { // NOTE: the bytecode we propose will at time use the following offsets (unless pcNew is large) // bytecode: @@ -99,7 +99,6 @@ private static List provideJumpiScenarioForJumpiCondition(String jump "jumpiOntoJumpDestByteOwnedBySomePush", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "8")), - // NOTE: in the cases below we add Arguments.of( "jumpiOutOfBoundsSmall", jumpiCondition, From 8c9b28f1fe0b9f9713e24dd8d5dbfc169eb54481 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 11 Jul 2024 16:59:28 +0200 Subject: [PATCH 200/461] feat(hub): implemented JUmpDestinationVettingTest --- .../JumpDestinationVettingTest.java | 55 ++++++++++++++++++- .../module/oob/OobJumpAndJumpiTest.java | 5 +- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java index 4bf3e40be0..3cc29cd5ab 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java @@ -14,13 +14,62 @@ */ package net.consensys.linea.zktracer.instructionprocessing; +import java.util.Random; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; import net.consensys.linea.zktracer.testing.EvmExtension; +import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; @ExtendWith(EvmExtension.class) public class JumpDestinationVettingTest { + final Random random = new Random(1); + final int N_JUMPS = 10; + + @ParameterizedTest + @ValueSource(ints = {1, 5, 15, 16, 17, 20, 31, 32}) + void jumpDestinationVettingTest(int positionOfDeceptiveJumpDest) { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + int nTotalInvalid = 0; + for (int i = 0; i < N_JUMPS; i++) { + int nPartialInvalid = random.nextInt(10) + 1; + nTotalInvalid += nPartialInvalid; + // NOTE: the last attempted JUMP "points" to a deceptive JUMPDEST owned by a PUSH32 + program + .push(3 + 4 * i + nTotalInvalid + (i < N_JUMPS - 1 ? 0 : positionOfDeceptiveJumpDest)) + .op(OpCode.JUMP) + .immediate(Bytes.repeat(OpCode.INVALID.byteValue(), nPartialInvalid)); + if (i < N_JUMPS - 1) { + program.op(OpCode.JUMPDEST); + } else { + String deceptivePush = generateDeceptivePush(positionOfDeceptiveJumpDest); + program.push(deceptivePush); + } + } + Bytes bytecode = program.compile(); + System.out.println(bytecode.toHexString()); + BytecodeRunner.of(bytecode).run(); + } - // @ParameterizedTest - // @MethodSource("methodSource") - void jumpDestinationVettingTest() {} + public String generateDeceptivePush(int positionOfDeceptiveJumpDest) { + if (positionOfDeceptiveJumpDest < 1 || positionOfDeceptiveJumpDest > 32) { + throw new IllegalArgumentException("positionOfDeceptiveJumpDest must be between 1 and 32"); + } + StringBuilder deceptivePush = new StringBuilder(); + for (int i = 1; i <= 31; i++) { + if (i == positionOfDeceptiveJumpDest) { + deceptivePush.append("5b"); // deceptive JUMPDEST "pointed" by the last JUMP + } else { + deceptivePush.append( + random.nextInt(2) == 0 + ? "60" + : "5b"); // PUSH1, JUMPDEST (not "pointed" by the last JUMP) + } + } + return deceptivePush.toString(); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java index e14f961fe7..e8ea4f88a0 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -547,9 +548,11 @@ void TestJumpiSequenceSuccessRandomBackAndForth() { } // Support methods + private Random random = new Random(1); + private List generateJumpDestinations( int N_JUMPS, int MAX_JUMPDESTINATION, int SPREADING_FACTOR) { - return ThreadLocalRandom.current() + return random .ints(1, MAX_JUMPDESTINATION) .distinct() .limit(N_JUMPS) From 100b5f86ac8945c0585a2cea63b604e21afdb142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 11 Jul 2024 17:38:14 +0200 Subject: [PATCH 201/461] GlobalConstants used to populate GasConstants --- .../zktracer/opcode/gas/GasConstants.java | 81 ++++++++++--------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java index dcd3fe974f..fbec05f21d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/GasConstants.java @@ -16,52 +16,53 @@ package net.consensys.linea.zktracer.opcode.gas; import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; // TODO we shouldn't use this, but takes value from constans/constants.lisp /** All the classes of gas prices per instruction used in the EVM. */ @RequiredArgsConstructor public enum GasConstants { - G_ZERO(0), - G_JUMP_DEST(1), - G_BASE(2), - G_VERY_LOW(3), - G_LOW(5), - G_MID(8), - G_HIGH(10), - G_WARM_ACCESS(100), - G_ACCESS_LIST_ADDRESS(2400), - G_ACCESS_LIST_STORAGE(1900), - G_COLD_ACCOUNT_ACCESS(2600), - G_COLD_S_LOAD(2100), - G_S_SET(20000), - G_S_RESET(2900), - R_S_CLEAR(15000), - R_SELF_DESTRUCT(24000), - G_SELF_DESTRUCT(5000), - G_CREATE(32000), - G_CODE_DEPOSIT(200), - G_CALL_VALUE(9000), - G_CALL_STIPEND(2300), - G_NEW_ACCOUNT(25000), - G_EXP(10), - G_EXP_BYTE(50), - G_MEMORY(3), - G_TX_CREATE(32000), - G_TX_DATA_ZERO(4), - G_TX_DATA_NON_ZERO(16), - G_TRANSACTION(21000), - G_LOG_0(Constants.LOG), - G_LOG_1(Constants.LOG + Constants.LOG_TOPIC), - G_LOG_2(Constants.LOG + 2 * Constants.LOG_TOPIC), - G_LOG_3(Constants.LOG + 3 * Constants.LOG_TOPIC), - G_LOG_4(Constants.LOG + 4 * Constants.LOG_TOPIC), - G_LOG_DATA(8), - G_LOG_TOPIC(375), - G_KECCAK_256(30), - G_KECCAK_256_WORD(6), - G_COPY(3), - G_BLOCK_HASH(20), + G_ZERO(GlobalConstants.GAS_CONST_G_ZERO), + G_JUMP_DEST(GlobalConstants.GAS_CONST_G_JUMPDEST), + G_BASE(GlobalConstants.GAS_CONST_G_BASE), + G_VERY_LOW(GlobalConstants.GAS_CONST_G_VERY_LOW), + G_LOW(GlobalConstants.GAS_CONST_G_LOW), + G_MID(GlobalConstants.GAS_CONST_G_MID), + G_HIGH(GlobalConstants.GAS_CONST_G_HIGH), + G_WARM_ACCESS(GlobalConstants.GAS_CONST_G_WARM_ACCESS), + G_ACCESS_LIST_ADDRESS(GlobalConstants.GAS_CONST_G_ACCESS_LIST_ADRESS), + G_ACCESS_LIST_STORAGE(GlobalConstants.GAS_CONST_G_ACCESS_LIST_STORAGE), + G_COLD_ACCOUNT_ACCESS(GlobalConstants.GAS_CONST_G_COLD_ACCOUNT_ACCESS), + G_COLD_S_LOAD(GlobalConstants.GAS_CONST_G_COLD_SLOAD), + G_S_SET(GlobalConstants.GAS_CONST_G_SSET), + G_S_RESET(GlobalConstants.GAS_CONST_G_SRESET), + R_S_CLEAR(GlobalConstants.REFUND_CONST_R_SCLEAR), + R_SELF_DESTRUCT(GlobalConstants.REFUND_CONST_R_SELFDESTRUCT), + G_SELF_DESTRUCT(GlobalConstants.GAS_CONST_G_SELFDESTRUCT), + G_CREATE(GlobalConstants.GAS_CONST_G_CREATE), + G_CODE_DEPOSIT(GlobalConstants.GAS_CONST_G_CODE_DEPOSIT), + G_CALL_VALUE(GlobalConstants.GAS_CONST_G_CALL_VALUE), + G_CALL_STIPEND(GlobalConstants.GAS_CONST_G_CALL_STIPEND), + G_NEW_ACCOUNT(GlobalConstants.GAS_CONST_G_NEW_ACCOUNT), + G_EXP(GlobalConstants.GAS_CONST_G_EXP), + G_EXP_BYTE(GlobalConstants.GAS_CONST_G_EXP_BYTE), + G_MEMORY(GlobalConstants.GAS_CONST_G_MEMORY), + G_TX_CREATE(GlobalConstants.GAS_CONST_G_TX_CREATE), + G_TX_DATA_ZERO(GlobalConstants.GAS_CONST_G_TX_DATA_ZERO), + G_TX_DATA_NON_ZERO(GlobalConstants.GAS_CONST_G_TX_DATA_NONZERO), + G_TRANSACTION(GlobalConstants.GAS_CONST_G_TRANSACTION), + G_LOG_0(GlobalConstants.GAS_CONST_G_LOG), + G_LOG_1(GlobalConstants.GAS_CONST_G_LOG + GlobalConstants.GAS_CONST_G_LOG_TOPIC), + G_LOG_2(GlobalConstants.GAS_CONST_G_LOG + 2 * GlobalConstants.GAS_CONST_G_LOG_TOPIC), + G_LOG_3(GlobalConstants.GAS_CONST_G_LOG + 3 * GlobalConstants.GAS_CONST_G_LOG_TOPIC), + G_LOG_4(GlobalConstants.GAS_CONST_G_LOG + 4 * GlobalConstants.GAS_CONST_G_LOG_TOPIC), + G_LOG_DATA(GlobalConstants.GAS_CONST_G_LOG_DATA), + G_LOG_TOPIC(GlobalConstants.GAS_CONST_G_LOG_TOPIC), + G_KECCAK_256(GlobalConstants.GAS_CONST_G_KECCAK_256), + G_KECCAK_256_WORD(GlobalConstants.GAS_CONST_G_KECCAK_256_WORD), + G_COPY(GlobalConstants.GAS_CONST_G_COPY), + G_BLOCK_HASH(GlobalConstants.GAS_CONST_G_BLOCKHASH), // below are markers for gas that is computed in other modules // that is: hub, memory expansion, stipend, precompile info S_MXP(0), From 43d34888195cdd61afde60b2054cdc81b67370c7 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 11 Jul 2024 18:06:54 +0200 Subject: [PATCH 202/461] feat(jump tests): generalized with respect to pushk and actual k --- .../JumpDestinationVettingTest.java | 44 +++++++++++++++---- .../module/oob/OobJumpAndJumpiTest.java | 3 +- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java index 3cc29cd5ab..1df904378b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java @@ -14,7 +14,11 @@ */ package net.consensys.linea.zktracer.instructionprocessing; +import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; + +import java.math.BigInteger; import java.util.Random; +import java.util.stream.Stream; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; @@ -23,7 +27,8 @@ import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; @ExtendWith(EvmExtension.class) public class JumpDestinationVettingTest { @@ -31,8 +36,9 @@ public class JumpDestinationVettingTest { final int N_JUMPS = 10; @ParameterizedTest - @ValueSource(ints = {1, 5, 15, 16, 17, 20, 31, 32}) - void jumpDestinationVettingTest(int positionOfDeceptiveJumpDest) { + @MethodSource("jumpDestinationVettingCases") + void jumpDestinationVettingTest( + int positionOfDeceptiveJumpDest, OpCode pushK, int pushKArgumentLength) { BytecodeCompiler program = BytecodeCompiler.newProgram(); int nTotalInvalid = 0; for (int i = 0; i < N_JUMPS; i++) { @@ -46,8 +52,10 @@ void jumpDestinationVettingTest(int positionOfDeceptiveJumpDest) { if (i < N_JUMPS - 1) { program.op(OpCode.JUMPDEST); } else { - String deceptivePush = generateDeceptivePush(positionOfDeceptiveJumpDest); - program.push(deceptivePush); + String pushKBytecode = Bytes.of(pushK.byteValue()).toHexString().substring(2); + String deceptivePush = + generateDeceptivePush(positionOfDeceptiveJumpDest, pushKArgumentLength); + program.immediate(bigIntegerToBytes(new BigInteger(pushKBytecode + deceptivePush, 16))); } } Bytes bytecode = program.compile(); @@ -55,12 +63,13 @@ void jumpDestinationVettingTest(int positionOfDeceptiveJumpDest) { BytecodeRunner.of(bytecode).run(); } - public String generateDeceptivePush(int positionOfDeceptiveJumpDest) { - if (positionOfDeceptiveJumpDest < 1 || positionOfDeceptiveJumpDest > 32) { - throw new IllegalArgumentException("positionOfDeceptiveJumpDest must be between 1 and 32"); + public String generateDeceptivePush(int positionOfDeceptiveJumpDest, int pushKArgumentLength) { + if (positionOfDeceptiveJumpDest < 1 || positionOfDeceptiveJumpDest > pushKArgumentLength) { + throw new IllegalArgumentException( + "positionOfDeceptiveJumpDest must be between 1 and pushKArgumentLength"); } StringBuilder deceptivePush = new StringBuilder(); - for (int i = 1; i <= 31; i++) { + for (int i = 1; i <= pushKArgumentLength; i++) { if (i == positionOfDeceptiveJumpDest) { deceptivePush.append("5b"); // deceptive JUMPDEST "pointed" by the last JUMP } else { @@ -72,4 +81,21 @@ public String generateDeceptivePush(int positionOfDeceptiveJumpDest) { } return deceptivePush.toString(); } + + static Stream jumpDestinationVettingCases() { + return Stream.of( + Arguments.of(1, OpCode.PUSH7, 5), // "Incomplete" push + Arguments.of(1, OpCode.PUSH1, 1), + Arguments.of(1, OpCode.PUSH2, 2), + Arguments.of(2, OpCode.PUSH2, 2), + Arguments.of(1, OpCode.PUSH32, 32), + Arguments.of(2, OpCode.PUSH32, 32), + Arguments.of(15, OpCode.PUSH32, 32), + Arguments.of(16, OpCode.PUSH32, 32), + Arguments.of(17, OpCode.PUSH32, 32), + Arguments.of(20, OpCode.PUSH32, 32), + Arguments.of(31, OpCode.PUSH32, 32), + Arguments.of(32, OpCode.PUSH32, 32)); + // TODO: add more test cases + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java index e8ea4f88a0..8a9b3ff0cb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -564,7 +563,7 @@ private List generateJumpDestinations( private List generatePermutation(int jumpDestinationsSize) { List permutation = - ThreadLocalRandom.current() + random .ints(0, jumpDestinationsSize - 1) .distinct() .limit(jumpDestinationsSize - 1) From 32e33a0d25ccd8664a94a62cec46f862e55eff05 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 11 Jul 2024 18:25:03 +0200 Subject: [PATCH 203/461] feat(jump tests): added cases where actual k of pushk is zero --- .../JumpDestinationVettingTest.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java index 1df904378b..305668b970 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java @@ -64,6 +64,9 @@ void jumpDestinationVettingTest( } public String generateDeceptivePush(int positionOfDeceptiveJumpDest, int pushKArgumentLength) { + if (pushKArgumentLength == 0) { + return ""; + } if (positionOfDeceptiveJumpDest < 1 || positionOfDeceptiveJumpDest > pushKArgumentLength) { throw new IllegalArgumentException( "positionOfDeceptiveJumpDest must be between 1 and pushKArgumentLength"); @@ -84,7 +87,6 @@ public String generateDeceptivePush(int positionOfDeceptiveJumpDest, int pushKAr static Stream jumpDestinationVettingCases() { return Stream.of( - Arguments.of(1, OpCode.PUSH7, 5), // "Incomplete" push Arguments.of(1, OpCode.PUSH1, 1), Arguments.of(1, OpCode.PUSH2, 2), Arguments.of(2, OpCode.PUSH2, 2), @@ -95,7 +97,17 @@ static Stream jumpDestinationVettingCases() { Arguments.of(17, OpCode.PUSH32, 32), Arguments.of(20, OpCode.PUSH32, 32), Arguments.of(31, OpCode.PUSH32, 32), - Arguments.of(32, OpCode.PUSH32, 32)); - // TODO: add more test cases + Arguments.of(32, OpCode.PUSH32, 32), + Arguments.of(1, OpCode.PUSH7, 5), // generic "incomplete" push + Arguments.of(1, OpCode.PUSH7, 0), // minimal edge case + Arguments.of(1, OpCode.PUSH7, 1), // the bytecode terminates in PUSH7 B1 + Arguments.of(1, OpCode.PUSH16, 0), // minimal edge case + missing 16 bytes + Arguments.of(1, OpCode.PUSH16, 1), // minimal edge case + missing 16 bytes + Arguments.of(1, OpCode.PUSH17, 0), // minimal edge case + missing 16 bytes + Arguments.of(1, OpCode.PUSH17, 1), // minimal edge case + missing 16 bytes + Arguments.of(1, OpCode.PUSH23, 7), // differs by 16 + Arguments.of(1, OpCode.PUSH32, 0), // minimal edge case, the final opcode is PUSH32 + Arguments.of(1, OpCode.PUSH32, 1), // the bytecode terminates in PUSH32 B1 + Arguments.of(1, OpCode.PUSH32, 31)); // missing a single byte } } From 2d9564263a3f170a9bc0047546826396acb548ac Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 12 Jul 2024 10:19:00 +0200 Subject: [PATCH 204/461] feat(jump tests): reduced jumps to 3 --- .../instructionprocessing/JumpDestinationVettingTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java index 305668b970..d7466847ce 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java @@ -33,7 +33,7 @@ @ExtendWith(EvmExtension.class) public class JumpDestinationVettingTest { final Random random = new Random(1); - final int N_JUMPS = 10; + final int N_JUMPS = 3; @ParameterizedTest @MethodSource("jumpDestinationVettingCases") From cf883a3ba63279f00ce73e878adce24a67ea3c1a Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 12 Jul 2024 13:15:01 +0200 Subject: [PATCH 205/461] res --- .../JumpDestinationVettingTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java index d7466847ce..d74ac9559a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java @@ -86,18 +86,23 @@ public String generateDeceptivePush(int positionOfDeceptiveJumpDest, int pushKAr } static Stream jumpDestinationVettingCases() { + // NOTE: these tests cases are chosen to test also ROM return Stream.of( - Arguments.of(1, OpCode.PUSH1, 1), - Arguments.of(1, OpCode.PUSH2, 2), - Arguments.of(2, OpCode.PUSH2, 2), - Arguments.of(1, OpCode.PUSH32, 32), + Arguments.of(1, OpCode.PUSH1, 1), // minimal complete push + Arguments.of( + 1, OpCode.PUSH2, 2), // deceptive jump destination in the beginning and small push + Arguments.of(2, OpCode.PUSH2, 2), // deceptive jump destination in the end and small push + Arguments.of( + 1, OpCode.PUSH32, 32), // deceptive jump destination in the beginning and large push Arguments.of(2, OpCode.PUSH32, 32), Arguments.of(15, OpCode.PUSH32, 32), - Arguments.of(16, OpCode.PUSH32, 32), - Arguments.of(17, OpCode.PUSH32, 32), + Arguments.of( + 16, OpCode.PUSH32, 32), // deceptive jump destination before middle and large push + Arguments.of( + 17, OpCode.PUSH32, 32), // deceptive jump destination after middle and large push Arguments.of(20, OpCode.PUSH32, 32), Arguments.of(31, OpCode.PUSH32, 32), - Arguments.of(32, OpCode.PUSH32, 32), + Arguments.of(32, OpCode.PUSH32, 32), // deceptive jump destination in the end and large push Arguments.of(1, OpCode.PUSH7, 5), // generic "incomplete" push Arguments.of(1, OpCode.PUSH7, 0), // minimal edge case Arguments.of(1, OpCode.PUSH7, 1), // the bytecode terminates in PUSH7 B1 From 59c0b772d8b2fbb890e0085d6788bcd14abc92da Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 12 Jul 2024 13:45:44 +0200 Subject: [PATCH 206/461] feat(hub): partially implemented DeployContractModifyingStorageTest --- .../DeployContractModifyingStorageTest.java | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java new file mode 100644 index 0000000000..f0c6c1e9e1 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java @@ -0,0 +1,88 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import java.util.List; + +import net.consensys.linea.zktracer.testing.EvmExtension; +import net.consensys.linea.zktracer.testing.ToyAccount; +import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; +import net.consensys.linea.zktracer.testing.ToyTransaction; +import net.consensys.linea.zktracer.testing.ToyWorld; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.TransactionType; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class DeployContractModifyingStorageTest { + + @Test + void deployContractModifyingStorageInConstructorTest() { + /* NOTE: The contract in this method is compiled by using + solc *.sol --bin-runtime --evm-version london -o compiledContracts + i.e., we do not include the init code of the contracts in the bytecode + */ + + // User address + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + ToyAccount userAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); + + // Contract modifying storage + ToyAccount contractModifyingStorageAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(2) + .address(Address.fromHexString("0x")) // NOTE: here the address is intentionally set to 0x + .code(Bytes.fromHexString("addherebytecodeofthecontractwithout0x")) + .build(); + + // Is this transaction necessary only if we want to invoke a specific function of the contract? + // If so, we need it only in the other test case + Transaction tx = + ToyTransaction.builder() + .sender(userAccount) + .to(contractModifyingStorageAccount) + .payload(Bytes.fromHexString("addherepayloadofthetransactionwith0x")) + .transactionType(TransactionType.FRONTIER) + .gasLimit(0xffffffffL) + .value(Wei.ZERO) + .keyPair(keyPair) + .build(); + + ToyWorld toyWorld = + ToyWorld.builder().accounts(List.of(userAccount, contractModifyingStorageAccount)).build(); + + ToyExecutionEnvironment toyExecutionEnvironment = + ToyExecutionEnvironment.builder() + .toyWorld(toyWorld) + .transaction(tx) + .testValidator(x -> {}) + .build(); + + toyExecutionEnvironment.run(); + } + + @Test + void deployContractModifyingStorageInFunctionTest() {} +} From de001e30ac6513ebaf29c8edf89f9ba4c859015f Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 12 Jul 2024 14:17:10 +0200 Subject: [PATCH 207/461] added comments for testing --- .../DeployContractModifyingStorageTest.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java index f0c6c1e9e1..9e081cbead 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java @@ -48,30 +48,39 @@ void deployContractModifyingStorageInConstructorTest() { ToyAccount userAccount = ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); - // Contract modifying storage - ToyAccount contractModifyingStorageAccount = - ToyAccount.builder() - .balance(Wei.fromEth(1)) - .nonce(2) - .address(Address.fromHexString("0x")) // NOTE: here the address is intentionally set to 0x - .code(Bytes.fromHexString("addherebytecodeofthecontractwithout0x")) - .build(); - - // Is this transaction necessary only if we want to invoke a specific function of the contract? - // If so, we need it only in the other test case + // Deployment transaction Transaction tx = ToyTransaction.builder() .sender(userAccount) - .to(contractModifyingStorageAccount) - .payload(Bytes.fromHexString("addherepayloadofthetransactionwith0x")) + //.to() + .payload(Bytes.fromHexString("addhereinitializationcodewith0x")) .transactionType(TransactionType.FRONTIER) .gasLimit(0xffffffffL) .value(Wei.ZERO) .keyPair(keyPair) .build(); + /* + - Initialization code is what you give in the payload of the transaction in case the "to" address is empty + - It should contain some SLOAD and SSTORE + - Have at least 2 storages keys to interact with (ideally 4). Both of them should be SLOAD and SSTORE several times. One should + contain 0 and 2-3 containing non-zero. + - Preferably interacting with the same storage key several times + - Finish by deploying bytecode + - At the end, it returns a slice of memory that will become the deployed bytecode + - That bytecode should do some SLOAD and SSTORE + - Preferably interacting with the same storage key several times + - In particular, with the storage key that was used in the initialization but also new others + + Remix: + - Deploy contract, initialization code is called "input". The construct should generate SLOAD nad SSTORE by modifying some variables in storage. + - Create variables (in storage by default), SLOAD them (not explicitly), modify them, SSTORE them (not explicitly). + - The same contract can have a function doing the same stuff. + */ + + ToyWorld toyWorld = - ToyWorld.builder().accounts(List.of(userAccount, contractModifyingStorageAccount)).build(); + ToyWorld.builder().accounts(List.of(userAccount)).build(); ToyExecutionEnvironment toyExecutionEnvironment = ToyExecutionEnvironment.builder() @@ -84,5 +93,7 @@ void deployContractModifyingStorageInConstructorTest() { } @Test - void deployContractModifyingStorageInFunctionTest() {} + void deployContractModifyingStorageInFunctionTest() { + + } } From a80e85057481dbced9a47ba0a3ce86b5fa96a98a Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Sun, 14 Jul 2024 16:59:07 +0200 Subject: [PATCH 208/461] feat(modify storage): partially implemented tests --- .../ContractModifyingStorageTest.java | 135 ++++++++++++++++++ .../DeployContractModifyingStorageTest.java | 99 ------------- .../ContractModifyingStorageInConstructor.sol | 29 ++++ .../ContractModifyingStorageInFunction.sol | 29 ++++ 4 files changed, 193 insertions(+), 99 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java create mode 100644 arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInConstructor.sol create mode 100644 arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInFunction.sol diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java new file mode 100644 index 0000000000..d32cfc6608 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -0,0 +1,135 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import java.util.List; + +import net.consensys.linea.zktracer.testing.EvmExtension; +import net.consensys.linea.zktracer.testing.ToyAccount; +import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; +import net.consensys.linea.zktracer.testing.ToyTransaction; +import net.consensys.linea.zktracer.testing.ToyWorld; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.TransactionType; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class ContractModifyingStorageTest { + + /* + - Initialization code is what you give in the payload of the transaction in case the "to" address is empty + - It should contain some SLOAD and SSTORE + - Have at least 2 storages keys to interact with (ideally 4). Both of them should be SLOAD and SSTORE several times. One should + contain 0 and 2-3 containing non-zero. + - Preferably interacting with the same storage key several times + - Finish by deploying bytecode + - At the end, it returns a slice of memory that will become the deployed bytecode + - That bytecode should do some SLOAD and SSTORE + - Preferably interacting with the same storage key several times + - In particular, with the storage key that was used in the initialization but also new others + + Remix: + - Deploy contract, initialization code is called "input". The construct should generate SLOAD nad SSTORE by modifying some variables in storage. + - Create variables (in storage by default), SLOAD them (not explicitly), modify them, SSTORE them (not explicitly). + - The same contract can have a function doing the same stuff. + */ + + @Test + void contractModifyingStorageInConstructorTest() { + /* NOTE: The contract in this method is compiled by using + solc *.sol --bin-runtime --evm-version london -o compiledContracts + i.e., we do not include the init code of the contracts in the bytecode + */ + + // User address + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + ToyAccount userAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); + + // Deployment transaction + Transaction tx = + ToyTransaction.builder() + .sender(userAccount) + // .to() + .payload( + Bytes.fromHexString( + "0x608060405234801561000f575f80fd5b505f8081905550600180819055506002808190555060038081905550600a5f546100399190610109565b5f81905550600b60015461004d9190610109565b600181905550600c6002546100629190610109565b600281905550600d6003546100779190610109565b6003819055505f805461008a919061013c565b5f81905550601460015461009e919061013c565b60018190555060156002546100b3919061013c565b60028190555060156003546100c8919061013c565b60038190555061017d565b5f819050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610113826100d3565b915061011e836100d3565b9250828201905080821115610136576101356100dc565b5b92915050565b5f610146826100d3565b9150610151836100d3565b925082820261015f816100d3565b91508282048414831517610176576101756100dc565b5b5092915050565b61012a8061018a5f395ff3fe6080604052348015600e575f80fd5b50600436106044575f3560e01c8063501e82121460485780636cc014de146062578063a314150f14607c578063a5d666a9146096575b5f80fd5b604e60b0565b6040516059919060dd565b60405180910390f35b606860b5565b6040516073919060dd565b60405180910390f35b608260bb565b604051608d919060dd565b60405180910390f35b609c60c1565b60405160a7919060dd565b60405180910390f35b5f5481565b60015481565b60025481565b60035481565b5f819050919050565b60d78160c7565b82525050565b5f60208201905060ee5f83018460d0565b9291505056fea26469706673582212203b939ad06f3d7d92a207fb36abc74231e00c81272ebf0645d4d40e917fc5e43b64736f6c634300081a0033")) + .transactionType(TransactionType.FRONTIER) + .gasLimit(0xffffffffL) + .value(Wei.ZERO) + .keyPair(keyPair) + .build(); + + ToyWorld toyWorld = ToyWorld.builder().accounts(List.of(userAccount)).build(); + + ToyExecutionEnvironment toyExecutionEnvironment = + ToyExecutionEnvironment.builder() + .toyWorld(toyWorld) + .transaction(tx) + .testValidator(x -> {}) + .build(); + + toyExecutionEnvironment.run(); + } + + @Test + void contractModifyingStorageInFunctionTest() { + /* NOTE: The contract in this method is compiled by using + solc *.sol --bin-runtime --evm-version london -o compiledContracts + i.e., we do not include the init code of the contracts in the bytecode + */ + + // User address + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + ToyAccount userAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); + + // Deployment transaction + Transaction tx = + ToyTransaction.builder() + .sender(userAccount) + // .to() + .payload( + Bytes.fromHexString( + "0x6080604052348015600e575f80fd5b506102ba8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610055575f3560e01c8063501e8212146100595780636cc014de14610077578063a314150f14610095578063a5d666a9146100b3578063e8af2fa5146100d1575b5f80fd5b6100616100db565b60405161006e91906101ca565b60405180910390f35b61007f6100e0565b60405161008c91906101ca565b60405180910390f35b61009d6100e6565b6040516100aa91906101ca565b60405180910390f35b6100bb6100ec565b6040516100c891906101ca565b60405180910390f35b6100d96100f2565b005b5f5481565b60015481565b60025481565b60035481565b5f8081905550600180819055506002808190555060038081905550600a5f5461011b9190610210565b5f81905550600b60015461012f9190610210565b600181905550600c6002546101449190610210565b600281905550600d6003546101599190610210565b6003819055505f805461016c9190610243565b5f8190555060146001546101809190610243565b60018190555060156002546101959190610243565b60028190555060156003546101aa9190610243565b600381905550565b5f819050919050565b6101c4816101b2565b82525050565b5f6020820190506101dd5f8301846101bb565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61021a826101b2565b9150610225836101b2565b925082820190508082111561023d5761023c6101e3565b5b92915050565b5f61024d826101b2565b9150610258836101b2565b9250828202610266816101b2565b9150828204841483151761027d5761027c6101e3565b5b509291505056fea2646970667358221220b40040e95e9f0674ff5c258759b2ac4564a8cf968f9d59477114688f3eff824364736f6c634300081a0033")) + .transactionType(TransactionType.FRONTIER) + .gasLimit(0xffffffffL) + .value(Wei.ZERO) + .keyPair(keyPair) + .build(); + + ToyWorld toyWorld = ToyWorld.builder().accounts(List.of(userAccount)).build(); + + ToyExecutionEnvironment toyExecutionEnvironment = + ToyExecutionEnvironment.builder() + .toyWorld(toyWorld) + .transaction(tx) + .testValidator(x -> {}) + .build(); + + // TODO: add transaction to invoke function + + toyExecutionEnvironment.run(); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java deleted file mode 100644 index 9e081cbead..0000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/DeployContractModifyingStorageTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package net.consensys.linea.zktracer.instructionprocessing; - -import java.util.List; - -import net.consensys.linea.zktracer.testing.EvmExtension; -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; -import net.consensys.linea.zktracer.testing.ToyTransaction; -import net.consensys.linea.zktracer.testing.ToyWorld; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.crypto.KeyPair; -import org.hyperledger.besu.crypto.SECP256K1; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; - -@ExtendWith(EvmExtension.class) -public class DeployContractModifyingStorageTest { - - @Test - void deployContractModifyingStorageInConstructorTest() { - /* NOTE: The contract in this method is compiled by using - solc *.sol --bin-runtime --evm-version london -o compiledContracts - i.e., we do not include the init code of the contracts in the bytecode - */ - - // User address - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount userAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); - - // Deployment transaction - Transaction tx = - ToyTransaction.builder() - .sender(userAccount) - //.to() - .payload(Bytes.fromHexString("addhereinitializationcodewith0x")) - .transactionType(TransactionType.FRONTIER) - .gasLimit(0xffffffffL) - .value(Wei.ZERO) - .keyPair(keyPair) - .build(); - /* - - Initialization code is what you give in the payload of the transaction in case the "to" address is empty - - It should contain some SLOAD and SSTORE - - Have at least 2 storages keys to interact with (ideally 4). Both of them should be SLOAD and SSTORE several times. One should - contain 0 and 2-3 containing non-zero. - - Preferably interacting with the same storage key several times - - Finish by deploying bytecode - - At the end, it returns a slice of memory that will become the deployed bytecode - - That bytecode should do some SLOAD and SSTORE - - Preferably interacting with the same storage key several times - - In particular, with the storage key that was used in the initialization but also new others - - Remix: - - Deploy contract, initialization code is called "input". The construct should generate SLOAD nad SSTORE by modifying some variables in storage. - - Create variables (in storage by default), SLOAD them (not explicitly), modify them, SSTORE them (not explicitly). - - The same contract can have a function doing the same stuff. - */ - - - - ToyWorld toyWorld = - ToyWorld.builder().accounts(List.of(userAccount)).build(); - - ToyExecutionEnvironment toyExecutionEnvironment = - ToyExecutionEnvironment.builder() - .toyWorld(toyWorld) - .transaction(tx) - .testValidator(x -> {}) - .build(); - - toyExecutionEnvironment.run(); - } - - @Test - void deployContractModifyingStorageInFunctionTest() { - - } -} diff --git a/arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInConstructor.sol b/arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInConstructor.sol new file mode 100644 index 0000000000..5017d01759 --- /dev/null +++ b/arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInConstructor.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract ContractModifyingStorageInConstructor { + // Storage variables + uint256 public s0; + uint256 public s1; + uint256 public s2; + uint256 public s3; + + // Constructor that modifies the storage variables + constructor() { + // Set initial values + s0 = 0; + s1 = 1; + s2 = 2; + s3 = 3; + // Change values + s0 = s0 + 10; + s1 = s1 + 11; + s2 = s2 + 12; + s3 = s3 + 13; + // Change values again and set s0 back to 0 + s0 = s0 * 0; + s1 = s1 * 20; + s2 = s2 * 21; + s3 = s3 * 21; + } +} \ No newline at end of file diff --git a/arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInFunction.sol b/arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInFunction.sol new file mode 100644 index 0000000000..e9593d9db4 --- /dev/null +++ b/arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInFunction.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract ContractModifyingStorageInFunction { + // Storage variables + uint256 public s0; + uint256 public s1; + uint256 public s2; + uint256 public s3; + + // Function that modifies the storage variables + function modifyStorage() public { + // Set initial values + s0 = 0; + s1 = 1; + s2 = 2; + s3 = 3; + // Change values + s0 = s0 + 10; + s1 = s1 + 11; + s2 = s2 + 12; + s3 = s3 + 13; + // Change values again and set s0 back to 0 + s0 = s0 * 0; + s1 = s1 * 20; + s2 = s2 * 21; + s3 = s3 * 21; + } +} \ No newline at end of file From 8b02c78449b57a32a02178d229cd373b53fb2694 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Sun, 14 Jul 2024 18:18:19 +0200 Subject: [PATCH 209/461] res --- .../ContractModifyingStorageTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index d32cfc6608..6b9bbce4dc 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -55,10 +55,8 @@ public class ContractModifyingStorageTest { @Test void contractModifyingStorageInConstructorTest() { - /* NOTE: The contract in this method is compiled by using - solc *.sol --bin-runtime --evm-version london -o compiledContracts - i.e., we do not include the init code of the contracts in the bytecode - */ + // Deploy + // arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInConstructor.sol // User address KeyPair keyPair = new SECP256K1().generateKeyPair(); @@ -94,10 +92,8 @@ void contractModifyingStorageInConstructorTest() { @Test void contractModifyingStorageInFunctionTest() { - /* NOTE: The contract in this method is compiled by using - solc *.sol --bin-runtime --evm-version london -o compiledContracts - i.e., we do not include the init code of the contracts in the bytecode - */ + // Deploy + // arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInFunction.sol // User address KeyPair keyPair = new SECP256K1().generateKeyPair(); From 1a090bae169da2f75bc8e335474b2778c7121e5e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 15 Jul 2024 13:13:52 +0530 Subject: [PATCH 210/461] fix(rollBackDefers): initialise the map when entering a context --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 3 +++ .../linea/zktracer/module/hub/defer/DeferRegistry.java | 4 ++++ .../zktracer/module/hub/section/CallDataLoadSection.java | 2 +- .../consensys/linea/zktracer/runtime/callstack/CallStack.java | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 29bd773576..f191601165 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -547,6 +547,7 @@ public void traceContextEnter(MessageFrame frame) { ? 0 : this.transients.conflation().deploymentInfo().number(toAddress), this.transients.conflation().deploymentInfo().isDeploying(toAddress)); + this.defers.enterFrame(this.callStack.current()); } else { this.callStack.newBedrock( this.state.stamps().hub(), @@ -567,6 +568,7 @@ public void traceContextEnter(MessageFrame frame) { ? 0 : this.transients.conflation().deploymentInfo().number(toAddress), this.transients.conflation().deploymentInfo().isDeploying(toAddress)); + this.defers.enterFrame(this.callStack.current()); } } else { // ...or CALL @@ -614,6 +616,7 @@ public void traceContextEnter(MessageFrame frame) { codeDeploymentNumber, isDeployment); + this.defers.enterFrame(this.callStack.current()); this.defers.resolveWithNextContext(this, frame); for (Module m : this.modules) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index e2ab64142e..fe34b9e8d5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -83,6 +83,10 @@ public void reEntry(ReEnterContextDefer defer) { this.reEntryDefers.add(defer); } + public void enterFrame(final CallFrame callFrame) { + this.rollbackDefers.put(callFrame, new ArrayList<>()); + } + public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame) { this.rollbackDefers.get(callFrame).add(defer); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index 1a917738e7..21945d552a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -56,7 +56,7 @@ public CallDataLoadSection(Hub hub) { this.currentContextNumber = hub.currentFrame().contextNumber(); this.callDataSize = hub.currentFrame().callDataInfo().memorySpan().length(); this.callDataOffset = hub.currentFrame().callDataInfo().memorySpan().offset(); - this.sourceOffset = (EWord) hub.currentFrame().frame().getStackItem(0); + this.sourceOffset = EWord.of(hub.currentFrame().frame().getStackItem(0)); this.callDataCN = hub.currentFrame().callDataInfo().callDataContextNumber(); this.callDataRam = hub.currentFrame().callDataInfo().data(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 1ecf90cc3f..7359ef9590 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -236,7 +236,7 @@ public void enter( callData = input; } - CallFrame newFrame = + final CallFrame newFrame = new CallFrame( accountDeploymentNumber, codeDeploymentNumber, From 0a5333eef10cb52bb0e45aca4ca6a04a5f51f971 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 15 Jul 2024 16:21:59 +0530 Subject: [PATCH 211/461] fix(mmuCall): defers call of MMU for COPY family --- .../hub/fragment/imc/call/mmu/MmuCall.java | 25 +++++++++-- .../imc/call/mmu/opcode/CodeCopy.java | 7 +++ .../imc/call/mmu/opcode/ExtCodeCopy.java | 9 +++- .../hub/section/copy/CallDataCopySection.java | 35 +++++++++------ .../hub/section/copy/CodeCopySection.java | 26 +++++------ .../hub/section/copy/ExtCodeCopySection.java | 45 ++++++++++--------- .../section/copy/ReturnDataCopySection.java | 40 ++++++++++------- 7 files changed, 121 insertions(+), 66 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index b3578c18e8..e1dc9110e8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -84,6 +84,7 @@ import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; /** @@ -178,9 +179,18 @@ public static MmuCall sha3(final Hub hub) { public static MmuCall callDataCopy(final Hub hub) { final MemorySpan callDataSegment = hub.currentFrame().callDataInfo().memorySpan(); + final int callDataContextNumber = callDataContextNumber(hub); + final MessageFrame callFrame = hub.callStack().getById(callDataContextNumber).frame(); + return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) - .sourceId(callDataContextNumber(hub)) + .sourceId(callDataContextNumber) + .sourceRamBytes(Optional.of(callFrame.shadowReadMemory(0, callFrame.memoryByteSize()))) .targetId(hub.currentFrame().contextNumber()) + .targetRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .targetOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(2))) @@ -223,10 +233,19 @@ public static MmuCall extCodeCopy(final Hub hub) { public static MmuCall returnDataCopy(final Hub hub) { final MemorySpan returnDataSegment = hub.currentFrame().latestReturnDataSource(); + final CallFrame returnerFrame = + hub.callStack().getById(hub.currentFrame().returnDataContextNumber()); return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) - .sourceId( - hub.callStack().getById(hub.currentFrame().returnDataContextNumber()).contextNumber()) + .sourceId(returnerFrame.contextNumber()) + .sourceRamBytes( + Optional.of( + returnerFrame.frame().shadowReadMemory(0, returnerFrame.frame().memoryByteSize()))) .targetId(hub.currentFrame().contextNumber()) + .targetRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .targetOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(2))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java index 82cbaf0b59..8049f8ce12 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java @@ -17,6 +17,8 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_ANY_TO_RAM_WITH_PADDING; +import java.util.Optional; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; @@ -37,6 +39,11 @@ public CodeCopy(final Hub hub) { this.contract = hub.currentFrame().metadata(); this.targetId(hub.currentFrame().contextNumber()) + .targetRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .targetOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(2))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java index ddf029ed3d..534e146b77 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java @@ -17,6 +17,8 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_ANY_TO_RAM_WITH_PADDING; +import java.util.Optional; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; @@ -35,7 +37,7 @@ public class ExtCodeCopy extends MmuCall { public ExtCodeCopy(final Hub hub) { super(MMU_INST_ANY_TO_RAM_WITH_PADDING); this.hub = hub; - Address sourceAddress = Words.toAddress(hub.messageFrame().getStackItem(0)); + final Address sourceAddress = Words.toAddress(hub.messageFrame().getStackItem(0)); this.contract = ContractMetadata.make( sourceAddress, @@ -43,6 +45,11 @@ public ExtCodeCopy(final Hub hub) { hub.transients().conflation().deploymentInfo().isDeploying(sourceAddress)); this.targetId(hub.currentFrame().contextNumber()) + .targetRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(2))) .targetOffset(EWord.of(hub.messageFrame().getStackItem(1))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(3))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index 45a0e2916a..a19c17d8cf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -17,16 +17,22 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class CallDataCopySection extends TraceSection { +public class CallDataCopySection extends TraceSection implements PostTransactionDefer { final short exceptions; + final ImcFragment miscFragment; + boolean triggerMmu = false; + MmuCall mmuCall; public CallDataCopySection(Hub hub) { // 3 = 1 + 2 @@ -34,18 +40,14 @@ public CallDataCopySection(Hub hub) { this.exceptions = hub.pch().exceptions(); hub.addTraceSection(this); - this.populate(hub); - } - - public void populate(Hub hub) { - ImcFragment imcFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, imcFragment); + miscFragment = ImcFragment.empty(hub); + this.addFragmentsAndStack(hub, miscFragment); // triggerOob = false // triggerMxp = true - MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); + final MxpCall mxpCall = new MxpCall(hub); + miscFragment.callMxp(mxpCall); Preconditions.checkArgument( mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); @@ -71,15 +73,22 @@ public void populate(Hub hub) { // The unexceptional case ///////////////////////// - ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); this.addFragment(currentContext); - final boolean triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; + triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; if (!triggerMmu) { return; } - MmuCall mmuCall = MmuCall.callDataCopy(hub); - imcFragment.callMmu(mmuCall); + mmuCall = MmuCall.callDataCopy(hub); + } + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (triggerMmu) { + miscFragment.callMmu(mmuCall); + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 3c2b13a128..21626c1744 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -34,28 +34,26 @@ import org.hyperledger.besu.evm.worldstate.WorldView; public class CodeCopySection extends TraceSection implements PostTransactionDefer { - ImcFragment imcFragment; + final ImcFragment imcFragment; boolean triggerMmu; final short exceptions; + MmuCall mmuCall; public CodeCopySection(Hub hub) { // 4 = 1 (stack row) + 3 (up to 3 non-stack rows) super(hub, (short) 4); this.exceptions = hub.pch().exceptions(); - this.populate(hub); hub.addTraceSection(this); - } - public void populate(Hub hub) { // Miscellaneous row imcFragment = ImcFragment.empty(hub); this.addFragmentsAndStack(hub, imcFragment); // triggerOob = false // triggerMxp = true - MxpCall mxpCall = new MxpCall(hub); + final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - boolean mxpx = mxpCall.mxpx; + final boolean mxpx = mxpCall.mxpx; Preconditions.checkArgument(mxpx == Exceptions.memoryExpansionException(exceptions)); // The MXPX case @@ -64,7 +62,7 @@ public void populate(Hub hub) { return; } - boolean xahoy = Exceptions.any(exceptions); + final boolean xahoy = Exceptions.any(exceptions); Preconditions.checkArgument(xahoy == (exceptions == Exceptions.OUT_OF_GAS_EXCEPTION)); // The OOGX case @@ -76,7 +74,7 @@ public void populate(Hub hub) { // Beyond this point we are in the xahoy = false case // Context row - ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); + final ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); this.addFragment(contextFragment); // Account row @@ -84,20 +82,20 @@ public void populate(Hub hub) { final Address codeAddress = frame.getContractAddress(); final Account codeAccount = frame.getWorldUpdater().get(codeAddress); - boolean warmth = frame.isAddressWarm(codeAddress); + final boolean warmth = frame.isAddressWarm(codeAddress); Preconditions.checkArgument(warmth); - AccountSnapshot codeAccountSnapshot = + final AccountSnapshot codeAccountSnapshot = AccountSnapshot.fromAccount( codeAccount, warmth, hub.transients().conflation().deploymentInfo().number(codeAddress), hub.transients().conflation().deploymentInfo().isDeploying(codeAddress)); - DomSubStampsSubFragment doingDomSubStamps = + final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 0); // Specifics for CODECOPY - AccountFragment accountReadingFragment = + final AccountFragment accountReadingFragment = hub.factories() .accountFragment() .make(codeAccountSnapshot, codeAccountSnapshot, doingDomSubStamps); @@ -107,6 +105,9 @@ public void populate(Hub hub) { this.addFragment(accountReadingFragment); triggerMmu = mxpCall.isMayTriggerNonTrivialMmuOperation(); + if (triggerMmu) { + mmuCall = MmuCall.codeCopy(hub); + } hub.defers().schedulePostTransaction(this); } @@ -114,7 +115,6 @@ public void populate(Hub hub) { public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (triggerMmu) { - MmuCall mmuCall = MmuCall.codeCopy(hub); imcFragment.callMmu(mmuCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index c44ad406e5..225815ba3f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -48,9 +48,16 @@ public class ExtCodeCopySection extends TraceSection implements PostRollbackDefe AccountSnapshot accountBefore; AccountSnapshot accountAfter; + final ImcFragment miscFragment; + boolean triggerMmu = false; + MmuCall mmuCall; + public ExtCodeCopySection(Hub hub) { // 4 = 1 + 3 super(hub, (short) 4); + + hub.addTraceSection(this); + final MessageFrame frame = hub.messageFrame(); this.rawAddress = frame.getStackItem(0); this.address = Address.extract((Bytes32) this.rawAddress); @@ -61,19 +68,13 @@ public ExtCodeCopySection(Hub hub) { this.incomingWarmth = frame.isAddressWarm(this.address); this.exceptions = hub.pch().exceptions(); - this.populate(hub); - hub.addTraceSection(this); - } - - public void populate(Hub hub) { - - ImcFragment imcFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, imcFragment); + miscFragment = ImcFragment.empty(hub); + this.addFragmentsAndStack(hub, miscFragment); // triggerOob = false // triggerMxp = true - MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); + final MxpCall mxpCall = new MxpCall(hub); + miscFragment.callMxp(mxpCall); Preconditions.checkArgument( mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); @@ -84,7 +85,6 @@ public void populate(Hub hub) { return; } - final MessageFrame frame = hub.messageFrame(); final Account foreignAccount = frame.getWorldUpdater().get(this.address); this.accountBefore = @@ -94,14 +94,14 @@ public void populate(Hub hub) { this.incomingDeploymentNumber, this.incomingDeploymentStatus); - DomSubStampsSubFragment doingDomSubStamps = + final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 0); // The OOGX case //////////////// if (outOfGasException(this.exceptions)) { // the last context row will be added automatically - AccountFragment accountReadingFragment = + final AccountFragment accountReadingFragment = hub.factories() .accountFragment() .makeWithTrm( @@ -113,10 +113,9 @@ public void populate(Hub hub) { // The unexceptional case ///////////////////////// - final boolean triggerMmu = none(this.exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; + triggerMmu = none(this.exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { - MmuCall mmuCall = MmuCall.extCodeCopy(hub); - imcFragment.callMmu(mmuCall); + mmuCall = MmuCall.extCodeCopy(hub); } // TODO: make sure that hasCode returns false during deployments @@ -127,7 +126,7 @@ public void populate(Hub hub) { AccountSnapshot.fromAccount( foreignAccount, true, this.incomingDeploymentNumber, this.incomingDeploymentStatus); - AccountFragment accountDoingFragment = + final AccountFragment accountDoingFragment = hub.factories() .accountFragment() .makeWithTrm(this.accountBefore, this.accountAfter, this.rawAddress, doingDomSubStamps); @@ -142,12 +141,16 @@ public void populate(Hub hub) { @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + if (triggerMmu) { + miscFragment.callMmu(mmuCall); + } + final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(this.address); final boolean deploymentStatusAtRollback = hub.transients().conflation().deploymentInfo().isDeploying(this.address); - AccountSnapshot revertFromSnapshot = + final AccountSnapshot revertFromSnapshot = new AccountSnapshot( this.accountAfter.address(), this.accountAfter.nonce(), @@ -157,7 +160,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca deploymentNumberAtRollback, deploymentStatusAtRollback); - AccountSnapshot revertToSnapshot = + final AccountSnapshot revertToSnapshot = new AccountSnapshot( this.accountBefore.address(), this.accountBefore.nonce(), @@ -167,9 +170,9 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca deploymentNumberAtRollback, deploymentStatusAtRollback); - DomSubStampsSubFragment undoingDomSubStamps = + final DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); - AccountFragment undoingAccountFragment = + final AccountFragment undoingAccountFragment = hub.factories() .accountFragment() .make(revertFromSnapshot, revertToSnapshot, undoingDomSubStamps); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 45209427e9..ae9b7de796 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -17,6 +17,7 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -24,30 +25,32 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class ReturnDataCopySection extends TraceSection { +public class ReturnDataCopySection extends TraceSection implements PostTransactionDefer { final short exceptions; + final ImcFragment miscFragment; + boolean triggerMmu = false; + MmuCall mmuCall; + public ReturnDataCopySection(Hub hub) { // 4 = 1 + 3 super(hub, (short) 4); this.exceptions = hub.pch().exceptions(); - this.populate(hub); hub.addTraceSection(this); - } - public void populate(Hub hub) { - - ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); this.addFragmentsAndStack(hub, currentContext); - ImcFragment imcFragment = ImcFragment.empty(hub); - this.addFragment(imcFragment); + miscFragment = ImcFragment.empty(hub); + this.addFragment(miscFragment); - ReturnDataCopyOobCall oobCall = new ReturnDataCopyOobCall(); - imcFragment.callOob(oobCall); + final ReturnDataCopyOobCall oobCall = new ReturnDataCopyOobCall(); + miscFragment.callOob(oobCall); final boolean returnDataCopyException = oobCall.isRdcx(); Preconditions.checkArgument( @@ -57,8 +60,8 @@ public void populate(Hub hub) { return; } - MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); + final MxpCall mxpCall = new MxpCall(hub); + miscFragment.callMxp(mxpCall); final boolean memoryExpansionException = mxpCall.mxpx; Preconditions.checkArgument( @@ -70,10 +73,17 @@ public void populate(Hub hub) { } // beyond this point unexceptional - final boolean triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; + triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; + if (triggerMmu) { + mmuCall = MmuCall.returnDataCopy(hub); + } + } + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (triggerMmu) { - MmuCall mmuCall = MmuCall.returnDataCopy(hub); - imcFragment.callMmu(mmuCall); + miscFragment.callMmu(mmuCall); } } } From d79ef48ba52de74c3cc8910fb9f773d34becda28 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 15 Jul 2024 17:24:50 +0530 Subject: [PATCH 212/461] fix(sha3): defers mmuCall --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 5 ++ .../module/hub/section/KeccakSection.java | 63 ++++++++++--------- .../hub/section/copy/CallDataCopySection.java | 1 + .../hub/section/copy/CodeCopySection.java | 2 +- .../hub/section/copy/ExtCodeCopySection.java | 19 ++++-- .../section/copy/ReturnDataCopySection.java | 1 + 7 files changed, 57 insertions(+), 36 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f191601165..7623688ca7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1110,7 +1110,7 @@ void traceOperation(MessageFrame frame) { } case KEC -> { - KeccakSection.appendToTrace(this); + new KeccakSection(this); } case CONTEXT -> this.addTraceSection( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index e1dc9110e8..a9215b14e7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -169,6 +169,11 @@ public static MmuCall nop() { public static MmuCall sha3(final Hub hub) { return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) + .sourceRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .auxId(hub.state().stamps().hub()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(1))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 4386cb87d0..15427c5b75 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -15,51 +15,56 @@ package net.consensys.linea.zktracer.module.hub.section; -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; - import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import org.apache.tuweni.bytes.Bytes; -import org.bouncycastle.crypto.digests.KeccakDigest; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.operation.Operation; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class KeccakSection extends TraceSection implements PostExecDefer, PostTransactionDefer { -public class KeccakSection extends TraceSection { + final ImcFragment miscFragment; + final boolean triggerMmu; + MmuCall mmuCall; - public static void appendToTrace(Hub hub) { + public KeccakSection(Hub hub) { + super(hub, (short) 3); + hub.addTraceSection(this); - final KeccakSection currentSection = new KeccakSection(hub); - hub.addTraceSection(currentSection); + hub.addTraceSection(this); - ImcFragment imcFragment = ImcFragment.empty(hub); - currentSection.addFragmentsAndStack(hub, imcFragment); + miscFragment = ImcFragment.empty(hub); + this.addFragmentsAndStack(hub, miscFragment); - MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); + final MxpCall mxpCall = new MxpCall(hub); + miscFragment.callMxp(mxpCall); final boolean mayTriggerNonTrivialOperation = mxpCall.isMayTriggerNonTrivialMmuOperation(); - final boolean triggerMmu = - mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); + triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); if (triggerMmu) { - imcFragment.callMmu(MmuCall.sha3(hub)); - - // TODO: computing the hash shouldn't be done here - final long offset = clampedToLong(hub.messageFrame().getStackItem(0)); - final long size = clampedToLong(hub.messageFrame().getStackItem(1)); - Bytes dataToHash = hub.messageFrame().shadowReadMemory(offset, size); - KeccakDigest keccakDigest = new KeccakDigest(256); - keccakDigest.update(dataToHash.toArray(), 0, dataToHash.size()); - byte[] hashOutput = new byte[keccakDigest.getDigestSize()]; - keccakDigest.doFinal(hashOutput, 0); - - // retroactively set HASH_INFO_FLAG and HASH_INFO_KECCAK_HI, HASH_INFO_KECCAK_LO - currentSection.triggerHashInfo(Bytes.of(hashOutput)); + hub.defers().schedulePostExecution(this); + hub.defers().schedulePostTransaction(this); + mmuCall = MmuCall.sha3(hub); } } - private KeccakSection(Hub hub) { - super(hub); + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + miscFragment.callMmu(mmuCall); + } + + @Override + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + // retroactively set HASH_INFO_FLAG and HASH_INFO_KECCAK_HI, HASH_INFO_KECCAK_LO + this.triggerHashInfo(frame.getStackItem(0)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index a19c17d8cf..f7bac61629 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -82,6 +82,7 @@ public CallDataCopySection(Hub hub) { } mmuCall = MmuCall.callDataCopy(hub); + hub.defers().schedulePostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 21626c1744..0585bb46a9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -107,8 +107,8 @@ public CodeCopySection(Hub hub) { triggerMmu = mxpCall.isMayTriggerNonTrivialMmuOperation(); if (triggerMmu) { mmuCall = MmuCall.codeCopy(hub); + hub.defers().schedulePostTransaction(this); } - hub.defers().schedulePostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 225815ba3f..683c3ea36c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -22,6 +22,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; @@ -33,10 +34,13 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class ExtCodeCopySection extends TraceSection implements PostRollbackDefer { +public class ExtCodeCopySection extends TraceSection + implements PostRollbackDefer, PostTransactionDefer { final Bytes rawAddress; final Address address; @@ -116,6 +120,7 @@ public ExtCodeCopySection(Hub hub) { triggerMmu = none(this.exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { mmuCall = MmuCall.extCodeCopy(hub); + hub.defers().schedulePostTransaction(this); } // TODO: make sure that hasCode returns false during deployments @@ -141,10 +146,6 @@ public ExtCodeCopySection(Hub hub) { @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - if (triggerMmu) { - miscFragment.callMmu(mmuCall); - } - final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(this.address); final boolean deploymentStatusAtRollback = @@ -179,4 +180,12 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca this.addFragment(undoingAccountFragment); } + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (triggerMmu) { + miscFragment.callMmu(mmuCall); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index ae9b7de796..5e985a9cf2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -76,6 +76,7 @@ public ReturnDataCopySection(Hub hub) { triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { mmuCall = MmuCall.returnDataCopy(hub); + hub.defers().schedulePostTransaction(this); } } From aca2eb323a8eb03d53474e8059d63175bb5577f2 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 15 Jul 2024 19:59:53 +0200 Subject: [PATCH 213/461] feat(test): added test to highlight issue related to deploy transaction --- .../ContractModifyingStorageTest.java | 110 ++++++++++++++++-- 1 file changed, 102 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index 6b9bbce4dc..b350d76ad2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -14,16 +14,23 @@ */ package net.consensys.linea.zktracer.instructionprocessing; +import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randData; + +import java.util.ArrayList; import java.util.List; +import java.util.Random; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyAccount; import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import net.consensys.linea.zktracer.testing.ToyTransaction; import net.consensys.linea.zktracer.testing.ToyWorld; +import net.consensys.linea.zktracer.types.AddressUtils; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.crypto.SECPPublicKey; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.TransactionType; @@ -62,22 +69,28 @@ void contractModifyingStorageInConstructorTest() { KeyPair keyPair = new SECP256K1().generateKeyPair(); Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount userAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1000)).nonce(1).address(userAddress).build(); + + System.out.println("User address: " + userAddress); // Deployment transaction + // NOTE: 3050 in the beginning has been added manually Transaction tx = ToyTransaction.builder() .sender(userAccount) - // .to() + .keyPair(keyPair) + .transactionType(TransactionType.FRONTIER) + .gasLimit(0xffffffL) // 0xffffffffL .payload( Bytes.fromHexString( - "0x608060405234801561000f575f80fd5b505f8081905550600180819055506002808190555060038081905550600a5f546100399190610109565b5f81905550600b60015461004d9190610109565b600181905550600c6002546100629190610109565b600281905550600d6003546100779190610109565b6003819055505f805461008a919061013c565b5f81905550601460015461009e919061013c565b60018190555060156002546100b3919061013c565b60028190555060156003546100c8919061013c565b60038190555061017d565b5f819050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610113826100d3565b915061011e836100d3565b9250828201905080821115610136576101356100dc565b5b92915050565b5f610146826100d3565b9150610151836100d3565b925082820261015f816100d3565b91508282048414831517610176576101756100dc565b5b5092915050565b61012a8061018a5f395ff3fe6080604052348015600e575f80fd5b50600436106044575f3560e01c8063501e82121460485780636cc014de146062578063a314150f14607c578063a5d666a9146096575b5f80fd5b604e60b0565b6040516059919060dd565b60405180910390f35b606860b5565b6040516073919060dd565b60405180910390f35b608260bb565b604051608d919060dd565b60405180910390f35b609c60c1565b60405160a7919060dd565b60405180910390f35b5f5481565b60015481565b60025481565b60035481565b5f819050919050565b60d78160c7565b82525050565b5f60208201905060ee5f83018460d0565b9291505056fea26469706673582212203b939ad06f3d7d92a207fb36abc74231e00c81272ebf0645d4d40e917fc5e43b64736f6c634300081a0033")) - .transactionType(TransactionType.FRONTIER) - .gasLimit(0xffffffffL) - .value(Wei.ZERO) - .keyPair(keyPair) + "0x3050608060405234801561000f575f80fd5b505f8081905550600180819055506002808190555060038081905550600a5f546100399190610109565b5f81905550600b60015461004d9190610109565b600181905550600c6002546100629190610109565b600281905550600d6003546100779190610109565b6003819055505f805461008a919061013c565b5f81905550601460015461009e919061013c565b60018190555060156002546100b3919061013c565b60028190555060156003546100c8919061013c565b60038190555061017d565b5f819050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610113826100d3565b915061011e836100d3565b9250828201905080821115610136576101356100dc565b5b92915050565b5f610146826100d3565b9150610151836100d3565b925082820261015f816100d3565b91508282048414831517610176576101756100dc565b5b5092915050565b61012a8061018a5f395ff3fe6080604052348015600e575f80fd5b50600436106044575f3560e01c8063501e82121460485780636cc014de146062578063a314150f14607c578063a5d666a9146096575b5f80fd5b604e60b0565b6040516059919060dd565b60405180910390f35b606860b5565b6040516073919060dd565b60405180910390f35b608260bb565b604051608d919060dd565b60405180910390f35b609c60c1565b60405160a7919060dd565b60405180910390f35b5f5481565b60015481565b60025481565b60035481565b5f819050919050565b60d78160c7565b82525050565b5f60208201905060ee5f83018460d0565b9291505056fea26469706673582212203b939ad06f3d7d92a207fb36abc74231e00c81272ebf0645d4d40e917fc5e43b64736f6c634300081a0033")) .build(); + Address deployedAddress = AddressUtils.effectiveToAddress(tx); + System.out.println("Deployed address: " + deployedAddress); + + Preconditions.checkArgument(tx.isContractCreation()); + ToyWorld toyWorld = ToyWorld.builder().accounts(List.of(userAccount)).build(); ToyExecutionEnvironment toyExecutionEnvironment = @@ -105,7 +118,6 @@ void contractModifyingStorageInFunctionTest() { Transaction tx = ToyTransaction.builder() .sender(userAccount) - // .to() .payload( Bytes.fromHexString( "0x6080604052348015600e575f80fd5b506102ba8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610055575f3560e01c8063501e8212146100595780636cc014de14610077578063a314150f14610095578063a5d666a9146100b3578063e8af2fa5146100d1575b5f80fd5b6100616100db565b60405161006e91906101ca565b60405180910390f35b61007f6100e0565b60405161008c91906101ca565b60405180910390f35b61009d6100e6565b6040516100aa91906101ca565b60405180910390f35b6100bb6100ec565b6040516100c891906101ca565b60405180910390f35b6100d96100f2565b005b5f5481565b60015481565b60025481565b60035481565b5f8081905550600180819055506002808190555060038081905550600a5f5461011b9190610210565b5f81905550600b60015461012f9190610210565b600181905550600c6002546101449190610210565b600281905550600d6003546101599190610210565b6003819055505f805461016c9190610243565b5f8190555060146001546101809190610243565b60018190555060156002546101959190610243565b60028190555060156003546101aa9190610243565b600381905550565b5f819050919050565b6101c4816101b2565b82525050565b5f6020820190506101dd5f8301846101bb565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61021a826101b2565b9150610225836101b2565b925082820190508082111561023d5761023c6101e3565b5b92915050565b5f61024d826101b2565b9150610258836101b2565b9250828202610266816101b2565b9150828204841483151761027d5761027c6101e3565b5b509291505056fea2646970667358221220b40040e95e9f0674ff5c258759b2ac4564a8cf968f9d59477114688f3eff824364736f6c634300081a0033")) @@ -128,4 +140,86 @@ void contractModifyingStorageInFunctionTest() { toyExecutionEnvironment.run(); } + + private final Random rnd = new Random(666); + + @Test + void temporaryTest() { + ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); + List txList = new ArrayList<>(); + + KeyPair keyPair1 = new SECP256K1().generateKeyPair(); + SECPPublicKey pk1 = keyPair1.getPublicKey(); + Address address1 = Address.extract(Hash.hash(pk1.getEncodedBytes())); + ToyAccount account1 = buildAnAccount(address1, 7); + + KeyPair keyPair2 = new SECP256K1().generateKeyPair(); + SECPPublicKey pk2 = keyPair2.getPublicKey(); + ToyAccount account2 = buildAnAccount(Address.extract(Hash.hash(pk2.getEncodedBytes())), 7); + + KeyPair keyPair3 = new SECP256K1().generateKeyPair(); + SECPPublicKey pk3 = keyPair3.getPublicKey(); + ToyAccount account3 = buildAnAccount(Address.extract(Hash.hash(pk3.getEncodedBytes())), 7); + + KeyPair keyPair4 = new SECP256K1().generateKeyPair(); + SECPPublicKey pk4 = keyPair4.getPublicKey(); + ToyAccount account4 = + ToyAccount.builder() + .balance(Wei.fromEth(10)) + .nonce(7) + .address(Address.extract(Hash.hash(pk4.getEncodedBytes()))) + .code(Bytes.fromHexString("0x3050")) + .build(); + + KeyPair keyPair5 = new SECP256K1().generateKeyPair(); + SECPPublicKey pk5 = keyPair5.getPublicKey(); + ToyAccount account5 = buildAnAccount(Address.extract(Hash.hash(pk5.getEncodedBytes())), 7); + + Bytes initCode = randData(true); + world.accounts(List.of(account1, account2, account3, account4, account5)); + + /* + txList.add( + ToyTransaction.builder() + .sender(account1) + .keyPair(keyPair1) + .transactionType(TransactionType.FRONTIER) + .gasLimit(rnd.nextLong(21000, 0xffffL)) + .payload(initCode) + .value(Wei.fromEth(1)) + .build()); + */ + + txList.add( + ToyTransaction.builder() + .sender(account2) + .to(account4) + .keyPair(keyPair2) + .transactionType(TransactionType.FRONTIER) + .gasLimit(rnd.nextLong(21000, 0xffffL)) + .value(Wei.fromEth(2)) + .build()); + + txList.add( + ToyTransaction.builder() + .sender(account3) + .to(account4) + .keyPair(keyPair3) + .transactionType(TransactionType.FRONTIER) + .gasLimit(rnd.nextLong(21000, 0xffffL)) + .value(Wei.fromEth(3)) + .build()); + + ToyExecutionEnvironment.builder() + .toyWorld(world.build()) + .transactions(txList) + .testValidator(x -> {}) + .build() + .run(); + } + + // Temporary support function + final ToyAccount buildAnAccount(Address address, long nonce) { + return ToyAccount.builder().balance(Wei.fromEth(10)).nonce(nonce).address(address).build(); + } } From 45f8b0fa7d0506439ac97396796691bc57249f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 15 Jul 2024 14:26:30 +0200 Subject: [PATCH 214/461] ras --- .../linea/zktracer/module/hub/Hub.java | 1 + .../hub/section/copy/ExtCodeCopySection.java | 3 + .../hub/section/halt/RevertSection.java | 63 +++++++++++++++++++ .../hub/section/{ => halt}/StopSection.java | 3 +- zkevm-constraints | 2 +- 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{ => halt}/StopSection.java (96%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 7623688ca7..c2591c80bb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -57,6 +57,7 @@ import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; import net.consensys.linea.zktracer.module.hub.section.copy.*; +import net.consensys.linea.zktracer.module.hub.section.halt.StopSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.Transients; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 683c3ea36c..1a1a13f6e6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -75,7 +75,10 @@ public ExtCodeCopySection(Hub hub) { miscFragment = ImcFragment.empty(hub); this.addFragmentsAndStack(hub, miscFragment); + // triggerExp = false // triggerOob = false + // triggerStp = false + // triggerMxp = true final MxpCall mxpCall = new MxpCall(hub); miscFragment.callMxp(mxpCall); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java new file mode 100644 index 0000000000..ed56237eba --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -0,0 +1,63 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section.halt; + +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; + +public class RevertSection extends TraceSection { + + final short exceptions; + + RevertSection(Hub hub) { + // up to 4 = 1 + 3 rows + super(hub, (short) 4); + this.exceptions = hub.pch().exceptions(); + + this.populate(hub); + hub.addTraceSection(this); + } + + public void populate(Hub hub) { + + ImcFragment imcFragment = ImcFragment.empty(hub); + this.addFragmentsAndStack(hub, imcFragment); + + // triggerExp = false + // triggerOob = false + // triggerStp = false + + // triggerMxp = true + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + + Preconditions.checkArgument( + mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + + // The XAHOY case + ///////////////// + if (Exceptions.any(this.exceptions)) { + return; + } + + ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + this.addFragment(currentContext); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index a5277f509b..733a8f9b8c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section; +package net.consensys.linea.zktracer.module.hub.section.halt; import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.executionProvidesEmptyReturnData; import static net.consensys.linea.zktracer.module.hub.fragment.ContextFragment.readCurrentContextData; @@ -23,6 +23,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.Bytecode; import org.hyperledger.besu.datatypes.Address; diff --git a/zkevm-constraints b/zkevm-constraints index 29b10da4cd..e175b4e319 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 29b10da4cd96cfbe8bf12d84020fb4df177021db +Subproject commit e175b4e3193dcc11113855b449f511a72e54d9a1 From 9451566f22209ceed79e54cd4896067da4544eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 15 Jul 2024 14:26:47 +0200 Subject: [PATCH 215/461] ras --- .../linea/zktracer/module/hub/section/halt/RevertSection.java | 1 - 1 file changed, 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index ed56237eba..f97f375bba 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -43,7 +43,6 @@ public void populate(Hub hub) { // triggerExp = false // triggerOob = false // triggerStp = false - // triggerMxp = true MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); From 7722e368aef9018e907c9e23ba3c07eadf43bc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 15 Jul 2024 22:27:39 +0200 Subject: [PATCH 216/461] fix(stop): StopSection now implements PostRollbackDefer and PostTransactionDefer --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/fragment/ContextFragment.java | 7 + .../hub/fragment/account/AccountFragment.java | 5 +- .../module/hub/section/halt/StopSection.java | 141 +++++++++++------- 4 files changed, 98 insertions(+), 57 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c2591c80bb..a2059922c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1101,8 +1101,8 @@ void traceOperation(MessageFrame frame) { final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); // TODO finish it } case STOP -> { + new StopSection(this); parentFrame.latestReturnData(Bytes.EMPTY); - StopSection.appendTo(this); } case SELFDESTRUCT -> { parentFrame.latestReturnData(Bytes.EMPTY); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 9c1a41dfe4..3f25342b26 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -86,6 +86,13 @@ public static ContextFragment executionProvidesEmptyReturnData(final Hub hub) { true); } + public static ContextFragment executionProvidesEmptyReturnData(final Hub hub, int contextNumber) { + CallStack callStack = hub.callStack(); + int parentId = callStack.getByContextNumber(contextNumber).parentFrame(); + return new ContextFragment( + hub, callStack, Either.left(parentId), contextNumber, MemorySpan.empty(), true); + } + public static ContextFragment nonExecutionEmptyReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 1d2a8fed9d..0847c0513a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -22,6 +22,7 @@ import java.util.Optional; import com.google.common.base.Preconditions; +import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; @@ -44,8 +45,8 @@ public final class AccountFragment implements TraceFragment, PostTransactionDefer, PostConflationDefer { - private final AccountSnapshot oldState; - private final AccountSnapshot newState; + @Getter private final AccountSnapshot oldState; + @Getter private final AccountSnapshot newState; @Setter private int deploymentNumberInfinity = 0; // retconned on conflation end private final int deploymentNumber; private final boolean isDeployment; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index 733a8f9b8c..39f3afeb1e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -20,78 +20,111 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.Bytecode; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class StopSection extends TraceSection { +public class StopSection extends TraceSection implements PostRollbackDefer, PostTransactionDefer { - public static void appendTo(Hub hub) { - CallFrame.provideParentContextWithEmptyReturnData(hub); + final Address address; + final int deploymentNumber; + final boolean deploymentStatus; + final int contextNumber; - if (hub.currentFrame().isMessageCall()) { - StopSection messageCallStopSection = messageCallStopSection(hub); - hub.addTraceSection(messageCallStopSection); + public StopSection(Hub hub) { + // 3 = 1 + 2 (max NON_STACK_ROWS in message call case) + // 5 = 1 + 4 (max NON_STACK_ROWS in deployment case) + super(hub, hub.callStack().current().isMessageCall() ? (short) 3 : (short) 5); + hub.addTraceSection(this); + + this.address = hub.currentFrame().accountAddress(); + this.contextNumber = hub.currentFrame().contextNumber(); + { + DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); + this.deploymentNumber = deploymentInfo.number(address); + this.deploymentStatus = deploymentInfo.isDeploying(address); + } + + Preconditions.checkArgument( + hub.currentFrame().isDeployment() == this.deploymentStatus); // sanity check + + // Message call case + //////////////////// + if (!this.deploymentStatus) { + this.addFragmentsAndStack(hub, readCurrentContextData(hub)); return; } - StopSection deploymentStopSection = deploymentStopSection(hub); - hub.addTraceSection(deploymentStopSection); + // Deployment case + ////////////////// + this.deploymentStopSection(hub); + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); } - private StopSection(Hub hub, TraceFragment... fragments) { - super(hub); - this.addFragmentsAndStack(hub, fragments); - } + public void deploymentStopSection(Hub hub) { + + AccountSnapshot priorEmptyDeployment = AccountSnapshot.canonical(hub, address); + AccountSnapshot afterEmptyDeployment = priorEmptyDeployment.deployByteCode(Bytecode.EMPTY); + AccountFragment doingAccountFragment = + hub.factories() + .accountFragment() + .make( + priorEmptyDeployment, + afterEmptyDeployment, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); - public static StopSection messageCallStopSection(Hub hub) { - StopSection messageCallStopSection = - new StopSection(hub, readCurrentContextData(hub), executionProvidesEmptyReturnData(hub)); - return messageCallStopSection; + this.addFragmentsAndStack(hub, readCurrentContextData(hub), doingAccountFragment); } - public static StopSection deploymentStopSection(Hub hub) { - AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - final Address address = hub.currentFrame().accountAddress(); - final int deploymentNumber = hub.transients().conflation().deploymentInfo().number(address); - final boolean deploymentStatus = - hub.transients().conflation().deploymentInfo().isDeploying(address); - - // we should be deploying - Preconditions.checkArgument(deploymentStatus); - - AccountSnapshot beforeEmptyDeployment = - AccountSnapshot.fromAddress(address, true, deploymentNumber, deploymentStatus); - AccountSnapshot afterEmptyDeployment = beforeEmptyDeployment.deployByteCode(Bytecode.EMPTY); - StopSection stopWhileDeploying = - new StopSection( - hub, - readCurrentContextData(hub), - // current (under deployment => deployed with empty byte code) - accountFragmentFactory.make( - beforeEmptyDeployment, - afterEmptyDeployment, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0))); - - if (hub.currentFrame().willRevert()) { - // undoing of the above - stopWhileDeploying.addFragmentsWithoutStack( - accountFragmentFactory.make( - afterEmptyDeployment, - beforeEmptyDeployment, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1)), - executionProvidesEmptyReturnData(hub)); - - } else { - stopWhileDeploying.addFragmentsWithoutStack(executionProvidesEmptyReturnData(hub)); + /** + * Adds the missing account "undoing operation" to the StopSection provided the relevant context + * reverted and the STOP instruction happened in a deployment context. + * + * @param hub + * @param messageFrame access point to world state & accrued state + * @param callFrame reference to call frame whose actions are to be undone + */ + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + + if (!this.deploymentStatus) { + return; } - return stopWhileDeploying; + Preconditions.checkArgument(this.fragments().getLast() instanceof AccountFragment); + AccountFragment lastAccountFragment = (AccountFragment) this.fragments().getLast(); + + this.addFragmentsWithoutStack( + hub.factories() + .accountFragment() + .make( + lastAccountFragment.newState(), + lastAccountFragment.oldState(), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1))); + } + + /** + * Adds the missing context fragment in all cases. This context fragment squashes the caller + * (parent) context return data. + * + * @param hub the {@link Hub} in which the {@link Transaction} took place + * @param state a view onto the current blockchain state + * @param tx the {@link Transaction} that just executed + * @param isSuccessful + */ + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + + this.addFragmentsWithoutStack(executionProvidesEmptyReturnData(hub, this.contextNumber)); } } From a26272eacf3db81ea701ae0de7526008d172d7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 15 Jul 2024 23:22:26 +0200 Subject: [PATCH 217/461] ras --- .../module/hub/section/halt/StopSection.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index 39f3afeb1e..24527bdfb1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -22,6 +22,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; @@ -39,27 +40,30 @@ public class StopSection extends TraceSection implements PostRollbackDefer, Post final int deploymentNumber; final boolean deploymentStatus; final int contextNumber; + final ContextFragment parentContextReturnDataRest; public StopSection(Hub hub) { - // 3 = 1 + 2 (max NON_STACK_ROWS in message call case) - // 5 = 1 + 4 (max NON_STACK_ROWS in deployment case) + // 3 = 1 + max_NON_STACK_ROWS in message call case + // 5 = 1 + max_NON_STACK_ROWS in deployment case super(hub, hub.callStack().current().isMessageCall() ? (short) 3 : (short) 5); hub.addTraceSection(this); + hub.defers().schedulePostTransaction(this); // always - this.address = hub.currentFrame().accountAddress(); - this.contextNumber = hub.currentFrame().contextNumber(); + address = hub.currentFrame().accountAddress(); + contextNumber = hub.currentFrame().contextNumber(); { DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); - this.deploymentNumber = deploymentInfo.number(address); - this.deploymentStatus = deploymentInfo.isDeploying(address); + deploymentNumber = deploymentInfo.number(address); + deploymentStatus = deploymentInfo.isDeploying(address); } + parentContextReturnDataRest = executionProvidesEmptyReturnData(hub); Preconditions.checkArgument( - hub.currentFrame().isDeployment() == this.deploymentStatus); // sanity check + hub.currentFrame().isDeployment() == deploymentStatus); // sanity check // Message call case //////////////////// - if (!this.deploymentStatus) { + if (!deploymentStatus) { this.addFragmentsAndStack(hub, readCurrentContextData(hub)); return; } @@ -67,7 +71,7 @@ public StopSection(Hub hub) { // Deployment case ////////////////// this.deploymentStopSection(hub); - hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); // for deployments only } public void deploymentStopSection(Hub hub) { @@ -113,8 +117,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca } /** - * Adds the missing context fragment in all cases. This context fragment squashes the caller - * (parent) context return data. + * Adds the missing context fragment. This context fragment squashes the caller + * (parent) context return data. Applies in all cases. * * @param hub the {@link Hub} in which the {@link Transaction} took place * @param state a view onto the current blockchain state @@ -124,7 +128,6 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - - this.addFragmentsWithoutStack(executionProvidesEmptyReturnData(hub, this.contextNumber)); + this.addFragmentsWithoutStack(this.parentContextReturnDataRest); } } From 5415ec33a478074787eb423d5ce7ec76e75c7940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 15 Jul 2024 23:57:45 +0200 Subject: [PATCH 218/461] fix(hub): uniformization of tarceOperation section creation/insertion --- .../linea/zktracer/module/hub/Hub.java | 26 +++++-------------- .../module/hub/section/ContextSection.java | 7 +++-- .../module/hub/section/ExpSection.java | 7 ++++- .../module/hub/section/StackOnlySection.java | 2 ++ .../hub/section/TransactionSection.java | 13 +++++++--- .../hub/section/copy/ExtCodeCopySection.java | 1 - 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a2059922c7..0358a6c45a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1057,12 +1057,8 @@ void traceOperation(MessageFrame frame) { .addTraceSection(new StackOnlySection(this)); case MUL -> { switch (this.opCode()) { - case OpCode.EXP -> { - this.addTraceSection(new ExpSection(this)); - } - case OpCode.MUL -> { - this.addTraceSection(new StackOnlySection(this)); - } + case OpCode.EXP -> new ExpSection(this); + case OpCode.MUL -> new StackOnlySection(this); default -> { throw new IllegalStateException( String.format("opcode %s not part of the MUL instruction family", this.opCode())); @@ -1105,22 +1101,15 @@ void traceOperation(MessageFrame frame) { parentFrame.latestReturnData(Bytes.EMPTY); } case SELFDESTRUCT -> { + // TODO parentFrame.latestReturnData(Bytes.EMPTY); } } } - case KEC -> { - new KeccakSection(this); - } - - case CONTEXT -> this.addTraceSection( - new ContextSection(this, ContextFragment.readCurrentContextData(this))); - - case LOG -> { - new LogSection(this); - } - + case KEC -> new KeccakSection(this); + case CONTEXT -> new ContextSection(this); + case LOG -> new LogSection(this); case ACCOUNT -> { final AccountSection accountSection = new AccountSection(this); accountSection.appendToTrace(this); @@ -1137,8 +1126,7 @@ void traceOperation(MessageFrame frame) { } } - case TRANSACTION -> this.addTraceSection( - new TransactionSection(this, TransactionFragment.prepare(this.txStack.current()))); + case TRANSACTION -> new TransactionSection(this); case STACK_RAM -> { switch (this.currentFrame().opCode()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java index 8ed79ff9cf..cc346bddc2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java @@ -19,8 +19,11 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; public class ContextSection extends TraceSection { - public ContextSection(Hub hub, ContextFragment fragment) { + public ContextSection(Hub hub) { super(hub, (short) 3); - this.addFragmentsAndStack(hub, fragment); + hub.addTraceSection(this); + + ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + this.addFragmentsAndStack(hub, currentContext); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java index c429ee9951..5179042fa2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java @@ -19,10 +19,15 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; public class ExpSection extends TraceSection { public ExpSection(Hub hub) { - super(hub, (short) 3); + // 1 + 1 (stack, misc) + // 1 + 1 + 1 (stack, misc, context) + super(hub, Exceptions.none(hub.pch().exceptions()) ? (short) 3 : (short) 2); + hub.addTraceSection(this); + final ExpCall expCall = new ExplogExpCall(); final ImcFragment miscFragment = ImcFragment.empty(hub).callExp(expCall); this.addFragmentsAndStack(hub, miscFragment); 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 9e80969285..70d1c61b58 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 @@ -20,6 +20,8 @@ public class StackOnlySection extends TraceSection { public StackOnlySection(Hub hub) { super(hub, (short) (hub.opCode().getData().stackSettings().twoLineInstruction() ? 2 : 1)); + hub.addTraceSection(this); + this.addStack(hub); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java index 0c45602610..fad86bb094 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java @@ -17,10 +17,17 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; public class TransactionSection extends TraceSection { - public TransactionSection(Hub hub, TraceFragment... chunks) { - super(hub); - this.addFragmentsAndStack(hub, chunks); + + public TransactionSection(Hub hub) { + // 2 = 1 + 1 (stack, transaction) + // 3 = 1 + 1 + 1 (stack, transaction, context) + super(hub, Exceptions.none(hub.pch().exceptions()) ? (short) 2 : (short) 3); + hub.addTraceSection(this); + + this.addFragmentsAndStack(hub, TransactionFragment.prepare(hub.txStack().current())); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 1a1a13f6e6..5c9f3fbede 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -59,7 +59,6 @@ public class ExtCodeCopySection extends TraceSection public ExtCodeCopySection(Hub hub) { // 4 = 1 + 3 super(hub, (short) 4); - hub.addTraceSection(this); final MessageFrame frame = hub.messageFrame(); From ec11cbff18b036750935e60194fd24d8eb302792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 16 Jul 2024 01:00:39 +0200 Subject: [PATCH 219/461] fix(revert): RevertSection now implements PostTransactionDefers for MMU instruction --- .../linea/zktracer/module/hub/Hub.java | 5 +- .../hub/section/halt/RevertSection.java | 72 ++++++++++++------- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 0358a6c45a..17b21cc411 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -57,6 +57,7 @@ import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; import net.consensys.linea.zktracer.module.hub.section.copy.*; +import net.consensys.linea.zktracer.module.hub.section.halt.RevertSection; import net.consensys.linea.zktracer.module.hub.section.halt.StopSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; @@ -1086,15 +1087,15 @@ void traceOperation(MessageFrame frame) { final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); // TODO finish it } case REVERT -> { + new RevertSection(this); final Bytes returnData = this.transients.op().returnData(); this.currentFrame().returnDataSource(transients.op().returnDataSegment()); this.currentFrame().returnData(returnData); - if (!Exceptions.any(this.pch.exceptions())) { + if (Exceptions.none(this.pch.exceptions())) { parentFrame.latestReturnData(returnData); } else { parentFrame.latestReturnData(Bytes.EMPTY); } - final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); // TODO finish it } case STOP -> { new StopSection(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index f97f375bba..c1ffe956bb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -16,47 +16,65 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class RevertSection extends TraceSection { +public class RevertSection extends TraceSection implements PostTransactionDefer { - final short exceptions; + final ImcFragment imcFragment; + final MmuCall mmuCall; + final boolean triggerMmu; - RevertSection(Hub hub) { - // up to 4 = 1 + 3 rows - super(hub, (short) 4); - this.exceptions = hub.pch().exceptions(); + public RevertSection(Hub hub) { + // up to 4 = 1 + 3 rows + super(hub, (short) 4); + hub.addTraceSection(this); - this.populate(hub); - hub.addTraceSection(this); - } + short exceptions = hub.pch().exceptions(); + + imcFragment = ImcFragment.empty(hub); + this.addFragmentsAndStack(hub, imcFragment); - public void populate(Hub hub) { + // triggerExp = false + // triggerOob = false + // triggerStp = false + // triggerMxp = true + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + Preconditions.checkArgument( + mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); - ImcFragment imcFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, imcFragment); + triggerMmu = + (Exceptions.none(exceptions)) + && !hub.currentFrame().isRoot() + && mxpCall.isMayTriggerNonTrivialMmuOperation() // i.e. size ≠ 0 ∧ ¬MXPX + && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); + mmuCall = (Exceptions.none(exceptions)) ? MmuCall.revert(hub) : new MmuCall(); - // triggerExp = false - // triggerOob = false - // triggerStp = false - // triggerMxp = true - MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); - Preconditions.checkArgument( - mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + // The XAHOY case + ///////////////// + if (Exceptions.any(exceptions)) { + return; + } - // The XAHOY case - ///////////////// - if (Exceptions.any(this.exceptions)) { - return; - } + ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + ContextFragment parentContext = ContextFragment.executionProvidesEmptyReturnData(hub); + this.addFragmentsWithoutStack(currentContext, parentContext); + } - ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); - this.addFragment(currentContext); + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (triggerMmu) { + imcFragment.callMmu(mmuCall); } + } } From c8dc8e7a0eedce0f8d0344d4119cd0265fa5218d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 16 Jul 2024 01:01:47 +0200 Subject: [PATCH 220/461] spotless --- .../module/hub/section/TransactionSection.java | 1 - .../module/hub/section/halt/RevertSection.java | 14 ++++++-------- .../module/hub/section/halt/StopSection.java | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java index fad86bb094..34add9e21b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java @@ -16,7 +16,6 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index c1ffe956bb..b342c7bcc8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -48,17 +48,15 @@ public RevertSection(Hub hub) { // triggerMxp = true MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - Preconditions.checkArgument( - mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); triggerMmu = - (Exceptions.none(exceptions)) - && !hub.currentFrame().isRoot() - && mxpCall.isMayTriggerNonTrivialMmuOperation() // i.e. size ≠ 0 ∧ ¬MXPX - && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); + (Exceptions.none(exceptions)) + && !hub.currentFrame().isRoot() + && mxpCall.isMayTriggerNonTrivialMmuOperation() // i.e. size ≠ 0 ∧ ¬MXPX + && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); mmuCall = (Exceptions.none(exceptions)) ? MmuCall.revert(hub) : new MmuCall(); - // The XAHOY case ///////////////// if (Exceptions.any(exceptions)) { @@ -72,7 +70,7 @@ public RevertSection(Hub hub) { @Override public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (triggerMmu) { imcFragment.callMmu(mmuCall); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index 24527bdfb1..fe36c91abd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -117,8 +117,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca } /** - * Adds the missing context fragment. This context fragment squashes the caller - * (parent) context return data. Applies in all cases. + * Adds the missing context fragment. This context fragment squashes the caller (parent) context + * return data. Applies in all cases. * * @param hub the {@link Hub} in which the {@link Transaction} took place * @param state a view onto the current blockchain state From 26657df9bb265c8fe7dd54a6fa6c81dfbce7cc47 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 16 Jul 2024 11:04:57 +0530 Subject: [PATCH 221/461] fix: forget to add section to defers mechanism --- .../module/hub/section/halt/RevertSection.java | 16 +++++++++------- zkevm-constraints | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index b342c7bcc8..aa552a2d31 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -29,7 +29,7 @@ public class RevertSection extends TraceSection implements PostTransactionDefer { final ImcFragment imcFragment; - final MmuCall mmuCall; + MmuCall mmuCall; final boolean triggerMmu; public RevertSection(Hub hub) { @@ -55,7 +55,11 @@ public RevertSection(Hub hub) { && !hub.currentFrame().isRoot() && mxpCall.isMayTriggerNonTrivialMmuOperation() // i.e. size ≠ 0 ∧ ¬MXPX && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); - mmuCall = (Exceptions.none(exceptions)) ? MmuCall.revert(hub) : new MmuCall(); + + if (triggerMmu) { + mmuCall = MmuCall.revert(hub); + hub.defers().schedulePostTransaction(this); + } // The XAHOY case ///////////////// @@ -63,16 +67,14 @@ public RevertSection(Hub hub) { return; } - ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); - ContextFragment parentContext = ContextFragment.executionProvidesEmptyReturnData(hub); + final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + final ContextFragment parentContext = ContextFragment.executionProvidesEmptyReturnData(hub); this.addFragmentsWithoutStack(currentContext, parentContext); } @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (triggerMmu) { - imcFragment.callMmu(mmuCall); - } + imcFragment.callMmu(mmuCall); } } diff --git a/zkevm-constraints b/zkevm-constraints index e175b4e319..29b10da4cd 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit e175b4e3193dcc11113855b449f511a72e54d9a1 +Subproject commit 29b10da4cd96cfbe8bf12d84020fb4df177021db From 9567a3c641798be95d8c4eea2506e37ce67ce84b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 16 Jul 2024 11:29:33 +0530 Subject: [PATCH 222/461] fix(hub): duplicate section created --- .../linea/zktracer/module/hub/Hub.java | 36 +++++++++---------- .../module/hub/section/AccountSection.java | 3 +- .../hub/section/CallDataLoadSection.java | 1 + .../module/hub/section/SloadSection.java | 3 -- .../module/hub/section/SstoreSection.java | 3 -- .../module/hub/section/StackRamSection.java | 1 + 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 17b21cc411..e82cb1d975 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1054,8 +1054,18 @@ public int cumulatedTxCount() { void traceOperation(MessageFrame frame) { switch (this.opCodeData().instructionFamily()) { - case ADD, MOD, SHF, BIN, WCP, EXT, BATCH, MACHINE_STATE, PUSH_POP, DUP, SWAP, INVALID -> this - .addTraceSection(new StackOnlySection(this)); + case ADD, + MOD, + SHF, + BIN, + WCP, + EXT, + BATCH, + MACHINE_STATE, + PUSH_POP, + DUP, + SWAP, + INVALID -> new StackOnlySection(this); case MUL -> { switch (this.opCode()) { case OpCode.EXP -> new ExpSection(this); @@ -1111,11 +1121,7 @@ void traceOperation(MessageFrame frame) { case KEC -> new KeccakSection(this); case CONTEXT -> new ContextSection(this); case LOG -> new LogSection(this); - case ACCOUNT -> { - final AccountSection accountSection = new AccountSection(this); - accountSection.appendToTrace(this); - } - + case ACCOUNT -> new AccountSection(this); case COPY -> { switch (this.opCode()) { case OpCode.CALLDATACOPY -> new CallDataCopySection(this); @@ -1131,24 +1137,16 @@ void traceOperation(MessageFrame frame) { case STACK_RAM -> { switch (this.currentFrame().opCode()) { - case CALLDATALOAD -> { - this.addTraceSection(new CallDataLoadSection(this)); - } - case MLOAD, MSTORE, MSTORE8 -> this.addTraceSection(new StackRamSection(this)); + case CALLDATALOAD -> new CallDataLoadSection(this); + case MLOAD, MSTORE, MSTORE8 -> new StackRamSection(this); default -> throw new IllegalStateException("unexpected STACK_RAM opcode"); } } case STORAGE -> { switch (this.currentFrame().opCode()) { - case SSTORE -> { - final SstoreSection sstoreSection = new SstoreSection(this, frame.getWorldUpdater()); - sstoreSection.populateSection(this); - } - case SLOAD -> { - final SloadSection sloadSection = new SloadSection(this, frame.getWorldUpdater()); - sloadSection.populateSection(this); - } + case SSTORE -> new SstoreSection(this, frame.getWorldUpdater()); + case SLOAD -> new SloadSection(this, frame.getWorldUpdater()); default -> throw new IllegalStateException("invalid operation in family STORAGE"); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 30abd9a22f..01357f82da 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -67,9 +67,10 @@ public void appendToTrace(Hub hub) { public AccountSection(Hub hub) { super(hub); + hub.addTraceSection(this); this.addFragmentsAndStack(hub); - MessageFrame frame = hub.messageFrame(); + final MessageFrame frame = hub.messageFrame(); this.rawTargetAddress = switch (hub.opCode()) { case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index 21945d552a..df9470bd29 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -50,6 +50,7 @@ public class CallDataLoadSection extends TraceSection implements PostTransaction public CallDataLoadSection(Hub hub) { super(hub, (short) (hub.opCode().equals(OpCode.CALLDATALOAD) ? 4 : 3)); + hub.addTraceSection(this); this.addStack(hub); this.exception = hub.pch().exceptions(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 60cc6ea022..23059fb8b3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -56,9 +56,6 @@ public SloadSection(Hub hub, WorldView world) { hub.addTraceSection(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - } - - public void populateSection(Hub hub) { // NOTE: SLOAD can only trigger // - stackUnderflowException diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 7dcd061804..adefd20872 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -59,9 +59,6 @@ public SstoreSection(Hub hub, WorldView world) { hub.addTraceSection(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - } - - public void populateSection(Hub hub) { final boolean staticContextException = Exceptions.staticFault(this.exceptions); final boolean sstoreException = Exceptions.outOfSStore(this.exceptions); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index f7b560c9be..d964a34c66 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -46,6 +46,7 @@ public class StackRamSection extends TraceSection implements PostTransactionDefe public StackRamSection(Hub hub) { super(hub, (short) 3); + hub.addTraceSection(this); this.addStack(hub); this.instruction = hub.opCode(); From 7ccd55e0eb933a8ef5783c65f8ca0827a46ec576 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 16 Jul 2024 12:30:25 +0530 Subject: [PATCH 223/461] fix(hub): java issues with callData in MMU Call --- .../zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index a9215b14e7..b41b070943 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -84,7 +84,6 @@ import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; /** @@ -185,11 +184,11 @@ public static MmuCall callDataCopy(final Hub hub) { final MemorySpan callDataSegment = hub.currentFrame().callDataInfo().memorySpan(); final int callDataContextNumber = callDataContextNumber(hub); - final MessageFrame callFrame = hub.callStack().getById(callDataContextNumber).frame(); + final CallFrame callFrame = hub.callStack().getByContextNumber(callDataContextNumber); return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) .sourceId(callDataContextNumber) - .sourceRamBytes(Optional.of(callFrame.shadowReadMemory(0, callFrame.memoryByteSize()))) + .sourceRamBytes(Optional.of(callFrame.callDataInfo().data())) .targetId(hub.currentFrame().contextNumber()) .targetRamBytes( Optional.of( From fb5a21b62dfc9cbdfdec4811e8a58bb88bd7479f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 17 Jul 2024 02:29:54 +0200 Subject: [PATCH 224/461] feat(return): wip --- .../scenario/ReturnScenarioFragment.java | 118 ++++++++++++++++++ .../hub/fragment/scenario/ScenarioEnum.java | 68 ++++++++++ .../fragment/scenario/ScenarioFragment.java | 49 +++----- .../hub/section/halt/ReturnSection.java | 86 +++++++++++++ .../module/hub/section/halt/StopSection.java | 6 +- 5 files changed, 292 insertions(+), 35 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java new file mode 100644 index 0000000000..43cbad3b21 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java @@ -0,0 +1,118 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment.scenario; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; + +import com.google.common.base.Preconditions; +import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; + +@Setter +public class ReturnScenarioFragment implements TraceFragment { + + ReturnScenario scenario; + + public ReturnScenarioFragment() { + this.scenario = UNDEFINED; + } + + public enum ReturnScenario { + UNDEFINED, + RETURN_EXCEPTION, + RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM, + RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM, + RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT, + RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT, + RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT, + RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT + } + + @Override + public Trace trace(Trace trace) { + Preconditions.checkArgument(!this.scenario.equals(UNDEFINED)); + return trace + .peekAtScenario(true) + // // CALL scenarios + //////////////////// + // .pScenarioCallException(false) + // .pScenarioCallAbort(false) + // .pScenarioCallPrcFailure(false) + // .pScenarioCallPrcSuccessCallerWillRevert(false) + // .pScenarioCallPrcSuccessCallerWontRevert(false) + // .pScenarioCallSmcFailureCallerWillRevert(false) + // .pScenarioCallSmcFailureCallerWontRevert(false) + // .pScenarioCallSmcSuccessCallerWontRevert(false) + // .pScenarioCallSmcSuccessCallerWillRevert(false) + // .pScenarioCallEoaSuccessCallerWontRevert(false) + // .pScenarioCallEoaSuccessCallerWillRevert(false) + // // CREATE scenarios + ////////////////////// + // .pScenarioCreateException(false) .pScenarioCreateAbort(false) + // .pScenarioCreateFailureConditionWillRevert(false) + // .pScenarioCreateFailureConditionWontRevert(false) + // .pScenarioCreateEmptyInitCodeWillRevert(false) + // .pScenarioCreateEmptyInitCodeWontRevert(false) + // .pScenarioCreateNonemptyInitCodeFailureWillRevert(false) + // .pScenarioCreateNonemptyInitCodeFailureWontRevert(false) + // .pScenarioCreateNonemptyInitCodeSuccessWillRevert(false) + // .pScenarioCreateNonemptyInitCodeSuccessWontRevert(false) + // // PRECOMPILE CALL scenarios + /////////////////////////////// + // .pScenarioPrcEcrecover(false) + // .pScenarioPrcSha2256(false) + // .pScenarioPrcRipemd160(false) + // .pScenarioPrcIdentity(false) + // .pScenarioPrcModexp(false) + // .pScenarioPrcEcadd(false) + // .pScenarioPrcEcmul(false) + // .pScenarioPrcEcpairing(false) + // .pScenarioPrcBlake2F(false) + // .pScenarioPrcSuccessCallerWillRevert(false) + // .pScenarioPrcSuccessCallerWontRevert(false) + // .pScenarioPrcFailureKnownToHub(false) + // .pScenarioPrcFailureKnownToRam(false) + // .pScenarioPrcCallerGas(0) + // .pScenarioPrcCalleeGas(0) + // .pScenarioPrcReturnGas(0) + // .pScenarioPrcCdo(0) + // .pScenarioPrcCds(0) + // .pScenarioPrcRao(0) + // .pScenarioPrcRac(0) + // RETURN scenarios + /////////////////// + .pScenarioReturnException(this.scenario.equals(RETURN_EXCEPTION)) + .pScenarioReturnFromMessageCallWillTouchRam( + this.scenario.equals(RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM)) + .pScenarioReturnFromMessageCallWontTouchRam( + this.scenario.equals(RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM)) + .pScenarioReturnFromDeploymentEmptyCodeWillRevert( + this.scenario.equals(RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT)) + .pScenarioReturnFromDeploymentEmptyCodeWontRevert( + this.scenario.equals(RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT)) + .pScenarioReturnFromDeploymentNonemptyCodeWillRevert( + this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT)) + .pScenarioReturnFromDeploymentNonemptyCodeWontRevert( + this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT)) + // // SELFDESTRUCT scenarios + //////////////////////////// + // .pScenarioSelfdestructException(false) + // .pScenarioSelfdestructWillRevert(false) + // .pScenarioSelfdestructWontRevertAlreadyMarked(false) + // .pScenarioSelfdestructWontRevertNotYetMarked(false) + ; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java new file mode 100644 index 0000000000..9042a5f51c --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java @@ -0,0 +1,68 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment.scenario; + +public enum ScenarioEnum { + /** scenarios related to CALL-type instructions */ + CALL, + /** scenarios related to CREATE(2) instructions */ + CREATE, + /** scenarios related to RETURN */ + RETURN, + RETURN_EXCEPTION, + RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM, + RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM, + RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT, + RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT, + RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT, + RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT, + /** scenarios related to SELFDESTRUCT */ + SELFDESTRUCT, + /** describes the second scenario line required by a call to a precompile */ + PRECOMPILE; + + boolean isCall() { + return this == CALL; + } + + boolean isPrecompile() { + return this == PRECOMPILE; + } + + boolean isCreate() { + return this == CREATE; + } + + boolean isReturn() { + return this.isAnyOf( + RETURN_EXCEPTION, + RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM, + RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM, + RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT, + RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT, + RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT, + RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); + } + + public boolean isAnyOf(ScenarioEnum... scenarios) { + for (ScenarioEnum scenario : scenarios) { + if (scenario.equals(this)) { + return true; + } + } + + return false; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 92f48956ff..90ccd96afb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -32,35 +32,12 @@ /** This machine generates lines */ @RequiredArgsConstructor public class ScenarioFragment implements TraceFragment, PostTransactionDefer { - private enum CallType { - /** describes a normal call */ - CALL, - /** describes the second scenario line required by a call to a precompile */ - PRECOMPILE, - /** describes a call into initcode */ - CREATE, - /** describes a RETURN from initcode */ - CODE_DEPOSIT; - boolean isCall() { - return this == CALL; - } - - boolean isPrecompile() { - return this == PRECOMPILE; - } - - boolean isCreate() { - return this == CREATE; - } - - boolean isDeposit() { - return this == CODE_DEPOSIT; - } - } + ScenarioEnum scenario; + // TODO: add the duplicate values required for PRC calls private final Optional precompileCall; - private final CallType type; + private final ScenarioEnum type; /** * Is set if: - this is a CALL to an EOA or a precompile - this is a CREATE with an empty initcode @@ -89,7 +66,7 @@ public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { ScenarioFragment r = new ScenarioFragment( Optional.empty(), - CallType.CALL, + ScenarioEnum.CALL, targetHasCode, hub.currentFrame().id(), hub.callStack().futureId(), @@ -104,7 +81,7 @@ public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { public static ScenarioFragment forCreate(final Hub hub, boolean targetHasCode) { return new ScenarioFragment( Optional.empty(), - CallType.CREATE, + ScenarioEnum.CREATE, targetHasCode, hub.currentFrame().id(), hub.callStack().futureId(), @@ -119,7 +96,7 @@ public static ScenarioFragment forSmartContractCallSection( final ScenarioFragment r = new ScenarioFragment( Optional.empty(), - CallType.CALL, + ScenarioEnum.CALL, true, callerFrameId, calledFrameId, @@ -138,12 +115,20 @@ public static ScenarioFragment forNoCodeCallSection( if (precompileCall.isPresent()) { r = new ScenarioFragment( - precompileCall, CallType.CALL, false, callerId, calleeId, false, false, false, false); + precompileCall, + ScenarioEnum.CALL, + false, + callerId, + calleeId, + false, + false, + false, + false); } else { r = new ScenarioFragment( Optional.empty(), - CallType.CALL, + ScenarioEnum.CALL, false, callerId, calleeId, @@ -164,7 +149,7 @@ public static ScenarioFragment forPrecompileEpilogue( final ScenarioFragment r = new ScenarioFragment( Optional.of(precompile), - CallType.PRECOMPILE, + ScenarioEnum.PRECOMPILE, false, callerId, calleeId, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java new file mode 100644 index 0000000000..1658b002b8 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -0,0 +1,86 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section.halt; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.RETURN_EXCEPTION; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; + +public class ReturnSection + extends TraceSection { // implements PostTransactionDefer, PostRollbackDefer { + + final short exceptions; + final ImcFragment imcFragment; + MmuCall mmuCall; + boolean triggerMmu = false; + boolean triggerOob = false; + boolean triggerHashInfo = false; + boolean messageCallTouchesRam = false; + + public ReturnSection(Hub hub) { + // 5 = 1 + 4 + // 8 = 1 + 7 + super(hub, Exceptions.any(hub.pch().exceptions()) ? (short) 5 : (short) 8); + hub.addTraceSection(this); + + exceptions = hub.pch().exceptions(); + + ReturnScenarioFragment returnScenarioFragment = new ReturnScenarioFragment(); + ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); + imcFragment = ImcFragment.empty(hub); + MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + + this.addStack(hub); + this.addFragment(returnScenarioFragment); + this.addFragment(currentContextFragment); + this.addFragment(imcFragment); + + if (Exceptions.any(exceptions)) { + returnScenarioFragment.setScenario(RETURN_EXCEPTION); + } + + if (Exceptions.memoryExpansionException(exceptions) + || Exceptions.outOfGasException(exceptions)) { + return; + } + + boolean triggerOobForMaxCodeSizeException = Exceptions.codeSizeOverflow(exceptions); + if (triggerOobForMaxCodeSizeException) { + OobCall oobCall = new XCallOobCall(); + imcFragment.callOob(oobCall); + return; + } + + boolean triggerMmuForInvalidCodePrefix = Exceptions.invalidCodePrefix(exceptions); + if (triggerMmuForInvalidCodePrefix) { + // mmuCall = MmuCall.invalidCodePrefix(); + } + + boolean triggerOobForNonemptyDeployments = + Exceptions.none(exceptions) + && hub.currentFrame().isDeployment() + && mxpCall.isMayTriggerNonTrivialMmuOperation(); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index fe36c91abd..4c82026801 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -40,7 +40,7 @@ public class StopSection extends TraceSection implements PostRollbackDefer, Post final int deploymentNumber; final boolean deploymentStatus; final int contextNumber; - final ContextFragment parentContextReturnDataRest; + final ContextFragment parentContextReturnDataReset; public StopSection(Hub hub) { // 3 = 1 + max_NON_STACK_ROWS in message call case @@ -56,7 +56,7 @@ public StopSection(Hub hub) { deploymentNumber = deploymentInfo.number(address); deploymentStatus = deploymentInfo.isDeploying(address); } - parentContextReturnDataRest = executionProvidesEmptyReturnData(hub); + parentContextReturnDataReset = executionProvidesEmptyReturnData(hub); Preconditions.checkArgument( hub.currentFrame().isDeployment() == deploymentStatus); // sanity check @@ -128,6 +128,6 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - this.addFragmentsWithoutStack(this.parentContextReturnDataRest); + this.addFragmentsWithoutStack(this.parentContextReturnDataReset); } } From 7ee39efbc4d7b91cf84a74457b4e57abd6aabbfa Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 17 Jul 2024 07:37:17 +0530 Subject: [PATCH 225/461] comment soon-to-die stuff --- .../module/hub/fragment/imc/ImcFragment.java | 23 ++++++++----------- .../zktracer/module/hub/signals/Signals.java | 2 +- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 2331fc5d52..31bdd179f7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -87,15 +87,11 @@ public static ImcFragment forTxInit(final Hub hub) { final boolean isMessageCallTransaction = currentTx.getBesuTransaction().getTo().isPresent(); final Optional txData = currentTx.getBesuTransaction().getData(); - final boolean shouldCopyTxCallData = - isMessageCallTransaction - && txData.isPresent() - && !txData.get().isEmpty() - && currentTx.requiresEvmExecution(); + final boolean shouldCopyTxCallData = currentTx.copyTransactionCallData(); - final ImcFragment emptyFragment = ImcFragment.empty(hub); + final ImcFragment miscFragment = ImcFragment.empty(hub); - return shouldCopyTxCallData ? emptyFragment.callMmu(MmuCall.txInit(hub)) : emptyFragment; + return shouldCopyTxCallData ? miscFragment.callMmu(MmuCall.txInit(hub)) : miscFragment; } /** @@ -167,11 +163,12 @@ public static ImcFragment forCall( public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { final ImcFragment r = new ImcFragment(hub); + /* TODO: this has been commented out since signals will die if (hub.pch().signals().mxp()) { r.callMxp(MxpCall.build(hub)); } - /* TODO: this has been commented out since signals will die + if (hub.pch().signals().exp()) { r.callExp(new ExplogExpCall()); } @@ -184,12 +181,12 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { if (hub.pch().signals().mmu()) { switch (hub.opCode()) { // commented instruction are done elsewhere, everything should be deleted - case SHA3 -> r.callMmu(MmuCall.sha3(hub)); + // case SHA3 -> r.callMmu(MmuCall.sha3(hub)); // case CALLDATALOAD -> r.callMmu(MmuCall.callDataLoad(hub)); - case CALLDATACOPY -> r.callMmu(MmuCall.callDataCopy(hub)); - case CODECOPY -> r.callMmu(MmuCall.codeCopy(hub)); - case EXTCODECOPY -> r.callMmu(MmuCall.extCodeCopy(hub)); - case RETURNDATACOPY -> r.callMmu(MmuCall.returnDataCopy(hub)); + // case CALLDATACOPY -> r.callMmu(MmuCall.callDataCopy(hub)); + // case CODECOPY -> r.callMmu(MmuCall.codeCopy(hub)); + // case EXTCODECOPY -> r.callMmu(MmuCall.extCodeCopy(hub)); + // case RETURNDATACOPY -> r.callMmu(MmuCall.returnDataCopy(hub)); // case MLOAD -> r.callMmu(MmuCall.mload(hub)); // case MSTORE -> r.callMmu(MmuCall.mstore(hub)); // case MSTORE8 -> r.callMmu(MmuCall.mstore8(hub)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index 67ed7c46a2..164610c1d1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -57,7 +57,7 @@ public class Signals { @Getter private boolean shf; @Getter private boolean gas; - @Getter private boolean mmu; + @Getter private boolean mmu; // TODO: SHOULD DIE @Getter private boolean mxp; @Getter private boolean oob; @Getter private boolean stp; From 9b5cb25d2de8cb551628c292b633338caabc7905 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 17 Jul 2024 10:59:24 +0530 Subject: [PATCH 226/461] regenerate Trace for ecdata --- .../linea/zktracer/module/ecdata/Trace.java | 18 +++++++++--------- .../module/hub/fragment/imc/ImcFragment.java | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java index 711d84ea33..56b8981084 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java @@ -67,7 +67,7 @@ public class Trace { private int currentLine = 0; private final MappedByteBuffer accPairings; - private final MappedByteBuffer acceptablePairOfPointsForPairingCircuit; + private final MappedByteBuffer acceptablePairOfPointForPairingCircuit; private final MappedByteBuffer byteDelta; private final MappedByteBuffer circuitSelectorEcadd; private final MappedByteBuffer circuitSelectorEcmul; @@ -124,7 +124,7 @@ public class Trace { static List headers(int length) { return List.of( new ColumnHeader("ecdata.ACC_PAIRINGS", 32, length), - new ColumnHeader("ecdata.ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT", 1, length), + new ColumnHeader("ecdata.ACCEPTABLE_PAIR_OF_POINT_FOR_PAIRING_CIRCUIT", 1, length), new ColumnHeader("ecdata.BYTE_DELTA", 1, length), new ColumnHeader("ecdata.CIRCUIT_SELECTOR_ECADD", 1, length), new ColumnHeader("ecdata.CIRCUIT_SELECTOR_ECMUL", 1, length), @@ -181,7 +181,7 @@ static List headers(int length) { public Trace(List buffers) { this.accPairings = buffers.get(0); - this.acceptablePairOfPointsForPairingCircuit = buffers.get(1); + this.acceptablePairOfPointForPairingCircuit = buffers.get(1); this.byteDelta = buffers.get(2); this.circuitSelectorEcadd = buffers.get(3); this.circuitSelectorEcmul = buffers.get(4); @@ -260,15 +260,15 @@ public Trace accPairings(final Bytes b) { return this; } - public Trace acceptablePairOfPointsForPairingCircuit(final Boolean b) { + public Trace acceptablePairOfPointForPairingCircuit(final Boolean b) { if (filled.get(0)) { throw new IllegalStateException( - "ecdata.ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT already set"); + "ecdata.ACCEPTABLE_PAIR_OF_POINT_FOR_PAIRING_CIRCUIT already set"); } else { filled.set(0); } - acceptablePairOfPointsForPairingCircuit.put((byte) (b ? 1 : 0)); + acceptablePairOfPointForPairingCircuit.put((byte) (b ? 1 : 0)); return this; } @@ -968,7 +968,7 @@ public Trace validateRow() { if (!filled.get(0)) { throw new IllegalStateException( - "ecdata.ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT has not been filled"); + "ecdata.ACCEPTABLE_PAIR_OF_POINT_FOR_PAIRING_CIRCUIT has not been filled"); } if (!filled.get(2)) { @@ -1191,8 +1191,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(0)) { - acceptablePairOfPointsForPairingCircuit.position( - acceptablePairOfPointsForPairingCircuit.position() + 1); + acceptablePairOfPointForPairingCircuit.position( + acceptablePairOfPointForPairingCircuit.position() + 1); } if (!filled.get(2)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 31bdd179f7..fff3350b1a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -160,6 +160,7 @@ public static ImcFragment forCall( return r; } + // TODO: should be deleted public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { final ImcFragment r = new ImcFragment(hub); From f4d0bb587e8c42ceb7a080b9bbad7ef6e66dda73 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 17 Jul 2024 11:25:48 +0530 Subject: [PATCH 227/461] regenerate Trace.java for the HUB --- .../module/ecdata/EcDataOperation.java | 2 +- .../linea/zktracer/module/hub/Trace.java | 2919 +++++++++++++---- ...eateSection.java => CreateSectionOld.java} | 0 .../hub/section/create/CreateSection.java | 19 + .../section/create/CreateSectionStaticX.java | 19 + 5 files changed, 2376 insertions(+), 583 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{CreateSection.java => CreateSectionOld.java} (100%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index db6e1aa719..f21390951b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -697,7 +697,7 @@ void trace(Trace trace, final int stamp, final long previousId) { && overallTrivialPairing.get( i)) // && conditions necessary because default value is true .g2MembershipTestRequired(g2MembershipTestRequired) - .acceptablePairOfPointsForPairingCircuit(acceptablePairOfPointsForPairingCircuit) + .acceptablePairOfPointForPairingCircuit(acceptablePairOfPointsForPairingCircuit) .circuitSelectorEcrecover(circuitSelectorEcrecover) .circuitSelectorEcadd(circuitSelectorEcadd) .circuitSelectorEcmul(circuitSelectorEcmul) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 208b27c5bb..72df3effbb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -244,63 +244,63 @@ public class Trace { static List headers(int length) { return List.of( - new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 4, length), + new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 2, length), new ColumnHeader("hub.acc_FINAL", 1, length), new ColumnHeader("hub.acc_FIRST", 1, length), new ColumnHeader( "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM", - 8, + 4, length), new ColumnHeader( "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", - 32, + 16, length), new ColumnHeader("hub.ALPHA", 1, length), new ColumnHeader( "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", - 32, + 16, length), new ColumnHeader( "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", - 32, + 16, length), - new ColumnHeader("hub.BATCH_NUMBER", 4, length), - new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 8, length), - new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 8, length), + new ColumnHeader("hub.BATCH_NUMBER", 2, length), + new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 4, length), + new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 4, length), new ColumnHeader("hub.CALL_STACK_DEPTH", 2, length), - new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 8, length), - new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 8, length), + new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 4, length), + new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 4, length), new ColumnHeader( "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE", - 8, + 4, length), new ColumnHeader( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 32, length), + "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE", 16, length), new ColumnHeader( "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", - 32, + 16, length), - new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 32, length), - new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 32, length), + new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO", 16, length), + new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI", 16, length), new ColumnHeader( "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI", - 8, + 4, length), new ColumnHeader( "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI", - 8, + 4, length), new ColumnHeader("hub.con_AGAIN", 1, length), new ColumnHeader("hub.con_FIRST", 1, length), new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length), new ColumnHeader("hub.CONTEXT_MAY_CHANGE", 1, length), - new ColumnHeader("hub.CONTEXT_NUMBER", 8, length), - new ColumnHeader("hub.CONTEXT_NUMBER_NEW", 8, length), - new ColumnHeader("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID", 8, length), - new ColumnHeader("hub.CONTEXT_REVERT_STAMP", 8, length), + new ColumnHeader("hub.CONTEXT_NUMBER", 4, length), + new ColumnHeader("hub.CONTEXT_NUMBER_NEW", 4, length), + new ColumnHeader("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID", 4, length), + new ColumnHeader("hub.CONTEXT_REVERT_STAMP", 4, length), new ColumnHeader("hub.CONTEXT_SELF_REVERTS", 1, length), new ColumnHeader("hub.CONTEXT_WILL_REVERT", 1, length), - new ColumnHeader("hub.COUNTER_NSR", 2, length), + new ColumnHeader("hub.COUNTER_NSR", 1, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), new ColumnHeader( @@ -315,15 +315,15 @@ static List headers(int length) { new ColumnHeader("hub.DELTA", 1, length), new ColumnHeader( "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", - 8, + 4, length), new ColumnHeader( "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", - 8, + 4, length), new ColumnHeader( "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE", - 8, + 4, length), new ColumnHeader( "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT", @@ -337,7 +337,7 @@ static List headers(int length) { "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD", 1, length), - new ColumnHeader("hub.DOM_STAMP", 8, length), + new ColumnHeader("hub.DOM_STAMP", 4, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), new ColumnHeader( "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE", @@ -347,12 +347,12 @@ static List headers(int length) { "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION", 1, length), - new ColumnHeader("hub.GAS_ACTUAL", 8, length), - new ColumnHeader("hub.GAS_COST", 32, length), - new ColumnHeader("hub.GAS_EXPECTED", 8, length), - new ColumnHeader("hub.GAS_LIMIT", 32, length), - new ColumnHeader("hub.GAS_NEXT", 8, length), - new ColumnHeader("hub.GAS_PRICE", 32, length), + new ColumnHeader("hub.GAS_ACTUAL", 4, length), + new ColumnHeader("hub.GAS_COST", 8, length), + new ColumnHeader("hub.GAS_EXPECTED", 4, length), + new ColumnHeader("hub.GAS_LIMIT", 8, length), + new ColumnHeader("hub.GAS_NEXT", 4, length), + new ColumnHeader("hub.GAS_PRICE", 8, length), new ColumnHeader( "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG", 1, @@ -361,17 +361,17 @@ static List headers(int length) { "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR", 1, length), - new ColumnHeader("hub.HASH_INFO_STAMP", 8, length), + new ColumnHeader("hub.HASH_INFO_STAMP", 4, length), new ColumnHeader("hub.HEIGHT", 2, length), new ColumnHeader("hub.HEIGHT_NEW", 2, length), - new ColumnHeader("hub.HUB_STAMP", 8, length), - new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 8, length), + new ColumnHeader("hub.HUB_STAMP", 4, length), + new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 4, length), new ColumnHeader("hub.INSTRUCTION", 32, length), new ColumnHeader( "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), - new ColumnHeader("hub.LOG_INFO_STAMP", 8, length), + new ColumnHeader("hub.LOG_INFO_STAMP", 4, length), new ColumnHeader( "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH", 1, @@ -380,30 +380,30 @@ static List headers(int length) { "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO", 1, length), - new ColumnHeader("hub.MMU_STAMP", 8, length), - new ColumnHeader("hub.MXP_OFFSET_2_HI", 32, length), - new ColumnHeader("hub.MXP_OFFSET_2_LO", 32, length), - new ColumnHeader("hub.MXP_SIZE_1_HI", 32, length), - new ColumnHeader("hub.MXP_SIZE_1_LO", 32, length), - new ColumnHeader("hub.MXP_SIZE_2_HI", 32, length), - new ColumnHeader("hub.MXP_SIZE_2_LO", 32, length), - new ColumnHeader("hub.MXP_STAMP", 8, length), - new ColumnHeader("hub.MXP_WORDS", 32, length), + new ColumnHeader("hub.MMU_STAMP", 4, length), + new ColumnHeader("hub.MXP_OFFSET_2_HI", 16, length), + new ColumnHeader("hub.MXP_OFFSET_2_LO", 16, length), + new ColumnHeader("hub.MXP_SIZE_1_HI", 16, length), + new ColumnHeader("hub.MXP_SIZE_1_LO", 16, length), + new ColumnHeader("hub.MXP_SIZE_2_HI", 16, length), + new ColumnHeader("hub.MXP_SIZE_2_LO", 16, length), + new ColumnHeader("hub.MXP_STAMP", 4, length), + new ColumnHeader("hub.MXP_WORDS", 16, length), new ColumnHeader("hub.NB_ADDED", 1, length), new ColumnHeader("hub.NB_REMOVED", 1, length), - new ColumnHeader("hub.NON_STACK_ROWS", 2, length), - new ColumnHeader("hub.NONCE", 32, length), + new ColumnHeader("hub.NON_STACK_ROWS", 1, length), + new ColumnHeader("hub.NONCE", 8, length), new ColumnHeader( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 32, length), - new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 32, length), - new ColumnHeader("hub.OOB_DATA_1", 32, length), - new ColumnHeader("hub.OOB_DATA_2", 32, length), - new ColumnHeader("hub.OOB_DATA_3", 32, length), - new ColumnHeader("hub.OOB_DATA_4", 32, length), - new ColumnHeader("hub.OOB_DATA_5", 32, length), - new ColumnHeader("hub.OOB_DATA_6", 32, length), - new ColumnHeader("hub.OOB_DATA_7", 32, length), - new ColumnHeader("hub.OOB_DATA_8", 32, length), + "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 8, length), + new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 8, length), + new ColumnHeader("hub.OOB_DATA_1", 16, length), + new ColumnHeader("hub.OOB_DATA_2", 16, length), + new ColumnHeader("hub.OOB_DATA_3", 16, length), + new ColumnHeader("hub.OOB_DATA_4", 16, length), + new ColumnHeader("hub.OOB_DATA_5", 16, length), + new ColumnHeader("hub.OOB_DATA_6", 16, length), + new ColumnHeader("hub.OOB_DATA_7", 16, length), + new ColumnHeader("hub.OOB_DATA_8", 16, length), new ColumnHeader("hub.PEEK_AT_ACCOUNT", 1, length), new ColumnHeader("hub.PEEK_AT_CONTEXT", 1, length), new ColumnHeader("hub.PEEK_AT_MISCELLANEOUS", 1, length), @@ -424,18 +424,18 @@ static List headers(int length) { new ColumnHeader("hub.PRC_SHA2-256_xor_OPCX", 1, length), new ColumnHeader("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG", 1, length), new ColumnHeader("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX", 1, length), - new ColumnHeader("hub.PRIORITY_FEE_PER_GAS", 32, length), - new ColumnHeader("hub.PROGRAM_COUNTER", 8, length), - new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 8, length), - new ColumnHeader("hub.REFUND_COUNTER", 8, length), - new ColumnHeader("hub.REFUND_COUNTER_INFINITY", 32, length), - new ColumnHeader("hub.REFUND_COUNTER_NEW", 8, length), - new ColumnHeader("hub.REFUND_EFFECTIVE", 32, length), - new ColumnHeader("hub.RETURN_AT_CAPACITY_xor_MXP_INST", 8, length), - new ColumnHeader("hub.RETURN_AT_OFFSET_xor_OOB_INST", 8, length), - new ColumnHeader("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND", 8, length), - new ColumnHeader("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION", 8, length), - new ColumnHeader("hub.RETURN_DATA_SIZE", 8, length), + new ColumnHeader("hub.PRIORITY_FEE_PER_GAS", 8, length), + new ColumnHeader("hub.PROGRAM_COUNTER", 4, length), + new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 4, length), + new ColumnHeader("hub.REFUND_COUNTER", 4, length), + new ColumnHeader("hub.REFUND_COUNTER_INFINITY", 8, length), + new ColumnHeader("hub.REFUND_COUNTER_NEW", 4, length), + new ColumnHeader("hub.REFUND_EFFECTIVE", 8, length), + new ColumnHeader("hub.RETURN_AT_CAPACITY_xor_MXP_INST", 4, length), + new ColumnHeader("hub.RETURN_AT_OFFSET_xor_OOB_INST", 4, length), + new ColumnHeader("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND", 4, length), + new ColumnHeader("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION", 4, length), + new ColumnHeader("hub.RETURN_DATA_SIZE", 4, length), new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), new ColumnHeader( @@ -449,19 +449,19 @@ static List headers(int length) { new ColumnHeader( "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 8, length), + "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 4, length), new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 32, length), + "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 16, length), new ColumnHeader( "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW", 1, length), - new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 32, length), - new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 32, length), + new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 16, length), + new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 16, length), new ColumnHeader( "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), - new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 32, length), - new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 32, length), + new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 16, length), + new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 16, length), new ColumnHeader( "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", 1, @@ -488,17 +488,17 @@ static List headers(int length) { new ColumnHeader("hub.STACK_ITEM_VALUE_LO_4", 32, length), new ColumnHeader("hub.sto_FINAL", 1, length), new ColumnHeader("hub.sto_FIRST", 1, length), - new ColumnHeader("hub.STP_GAS_HI", 32, length), - new ColumnHeader("hub.STP_GAS_LO", 32, length), - new ColumnHeader("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER", 32, length), - new ColumnHeader("hub.STP_VALUE_HI", 32, length), - new ColumnHeader("hub.STP_VALUE_LO", 32, length), - new ColumnHeader("hub.SUB_STAMP", 8, length), + new ColumnHeader("hub.STP_GAS_HI", 16, length), + new ColumnHeader("hub.STP_GAS_LO", 16, length), + new ColumnHeader("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER", 8, length), + new ColumnHeader("hub.STP_VALUE_HI", 16, length), + new ColumnHeader("hub.STP_VALUE_LO", 16, length), + new ColumnHeader("hub.SUB_STAMP", 4, length), new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), new ColumnHeader( "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), - new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 32, length), + new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 16, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), new ColumnHeader("hub.TX_FINL", 1, length), @@ -734,14 +734,18 @@ public int size() { return this.currentLine; } - public Trace absoluteTransactionNumber(final int b) { + public Trace absoluteTransactionNumber(final long b) { if (filled.get(0)) { throw new IllegalStateException("hub.ABSOLUTE_TRANSACTION_NUMBER already set"); } else { filled.set(0); } - absoluteTransactionNumber.putInt(b); + if (b >= 65536L) { + throw new IllegalArgumentException("absoluteTransactionNumber has invalid value (" + b + ")"); + } + absoluteTransactionNumber.put((byte) (b >> 8)); + absoluteTransactionNumber.put((byte) b); return this; } @@ -770,14 +774,18 @@ public Trace accFirst(final Boolean b) { return this; } - public Trace batchNumber(final int b) { + public Trace batchNumber(final long b) { if (filled.get(1)) { throw new IllegalStateException("hub.BATCH_NUMBER already set"); } else { filled.set(1); } - batchNumber.putInt(b); + if (b >= 65536L) { + throw new IllegalArgumentException("batchNumber has invalid value (" + b + ")"); + } + batchNumber.put((byte) (b >> 8)); + batchNumber.put((byte) b); return this; } @@ -789,7 +797,13 @@ public Trace callerContextNumber(final long b) { filled.set(2); } - callerContextNumber.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("callerContextNumber has invalid value (" + b + ")"); + } + callerContextNumber.put((byte) (b >> 24)); + callerContextNumber.put((byte) (b >> 16)); + callerContextNumber.put((byte) (b >> 8)); + callerContextNumber.put((byte) b); return this; } @@ -801,7 +815,13 @@ public Trace codeFragmentIndex(final long b) { filled.set(3); } - codeFragmentIndex.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("codeFragmentIndex has invalid value (" + b + ")"); + } + codeFragmentIndex.put((byte) (b >> 24)); + codeFragmentIndex.put((byte) (b >> 16)); + codeFragmentIndex.put((byte) (b >> 8)); + codeFragmentIndex.put((byte) b); return this; } @@ -861,7 +881,13 @@ public Trace contextNumber(final long b) { filled.set(6); } - contextNumber.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("contextNumber has invalid value (" + b + ")"); + } + contextNumber.put((byte) (b >> 24)); + contextNumber.put((byte) (b >> 16)); + contextNumber.put((byte) (b >> 8)); + contextNumber.put((byte) b); return this; } @@ -873,7 +899,13 @@ public Trace contextNumberNew(final long b) { filled.set(7); } - contextNumberNew.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("contextNumberNew has invalid value (" + b + ")"); + } + contextNumberNew.put((byte) (b >> 24)); + contextNumberNew.put((byte) (b >> 16)); + contextNumberNew.put((byte) (b >> 8)); + contextNumberNew.put((byte) b); return this; } @@ -885,7 +917,13 @@ public Trace contextRevertStamp(final long b) { filled.set(8); } - contextRevertStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("contextRevertStamp has invalid value (" + b + ")"); + } + contextRevertStamp.put((byte) (b >> 24)); + contextRevertStamp.put((byte) (b >> 16)); + contextRevertStamp.put((byte) (b >> 8)); + contextRevertStamp.put((byte) b); return this; } @@ -914,14 +952,17 @@ public Trace contextWillRevert(final Boolean b) { return this; } - public Trace counterNsr(final short b) { + public Trace counterNsr(final long b) { if (filled.get(11)) { throw new IllegalStateException("hub.COUNTER_NSR already set"); } else { filled.set(11); } - counterNsr.putShort(b); + if (b >= 256L) { + throw new IllegalArgumentException("counterNsr has invalid value (" + b + ")"); + } + counterNsr.put((byte) b); return this; } @@ -945,7 +986,13 @@ public Trace domStamp(final long b) { filled.set(13); } - domStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("domStamp has invalid value (" + b + ")"); + } + domStamp.put((byte) (b >> 24)); + domStamp.put((byte) (b >> 16)); + domStamp.put((byte) (b >> 8)); + domStamp.put((byte) b); return this; } @@ -969,7 +1016,13 @@ public Trace gasActual(final long b) { filled.set(15); } - gasActual.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("gasActual has invalid value (" + b + ")"); + } + gasActual.put((byte) (b >> 24)); + gasActual.put((byte) (b >> 16)); + gasActual.put((byte) (b >> 8)); + gasActual.put((byte) b); return this; } @@ -981,11 +1034,20 @@ public Trace gasCost(final Bytes b) { filled.set(16); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException("gasCost has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { gasCost.put((byte) 0); } - gasCost.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + gasCost.put(bs.get(j)); + } return this; } @@ -997,7 +1059,13 @@ public Trace gasExpected(final long b) { filled.set(17); } - gasExpected.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("gasExpected has invalid value (" + b + ")"); + } + gasExpected.put((byte) (b >> 24)); + gasExpected.put((byte) (b >> 16)); + gasExpected.put((byte) (b >> 8)); + gasExpected.put((byte) b); return this; } @@ -1009,7 +1077,13 @@ public Trace gasNext(final long b) { filled.set(18); } - gasNext.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("gasNext has invalid value (" + b + ")"); + } + gasNext.put((byte) (b >> 24)); + gasNext.put((byte) (b >> 16)); + gasNext.put((byte) (b >> 8)); + gasNext.put((byte) b); return this; } @@ -1021,31 +1095,45 @@ public Trace hashInfoStamp(final long b) { filled.set(19); } - hashInfoStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("hashInfoStamp has invalid value (" + b + ")"); + } + hashInfoStamp.put((byte) (b >> 24)); + hashInfoStamp.put((byte) (b >> 16)); + hashInfoStamp.put((byte) (b >> 8)); + hashInfoStamp.put((byte) b); return this; } - public Trace height(final short b) { + public Trace height(final long b) { if (filled.get(20)) { throw new IllegalStateException("hub.HEIGHT already set"); } else { filled.set(20); } - height.putShort(b); + if (b >= 2048L) { + throw new IllegalArgumentException("height has invalid value (" + b + ")"); + } + height.put((byte) (b >> 8)); + height.put((byte) b); return this; } - public Trace heightNew(final short b) { + public Trace heightNew(final long b) { if (filled.get(21)) { throw new IllegalStateException("hub.HEIGHT_NEW already set"); } else { filled.set(21); } - heightNew.putShort(b); + if (b >= 2048L) { + throw new IllegalArgumentException("heightNew has invalid value (" + b + ")"); + } + heightNew.put((byte) (b >> 8)); + heightNew.put((byte) b); return this; } @@ -1057,7 +1145,13 @@ public Trace hubStamp(final long b) { filled.set(22); } - hubStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("hubStamp has invalid value (" + b + ")"); + } + hubStamp.put((byte) (b >> 24)); + hubStamp.put((byte) (b >> 16)); + hubStamp.put((byte) (b >> 8)); + hubStamp.put((byte) b); return this; } @@ -1069,7 +1163,13 @@ public Trace hubStampTransactionEnd(final long b) { filled.set(23); } - hubStampTransactionEnd.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("hubStampTransactionEnd has invalid value (" + b + ")"); + } + hubStampTransactionEnd.put((byte) (b >> 24)); + hubStampTransactionEnd.put((byte) (b >> 16)); + hubStampTransactionEnd.put((byte) (b >> 8)); + hubStampTransactionEnd.put((byte) b); return this; } @@ -1081,7 +1181,13 @@ public Trace logInfoStamp(final long b) { filled.set(24); } - logInfoStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("logInfoStamp has invalid value (" + b + ")"); + } + logInfoStamp.put((byte) (b >> 24)); + logInfoStamp.put((byte) (b >> 16)); + logInfoStamp.put((byte) (b >> 8)); + logInfoStamp.put((byte) b); return this; } @@ -1093,7 +1199,13 @@ public Trace mmuStamp(final long b) { filled.set(25); } - mmuStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("mmuStamp has invalid value (" + b + ")"); + } + mmuStamp.put((byte) (b >> 24)); + mmuStamp.put((byte) (b >> 16)); + mmuStamp.put((byte) (b >> 8)); + mmuStamp.put((byte) b); return this; } @@ -1105,19 +1217,28 @@ public Trace mxpStamp(final long b) { filled.set(26); } - mxpStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("mxpStamp has invalid value (" + b + ")"); + } + mxpStamp.put((byte) (b >> 24)); + mxpStamp.put((byte) (b >> 16)); + mxpStamp.put((byte) (b >> 8)); + mxpStamp.put((byte) b); return this; } - public Trace nonStackRows(final short b) { + public Trace nonStackRows(final long b) { if (filled.get(27)) { throw new IllegalStateException("hub.NON_STACK_ROWS already set"); } else { filled.set(27); } - nonStackRows.putShort(b); + if (b >= 256L) { + throw new IllegalArgumentException("nonStackRows has invalid value (" + b + ")"); + } + nonStackRows.put((byte) b); return this; } @@ -1129,8 +1250,20 @@ public Trace pAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum has invalid value (" + + b + + ")"); + } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) b); return this; } @@ -1142,13 +1275,25 @@ public Trace pAccountAddressLo(final Bytes b) { filled.set(131); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put(bs.get(j)); + } return this; } @@ -1160,13 +1305,25 @@ public Trace pAccountBalance(final Bytes b) { filled.set(132); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + bs.get(j)); + } return this; } @@ -1178,13 +1335,25 @@ public Trace pAccountBalanceNew(final Bytes b) { filled.set(133); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + bs.get(j)); + } return this; } @@ -1196,8 +1365,20 @@ public Trace pAccountCodeFragmentIndex(final long b) { filled.set(107); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize has invalid value (" + + b + + ")"); + } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 8)); codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + .put((byte) b); return this; } @@ -1209,12 +1390,23 @@ public Trace pAccountCodeHashHi(final Bytes b) { filled.set(134); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); + } return this; } @@ -1226,11 +1418,23 @@ public Trace pAccountCodeHashHiNew(final Bytes b) { filled.set(135); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiNewXorExpData5XorValueCurrLoXorValue has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(bs.get(j)); + } return this; } @@ -1242,11 +1446,21 @@ public Trace pAccountCodeHashLo(final Bytes b) { filled.set(136); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashLoXorMmuLimb1XorValueNextHi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashLoXorMmuLimb1XorValueNextHi.put((byte) 0); } - codeHashLoXorMmuLimb1XorValueNextHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashLoXorMmuLimb1XorValueNextHi.put(bs.get(j)); + } return this; } @@ -1258,11 +1472,21 @@ public Trace pAccountCodeHashLoNew(final Bytes b) { filled.set(137); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashLoNewXorMmuLimb2XorValueNextLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashLoNewXorMmuLimb2XorValueNextLo.put((byte) 0); } - codeHashLoNewXorMmuLimb2XorValueNextLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashLoNewXorMmuLimb2XorValueNextLo.put(bs.get(j)); + } return this; } @@ -1274,8 +1498,20 @@ public Trace pAccountCodeSize(final long b) { filled.set(108); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi has invalid value (" + + b + + ")"); + } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 16)); codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + .put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) b); return this; } @@ -1287,7 +1523,19 @@ public Trace pAccountCodeSizeNew(final long b) { filled.set(109); } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi has invalid value (" + + b + + ")"); + } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 8)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put((byte) b); return this; } @@ -1299,7 +1547,19 @@ public Trace pAccountDeploymentNumber(final long b) { filled.set(110); } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize has invalid value (" + + b + + ")"); + } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 8)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put((byte) b); return this; } @@ -1311,7 +1571,20 @@ public Trace pAccountDeploymentNumberInfty(final long b) { filled.set(111); } - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi has invalid value (" + + b + + ")"); + } + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 24)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 16)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 8)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) b); return this; } @@ -1323,7 +1596,16 @@ public Trace pAccountDeploymentNumberNew(final long b) { filled.set(112); } - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas has invalid value (" + + b + + ")"); + } + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); return this; } @@ -1465,11 +1747,21 @@ public Trace pAccountNonce(final Bytes b) { filled.set(122); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "nonceXorStpGasMxpXorBasefee has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { nonceXorStpGasMxpXorBasefee.put((byte) 0); } - nonceXorStpGasMxpXorBasefee.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + nonceXorStpGasMxpXorBasefee.put(bs.get(j)); + } return this; } @@ -1481,11 +1773,23 @@ public Trace pAccountNonceNew(final Bytes b) { filled.set(123); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(bs.get(j)); + } return this; } @@ -1497,7 +1801,14 @@ public Trace pAccountRlpaddrDepAddrHi(final long b) { filled.set(113); } - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize has invalid value (" + b + ")"); + } + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 24)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 16)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 8)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) b); return this; } @@ -1509,11 +1820,23 @@ public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { filled.set(138); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put((byte) 0); } - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(bs.get(j)); + } return this; } @@ -1538,11 +1861,23 @@ public Trace pAccountRlpaddrKecHi(final Bytes b) { filled.set(139); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put((byte) 0); } - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(bs.get(j)); + } return this; } @@ -1554,11 +1889,21 @@ public Trace pAccountRlpaddrKecLo(final Bytes b) { filled.set(140); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrKecLoXorMmuTgtOffsetLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrKecLoXorMmuTgtOffsetLo.put((byte) 0); } - rlpaddrKecLoXorMmuTgtOffsetLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrKecLoXorMmuTgtOffsetLo.put(bs.get(j)); + } return this; } @@ -1582,11 +1927,21 @@ public Trace pAccountRlpaddrSaltHi(final Bytes b) { filled.set(141); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrSaltHiXorMxpGasMxp has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrSaltHiXorMxpGasMxp.put((byte) 0); } - rlpaddrSaltHiXorMxpGasMxp.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrSaltHiXorMxpGasMxp.put(bs.get(j)); + } return this; } @@ -1598,11 +1953,21 @@ public Trace pAccountRlpaddrSaltLo(final Bytes b) { filled.set(142); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrSaltLoXorMxpOffset1Hi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrSaltLoXorMxpOffset1Hi.put((byte) 0); } - rlpaddrSaltLoXorMxpOffset1Hi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrSaltLoXorMxpOffset1Hi.put(bs.get(j)); + } return this; } @@ -1638,11 +2003,21 @@ public Trace pAccountTrmRawAddressHi(final Bytes b) { filled.set(143); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "trmRawAddressHiXorMxpOffset1Lo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); } - trmRawAddressHiXorMxpOffset1Lo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + trmRawAddressHiXorMxpOffset1Lo.put(bs.get(j)); + } return this; } @@ -1678,8 +2053,20 @@ public Trace pContextAccountAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum has invalid value (" + + b + + ")"); + } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) b); return this; } @@ -1691,13 +2078,25 @@ public Trace pContextAccountAddressLo(final Bytes b) { filled.set(131); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put(bs.get(j)); + } return this; } @@ -1709,8 +2108,20 @@ public Trace pContextAccountDeploymentNumber(final long b) { filled.set(107); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize has invalid value (" + + b + + ")"); + } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 16)); codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + .put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) b); return this; } @@ -1722,8 +2133,20 @@ public Trace pContextByteCodeAddressHi(final long b) { filled.set(108); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi has invalid value (" + + b + + ")"); + } codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + .put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) b); return this; } @@ -1735,13 +2158,25 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { filled.set(132); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + bs.get(j)); + } return this; } @@ -1753,7 +2188,19 @@ public Trace pContextByteCodeCodeFragmentIndex(final long b) { filled.set(109); } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi has invalid value (" + + b + + ")"); + } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 8)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put((byte) b); return this; } @@ -1765,7 +2212,19 @@ public Trace pContextByteCodeDeploymentNumber(final long b) { filled.set(110); } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize has invalid value (" + + b + + ")"); + } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 8)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put((byte) b); return this; } @@ -1777,7 +2236,20 @@ public Trace pContextByteCodeDeploymentStatus(final long b) { filled.set(111); } - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi has invalid value (" + + b + + ")"); + } + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 24)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 16)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 8)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) b); return this; } @@ -1789,7 +2261,14 @@ public Trace pContextCallDataContextNumber(final long b) { filled.set(113); } - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize has invalid value (" + b + ")"); + } + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 24)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 16)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 8)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) b); return this; } @@ -1801,7 +2280,13 @@ public Trace pContextCallDataOffset(final long b) { filled.set(114); } - callDataOffsetXorMmuSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("callDataOffsetXorMmuSize has invalid value (" + b + ")"); + } + callDataOffsetXorMmuSize.put((byte) (b >> 24)); + callDataOffsetXorMmuSize.put((byte) (b >> 16)); + callDataOffsetXorMmuSize.put((byte) (b >> 8)); + callDataOffsetXorMmuSize.put((byte) b); return this; } @@ -1813,19 +2298,29 @@ public Trace pContextCallDataSize(final long b) { filled.set(115); } - callDataSizeXorMmuSrcId.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("callDataSizeXorMmuSrcId has invalid value (" + b + ")"); + } + callDataSizeXorMmuSrcId.put((byte) (b >> 24)); + callDataSizeXorMmuSrcId.put((byte) (b >> 16)); + callDataSizeXorMmuSrcId.put((byte) (b >> 8)); + callDataSizeXorMmuSrcId.put((byte) b); return this; } - public Trace pContextCallStackDepth(final short b) { + public Trace pContextCallStackDepth(final long b) { if (filled.get(105)) { throw new IllegalStateException("hub.context/CALL_STACK_DEPTH already set"); } else { filled.set(105); } - callStackDepth.putShort(b); + if (b >= 2048L) { + throw new IllegalArgumentException("callStackDepth has invalid value (" + b + ")"); + } + callStackDepth.put((byte) (b >> 8)); + callStackDepth.put((byte) b); return this; } @@ -1837,12 +2332,23 @@ public Trace pContextCallValue(final Bytes b) { filled.set(134); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); + } return this; } @@ -1854,7 +2360,16 @@ public Trace pContextCallerAddressHi(final long b) { filled.set(112); } - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas has invalid value (" + + b + + ")"); + } + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); return this; } @@ -1866,13 +2381,25 @@ public Trace pContextCallerAddressLo(final Bytes b) { filled.set(133); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + bs.get(j)); + } return this; } @@ -1884,7 +2411,13 @@ public Trace pContextContextNumber(final long b) { filled.set(116); } - contextNumberXorMmuTgtId.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("contextNumberXorMmuTgtId has invalid value (" + b + ")"); + } + contextNumberXorMmuTgtId.put((byte) (b >> 24)); + contextNumberXorMmuTgtId.put((byte) (b >> 16)); + contextNumberXorMmuTgtId.put((byte) (b >> 8)); + contextNumberXorMmuTgtId.put((byte) b); return this; } @@ -1922,7 +2455,14 @@ public Trace pContextReturnAtCapacity(final long b) { filled.set(117); } - returnAtCapacityXorMxpInst.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "returnAtCapacityXorMxpInst has invalid value (" + b + ")"); + } + returnAtCapacityXorMxpInst.put((byte) (b >> 24)); + returnAtCapacityXorMxpInst.put((byte) (b >> 16)); + returnAtCapacityXorMxpInst.put((byte) (b >> 8)); + returnAtCapacityXorMxpInst.put((byte) b); return this; } @@ -1934,7 +2474,13 @@ public Trace pContextReturnAtOffset(final long b) { filled.set(118); } - returnAtOffsetXorOobInst.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("returnAtOffsetXorOobInst has invalid value (" + b + ")"); + } + returnAtOffsetXorOobInst.put((byte) (b >> 24)); + returnAtOffsetXorOobInst.put((byte) (b >> 16)); + returnAtOffsetXorOobInst.put((byte) (b >> 8)); + returnAtOffsetXorOobInst.put((byte) b); return this; } @@ -1946,7 +2492,14 @@ public Trace pContextReturnDataContextNumber(final long b) { filled.set(119); } - returnDataContextNumberXorStpGasStipend.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "returnDataContextNumberXorStpGasStipend has invalid value (" + b + ")"); + } + returnDataContextNumberXorStpGasStipend.put((byte) (b >> 24)); + returnDataContextNumberXorStpGasStipend.put((byte) (b >> 16)); + returnDataContextNumberXorStpGasStipend.put((byte) (b >> 8)); + returnDataContextNumberXorStpGasStipend.put((byte) b); return this; } @@ -1958,7 +2511,14 @@ public Trace pContextReturnDataOffset(final long b) { filled.set(120); } - returnDataOffsetXorStpInstruction.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "returnDataOffsetXorStpInstruction has invalid value (" + b + ")"); + } + returnDataOffsetXorStpInstruction.put((byte) (b >> 24)); + returnDataOffsetXorStpInstruction.put((byte) (b >> 16)); + returnDataOffsetXorStpInstruction.put((byte) (b >> 8)); + returnDataOffsetXorStpInstruction.put((byte) b); return this; } @@ -1970,7 +2530,13 @@ public Trace pContextReturnDataSize(final long b) { filled.set(121); } - returnDataSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("returnDataSize has invalid value (" + b + ")"); + } + returnDataSize.put((byte) (b >> 24)); + returnDataSize.put((byte) (b >> 16)); + returnDataSize.put((byte) (b >> 8)); + returnDataSize.put((byte) b); return this; } @@ -1995,8 +2561,20 @@ public Trace pMiscCcrsStamp(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum has invalid value (" + + b + + ")"); + } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) b); return this; } @@ -2021,13 +2599,25 @@ public Trace pMiscExpData1(final Bytes b) { filled.set(131); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put(bs.get(j)); + } return this; } @@ -2039,13 +2629,25 @@ public Trace pMiscExpData2(final Bytes b) { filled.set(132); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + bs.get(j)); + } return this; } @@ -2057,13 +2659,25 @@ public Trace pMiscExpData3(final Bytes b) { filled.set(133); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + bs.get(j)); + } return this; } @@ -2075,12 +2689,23 @@ public Trace pMiscExpData4(final Bytes b) { filled.set(134); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); + } return this; } @@ -2092,11 +2717,23 @@ public Trace pMiscExpData5(final Bytes b) { filled.set(135); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiNewXorExpData5XorValueCurrLoXorValue has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(bs.get(j)); + } return this; } @@ -2121,8 +2758,20 @@ public Trace pMiscExpInst(final long b) { filled.set(107); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize has invalid value (" + + b + + ")"); + } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 16)); codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + .put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) b); return this; } @@ -2134,8 +2783,20 @@ public Trace pMiscMmuAuxId(final long b) { filled.set(108); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi has invalid value (" + + b + + ")"); + } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 8)); codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + .put((byte) b); return this; } @@ -2147,7 +2808,19 @@ public Trace pMiscMmuExoSum(final long b) { filled.set(109); } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi has invalid value (" + + b + + ")"); + } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 8)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put((byte) b); return this; } @@ -2172,7 +2845,19 @@ public Trace pMiscMmuInst(final long b) { filled.set(110); } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize has invalid value (" + + b + + ")"); + } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 8)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put((byte) b); return this; } @@ -2184,11 +2869,21 @@ public Trace pMiscMmuLimb1(final Bytes b) { filled.set(136); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashLoXorMmuLimb1XorValueNextHi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashLoXorMmuLimb1XorValueNextHi.put((byte) 0); } - codeHashLoXorMmuLimb1XorValueNextHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashLoXorMmuLimb1XorValueNextHi.put(bs.get(j)); + } return this; } @@ -2200,11 +2895,21 @@ public Trace pMiscMmuLimb2(final Bytes b) { filled.set(137); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashLoNewXorMmuLimb2XorValueNextLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashLoNewXorMmuLimb2XorValueNextLo.put((byte) 0); } - codeHashLoNewXorMmuLimb2XorValueNextLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashLoNewXorMmuLimb2XorValueNextLo.put(bs.get(j)); + } return this; } @@ -2216,7 +2921,20 @@ public Trace pMiscMmuPhase(final long b) { filled.set(111); } - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi has invalid value (" + + b + + ")"); + } + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 24)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 16)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 8)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) b); return this; } @@ -2228,7 +2946,16 @@ public Trace pMiscMmuRefOffset(final long b) { filled.set(112); } - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas has invalid value (" + + b + + ")"); + } + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); return this; } @@ -2240,7 +2967,14 @@ public Trace pMiscMmuRefSize(final long b) { filled.set(113); } - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize has invalid value (" + b + ")"); + } + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 24)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 16)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 8)); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) b); return this; } @@ -2252,7 +2986,13 @@ public Trace pMiscMmuSize(final long b) { filled.set(114); } - callDataOffsetXorMmuSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("callDataOffsetXorMmuSize has invalid value (" + b + ")"); + } + callDataOffsetXorMmuSize.put((byte) (b >> 24)); + callDataOffsetXorMmuSize.put((byte) (b >> 16)); + callDataOffsetXorMmuSize.put((byte) (b >> 8)); + callDataOffsetXorMmuSize.put((byte) b); return this; } @@ -2264,7 +3004,13 @@ public Trace pMiscMmuSrcId(final long b) { filled.set(115); } - callDataSizeXorMmuSrcId.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("callDataSizeXorMmuSrcId has invalid value (" + b + ")"); + } + callDataSizeXorMmuSrcId.put((byte) (b >> 24)); + callDataSizeXorMmuSrcId.put((byte) (b >> 16)); + callDataSizeXorMmuSrcId.put((byte) (b >> 8)); + callDataSizeXorMmuSrcId.put((byte) b); return this; } @@ -2276,11 +3022,23 @@ public Trace pMiscMmuSrcOffsetHi(final Bytes b) { filled.set(138); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put((byte) 0); } - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(bs.get(j)); + } return this; } @@ -2292,11 +3050,23 @@ public Trace pMiscMmuSrcOffsetLo(final Bytes b) { filled.set(139); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put((byte) 0); } - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(bs.get(j)); + } return this; } @@ -2321,7 +3091,13 @@ public Trace pMiscMmuTgtId(final long b) { filled.set(116); } - contextNumberXorMmuTgtId.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("contextNumberXorMmuTgtId has invalid value (" + b + ")"); + } + contextNumberXorMmuTgtId.put((byte) (b >> 24)); + contextNumberXorMmuTgtId.put((byte) (b >> 16)); + contextNumberXorMmuTgtId.put((byte) (b >> 8)); + contextNumberXorMmuTgtId.put((byte) b); return this; } @@ -2333,11 +3109,21 @@ public Trace pMiscMmuTgtOffsetLo(final Bytes b) { filled.set(140); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrKecLoXorMmuTgtOffsetLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrKecLoXorMmuTgtOffsetLo.put((byte) 0); } - rlpaddrKecLoXorMmuTgtOffsetLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrKecLoXorMmuTgtOffsetLo.put(bs.get(j)); + } return this; } @@ -2375,11 +3161,21 @@ public Trace pMiscMxpGasMxp(final Bytes b) { filled.set(141); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrSaltHiXorMxpGasMxp has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrSaltHiXorMxpGasMxp.put((byte) 0); } - rlpaddrSaltHiXorMxpGasMxp.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrSaltHiXorMxpGasMxp.put(bs.get(j)); + } return this; } @@ -2391,7 +3187,14 @@ public Trace pMiscMxpInst(final long b) { filled.set(117); } - returnAtCapacityXorMxpInst.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "returnAtCapacityXorMxpInst has invalid value (" + b + ")"); + } + returnAtCapacityXorMxpInst.put((byte) (b >> 24)); + returnAtCapacityXorMxpInst.put((byte) (b >> 16)); + returnAtCapacityXorMxpInst.put((byte) (b >> 8)); + returnAtCapacityXorMxpInst.put((byte) b); return this; } @@ -2429,11 +3232,21 @@ public Trace pMiscMxpOffset1Hi(final Bytes b) { filled.set(142); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrSaltLoXorMxpOffset1Hi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrSaltLoXorMxpOffset1Hi.put((byte) 0); } - rlpaddrSaltLoXorMxpOffset1Hi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrSaltLoXorMxpOffset1Hi.put(bs.get(j)); + } return this; } @@ -2445,11 +3258,21 @@ public Trace pMiscMxpOffset1Lo(final Bytes b) { filled.set(143); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "trmRawAddressHiXorMxpOffset1Lo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); } - trmRawAddressHiXorMxpOffset1Lo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + trmRawAddressHiXorMxpOffset1Lo.put(bs.get(j)); + } return this; } @@ -2461,11 +3284,21 @@ public Trace pMiscMxpOffset2Hi(final Bytes b) { filled.set(144); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "mxpOffset2Hi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { mxpOffset2Hi.put((byte) 0); } - mxpOffset2Hi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + mxpOffset2Hi.put(bs.get(j)); + } return this; } @@ -2477,11 +3310,21 @@ public Trace pMiscMxpOffset2Lo(final Bytes b) { filled.set(145); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "mxpOffset2Lo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { mxpOffset2Lo.put((byte) 0); } - mxpOffset2Lo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + mxpOffset2Lo.put(bs.get(j)); + } return this; } @@ -2493,11 +3336,21 @@ public Trace pMiscMxpSize1Hi(final Bytes b) { filled.set(146); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "mxpSize1Hi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { mxpSize1Hi.put((byte) 0); } - mxpSize1Hi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + mxpSize1Hi.put(bs.get(j)); + } return this; } @@ -2509,11 +3362,21 @@ public Trace pMiscMxpSize1Lo(final Bytes b) { filled.set(147); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "mxpSize1Lo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { mxpSize1Lo.put((byte) 0); } - mxpSize1Lo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + mxpSize1Lo.put(bs.get(j)); + } return this; } @@ -2525,11 +3388,21 @@ public Trace pMiscMxpSize2Hi(final Bytes b) { filled.set(148); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "mxpSize2Hi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { mxpSize2Hi.put((byte) 0); } - mxpSize2Hi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + mxpSize2Hi.put(bs.get(j)); + } return this; } @@ -2541,11 +3414,21 @@ public Trace pMiscMxpSize2Lo(final Bytes b) { filled.set(149); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "mxpSize2Lo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { mxpSize2Lo.put((byte) 0); } - mxpSize2Lo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + mxpSize2Lo.put(bs.get(j)); + } return this; } @@ -2557,11 +3440,20 @@ public Trace pMiscMxpWords(final Bytes b) { filled.set(150); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("mxpWords has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { mxpWords.put((byte) 0); } - mxpWords.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + mxpWords.put(bs.get(j)); + } return this; } @@ -2573,11 +3465,20 @@ public Trace pMiscOobData1(final Bytes b) { filled.set(151); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData1 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData1.put((byte) 0); } - oobData1.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData1.put(bs.get(j)); + } return this; } @@ -2589,11 +3490,20 @@ public Trace pMiscOobData2(final Bytes b) { filled.set(152); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData2 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData2.put((byte) 0); } - oobData2.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData2.put(bs.get(j)); + } return this; } @@ -2605,11 +3515,20 @@ public Trace pMiscOobData3(final Bytes b) { filled.set(153); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData3 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData3.put((byte) 0); } - oobData3.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData3.put(bs.get(j)); + } return this; } @@ -2621,11 +3540,20 @@ public Trace pMiscOobData4(final Bytes b) { filled.set(154); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData4 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData4.put((byte) 0); } - oobData4.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData4.put(bs.get(j)); + } return this; } @@ -2637,11 +3565,20 @@ public Trace pMiscOobData5(final Bytes b) { filled.set(155); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData5 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData5.put((byte) 0); } - oobData5.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData5.put(bs.get(j)); + } return this; } @@ -2653,11 +3590,20 @@ public Trace pMiscOobData6(final Bytes b) { filled.set(156); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData6 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData6.put((byte) 0); } - oobData6.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData6.put(bs.get(j)); + } return this; } @@ -2669,11 +3615,20 @@ public Trace pMiscOobData7(final Bytes b) { filled.set(157); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData7 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData7.put((byte) 0); } - oobData7.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData7.put(bs.get(j)); + } return this; } @@ -2685,11 +3640,20 @@ public Trace pMiscOobData8(final Bytes b) { filled.set(158); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("oobData8 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { oobData8.put((byte) 0); } - oobData8.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + oobData8.put(bs.get(j)); + } return this; } @@ -2714,7 +3678,13 @@ public Trace pMiscOobInst(final long b) { filled.set(118); } - returnAtOffsetXorOobInst.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("returnAtOffsetXorOobInst has invalid value (" + b + ")"); + } + returnAtOffsetXorOobInst.put((byte) (b >> 24)); + returnAtOffsetXorOobInst.put((byte) (b >> 16)); + returnAtOffsetXorOobInst.put((byte) (b >> 8)); + returnAtOffsetXorOobInst.put((byte) b); return this; } @@ -2752,11 +3722,20 @@ public Trace pMiscStpGasHi(final Bytes b) { filled.set(159); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("stpGasHi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { stpGasHi.put((byte) 0); } - stpGasHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stpGasHi.put(bs.get(j)); + } return this; } @@ -2768,11 +3747,20 @@ public Trace pMiscStpGasLo(final Bytes b) { filled.set(160); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("stpGasLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { stpGasLo.put((byte) 0); } - stpGasLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stpGasLo.put(bs.get(j)); + } return this; } @@ -2784,11 +3772,21 @@ public Trace pMiscStpGasMxp(final Bytes b) { filled.set(122); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "nonceXorStpGasMxpXorBasefee has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { nonceXorStpGasMxpXorBasefee.put((byte) 0); } - nonceXorStpGasMxpXorBasefee.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + nonceXorStpGasMxpXorBasefee.put(bs.get(j)); + } return this; } @@ -2800,11 +3798,23 @@ public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { filled.set(123); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(bs.get(j)); + } return this; } @@ -2816,7 +3826,14 @@ public Trace pMiscStpGasStipend(final long b) { filled.set(119); } - returnDataContextNumberXorStpGasStipend.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "returnDataContextNumberXorStpGasStipend has invalid value (" + b + ")"); + } + returnDataContextNumberXorStpGasStipend.put((byte) (b >> 24)); + returnDataContextNumberXorStpGasStipend.put((byte) (b >> 16)); + returnDataContextNumberXorStpGasStipend.put((byte) (b >> 8)); + returnDataContextNumberXorStpGasStipend.put((byte) b); return this; } @@ -2828,11 +3845,21 @@ public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { filled.set(124); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "stpGasUpfrontGasCostXorGasLeftover has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); } - stpGasUpfrontGasCostXorGasLeftover.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stpGasUpfrontGasCostXorGasLeftover.put(bs.get(j)); + } return this; } @@ -2844,7 +3871,14 @@ public Trace pMiscStpInstruction(final long b) { filled.set(120); } - returnDataOffsetXorStpInstruction.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "returnDataOffsetXorStpInstruction has invalid value (" + b + ")"); + } + returnDataOffsetXorStpInstruction.put((byte) (b >> 24)); + returnDataOffsetXorStpInstruction.put((byte) (b >> 16)); + returnDataOffsetXorStpInstruction.put((byte) (b >> 8)); + returnDataOffsetXorStpInstruction.put((byte) b); return this; } @@ -2868,11 +3902,21 @@ public Trace pMiscStpValueHi(final Bytes b) { filled.set(161); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "stpValueHi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { stpValueHi.put((byte) 0); } - stpValueHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stpValueHi.put(bs.get(j)); + } return this; } @@ -2884,11 +3928,21 @@ public Trace pMiscStpValueLo(final Bytes b) { filled.set(162); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "stpValueLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { stpValueLo.put((byte) 0); } - stpValueLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stpValueLo.put(bs.get(j)); + } return this; } @@ -3204,8 +4258,20 @@ public Trace pScenarioPrcCalleeGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum has invalid value (" + + b + + ")"); + } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) b); return this; } @@ -3217,8 +4283,20 @@ public Trace pScenarioPrcCallerGas(final long b) { filled.set(107); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize has invalid value (" + + b + + ")"); + } codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + .put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) b); return this; } @@ -3230,8 +4308,20 @@ public Trace pScenarioPrcCdo(final long b) { filled.set(108); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi has invalid value (" + + b + + ")"); + } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 24)); codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + .put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) b); return this; } @@ -3243,7 +4333,19 @@ public Trace pScenarioPrcCds(final long b) { filled.set(109); } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi has invalid value (" + + b + + ")"); + } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 8)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put((byte) b); return this; } @@ -3351,7 +4453,19 @@ public Trace pScenarioPrcRac(final long b) { filled.set(110); } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize has invalid value (" + + b + + ")"); + } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 8)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put((byte) b); return this; } @@ -3363,7 +4477,20 @@ public Trace pScenarioPrcRao(final long b) { filled.set(111); } - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi has invalid value (" + + b + + ")"); + } + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 24)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 16)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 8)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) b); return this; } @@ -3375,7 +4502,16 @@ public Trace pScenarioPrcReturnGas(final long b) { filled.set(112); } - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas has invalid value (" + + b + + ")"); + } + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); return this; } @@ -3802,13 +4938,25 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { filled.set(131); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put(bs.get(j)); + } return this; } @@ -3820,13 +4968,25 @@ public Trace pStackHashInfoKeccakLo(final Bytes b) { filled.set(132); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + bs.get(j)); + } return this; } @@ -3850,11 +5010,21 @@ public Trace pStackInstruction(final Bytes b) { filled.set(163); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "instruction has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { instruction.put((byte) 0); } - instruction.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + instruction.put(bs.get(j)); + } return this; } @@ -4071,13 +5241,25 @@ public Trace pStackPushValueHi(final Bytes b) { filled.set(133); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + bs.get(j)); + } return this; } @@ -4089,12 +5271,23 @@ public Trace pStackPushValueLo(final Bytes b) { filled.set(134); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); + } return this; } @@ -4166,11 +5359,21 @@ public Trace pStackStackItemHeight1(final Bytes b) { filled.set(164); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemHeight1 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemHeight1.put((byte) 0); } - stackItemHeight1.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemHeight1.put(bs.get(j)); + } return this; } @@ -4182,11 +5385,21 @@ public Trace pStackStackItemHeight2(final Bytes b) { filled.set(165); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemHeight2 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemHeight2.put((byte) 0); } - stackItemHeight2.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemHeight2.put(bs.get(j)); + } return this; } @@ -4198,11 +5411,21 @@ public Trace pStackStackItemHeight3(final Bytes b) { filled.set(166); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemHeight3 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemHeight3.put((byte) 0); } - stackItemHeight3.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemHeight3.put(bs.get(j)); + } return this; } @@ -4214,11 +5437,21 @@ public Trace pStackStackItemHeight4(final Bytes b) { filled.set(167); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemHeight4 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemHeight4.put((byte) 0); } - stackItemHeight4.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemHeight4.put(bs.get(j)); + } return this; } @@ -4278,11 +5511,21 @@ public Trace pStackStackItemStamp1(final Bytes b) { filled.set(168); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemStamp1 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemStamp1.put((byte) 0); } - stackItemStamp1.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemStamp1.put(bs.get(j)); + } return this; } @@ -4294,11 +5537,21 @@ public Trace pStackStackItemStamp2(final Bytes b) { filled.set(169); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemStamp2 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemStamp2.put((byte) 0); } - stackItemStamp2.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemStamp2.put(bs.get(j)); + } return this; } @@ -4310,11 +5563,21 @@ public Trace pStackStackItemStamp3(final Bytes b) { filled.set(170); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemStamp3 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemStamp3.put((byte) 0); } - stackItemStamp3.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemStamp3.put(bs.get(j)); + } return this; } @@ -4326,11 +5589,21 @@ public Trace pStackStackItemStamp4(final Bytes b) { filled.set(171); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemStamp4 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemStamp4.put((byte) 0); } - stackItemStamp4.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemStamp4.put(bs.get(j)); + } return this; } @@ -4342,11 +5615,21 @@ public Trace pStackStackItemValueHi1(final Bytes b) { filled.set(172); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueHi1 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueHi1.put((byte) 0); } - stackItemValueHi1.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueHi1.put(bs.get(j)); + } return this; } @@ -4358,11 +5641,21 @@ public Trace pStackStackItemValueHi2(final Bytes b) { filled.set(173); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueHi2 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueHi2.put((byte) 0); } - stackItemValueHi2.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueHi2.put(bs.get(j)); + } return this; } @@ -4374,11 +5667,21 @@ public Trace pStackStackItemValueHi3(final Bytes b) { filled.set(174); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueHi3 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueHi3.put((byte) 0); } - stackItemValueHi3.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueHi3.put(bs.get(j)); + } return this; } @@ -4390,11 +5693,21 @@ public Trace pStackStackItemValueHi4(final Bytes b) { filled.set(175); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueHi4 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueHi4.put((byte) 0); } - stackItemValueHi4.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueHi4.put(bs.get(j)); + } return this; } @@ -4406,11 +5719,21 @@ public Trace pStackStackItemValueLo1(final Bytes b) { filled.set(176); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueLo1 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueLo1.put((byte) 0); } - stackItemValueLo1.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueLo1.put(bs.get(j)); + } return this; } @@ -4422,11 +5745,21 @@ public Trace pStackStackItemValueLo2(final Bytes b) { filled.set(177); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueLo2 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueLo2.put((byte) 0); } - stackItemValueLo2.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueLo2.put(bs.get(j)); + } return this; } @@ -4438,11 +5771,21 @@ public Trace pStackStackItemValueLo3(final Bytes b) { filled.set(178); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueLo3 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueLo3.put((byte) 0); } - stackItemValueLo3.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueLo3.put(bs.get(j)); + } return this; } @@ -4454,11 +5797,21 @@ public Trace pStackStackItemValueLo4(final Bytes b) { filled.set(179); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 256) { + throw new IllegalArgumentException( + "stackItemValueLo4 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 32; i++) { stackItemValueLo4.put((byte) 0); } - stackItemValueLo4.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stackItemValueLo4.put(bs.get(j)); + } return this; } @@ -4494,8 +5847,20 @@ public Trace pStackStaticGas(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum has invalid value (" + + b + + ")"); + } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) b); return this; } @@ -4579,8 +5944,20 @@ public Trace pStorageAddressHi(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum has invalid value (" + + b + + ")"); + } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) b); return this; } @@ -4592,13 +5969,25 @@ public Trace pStorageAddressLo(final Bytes b) { filled.set(131); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put(bs.get(j)); + } return this; } @@ -4610,8 +5999,20 @@ public Trace pStorageDeploymentNumber(final long b) { filled.set(107); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize has invalid value (" + + b + + ")"); + } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 24)); codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + .put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) b); return this; } @@ -4623,8 +6024,20 @@ public Trace pStorageDeploymentNumberInfty(final long b) { filled.set(108); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi has invalid value (" + + b + + ")"); + } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 16)); codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + .put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) b); return this; } @@ -4636,13 +6049,25 @@ public Trace pStorageStorageKeyHi(final Bytes b) { filled.set(132); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + bs.get(j)); + } return this; } @@ -4654,13 +6079,25 @@ public Trace pStorageStorageKeyLo(final Bytes b) { filled.set(133); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + bs.get(j)); + } return this; } @@ -4711,12 +6148,23 @@ public Trace pStorageValueCurrHi(final Bytes b) { filled.set(134); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); + } return this; } @@ -4754,11 +6202,23 @@ public Trace pStorageValueCurrLo(final Bytes b) { filled.set(135); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiNewXorExpData5XorValueCurrLoXorValue has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(bs.get(j)); + } return this; } @@ -4770,11 +6230,21 @@ public Trace pStorageValueNextHi(final Bytes b) { filled.set(136); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashLoXorMmuLimb1XorValueNextHi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashLoXorMmuLimb1XorValueNextHi.put((byte) 0); } - codeHashLoXorMmuLimb1XorValueNextHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashLoXorMmuLimb1XorValueNextHi.put(bs.get(j)); + } return this; } @@ -4825,11 +6295,21 @@ public Trace pStorageValueNextLo(final Bytes b) { filled.set(137); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashLoNewXorMmuLimb2XorValueNextLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashLoNewXorMmuLimb2XorValueNextLo.put((byte) 0); } - codeHashLoNewXorMmuLimb2XorValueNextLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashLoNewXorMmuLimb2XorValueNextLo.put(bs.get(j)); + } return this; } @@ -4841,11 +6321,23 @@ public Trace pStorageValueOrigHi(final Bytes b) { filled.set(138); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put((byte) 0); } - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.put(bs.get(j)); + } return this; } @@ -4870,11 +6362,23 @@ public Trace pStorageValueOrigLo(final Bytes b) { filled.set(139); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put((byte) 0); } - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.put(bs.get(j)); + } return this; } @@ -4912,11 +6416,21 @@ public Trace pTransactionBasefee(final Bytes b) { filled.set(122); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "nonceXorStpGasMxpXorBasefee has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { nonceXorStpGasMxpXorBasefee.put((byte) 0); } - nonceXorStpGasMxpXorBasefee.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + nonceXorStpGasMxpXorBasefee.put(bs.get(j)); + } return this; } @@ -4928,8 +6442,20 @@ public Trace pTransactionBatchNum(final long b) { filled.set(106); } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum - .putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum has invalid value (" + + b + + ")"); + } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum.put( + (byte) b); return this; } @@ -4941,8 +6467,20 @@ public Trace pTransactionCallDataSize(final long b) { filled.set(107); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize has invalid value (" + + b + + ")"); + } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize + .put((byte) (b >> 8)); codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize - .putLong(b); + .put((byte) b); return this; } @@ -4954,8 +6492,20 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { filled.set(108); } + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi has invalid value (" + + b + + ")"); + } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) (b >> 16)); codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi - .putLong(b); + .put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi + .put((byte) b); return this; } @@ -4967,13 +6517,25 @@ public Trace pTransactionCoinbaseAddressLo(final Bytes b) { filled.set(131); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .put((byte) 0); } - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo + .put(bs.get(j)); + } return this; } @@ -4998,7 +6560,19 @@ public Trace pTransactionFromAddressHi(final long b) { filled.set(109); } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi has invalid value (" + + b + + ")"); + } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put( + (byte) (b >> 8)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.put((byte) b); return this; } @@ -5010,13 +6584,25 @@ public Trace pTransactionFromAddressLo(final Bytes b) { filled.set(132); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( (byte) 0); } - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( + bs.get(j)); + } return this; } @@ -5028,11 +6614,23 @@ public Trace pTransactionGasInitiallyAvailable(final Bytes b) { filled.set(123); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(bs.get(j)); + } return this; } @@ -5044,11 +6642,21 @@ public Trace pTransactionGasLeftover(final Bytes b) { filled.set(124); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "stpGasUpfrontGasCostXorGasLeftover has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); } - stpGasUpfrontGasCostXorGasLeftover.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + stpGasUpfrontGasCostXorGasLeftover.put(bs.get(j)); + } return this; } @@ -5060,11 +6668,20 @@ public Trace pTransactionGasLimit(final Bytes b) { filled.set(125); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException("gasLimit has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { gasLimit.put((byte) 0); } - gasLimit.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + gasLimit.put(bs.get(j)); + } return this; } @@ -5076,11 +6693,20 @@ public Trace pTransactionGasPrice(final Bytes b) { filled.set(126); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException("gasPrice has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { gasPrice.put((byte) 0); } - gasPrice.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + gasPrice.put(bs.get(j)); + } return this; } @@ -5092,7 +6718,19 @@ public Trace pTransactionInitCodeSize(final long b) { filled.set(110); } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize has invalid value (" + + b + + ")"); + } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put( + (byte) (b >> 8)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.put((byte) b); return this; } @@ -5104,13 +6742,25 @@ public Trace pTransactionInitialBalance(final Bytes b) { filled.set(133); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( (byte) 0); } - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( + bs.get(j)); + } return this; } @@ -5148,11 +6798,20 @@ public Trace pTransactionNonce(final Bytes b) { filled.set(127); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException("nonce has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { nonce.put((byte) 0); } - nonce.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + nonce.put(bs.get(j)); + } return this; } @@ -5164,11 +6823,21 @@ public Trace pTransactionPriorityFeePerGas(final Bytes b) { filled.set(128); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "priorityFeePerGas has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { priorityFeePerGas.put((byte) 0); } - priorityFeePerGas.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + priorityFeePerGas.put(bs.get(j)); + } return this; } @@ -5180,11 +6849,21 @@ public Trace pTransactionRefundCounterInfinity(final Bytes b) { filled.set(129); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "refundCounterInfinity has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { refundCounterInfinity.put((byte) 0); } - refundCounterInfinity.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + refundCounterInfinity.put(bs.get(j)); + } return this; } @@ -5196,11 +6875,21 @@ public Trace pTransactionRefundEffective(final Bytes b) { filled.set(130); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 64) { + throw new IllegalArgumentException( + "refundEffective has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 8; i++) { refundEffective.put((byte) 0); } - refundEffective.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + refundEffective.put(bs.get(j)); + } return this; } @@ -5238,7 +6927,20 @@ public Trace pTransactionToAddressHi(final long b) { filled.set(111); } - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException( + "deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi has invalid value (" + + b + + ")"); + } + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 24)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 16)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) (b >> 8)); + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.put( + (byte) b); return this; } @@ -5250,12 +6952,23 @@ public Trace pTransactionToAddressLo(final Bytes b) { filled.set(134); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put( - b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); + } return this; } @@ -5267,11 +6980,23 @@ public Trace pTransactionValue(final Bytes b) { filled.set(135); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "codeHashHiNewXorExpData5XorValueCurrLoXorValue has invalid width (" + + bs.bitLength() + + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { codeHashHiNewXorExpData5XorValueCurrLoXorValue.put((byte) 0); } - codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + codeHashHiNewXorExpData5XorValueCurrLoXorValue.put(bs.get(j)); + } return this; } @@ -5367,7 +7092,13 @@ public Trace programCounter(final long b) { filled.set(35); } - programCounter.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("programCounter has invalid value (" + b + ")"); + } + programCounter.put((byte) (b >> 24)); + programCounter.put((byte) (b >> 16)); + programCounter.put((byte) (b >> 8)); + programCounter.put((byte) b); return this; } @@ -5379,7 +7110,13 @@ public Trace programCounterNew(final long b) { filled.set(36); } - programCounterNew.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("programCounterNew has invalid value (" + b + ")"); + } + programCounterNew.put((byte) (b >> 24)); + programCounterNew.put((byte) (b >> 16)); + programCounterNew.put((byte) (b >> 8)); + programCounterNew.put((byte) b); return this; } @@ -5391,7 +7128,13 @@ public Trace refundCounter(final long b) { filled.set(37); } - refundCounter.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("refundCounter has invalid value (" + b + ")"); + } + refundCounter.put((byte) (b >> 24)); + refundCounter.put((byte) (b >> 16)); + refundCounter.put((byte) (b >> 8)); + refundCounter.put((byte) b); return this; } @@ -5403,7 +7146,13 @@ public Trace refundCounterNew(final long b) { filled.set(38); } - refundCounterNew.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("refundCounterNew has invalid value (" + b + ")"); + } + refundCounterNew.put((byte) (b >> 24)); + refundCounterNew.put((byte) (b >> 16)); + refundCounterNew.put((byte) (b >> 8)); + refundCounterNew.put((byte) b); return this; } @@ -5439,7 +7188,13 @@ public Trace subStamp(final long b) { filled.set(39); } - subStamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("subStamp has invalid value (" + b + ")"); + } + subStamp.put((byte) (b >> 24)); + subStamp.put((byte) (b >> 16)); + subStamp.put((byte) (b >> 8)); + subStamp.put((byte) b); return this; } @@ -6305,7 +8060,7 @@ public Trace validateRow() { public Trace fillAndValidateRow() { if (!filled.get(0)) { - absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 4); + absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 2); } if (!filled.get(46)) { @@ -6321,7 +8076,7 @@ public Trace fillAndValidateRow() { .position( addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum .position() - + 8); + + 4); } if (!filled.get(131)) { @@ -6329,7 +8084,7 @@ public Trace fillAndValidateRow() { .position( addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .position() - + 32); + + 16); } if (!filled.get(101)) { @@ -6341,7 +8096,7 @@ public Trace fillAndValidateRow() { .position( balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance .position() - + 32); + + 16); } if (!filled.get(132)) { @@ -6349,19 +8104,19 @@ public Trace fillAndValidateRow() { .position( balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo .position() - + 32); + + 16); } if (!filled.get(1)) { - batchNumber.position(batchNumber.position() + 4); + batchNumber.position(batchNumber.position() + 2); } if (!filled.get(114)) { - callDataOffsetXorMmuSize.position(callDataOffsetXorMmuSize.position() + 8); + callDataOffsetXorMmuSize.position(callDataOffsetXorMmuSize.position() + 4); } if (!filled.get(115)) { - callDataSizeXorMmuSrcId.position(callDataSizeXorMmuSrcId.position() + 8); + callDataSizeXorMmuSrcId.position(callDataSizeXorMmuSrcId.position() + 4); } if (!filled.get(105)) { @@ -6369,11 +8124,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(2)) { - callerContextNumber.position(callerContextNumber.position() + 8); + callerContextNumber.position(callerContextNumber.position() + 4); } if (!filled.get(3)) { - codeFragmentIndex.position(codeFragmentIndex.position() + 8); + codeFragmentIndex.position(codeFragmentIndex.position() + 4); } if (!filled.get(107)) { @@ -6381,34 +8136,34 @@ public Trace fillAndValidateRow() { .position( codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize .position() - + 8); + + 4); } if (!filled.get(135)) { codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( - codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 32); + codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 16); } if (!filled.get(134)) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() - + 32); + + 16); } if (!filled.get(137)) { codeHashLoNewXorMmuLimb2XorValueNextLo.position( - codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 32); + codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 16); } if (!filled.get(136)) { codeHashLoXorMmuLimb1XorValueNextHi.position( - codeHashLoXorMmuLimb1XorValueNextHi.position() + 32); + codeHashLoXorMmuLimb1XorValueNextHi.position() + 16); } if (!filled.get(109)) { codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() - + 8); + + 4); } if (!filled.get(108)) { @@ -6416,7 +8171,7 @@ public Trace fillAndValidateRow() { .position( codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi .position() - + 8); + + 4); } if (!filled.get(48)) { @@ -6436,19 +8191,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(6)) { - contextNumber.position(contextNumber.position() + 8); + contextNumber.position(contextNumber.position() + 4); } if (!filled.get(7)) { - contextNumberNew.position(contextNumberNew.position() + 8); + contextNumberNew.position(contextNumberNew.position() + 4); } if (!filled.get(116)) { - contextNumberXorMmuTgtId.position(contextNumberXorMmuTgtId.position() + 8); + contextNumberXorMmuTgtId.position(contextNumberXorMmuTgtId.position() + 4); } if (!filled.get(8)) { - contextRevertStamp.position(contextRevertStamp.position() + 8); + contextRevertStamp.position(contextRevertStamp.position() + 4); } if (!filled.get(9)) { @@ -6460,7 +8215,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(11)) { - counterNsr.position(counterNsr.position() + 2); + counterNsr.position(counterNsr.position() + 1); } if (!filled.get(12)) { @@ -6500,18 +8255,18 @@ public Trace fillAndValidateRow() { deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi .position() - + 8); + + 4); } if (!filled.get(112)) { deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 8); + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 4); } if (!filled.get(110)) { deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() - + 8); + + 4); } if (!filled.get(53)) { @@ -6539,7 +8294,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(13)) { - domStamp.position(domStamp.position() + 8); + domStamp.position(domStamp.position() + 4); } if (!filled.get(14)) { @@ -6562,27 +8317,27 @@ public Trace fillAndValidateRow() { } if (!filled.get(15)) { - gasActual.position(gasActual.position() + 8); + gasActual.position(gasActual.position() + 4); } if (!filled.get(16)) { - gasCost.position(gasCost.position() + 32); + gasCost.position(gasCost.position() + 8); } if (!filled.get(17)) { - gasExpected.position(gasExpected.position() + 8); + gasExpected.position(gasExpected.position() + 4); } if (!filled.get(125)) { - gasLimit.position(gasLimit.position() + 32); + gasLimit.position(gasLimit.position() + 8); } if (!filled.get(18)) { - gasNext.position(gasNext.position() + 8); + gasNext.position(gasNext.position() + 4); } if (!filled.get(126)) { - gasPrice.position(gasPrice.position() + 32); + gasPrice.position(gasPrice.position() + 8); } if (!filled.get(58)) { @@ -6599,7 +8354,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(19)) { - hashInfoStamp.position(hashInfoStamp.position() + 8); + hashInfoStamp.position(hashInfoStamp.position() + 4); } if (!filled.get(20)) { @@ -6611,11 +8366,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(22)) { - hubStamp.position(hubStamp.position() + 8); + hubStamp.position(hubStamp.position() + 4); } if (!filled.get(23)) { - hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 8); + hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 4); } if (!filled.get(163)) { @@ -6631,7 +8386,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(24)) { - logInfoStamp.position(logInfoStamp.position() + 8); + logInfoStamp.position(logInfoStamp.position() + 4); } if (!filled.get(61)) { @@ -6651,39 +8406,39 @@ public Trace fillAndValidateRow() { } if (!filled.get(25)) { - mmuStamp.position(mmuStamp.position() + 8); + mmuStamp.position(mmuStamp.position() + 4); } if (!filled.get(144)) { - mxpOffset2Hi.position(mxpOffset2Hi.position() + 32); + mxpOffset2Hi.position(mxpOffset2Hi.position() + 16); } if (!filled.get(145)) { - mxpOffset2Lo.position(mxpOffset2Lo.position() + 32); + mxpOffset2Lo.position(mxpOffset2Lo.position() + 16); } if (!filled.get(146)) { - mxpSize1Hi.position(mxpSize1Hi.position() + 32); + mxpSize1Hi.position(mxpSize1Hi.position() + 16); } if (!filled.get(147)) { - mxpSize1Lo.position(mxpSize1Lo.position() + 32); + mxpSize1Lo.position(mxpSize1Lo.position() + 16); } if (!filled.get(148)) { - mxpSize2Hi.position(mxpSize2Hi.position() + 32); + mxpSize2Hi.position(mxpSize2Hi.position() + 16); } if (!filled.get(149)) { - mxpSize2Lo.position(mxpSize2Lo.position() + 32); + mxpSize2Lo.position(mxpSize2Lo.position() + 16); } if (!filled.get(26)) { - mxpStamp.position(mxpStamp.position() + 8); + mxpStamp.position(mxpStamp.position() + 4); } if (!filled.get(150)) { - mxpWords.position(mxpWords.position() + 32); + mxpWords.position(mxpWords.position() + 16); } if (!filled.get(103)) { @@ -6695,52 +8450,52 @@ public Trace fillAndValidateRow() { } if (!filled.get(27)) { - nonStackRows.position(nonStackRows.position() + 2); + nonStackRows.position(nonStackRows.position() + 1); } if (!filled.get(127)) { - nonce.position(nonce.position() + 32); + nonce.position(nonce.position() + 8); } if (!filled.get(123)) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 32); + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 8); } if (!filled.get(122)) { - nonceXorStpGasMxpXorBasefee.position(nonceXorStpGasMxpXorBasefee.position() + 32); + nonceXorStpGasMxpXorBasefee.position(nonceXorStpGasMxpXorBasefee.position() + 8); } if (!filled.get(151)) { - oobData1.position(oobData1.position() + 32); + oobData1.position(oobData1.position() + 16); } if (!filled.get(152)) { - oobData2.position(oobData2.position() + 32); + oobData2.position(oobData2.position() + 16); } if (!filled.get(153)) { - oobData3.position(oobData3.position() + 32); + oobData3.position(oobData3.position() + 16); } if (!filled.get(154)) { - oobData4.position(oobData4.position() + 32); + oobData4.position(oobData4.position() + 16); } if (!filled.get(155)) { - oobData5.position(oobData5.position() + 32); + oobData5.position(oobData5.position() + 16); } if (!filled.get(156)) { - oobData6.position(oobData6.position() + 32); + oobData6.position(oobData6.position() + 16); } if (!filled.get(157)) { - oobData7.position(oobData7.position() + 32); + oobData7.position(oobData7.position() + 16); } if (!filled.get(158)) { - oobData8.position(oobData8.position() + 32); + oobData8.position(oobData8.position() + 16); } if (!filled.get(28)) { @@ -6825,52 +8580,52 @@ public Trace fillAndValidateRow() { } if (!filled.get(128)) { - priorityFeePerGas.position(priorityFeePerGas.position() + 32); + priorityFeePerGas.position(priorityFeePerGas.position() + 8); } if (!filled.get(35)) { - programCounter.position(programCounter.position() + 8); + programCounter.position(programCounter.position() + 4); } if (!filled.get(36)) { - programCounterNew.position(programCounterNew.position() + 8); + programCounterNew.position(programCounterNew.position() + 4); } if (!filled.get(37)) { - refundCounter.position(refundCounter.position() + 8); + refundCounter.position(refundCounter.position() + 4); } if (!filled.get(129)) { - refundCounterInfinity.position(refundCounterInfinity.position() + 32); + refundCounterInfinity.position(refundCounterInfinity.position() + 8); } if (!filled.get(38)) { - refundCounterNew.position(refundCounterNew.position() + 8); + refundCounterNew.position(refundCounterNew.position() + 4); } if (!filled.get(130)) { - refundEffective.position(refundEffective.position() + 32); + refundEffective.position(refundEffective.position() + 8); } if (!filled.get(117)) { - returnAtCapacityXorMxpInst.position(returnAtCapacityXorMxpInst.position() + 8); + returnAtCapacityXorMxpInst.position(returnAtCapacityXorMxpInst.position() + 4); } if (!filled.get(118)) { - returnAtOffsetXorOobInst.position(returnAtOffsetXorOobInst.position() + 8); + returnAtOffsetXorOobInst.position(returnAtOffsetXorOobInst.position() + 4); } if (!filled.get(119)) { returnDataContextNumberXorStpGasStipend.position( - returnDataContextNumberXorStpGasStipend.position() + 8); + returnDataContextNumberXorStpGasStipend.position() + 4); } if (!filled.get(120)) { - returnDataOffsetXorStpInstruction.position(returnDataOffsetXorStpInstruction.position() + 8); + returnDataOffsetXorStpInstruction.position(returnDataOffsetXorStpInstruction.position() + 4); } if (!filled.get(121)) { - returnDataSize.position(returnDataSize.position() + 8); + returnDataSize.position(returnDataSize.position() + 4); } if (!filled.get(86)) { @@ -6909,12 +8664,12 @@ public Trace fillAndValidateRow() { if (!filled.get(113)) { rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 8); + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 4); } if (!filled.get(138)) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 32); + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 16); } if (!filled.get(62)) { @@ -6925,11 +8680,11 @@ public Trace fillAndValidateRow() { if (!filled.get(139)) { rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( - rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 32); + rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 16); } if (!filled.get(140)) { - rlpaddrKecLoXorMmuTgtOffsetLo.position(rlpaddrKecLoXorMmuTgtOffsetLo.position() + 32); + rlpaddrKecLoXorMmuTgtOffsetLo.position(rlpaddrKecLoXorMmuTgtOffsetLo.position() + 16); } if (!filled.get(63)) { @@ -6938,11 +8693,11 @@ public Trace fillAndValidateRow() { } if (!filled.get(141)) { - rlpaddrSaltHiXorMxpGasMxp.position(rlpaddrSaltHiXorMxpGasMxp.position() + 32); + rlpaddrSaltHiXorMxpGasMxp.position(rlpaddrSaltHiXorMxpGasMxp.position() + 16); } if (!filled.get(142)) { - rlpaddrSaltLoXorMxpOffset1Hi.position(rlpaddrSaltLoXorMxpOffset1Hi.position() + 32); + rlpaddrSaltLoXorMxpOffset1Hi.position(rlpaddrSaltLoXorMxpOffset1Hi.position() + 16); } if (!filled.get(64)) { @@ -7042,28 +8797,28 @@ public Trace fillAndValidateRow() { } if (!filled.get(159)) { - stpGasHi.position(stpGasHi.position() + 32); + stpGasHi.position(stpGasHi.position() + 16); } if (!filled.get(160)) { - stpGasLo.position(stpGasLo.position() + 32); + stpGasLo.position(stpGasLo.position() + 16); } if (!filled.get(124)) { stpGasUpfrontGasCostXorGasLeftover.position( - stpGasUpfrontGasCostXorGasLeftover.position() + 32); + stpGasUpfrontGasCostXorGasLeftover.position() + 8); } if (!filled.get(161)) { - stpValueHi.position(stpValueHi.position() + 32); + stpValueHi.position(stpValueHi.position() + 16); } if (!filled.get(162)) { - stpValueLo.position(stpValueLo.position() + 32); + stpValueLo.position(stpValueLo.position() + 16); } if (!filled.get(39)) { - subStamp.position(subStamp.position() + 8); + subStamp.position(subStamp.position() + 4); } if (!filled.get(97)) { @@ -7080,7 +8835,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(143)) { - trmRawAddressHiXorMxpOffset1Lo.position(trmRawAddressHiXorMxpOffset1Lo.position() + 32); + trmRawAddressHiXorMxpOffset1Lo.position(trmRawAddressHiXorMxpOffset1Lo.position() + 16); } if (!filled.get(40)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java similarity index 100% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java new file mode 100644 index 0000000000..1a6b6938c5 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -0,0 +1,19 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.create; + +public class CreateSection { +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java new file mode 100644 index 0000000000..64003c1410 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java @@ -0,0 +1,19 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.create; + +public class StaticException { +} From d761b1e95dacde1ba63a3e4f0613130d83fd676f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 17 Jul 2024 09:24:39 +0200 Subject: [PATCH 228/461] fix(sstore): calling OOB directly calling the OOB instruction directly as opposed to calling it through the "forOpcode" method Note: forOpcode uses signals under the hood, which ought to disappear --- .../linea/zktracer/module/hub/section/SstoreSection.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index adefd20872..2d80f1741a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -22,6 +22,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobCall; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -72,8 +73,10 @@ public SstoreSection(Hub hub, WorldView world) { } // MISC fragment - ImcFragment miscForSstore = ImcFragment.forOpcode(hub, hub.messageFrame()); + ImcFragment miscForSstore = ImcFragment.empty(hub); this.addFragment(miscForSstore); + + miscForSstore.callOob(new SstoreOobCall()); if (sstoreException) { return; From d0217d8da64be6634794afbd0be44807d9f189f4 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 17 Jul 2024 17:07:37 +0530 Subject: [PATCH 229/461] feat(create): wip --- .../linea/zktracer/module/hub/Hub.java | 6 +- .../scenario/CreateScenarioFragment.java | 59 +++++++ .../hub/fragment/scenario/ScenarioEnum.java | 27 +++- .../fragment/scenario/ScenarioFragment.java | 33 ++-- .../module/hub/section/CreateSectionOld.java | 12 +- .../hub/section/create/CreateSection.java | 147 ++++++++++++++++++ .../section/create/CreateSectionStaticX.java | 19 --- 7 files changed, 257 insertions(+), 46 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index e82cb1d975..8ab5f7c198 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -57,6 +57,7 @@ import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; import net.consensys.linea.zktracer.module.hub.section.copy.*; +import net.consensys.linea.zktracer.module.hub.section.create.CreateSection; import net.consensys.linea.zktracer.module.hub.section.halt.RevertSection; import net.consensys.linea.zktracer.module.hub.section.halt.StopSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; @@ -1152,6 +1153,7 @@ void traceOperation(MessageFrame frame) { } case CREATE -> { + new CreateSection(this); final Address myAddress = this.currentFrame().accountAddress(); final Account myAccount = frame.getWorldUpdater().get(myAddress); AccountSnapshot myAccountSnapshot = @@ -1170,8 +1172,8 @@ void traceOperation(MessageFrame frame) { this.transients.conflation().deploymentInfo().number(createdAddress), this.transients.conflation().deploymentInfo().isDeploying(createdAddress)); - CreateSection createSection = - new CreateSection(this, myAccountSnapshot, createdAccountSnapshot); + CreateSectionOld createSection = + new CreateSectionOld(this, myAccountSnapshot, createdAccountSnapshot); this.addTraceSection(createSection); this.currentFrame().needsUnlatchingAtReEntry(createSection); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java new file mode 100644 index 0000000000..cd6af3dcb9 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java @@ -0,0 +1,59 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment.scenario; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; + +import com.google.common.base.Preconditions; +import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; + +@Setter +public class CreateScenarioFragment implements TraceFragment { + + ScenarioEnum scenario; + + public CreateScenarioFragment() { + this.scenario = ScenarioEnum.UNDEFINED; + } + + @Override + public Trace trace(Trace trace) { + Preconditions.checkArgument(this.scenario.isCreate()); + return trace + .peekAtScenario(true) + // CREATE scenarios + //////////////////// + .pScenarioCreateException(scenario == ScenarioEnum.CREATE_EXCEPTION) + .pScenarioCreateAbort(scenario == ScenarioEnum.CREATE_ABORT) + .pScenarioCreateFailureConditionWillRevert( + scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT) + .pScenarioCreateFailureConditionWontRevert( + scenario == ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT) + .pScenarioCreateEmptyInitCodeWillRevert( + scenario == ScenarioEnum.CREATE_EMPTY_INIT_CODE_WILL_REVERT) + .pScenarioCreateEmptyInitCodeWontRevert( + scenario == ScenarioEnum.CREATE_EMPTY_INIT_CODE_WONT_REVERT) + .pScenarioCreateNonemptyInitCodeFailureWillRevert( + scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT) + .pScenarioCreateNonemptyInitCodeFailureWontRevert( + scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT) + .pScenarioCreateNonemptyInitCodeSuccessWillRevert( + scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT) + .pScenarioCreateNonemptyInitCodeSuccessWontRevert( + scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java index 9042a5f51c..462588032a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java @@ -15,10 +15,21 @@ package net.consensys.linea.zktracer.module.hub.fragment.scenario; public enum ScenarioEnum { + /** unset values, to be defined */ + UNDEFINED, /** scenarios related to CALL-type instructions */ CALL, /** scenarios related to CREATE(2) instructions */ - CREATE, + CREATE_EXCEPTION, + CREATE_ABORT, + CREATE_FAILURE_CONDITION_WILL_REVERT, + CREATE_FAILURE_CONDITION_WONT_REVERT, + CREATE_EMPTY_INIT_CODE_WILL_REVERT, + CREATE_EMPTY_INIT_CODE_WONT_REVERT, + CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT, + CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT, + CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT, + CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT, /** scenarios related to RETURN */ RETURN, RETURN_EXCEPTION, @@ -41,8 +52,18 @@ boolean isPrecompile() { return this == PRECOMPILE; } - boolean isCreate() { - return this == CREATE; + public boolean isCreate() { + return this.isAnyOf( + CREATE_EXCEPTION, + CREATE_ABORT, + CREATE_FAILURE_CONDITION_WILL_REVERT, + CREATE_FAILURE_CONDITION_WONT_REVERT, + CREATE_EMPTY_INIT_CODE_WILL_REVERT, + CREATE_EMPTY_INIT_CODE_WONT_REVERT, + CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT, + CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT, + CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT, + CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT); } boolean isReturn() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 90ccd96afb..e460d4e60c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -81,7 +81,7 @@ public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { public static ScenarioFragment forCreate(final Hub hub, boolean targetHasCode) { return new ScenarioFragment( Optional.empty(), - ScenarioEnum.CREATE, + ScenarioEnum.CREATE_EXCEPTION, // this is wrong, but all will be deleted targetHasCode, hub.currentFrame().id(), hub.callStack().futureId(), @@ -274,20 +274,23 @@ && targetIsPrecompile() && !targetIsPrecompile() && !targetHasCode && callerReverts) - .pScenarioCreateException(type.isCreate() && raisedException) - .pScenarioCreateAbort(type.isCreate() && hasAborted) - .pScenarioCreateFailureConditionWillRevert(type.isCreate() && hasFailed && callerReverts) - .pScenarioCreateFailureConditionWontRevert(type.isCreate() && hasFailed && !callerReverts) - .pScenarioCreateEmptyInitCodeWillRevert(type.isCreate() && !targetHasCode && callerReverts) - .pScenarioCreateEmptyInitCodeWontRevert(type.isCreate() && !targetHasCode && !callerReverts) - .pScenarioCreateNonemptyInitCodeFailureWillRevert( - type.isCreate() && targetHasCode && creationFailed() && callerReverts) - .pScenarioCreateNonemptyInitCodeFailureWontRevert( - type.isCreate() && targetHasCode && creationFailed() && !callerReverts) - .pScenarioCreateNonemptyInitCodeSuccessWillRevert( - type.isCreate() && targetHasCode && !creationFailed() && callerReverts) - .pScenarioCreateNonemptyInitCodeSuccessWontRevert( - type.isCreate() && targetHasCode && !creationFailed() && !callerReverts) + // .pScenarioCreateException(type.isCreate() && raisedException) + // .pScenarioCreateAbort(type.isCreate() && hasAborted) + // .pScenarioCreateFailureConditionWillRevert(type.isCreate() && hasFailed && callerReverts) + // .pScenarioCreateFailureConditionWontRevert(type.isCreate() && hasFailed && + // !callerReverts) + // .pScenarioCreateEmptyInitCodeWillRevert(type.isCreate() && !targetHasCode && + // callerReverts) + // .pScenarioCreateEmptyInitCodeWontRevert(type.isCreate() && !targetHasCode && + // !callerReverts) + // .pScenarioCreateNonemptyInitCodeFailureWillRevert( + // type.isCreate() && targetHasCode && creationFailed() && callerReverts) + // .pScenarioCreateNonemptyInitCodeFailureWontRevert( + // type.isCreate() && targetHasCode && creationFailed() && !callerReverts) + // .pScenarioCreateNonemptyInitCodeSuccessWillRevert( + // type.isCreate() && targetHasCode && !creationFailed() && callerReverts) + // .pScenarioCreateNonemptyInitCodeSuccessWontRevert( + // type.isCreate() && targetHasCode && !creationFailed() && !callerReverts) .pScenarioPrcEcrecover( precompileCall.map(x -> x.precompile().equals(Precompile.EC_RECOVER)).orElse(false)) .pScenarioPrcSha2256( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java index f1f3e3977e..f09b63ad72 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java @@ -28,7 +28,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; @@ -40,7 +39,7 @@ import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldView; -public class CreateSection extends TraceSection +public class CreateSectionOld extends TraceSection implements PostExecDefer, NextContextDefer, PostTransactionDefer, ReEnterContextDefer { private final int creatorContextId; private final boolean emptyInitCode; @@ -49,7 +48,6 @@ public class CreateSection extends TraceSection private final AbortingConditions aborts; private final short exceptions; private final FailureConditions failures; - private final ScenarioFragment scenarioFragment; // Just before create private final AccountSnapshot oldCreatorSnapshot; @@ -70,7 +68,7 @@ private boolean targetHasCode() { return !oldCreatedSnapshot.code().isEmpty(); } - public CreateSection( + public CreateSectionOld( Hub hub, AccountSnapshot oldCreatorSnapshot, AccountSnapshot oldCreatedSnapshot) { super(hub); this.creatorContextId = hub.currentFrame().id(); @@ -84,7 +82,7 @@ public CreateSection( this.oldCreatorSnapshot = oldCreatorSnapshot; this.oldCreatedSnapshot = oldCreatedSnapshot; - this.scenarioFragment = ScenarioFragment.forCreate(hub, this.targetHasCode()); + // this.scenarioFragment = ScenarioFragment.forCreate(hub, this.targetHasCode()); this.addStack(hub); @@ -170,8 +168,8 @@ public void resolvePostTransaction( // 0)) ; - this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); - this.addFragmentsWithoutStack(scenarioFragment); + // this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); + // this.addFragmentsWithoutStack(scenarioFragment); if (Exceptions.staticFault(this.exceptions)) { this.addFragmentsWithoutStack( ImcFragment.empty(hub), diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 1a6b6938c5..47bf742f18 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -15,5 +15,152 @@ package net.consensys.linea.zktracer.module.hub.section.create; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.frame.MessageFrame; + public class CreateSection { + + private int creatorContextId; + private boolean emptyInitCode; + + // Just before create + private AccountSnapshot oldCreatorSnapshot; + private AccountSnapshot oldCreatedSnapshot; + + // Just after create but before entering child frame + private AccountSnapshot midCreatorSnapshot; + private AccountSnapshot midCreatedSnapshot; + + // After return from child-context + private AccountSnapshot newCreatorSnapshot; + private AccountSnapshot newCreatedSnapshot; + + private boolean createSuccessful; + + /* true if the putatively created account already has code **/ + + private boolean targetHasCode() { + return !oldCreatedSnapshot.code().isEmpty(); + } + + // row i+ 0 + private final CreateScenarioFragment scenarioFragment = new CreateScenarioFragment(); + // row i+2 + private final ImcFragment imcFragment; + + public CreateSection(Hub hub) { + final short exception = hub.pch().exceptions(); + + final ContextFragment commonContext = ContextFragment.readCurrentContextData(hub); + imcFragment = ImcFragment.empty(hub); + + if (Exceptions.staticFault(exception)) { + new ExceptionalCreate(hub, commonContext); + return; + } + + final MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + + if (Exceptions.memoryExpansionException(exception)) { + new ExceptionalCreate(hub, commonContext); + return; + } + + final StpCall stpCall = new StpCall(hub, mxpCall.getGasMxp()); + stpCall.stpCallForCreates(hub); + imcFragment.callStp(stpCall); + + if (Exceptions.outOfGasException(exception)) { + new ExceptionalCreate(hub, commonContext); + return; + } + + final OobCall oobCall = new CreateOobCall(); + imcFragment.callOob(oobCall); + + // We are now with unexceptional create + final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); + this.creatorContextId = hub.currentFrame().id(); + this.emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); + + final CallFrame callFrame = hub.currentFrame(); + final MessageFrame frame = callFrame.frame(); + + final Address creatorAddress = callFrame.accountAddress(); + final Account creatorAccount = frame.getWorldUpdater().get(creatorAddress); + oldCreatorSnapshot = + AccountSnapshot.fromAccount( + creatorAccount, + frame.isAddressWarm(creatorAddress), + hub.transients().conflation().deploymentInfo().number(creatorAddress), + hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); + + if (aborts.any()) { + new AbortCreate(hub, commonContext); + return; + } + + // We are now with unexceptional, non-aborting create + final FailureConditions failures = hub.pch().failureConditions().snapshot(); + + // final Address createdAddress = getCreateAddress(frame); + // final Account createdAccount = frame.getWorldUpdater().get(createdAddress); + // oldCreatedSnapshot = + // AccountSnapshot.fromAccount( + // createdAccount, + // frame.isAddressWarm(createdAddress), + // hub.transients().conflation().deploymentInfo().number(createdAddress), + // hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + + } + + private class ExceptionalCreate extends TraceSection { + public ExceptionalCreate(final Hub hub, final ContextFragment commonContext) { + super(hub, (short) 6); + hub.addTraceSection(this); + + scenarioFragment.setScenario(ScenarioEnum.CREATE_EXCEPTION); + + this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); + } + } + + private class AbortCreate extends TraceSection { + public AbortCreate(final Hub hub, final ContextFragment commonContext) { + super(hub, (short) 7); + hub.addTraceSection(this); + + scenarioFragment.setScenario(ScenarioEnum.CREATE_ABORT); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + final AccountFragment creatorAccountFragment = + accountFragmentFactory.make( + oldCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + + this.addFragmentsAndStack( + hub, scenarioFragment, commonContext, imcFragment, creatorAccountFragment); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java deleted file mode 100644 index 64003c1410..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSectionStaticX.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.create; - -public class StaticException { -} From 44191cf75fa05d7c30a153badd5b171945a52411 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 17 Jul 2024 14:32:25 +0200 Subject: [PATCH 230/461] feat(selfdestruct): partially handled --- .../hub/fragment/scenario/ScenarioEnum.java | 15 ++- .../SelfdestructScenarioFragment.java | 118 ++++++++++++++++++ .../hub/section/halt/SelfdestructSection.java | 75 +++++++++++ 3 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java index 462588032a..248844fd29 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java @@ -40,7 +40,11 @@ public enum ScenarioEnum { RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT, RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT, /** scenarios related to SELFDESTRUCT */ - SELFDESTRUCT, + SELFDESTRUCT, // duplicated logic? + SELFDESTRUCT_EXCEPTION, + SELFDESTRUCT_WILL_REVERT, + SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED, + SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED, /** describes the second scenario line required by a call to a precompile */ PRECOMPILE; @@ -77,6 +81,15 @@ boolean isReturn() { RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); } + boolean isSelfDestruct() { + return this.isAnyOf( + SELFDESTRUCT, + SELFDESTRUCT_EXCEPTION, + SELFDESTRUCT_WILL_REVERT, + SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED, + SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED); + } + public boolean isAnyOf(ScenarioEnum... scenarios) { for (ScenarioEnum scenario : scenarios) { if (scenario.equals(this)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java new file mode 100644 index 0000000000..644f29fbea --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java @@ -0,0 +1,118 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment.scenario; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.SelfdestructScenarioFragment.SelfdestructScenario.UNDEFINED; + +import com.google.common.base.Preconditions; +import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; + +@Setter +public class SelfdestructScenarioFragment implements TraceFragment { + + SelfdestructScenario scenario; + + public SelfdestructScenarioFragment() { + this.scenario = UNDEFINED; + } + + public enum SelfdestructScenario { + UNDEFINED, + SELFDESTRUCT_EXCEPTION, + SELFDESTRUCT_WILL_REVERT, + SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED, + SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED + } + + @Override + public Trace trace(Trace trace) { + Preconditions.checkArgument(!this.scenario.equals(UNDEFINED)); + return trace + .peekAtScenario(true) + // // CALL scenarios + //////////////////// + // .pScenarioCallException(false) + // .pScenarioCallAbort(false) + // .pScenarioCallPrcFailure(false) + // .pScenarioCallPrcSuccessCallerWillRevert(false) + // .pScenarioCallPrcSuccessCallerWontRevert(false) + // .pScenarioCallSmcFailureCallerWillRevert(false) + // .pScenarioCallSmcFailureCallerWontRevert(false) + // .pScenarioCallSmcSuccessCallerWontRevert(false) + // .pScenarioCallSmcSuccessCallerWillRevert(false) + // .pScenarioCallEoaSuccessCallerWontRevert(false) + // .pScenarioCallEoaSuccessCallerWillRevert(false) + // // CREATE scenarios + ////////////////////// + // .pScenarioCreateException(false) .pScenarioCreateAbort(false) + // .pScenarioCreateFailureConditionWillRevert(false) + // .pScenarioCreateFailureConditionWontRevert(false) + // .pScenarioCreateEmptyInitCodeWillRevert(false) + // .pScenarioCreateEmptyInitCodeWontRevert(false) + // .pScenarioCreateNonemptyInitCodeFailureWillRevert(false) + // .pScenarioCreateNonemptyInitCodeFailureWontRevert(false) + // .pScenarioCreateNonemptyInitCodeSuccessWillRevert(false) + // .pScenarioCreateNonemptyInitCodeSuccessWontRevert(false) + // // PRECOMPILE CALL scenarios + /////////////////////////////// + // .pScenarioPrcEcrecover(false) + // .pScenarioPrcSha2256(false) + // .pScenarioPrcRipemd160(false) + // .pScenarioPrcIdentity(false) + // .pScenarioPrcModexp(false) + // .pScenarioPrcEcadd(false) + // .pScenarioPrcEcmul(false) + // .pScenarioPrcEcpairing(false) + // .pScenarioPrcBlake2F(false) + // .pScenarioPrcSuccessCallerWillRevert(false) + // .pScenarioPrcSuccessCallerWontRevert(false) + // .pScenarioPrcFailureKnownToHub(false) + // .pScenarioPrcFailureKnownToRam(false) + // .pScenarioPrcCallerGas(0) + // .pScenarioPrcCalleeGas(0) + // .pScenarioPrcReturnGas(0) + // .pScenarioPrcCdo(0) + // .pScenarioPrcCds(0) + // .pScenarioPrcRao(0) + // .pScenarioPrcRac(0) + // RETURN scenarios + /////////////////// + // .pScenarioReturnException(this.scenario.equals(RETURN_EXCEPTION)) + // .pScenarioReturnFromMessageCallWillTouchRam( + // this.scenario.equals(RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM)) + // .pScenarioReturnFromMessageCallWontTouchRam( + // this.scenario.equals(RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM)) + // .pScenarioReturnFromDeploymentEmptyCodeWillRevert( + // this.scenario.equals(RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT)) + // .pScenarioReturnFromDeploymentEmptyCodeWontRevert( + // this.scenario.equals(RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT)) + // .pScenarioReturnFromDeploymentNonemptyCodeWillRevert( + // this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT)) + // .pScenarioReturnFromDeploymentNonemptyCodeWontRevert( + // this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT)) + // // SELFDESTRUCT scenarios + //////////////////////////// + .pScenarioSelfdestructException( + this.scenario.equals(SelfdestructScenario.SELFDESTRUCT_EXCEPTION)) + .pScenarioSelfdestructWillRevert( + this.scenario.equals(SelfdestructScenario.SELFDESTRUCT_WILL_REVERT)) + .pScenarioSelfdestructWontRevertAlreadyMarked( + this.scenario.equals(SelfdestructScenario.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED)) + .pScenarioSelfdestructWontRevertNotYetMarked( + this.scenario.equals(SelfdestructScenario.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED)); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java new file mode 100644 index 0000000000..bc2cc09893 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -0,0 +1,75 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section.halt; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.SelfdestructScenarioFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class SelfdestructSection extends TraceSection implements PostTransactionDefer { + + public SelfdestructSection(Hub hub) { + // up to 8 = 1 + 7 rows + super(hub, (short) 8); + hub.addTraceSection(this); + + short exceptions = hub.pch().exceptions(); + + // STATICX case + // SCN fragment + SelfdestructScenarioFragment selfdestructScenarioFragment = new SelfdestructScenarioFragment(); + this.addFragment(selfdestructScenarioFragment); + + // CON fragment (1) + ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); + this.addFragment(contextFragment); + + if (Exceptions.staticFault(exceptions)) { + return; + } + + // OOGX case + // ACC fragment (1) + AccountFragment accountFragment1 = null; + this.addFragment(accountFragment1); + + // ACC fragment (2) + AccountFragment accountFragment2 = null; + this.addFragment(accountFragment2); + + if (Exceptions.outOfGasException(exceptions)) { + return; + } + + // From now on everything is deferred + boolean willRevert = hub.callStack().frames().getLast().willRevert(); // ? + + boolean wontRevertAlreadyMarked; + + boolean wontRevertNotYetMarked; + + // TODO: look at EXTCODECOPY, RETURN, ACCOUNT + } + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} +} From f5c0fd4df3288e72a786b3ae12eac2de0e1092d6 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 17 Jul 2024 16:23:46 +0200 Subject: [PATCH 231/461] feat(selfdestruct): made some progress with implementation and added comments --- .../module/hub/section/SstoreSection.java | 2 +- .../hub/section/halt/SelfdestructSection.java | 112 +++++++++++++++--- 2 files changed, 96 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 2d80f1741a..df4e06ac5c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -75,7 +75,7 @@ public SstoreSection(Hub hub, WorldView world) { // MISC fragment ImcFragment miscForSstore = ImcFragment.empty(hub); this.addFragment(miscForSstore); - + miscForSstore.callOob(new SstoreOobCall()); if (sstoreException) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index bc2cc09893..466df6e612 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -14,17 +14,25 @@ */ package net.consensys.linea.zktracer.module.hub.section.halt; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.SelfdestructScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; -public class SelfdestructSection extends TraceSection implements PostTransactionDefer { +public class SelfdestructSection extends TraceSection + implements PostRollbackDefer, PostTransactionDefer { + + AccountFragment selfDestroyerFirstAccountFragment; + AccountFragment recipientFirstAccountFragment; public SelfdestructSection(Hub hub) { // up to 8 = 1 + 7 rows @@ -33,43 +41,113 @@ public SelfdestructSection(Hub hub) { short exceptions = hub.pch().exceptions(); - // STATICX case - // SCN fragment SelfdestructScenarioFragment selfdestructScenarioFragment = new SelfdestructScenarioFragment(); + // SCN fragment this.addFragment(selfdestructScenarioFragment); + if (Exceptions.any(exceptions)) { + selfdestructScenarioFragment.setScenario( + SelfdestructScenarioFragment.SelfdestructScenario.SELFDESTRUCT_EXCEPTION); + } // CON fragment (1) ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); this.addFragment(contextFragment); + // STATICX case if (Exceptions.staticFault(exceptions)) { return; } // OOGX case - // ACC fragment (1) - AccountFragment accountFragment1 = null; - this.addFragment(accountFragment1); + if (Exceptions.any(exceptions)) { + Preconditions.checkArgument(exceptions == Exceptions.OUT_OF_GAS_EXCEPTION); - // ACC fragment (2) - AccountFragment accountFragment2 = null; - this.addFragment(accountFragment2); + // ACC fragment (1) + selfDestroyerFirstAccountFragment = null; + /* + Use current account and see if it has balance or not: + hub.factories() + .accountFragment() + .makeWithTrm( + this.accountBefore, this.accountBefore, this.rawAddress, TODOdoingDomSubStamps); + */ + this.addFragment(selfDestroyerFirstAccountFragment); // i+2 - if (Exceptions.outOfGasException(exceptions)) { - return; - } + // ACC fragment (2) + recipientFirstAccountFragment = null; + /* + Account recipient of the SELFDESTRUCT + See EXTCODECOPY for an example of how to create an AccountFragment: + hub.factories() + .accountFragment() + .makeWithTrm( + this.accountBefore, this.accountBefore, this.rawAddress, TODOdoingDomSubStamps); + We do not modify accounts in exception cases, otherwise we do + */ + this.addFragment(recipientFirstAccountFragment); // i+3 - // From now on everything is deferred - boolean willRevert = hub.callStack().frames().getLast().willRevert(); // ? + return; + } - boolean wontRevertAlreadyMarked; + // Unexceptional case (add CON row in the end manually in any case) + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + hub.defers().schedulePostTransaction(this); - boolean wontRevertNotYetMarked; + // Modify the current account and the recipient account + // - The current account has its balance reduced to 0 (i+2) + // * selfDestroyerFirstAccountFragment + // - The recipient account, if it is not the current account, receive that balance (+= balance), + // otherwise remains 0 (i+3) + // - The recipient address will become warm (i+3) + // * recipientFirstAccountFragment // TODO: look at EXTCODECOPY, RETURN, ACCOUNT } + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + /* willRevert case + TODO: undo the modifications we applied to selfDestroyerFirstAccountFragment and recipientFirstAccountFragment + this will add account rows + */ + } + @Override public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + // will not revert (sub cases: already marked, not yet marked) + // not yet marked corresponds to when SELFDESTRUCT produces no exceptions, will not be reverted + // and it + // is the first time this account will be succeseful in self destructing + // already marked corresponds to when SELFDESTRUCT produces no exceptions, will not be reverted + // and it + // is not the first time this account will be successful in self destructing + // mark for self destruct is associated to an address and a deployment number + // use a maps that keeps track the (hub stamp, call frame) of all the unexceptional + // SELFDESTRUCT for a given (address, deployment number) + // at the end of the transaction we have that map + // we analyse that map: + // for every (address, deployment number) we walk through the list of [(hub stamp, call frame), + // ...] + // for every call frame we know if it was reverted or not + // the first time (selfDestructTime) we find a call frame that has not been reverted, we + // remember the hub stamp + // this produces a new map (address, deployment number) -> selfDestructTime (of the first + // succeseful and unreverted + // SELFDESTRUCT) + // we know have a map of all (addresse, deployment number) that have been succeseful in self + // destructing + // and the hub stamp in which it happened + // for every account row in the entire trace, we can now decide what to write in the + // MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW columns + // MARKED_FOR_SELFDESTRUCT = [hub stamp < selfDestructTime] + // MARKED_FOR_SELFDESTRUCT_NEW = [hub stamp >= selfDestructTime] + + // This will only be triggered at the hub stamp = selfDestructTime + // i+4 for not yet marked case + // we wipe the entire account + // in the already marked case we know that this action has already been scheduled for the future + + // every transaction should start with an empty map + } } From cf4c8ef1b50c06e47bbeb4c878a07dc08ffcc838 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 17 Jul 2024 18:29:04 +0200 Subject: [PATCH 232/461] ras --- .../hub/section/halt/SelfdestructSection.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 466df6e612..bc96cc1709 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -98,16 +98,17 @@ public SelfdestructSection(Hub hub) { // * selfDestroyerFirstAccountFragment // - The recipient account, if it is not the current account, receive that balance (+= balance), // otherwise remains 0 (i+3) + // * recipientFirstAccountFragment // - The recipient address will become warm (i+3) // * recipientFirstAccountFragment - // TODO: look at EXTCODECOPY, RETURN, ACCOUNT + // take a look at EXTCODECOPY, RETURN, ACCOUNT for reference } @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { /* willRevert case - TODO: undo the modifications we applied to selfDestroyerFirstAccountFragment and recipientFirstAccountFragment + undo the modifications we applied to selfDestroyerFirstAccountFragment and recipientFirstAccountFragment this will add account rows */ } @@ -115,14 +116,14 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - // will not revert (sub cases: already marked, not yet marked) - // not yet marked corresponds to when SELFDESTRUCT produces no exceptions, will not be reverted - // and it - // is the first time this account will be succeseful in self destructing - // already marked corresponds to when SELFDESTRUCT produces no exceptions, will not be reverted - // and it - // is not the first time this account will be successful in self destructing - // mark for self destruct is associated to an address and a deployment number + // will not revert (subcases: already marked, not yet marked) + // - not yet marked corresponds to when SELFDESTRUCT produces no exceptions, will not be + // reverted + // ,and it is the first time this account will be successful in self-destructing + // - already marked corresponds to when SELFDESTRUCT produces no exceptions, will not be + // reverted + // ,and it is not the first time this account will be successful in self-destructing + // mark for self-destructing is associated to an address and a deployment number // use a maps that keeps track the (hub stamp, call frame) of all the unexceptional // SELFDESTRUCT for a given (address, deployment number) // at the end of the transaction we have that map @@ -133,10 +134,10 @@ public void resolvePostTransaction( // the first time (selfDestructTime) we find a call frame that has not been reverted, we // remember the hub stamp // this produces a new map (address, deployment number) -> selfDestructTime (of the first - // succeseful and unreverted + // successful and un-reverted // SELFDESTRUCT) - // we know have a map of all (addresse, deployment number) that have been succeseful in self - // destructing + // we know have a map of all (address, deployment number) that have been successful in + // self-destructing // and the hub stamp in which it happened // for every account row in the entire trace, we can now decide what to write in the // MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW columns From 86573ec0d6a4518c73d0b0ca6f3fcd1a695dc484 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 18 Jul 2024 12:50:40 +0200 Subject: [PATCH 233/461] feat(selfdestruct): managed STATICX and OOGX cases --- .../hub/section/halt/SelfdestructSection.java | 98 +++++++++++++++---- 1 file changed, 79 insertions(+), 19 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index bc96cc1709..fd2b9e80ce 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -15,22 +15,45 @@ package net.consensys.linea.zktracer.module.hub.section.halt; import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.SelfdestructScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; public class SelfdestructSection extends TraceSection implements PostRollbackDefer, PostTransactionDefer { + final short exceptions; + + final Address address; + final int incomingDeploymentNumber; + final boolean incomingDeploymentStatus; + final boolean incomingWarmth; + AccountSnapshot accountBefore; + // AccountSnapshot accountAfter; + + final Bytes recipientRawAddress; + final Address recipientAddress; + final int recipientIncomingDeploymentNumber; + final boolean recipientIncomingDeploymentStatus; + final boolean recipientIncomingWarmth; + AccountSnapshot recipientAccountBefore; + // AccountSnapshot recipientAccountAfter; + AccountFragment selfDestroyerFirstAccountFragment; AccountFragment recipientFirstAccountFragment; @@ -39,7 +62,42 @@ public SelfdestructSection(Hub hub) { super(hub, (short) 8); hub.addTraceSection(this); - short exceptions = hub.pch().exceptions(); + // Init + this.exceptions = hub.pch().exceptions(); + + final MessageFrame frame = hub.messageFrame(); + + // Account + this.address = frame.getSenderAddress(); // TODO: is this correct? + this.incomingDeploymentNumber = + hub.transients().conflation().deploymentInfo().number(this.address); + this.incomingDeploymentStatus = + hub.transients().conflation().deploymentInfo().isDeploying(this.address); + this.incomingWarmth = frame.isAddressWarm(this.address); + final Account accountAccount = frame.getWorldUpdater().get(this.address); + this.accountBefore = + AccountSnapshot.fromAccount( + accountAccount, + this.incomingWarmth, + this.incomingDeploymentNumber, + this.incomingDeploymentStatus); + + // Recipient + this.recipientRawAddress = frame.getStackItem(0); + this.recipientAddress = Address.extract((Bytes32) this.recipientRawAddress); + this.recipientIncomingDeploymentNumber = + hub.transients().conflation().deploymentInfo().number(this.recipientAddress); + this.recipientIncomingDeploymentStatus = + hub.transients().conflation().deploymentInfo().isDeploying(this.recipientAddress); + this.recipientIncomingWarmth = frame.isAddressWarm(this.recipientAddress); + final Account recipientAccount = frame.getWorldUpdater().get(this.recipientAddress); + this.recipientAccountBefore = + AccountSnapshot.fromAccount( + recipientAccount, + this.recipientIncomingWarmth, + this.recipientIncomingDeploymentNumber, + this.recipientIncomingDeploymentStatus); + // SelfdestructScenarioFragment selfdestructScenarioFragment = new SelfdestructScenarioFragment(); // SCN fragment @@ -63,27 +121,29 @@ public SelfdestructSection(Hub hub) { Preconditions.checkArgument(exceptions == Exceptions.OUT_OF_GAS_EXCEPTION); // ACC fragment (1) - selfDestroyerFirstAccountFragment = null; - /* - Use current account and see if it has balance or not: - hub.factories() - .accountFragment() - .makeWithTrm( - this.accountBefore, this.accountBefore, this.rawAddress, TODOdoingDomSubStamps); - */ + selfDestroyerFirstAccountFragment = + hub.factories() + .accountFragment() + .make( + this.accountBefore, + this.accountBefore, + // this.accountAddress, no need to explicitly pass the address? + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + + // TODO: check if the account has balance or not + this.addFragment(selfDestroyerFirstAccountFragment); // i+2 // ACC fragment (2) - recipientFirstAccountFragment = null; - /* - Account recipient of the SELFDESTRUCT - See EXTCODECOPY for an example of how to create an AccountFragment: - hub.factories() - .accountFragment() - .makeWithTrm( - this.accountBefore, this.accountBefore, this.rawAddress, TODOdoingDomSubStamps); - We do not modify accounts in exception cases, otherwise we do - */ + recipientFirstAccountFragment = + hub.factories() + .accountFragment() + .makeWithTrm( + this.recipientAccountBefore, + this.recipientAccountBefore, + this.recipientRawAddress, + DomSubStampsSubFragment.standardDomSubStamps(hub, 1)); + this.addFragment(recipientFirstAccountFragment); // i+3 return; From 96afdf72d8e660477162f1e0e3cc7295188bf6eb Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 18 Jul 2024 17:27:08 +0530 Subject: [PATCH 234/461] feat(create): still wip --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../hub/fragment/DomSubStampsSubFragment.java | 4 + .../module/hub/fragment/TraceSubFragment.java | 3 - .../hub/fragment/account/AccountFragment.java | 13 +- .../fragment/account/RlpAddrSubFragment.java | 57 ++++++ .../fragment/imc/call/mmu/opcode/Create2.java | 7 + .../scenario/CreateScenarioFragment.java | 9 +- .../hub/section/create/AbortCreate.java | 53 ++++++ .../hub/section/create/CreateSection.java | 165 +++++++++++++----- .../hub/section/create/ExceptionalCreate.java | 36 ++++ .../create/FailureOrEmptyInitCreate.java | 116 ++++++++++++ .../hub/section/create/FillCreateSection.java | 42 +++++ .../create/NonEmptyInitCodeCreate.java | 40 +++++ .../hub/section/halt/ReturnSection.java | 12 +- 14 files changed, 490 insertions(+), 69 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 8ab5f7c198..78385fecee 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1028,7 +1028,6 @@ void processStateExec(MessageFrame frame) { } this.traceOperation(frame); } else { - this.addTraceSection(new StackOnlySection(this)); } } @@ -1154,6 +1153,7 @@ void traceOperation(MessageFrame frame) { case CREATE -> { new CreateSection(this); + final Address myAddress = this.currentFrame().accountAddress(); final Account myAccount = frame.getWorldUpdater().get(myAddress); AccountSnapshot myAccountSnapshot = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java index 6d771090d9..390707f182 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java @@ -43,6 +43,10 @@ public static DomSubStampsSubFragment standardDomSubStamps(final Hub hub, final return new DomSubStampsSubFragment(DomSubType.STANDARD, hub.stamp(), domOffset, 0, 0, 0, 0); } + public static DomSubStampsSubFragment standardDomSubStamps(final int h, final int domOffset) { + return new DomSubStampsSubFragment(DomSubType.STANDARD, h, domOffset, 0, 0, 0, 0); + } + public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( final Hub hub, final int subOffset) { return new DomSubStampsSubFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java index 5e167ce150..2b5c15dfa2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TraceSubFragment.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.hub.fragment; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; @@ -27,6 +26,4 @@ default Trace trace(Trace trace) { default Trace trace(Trace trace, State.TxState.Stamps stamps) { return trace(trace); } - - default void postConflationRetcon(final Hub hub) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 0847c0513a..7b5615f143 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -55,6 +55,7 @@ public final class AccountFragment private int codeFragmentIndex; private final Optional addressToTrim; private final DomSubStampsSubFragment domSubStampsSubFragment; + @Setter private RlpAddrSubFragment rlpAddrSubFragment; /** * {@link AccountFragment} creation requires access to a {@link DeferRegistry} for post-conflation @@ -107,6 +108,7 @@ public Trace trace(Trace trace) { // tracing this.domSubStampsSubFragment.trace(trace); + this.rlpAddrSubFragment.trace(trace); return trace .peekAtAccount(true) @@ -146,16 +148,7 @@ public Trace trace(Trace trace) { .pAccountDeploymentStatusInfty(existsInfinity) .pAccountTrmFlag(this.addressToTrim.isPresent()) .pAccountTrmRawAddressHi(this.addressToTrim.map(a -> EWord.of(a).hi()).orElse(Bytes.EMPTY)) - .pAccountIsPrecompile(isPrecompile(oldState.address())) - .pAccountRlpaddrFlag(false) // TODO - .pAccountRlpaddrRecipe(false) // TODO - .pAccountRlpaddrDepAddrHi(0) // TODO - .pAccountRlpaddrDepAddrLo(Bytes.EMPTY) // TODO - .pAccountRlpaddrSaltHi(Bytes.EMPTY) // TODO - .pAccountRlpaddrSaltLo(Bytes.EMPTY) // TODO - .pAccountRlpaddrKecHi(Bytes.EMPTY) // TODO - .pAccountRlpaddrKecLo(Bytes.EMPTY) // TODO - ; + .pAccountIsPrecompile(isPrecompile(oldState.address())); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java new file mode 100644 index 0000000000..d7eb7aa137 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java @@ -0,0 +1,57 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.fragment.account; + +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; +import static net.consensys.linea.zktracer.types.AddressUtils.highPart; +import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; + +import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.datatypes.Address; + +@RequiredArgsConstructor +public class RlpAddrSubFragment implements TraceSubFragment { + private final short recipe; + private final Address depAddress; + private final Bytes32 salt; + private final Bytes32 keccak; + + public static RlpAddrSubFragment rlpAddrSubFragmentForCreate2( + final Address depAddress, final Bytes32 Salt, final Bytes32 Keccak) { + return new RlpAddrSubFragment((short) 2, depAddress, Salt, Keccak); + } + + public static RlpAddrSubFragment rlpAddrSubFragmentForCreate(final Address depAddress) { + return new RlpAddrSubFragment( + (short) 1, depAddress, (Bytes32) Bytes32.EMPTY, (Bytes32) Bytes32.EMPTY); + } + + @Override + public Trace trace(Trace trace) { + return trace + .pAccountRlpaddrFlag(true) + .pAccountRlpaddrRecipe(recipe == 2) + .pAccountRlpaddrDepAddrHi(highPart(depAddress)) + .pAccountRlpaddrDepAddrLo(lowPart(depAddress)) + .pAccountRlpaddrSaltHi(salt.slice(0, LLARGE)) + .pAccountRlpaddrSaltLo(salt.slice(LLARGE, LLARGE)) + .pAccountRlpaddrKecHi(keccak.slice(0, LLARGE)) + .pAccountRlpaddrKecLo(keccak.slice(LLARGE, LLARGE)); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java index 7d666744b8..029e6fd36d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java @@ -17,6 +17,8 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING; +import java.util.Optional; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; @@ -38,6 +40,11 @@ public Create2(final Hub hub) { this.hub.romLex().createDefers().register(this); this.sourceId(hub.currentFrame().contextNumber()) + .sourceRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .auxId(hub.state().stamps().hub()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(2))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java index cd6af3dcb9..d71b359ff2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java @@ -17,26 +17,29 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; import com.google.common.base.Preconditions; +import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -@Setter public class CreateScenarioFragment implements TraceFragment { - ScenarioEnum scenario; + @Setter @Getter private ScenarioEnum scenario; public CreateScenarioFragment() { this.scenario = ScenarioEnum.UNDEFINED; } + public CreateScenarioFragment(ScenarioEnum scenario) { + this.scenario = scenario; + } + @Override public Trace trace(Trace trace) { Preconditions.checkArgument(this.scenario.isCreate()); return trace .peekAtScenario(true) // CREATE scenarios - //////////////////// .pScenarioCreateException(scenario == ScenarioEnum.CREATE_EXCEPTION) .pScenarioCreateAbort(scenario == ScenarioEnum.CREATE_ABORT) .pScenarioCreateFailureConditionWillRevert( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java new file mode 100644 index 0000000000..3785047783 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java @@ -0,0 +1,53 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.create; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_ABORT; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +class AbortCreate extends TraceSection { + public AbortCreate( + final Hub hub, + final ContextFragment commonContext, + final ImcFragment imcFragment, + final AccountSnapshot oldCreatorSnapshot) { + super(hub, (short) 7); + hub.addTraceSection(this); + + final CreateScenarioFragment scenarioFragment = new CreateScenarioFragment(CREATE_ABORT); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + final AccountFragment creatorAccountFragment = + accountFragmentFactory.make( + oldCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + + final ContextFragment contextFragment = ContextFragment.nonExecutionEmptyReturnData(hub); + + this.addFragmentsAndStack( + hub, scenarioFragment, commonContext, imcFragment, creatorAccountFragment, contextFragment); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 47bf742f18..812c43a09d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -15,28 +15,37 @@ package net.consensys.linea.zktracer.module.hub.section.create; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_EMPTY_INIT_CODE_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT; +import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; + import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; +import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.operation.Operation; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class CreateSection { +public class CreateSection implements PostExecDefer, ReEnterContextDefer, PostTransactionDefer { + private FillCreateSection createSection; + private boolean failure; private int creatorContextId; private boolean emptyInitCode; @@ -56,24 +65,27 @@ public class CreateSection { private boolean createSuccessful; /* true if the putatively created account already has code **/ - private boolean targetHasCode() { return !oldCreatedSnapshot.code().isEmpty(); } - // row i+ 0 - private final CreateScenarioFragment scenarioFragment = new CreateScenarioFragment(); // row i+2 private final ImcFragment imcFragment; + private MmuCall mmuCall; + + // row i+ ? + private ContextFragment lastContextFragment; public CreateSection(Hub hub) { final short exception = hub.pch().exceptions(); + // row i +1 final ContextFragment commonContext = ContextFragment.readCurrentContextData(hub); + imcFragment = ImcFragment.empty(hub); if (Exceptions.staticFault(exception)) { - new ExceptionalCreate(hub, commonContext); + new ExceptionalCreate(hub, commonContext, imcFragment); return; } @@ -81,7 +93,7 @@ public CreateSection(Hub hub) { imcFragment.callMxp(mxpCall); if (Exceptions.memoryExpansionException(exception)) { - new ExceptionalCreate(hub, commonContext); + new ExceptionalCreate(hub, commonContext, imcFragment); return; } @@ -90,7 +102,7 @@ public CreateSection(Hub hub) { imcFragment.callStp(stpCall); if (Exceptions.outOfGasException(exception)) { - new ExceptionalCreate(hub, commonContext); + new ExceptionalCreate(hub, commonContext, imcFragment); return; } @@ -99,8 +111,6 @@ public CreateSection(Hub hub) { // We are now with unexceptional create final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); - this.creatorContextId = hub.currentFrame().id(); - this.emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); final CallFrame callFrame = hub.currentFrame(); final MessageFrame frame = callFrame.frame(); @@ -115,52 +125,115 @@ public CreateSection(Hub hub) { hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); if (aborts.any()) { - new AbortCreate(hub, commonContext); + new AbortCreate(hub, commonContext, imcFragment, oldCreatorSnapshot); return; } // We are now with unexceptional, non-aborting create - final FailureConditions failures = hub.pch().failureConditions().snapshot(); + hub.defers().schedulePostExecution(this); + hub.defers().reEntry(this); + hub.defers().schedulePostTransaction(this); - // final Address createdAddress = getCreateAddress(frame); - // final Account createdAccount = frame.getWorldUpdater().get(createdAddress); - // oldCreatedSnapshot = - // AccountSnapshot.fromAccount( - // createdAccount, - // frame.isAddressWarm(createdAddress), - // hub.transients().conflation().deploymentInfo().number(createdAddress), - // hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + final Address createdAddress = getCreateAddress(frame); + final Account createdAccount = frame.getWorldUpdater().get(createdAddress); + oldCreatedSnapshot = + AccountSnapshot.fromAccount( + createdAccount, + frame.isAddressWarm(createdAddress), + hub.transients().conflation().deploymentInfo().number(createdAddress), + hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + + failure = hub.pch().failureConditions().any(); + emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); + + if (failure || emptyInitCode) { + final ScenarioEnum scenario = + failure ? CREATE_FAILURE_CONDITION_WONT_REVERT : CREATE_EMPTY_INIT_CODE_WONT_REVERT; + this.createSection = new FailureOrEmptyInitCreate(hub, scenario, commonContext, imcFragment); + this.lastContextFragment = ContextFragment.nonExecutionEmptyReturnData(hub); + if (hub.opCode() == OpCode.CREATE2 && !emptyInitCode) { + this.mmuCall = MmuCall.create2(hub); + } + return; + } + // Finally, non-exceptional, non-aborting, non-failing, non-emptyInitCode create + this.createSection = new NonEmptyInitCodeCreate(hub, commonContext, imcFragment); } - private class ExceptionalCreate extends TraceSection { - public ExceptionalCreate(final Hub hub, final ContextFragment commonContext) { - super(hub, (short) 6); - hub.addTraceSection(this); - - scenarioFragment.setScenario(ScenarioEnum.CREATE_EXCEPTION); + @Override + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + final Address creatorAddress = oldCreatorSnapshot.address(); + this.midCreatorSnapshot = + AccountSnapshot.fromAccount( + frame.getWorldUpdater().get(creatorAddress), + true, + hub.transients().conflation().deploymentInfo().number(creatorAddress), + hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); - this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); - } + final Address createdAddress = oldCreatedSnapshot.address(); + this.midCreatedSnapshot = + AccountSnapshot.fromAccount( + frame.getWorldUpdater().get(createdAddress), + true, + hub.transients().conflation().deploymentInfo().number(createdAddress), + hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + + // Pre-emptively set new* snapshots in case we never enter the child frame. + // Will be overwritten if we enter the child frame and runNextContext is explicitly called by + // the defer registry. + this.resolveAtContextReEntry(hub, frame); } - private class AbortCreate extends TraceSection { - public AbortCreate(final Hub hub, final ContextFragment commonContext) { - super(hub, (short) 7); - hub.addTraceSection(this); + @Override + public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { + this.createSuccessful = !frame.getStackItem(0).isZero(); + + final Address creatorAddress = oldCreatorSnapshot.address(); + this.newCreatorSnapshot = + AccountSnapshot.fromAccount( + frame.getWorldUpdater().get(creatorAddress), + true, + hub.transients().conflation().deploymentInfo().number(creatorAddress), + hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); - scenarioFragment.setScenario(ScenarioEnum.CREATE_ABORT); + final Address createdAddress = oldCreatedSnapshot.address(); + this.newCreatedSnapshot = + AccountSnapshot.fromAccount( + frame.getWorldUpdater().get(createdAddress), + true, + hub.transients().conflation().deploymentInfo().number(createdAddress), + hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + } - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - final AccountFragment creatorAccountFragment = - accountFragmentFactory.make( - oldCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (this.mmuCall != null) { + this.imcFragment.callMmu(this.mmuCall); + } - this.addFragmentsAndStack( - hub, scenarioFragment, commonContext, imcFragment, creatorAccountFragment); + this.createSection.fillAccountFragment( + hub, + oldCreatorSnapshot, + midCreatorSnapshot, + newCreatorSnapshot, + oldCreatedSnapshot, + midCreatedSnapshot, + newCreatedSnapshot); + + if (hub.callStack().getById(this.creatorContextId).hasReverted()) { + this.createSection.fillReverting( + hub, + oldCreatorSnapshot, + midCreatorSnapshot, + newCreatorSnapshot, + oldCreatedSnapshot, + midCreatedSnapshot, + newCreatedSnapshot); } + + this.createSection.fillContextFragment(this.lastContextFragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java new file mode 100644 index 0000000000..29dfd4ca4c --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java @@ -0,0 +1,36 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.create; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_EXCEPTION; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class ExceptionalCreate extends TraceSection { + public ExceptionalCreate( + final Hub hub, final ContextFragment commonContext, final ImcFragment imcFragment) { + super(hub, (short) 6); + hub.addTraceSection(this); + + final CreateScenarioFragment scenarioFragment = new CreateScenarioFragment(CREATE_EXCEPTION); + + this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java new file mode 100644 index 0000000000..b6a9141db1 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -0,0 +1,116 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.create; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_EMPTY_INIT_CODE_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class FailureOrEmptyInitCreate extends TraceSection implements FillCreateSection { + private final int hubStamp; + final CreateScenarioFragment scenarioFragment; + + public FailureOrEmptyInitCreate( + final Hub hub, + final ScenarioEnum scenario, + final ContextFragment commonContext, + final ImcFragment imcFragment) { + super(hub, (short) 10); + hub.addTraceSection(this); + + this.hubStamp = hub.stamp(); + + this.scenarioFragment = new CreateScenarioFragment(scenario); + + this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); + } + + @Override + public void fillAccountFragment( + Hub hub, + AccountSnapshot oldCreatorSnapshot, + AccountSnapshot midCreatorSnapshot, + AccountSnapshot newCreatorSnapshot, + AccountSnapshot oldCreatedSnapshot, + AccountSnapshot midCreatedSnapshot, + AccountSnapshot newCreatedSnapshot) { + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final AccountFragment creatorAccountFragment = + accountFragmentFactory.make( + oldCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps( + hubStamp, 0)); // TODO: RLP_ADDR subFragment + + final AccountFragment createdAccountFragment = + accountFragmentFactory.make( + oldCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 1)); + + this.addFragmentsWithoutStack(creatorAccountFragment, createdAccountFragment); + } + + @Override + public void fillReverting( + Hub hub, + AccountSnapshot oldCreatorSnapshot, + AccountSnapshot midCreatorSnapshot, + AccountSnapshot newCreatorSnapshot, + AccountSnapshot oldCreatedSnapshot, + AccountSnapshot midCreatedSnapshot, + AccountSnapshot newCreatedSnapshot) { + final ScenarioEnum newScenario = + this.scenarioFragment.getScenario() == CREATE_FAILURE_CONDITION_WONT_REVERT + ? CREATE_FAILURE_CONDITION_WILL_REVERT + : CREATE_EMPTY_INIT_CODE_WILL_REVERT; + this.scenarioFragment.setScenario(newScenario); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final AccountFragment undoCreatorAccountFragment = + accountFragmentFactory.make( + newCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 0)); // TODO domsub + + final AccountFragment undoCreatedAccountFragment = + accountFragmentFactory.make( + newCreatedSnapshot, + oldCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 1)); // TODO domsub + + this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); + } + + @Override + public void fillContextFragment(ContextFragment contextFragment) { + this.addFragment(contextFragment); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java new file mode 100644 index 0000000000..9fb28b0781 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java @@ -0,0 +1,42 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.create; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; + +public interface FillCreateSection { + void fillAccountFragment( + final Hub hub, + final AccountSnapshot oldCreatorSnapshot, + final AccountSnapshot midCreatorSnapshot, + final AccountSnapshot newCreatorSnapshot, + final AccountSnapshot oldCreatedSnapshot, + final AccountSnapshot midCreatedSnapshot, + final AccountSnapshot newCreatedSnapshot); + + void fillReverting( + final Hub hub, + final AccountSnapshot oldCreatorSnapshot, + final AccountSnapshot midCreatorSnapshot, + final AccountSnapshot newCreatorSnapshot, + final AccountSnapshot oldCreatedSnapshot, + final AccountSnapshot midCreatedSnapshot, + final AccountSnapshot newCreatedSnapshot); + + void fillContextFragment(final ContextFragment contextFragment); +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java new file mode 100644 index 0000000000..df9465be5b --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -0,0 +1,40 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.create; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class NonEmptyInitCodeCreate extends TraceSection implements FillCreateSection { + public NonEmptyInitCodeCreate( + final Hub hub, final ContextFragment commonContext, final ImcFragment imcFragment) { + super(hub, (short) 11); + hub.addTraceSection(this); + } + + @Override + public void fillAccountFragment( + Hub hub, + AccountSnapshot oldCreatorSnapshot, + AccountSnapshot midCreatorSnapshot, + AccountSnapshot newCreatorSnapshot, + AccountSnapshot oldCreatedSnapshot, + AccountSnapshot midCreatedSnapshot, + AccountSnapshot newCreatedSnapshot) {} +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 1658b002b8..5611ff2726 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -46,10 +46,10 @@ public ReturnSection(Hub hub) { exceptions = hub.pch().exceptions(); - ReturnScenarioFragment returnScenarioFragment = new ReturnScenarioFragment(); - ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); + final ReturnScenarioFragment returnScenarioFragment = new ReturnScenarioFragment(); + final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); imcFragment = ImcFragment.empty(hub); - MxpCall mxpCall = new MxpCall(hub); + final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); this.addStack(hub); @@ -73,12 +73,12 @@ public ReturnSection(Hub hub) { return; } - boolean triggerMmuForInvalidCodePrefix = Exceptions.invalidCodePrefix(exceptions); + final boolean triggerMmuForInvalidCodePrefix = Exceptions.invalidCodePrefix(exceptions); if (triggerMmuForInvalidCodePrefix) { - // mmuCall = MmuCall.invalidCodePrefix(); + // mmuCall = MmuCall.invalidCodePrefix(); TODO: } - boolean triggerOobForNonemptyDeployments = + final boolean triggerOobForNonemptyDeployments = Exceptions.none(exceptions) && hub.currentFrame().isDeployment() && mxpCall.isMayTriggerNonTrivialMmuOperation(); From bcf78254beb9e30f0fb0e6f9ee587d5c777723af Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 18 Jul 2024 15:49:29 +0200 Subject: [PATCH 235/461] fix: improve granularity of account snapshot --- .../zktracer/module/hub/AccountSnapshot.java | 35 +++++++++++++++---- .../hub/section/TxInitializationSection.java | 8 +++-- .../module/hub/transients/DeploymentInfo.java | 4 +++ .../linea/zktracer/testing/ToyWorld.java | 5 +++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index cbd8d4f447..e3844039f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -56,7 +56,8 @@ public static AccountSnapshot canonical(Hub hub, Address address) { public AccountSnapshot decrementBalance(Wei quantity) { Preconditions.checkState( this.balance.greaterOrEqualThan(quantity), - "Insufficient balance: %s".formatted(this.balance)); + "Insufficient balance\n Address: %s\n Balance: %s\n Value: %s" + .formatted(this.address, this.balance, quantity)); this.balance = this.balance.subtract(quantity); return this; } @@ -106,19 +107,41 @@ public static AccountSnapshot fromAccount( .orElseGet(() -> AccountSnapshot.empty(isWarm, deploymentNumber, deploymentStatus)); } - public AccountSnapshot debit(Wei quantity, boolean isWarm) { + public AccountSnapshot debit(Wei quantity) { return new AccountSnapshot( this.address, - this.nonce + 1, + this.nonce, this.balance.subtract(quantity), - isWarm, + this.isWarm, + this.code, + this.deploymentNumber, + this.deploymentStatus); + } + + public AccountSnapshot turnOnWarmth() { + return new AccountSnapshot( + this.address, + this.nonce, + this.balance, + true, + this.code, + this.deploymentNumber, + this.deploymentStatus); + } + + public AccountSnapshot raiseNonce() { + return new AccountSnapshot( + this.address, + this.nonce + 1, + this.balance, + this.isWarm, this.code, this.deploymentNumber, this.deploymentStatus); } // TODO: does this update the deployment number in the deploymentInfo object ? - public AccountSnapshot initiateDeployment(Wei value, Bytecode code) { + public AccountSnapshot initiateDeployment(Wei value, Bytecode code, int updatedDeploymentNumber) { Preconditions.checkState( !this.deploymentStatus, "Deployment status should be false before initiating a deployment."); @@ -128,7 +151,7 @@ public AccountSnapshot initiateDeployment(Wei value, Bytecode code) { this.balance.add(value), true, code, - this.deploymentNumber + 1, + updatedDeploymentNumber, true); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 922b63d2ae..2ebbec4e97 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -58,9 +58,10 @@ public TxInitializationSection(Hub hub, WorldView world) { final Wei transactionGasPrice = Wei.of(tx.getEffectiveGasPrice()); final Wei value = (Wei) tx.getBesuTransaction().getValue(); + final Wei valueAndGasCost = + transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value); final AccountSnapshot senderAfterPayingForTransaction = - senderBeforePayingForTransaction.debit( - transactionGasPrice.multiply(tx.getBesuTransaction().getGasLimit()).add(value), true); + senderBeforePayingForTransaction.debit(valueAndGasCost).turnOnWarmth().raiseNonce(); final boolean isSelfCredit = toAddress.equals(senderAddress); @@ -83,7 +84,8 @@ public TxInitializationSection(Hub hub, WorldView world) { new Bytecode(tx.getBesuTransaction().getInit().orElse(Bytes.EMPTY)); final AccountSnapshot recipientAfterValueTransfer = isDeployment - ? recipientBeforeValueTransfer.initiateDeployment(value, initBytecode) + ? recipientBeforeValueTransfer.initiateDeployment( + value, initBytecode, deploymentInfo.getDeploymentNumber(toAddress)) : recipientBeforeValueTransfer.credit(value, true); final DomSubStampsSubFragment recipientDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 1); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/DeploymentInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/DeploymentInfo.java index 5d32519547..ce94e57d85 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/DeploymentInfo.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/DeploymentInfo.java @@ -41,6 +41,10 @@ public void deploy(Address address) { this.markDeploying(address); } + public int getDeploymentNumber(Address address) { + return this.deploymentNumber.get(address); + } + public final boolean isDeploying(Address address) { return this.isDeploying.getOrDefault(address, false); } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java index b2b291526b..ac071a2266 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java @@ -55,6 +55,9 @@ private ToyWorld(final ToyWorld parent, @Singular final List account this.parent = parent; this.accounts = accounts; this.addressAccountMap = new HashMap<>(); + for (ToyAccount account : accounts) { + addressAccountMap.put(account.getAddress(), account); + } } public static ToyWorld empty() { @@ -104,6 +107,8 @@ public MutableAccount createAccount(final Address address, final long nonce, fin return createAccount(null, address, nonce, balance, Bytes.EMPTY); } + // Why are we not forced to override a method that allows us to also set the code for an account? + public MutableAccount createAccount( final Account parentAccount, final Address address, From 488f49d7e5f129c98e0b26596c69c14698dad0bb Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 18 Jul 2024 16:42:18 +0200 Subject: [PATCH 236/461] fix: simplified SELFDESTRUCT handling --- .../hub/section/halt/SelfdestructSection.java | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index fd2b9e80ce..43bad73171 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -30,7 +30,6 @@ import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -40,17 +39,11 @@ public class SelfdestructSection extends TraceSection final short exceptions; final Address address; - final int incomingDeploymentNumber; - final boolean incomingDeploymentStatus; - final boolean incomingWarmth; AccountSnapshot accountBefore; // AccountSnapshot accountAfter; final Bytes recipientRawAddress; final Address recipientAddress; - final int recipientIncomingDeploymentNumber; - final boolean recipientIncomingDeploymentStatus; - final boolean recipientIncomingWarmth; AccountSnapshot recipientAccountBefore; // AccountSnapshot recipientAccountAfter; @@ -68,35 +61,15 @@ public SelfdestructSection(Hub hub) { final MessageFrame frame = hub.messageFrame(); // Account - this.address = frame.getSenderAddress(); // TODO: is this correct? - this.incomingDeploymentNumber = - hub.transients().conflation().deploymentInfo().number(this.address); - this.incomingDeploymentStatus = - hub.transients().conflation().deploymentInfo().isDeploying(this.address); - this.incomingWarmth = frame.isAddressWarm(this.address); - final Account accountAccount = frame.getWorldUpdater().get(this.address); - this.accountBefore = - AccountSnapshot.fromAccount( - accountAccount, - this.incomingWarmth, - this.incomingDeploymentNumber, - this.incomingDeploymentStatus); + this.address = frame.getSenderAddress(); + // final Account accountAccount = frame.getWorldUpdater().get(this.address); + this.accountBefore = AccountSnapshot.canonical(hub, this.address); // Recipient this.recipientRawAddress = frame.getStackItem(0); this.recipientAddress = Address.extract((Bytes32) this.recipientRawAddress); - this.recipientIncomingDeploymentNumber = - hub.transients().conflation().deploymentInfo().number(this.recipientAddress); - this.recipientIncomingDeploymentStatus = - hub.transients().conflation().deploymentInfo().isDeploying(this.recipientAddress); - this.recipientIncomingWarmth = frame.isAddressWarm(this.recipientAddress); - final Account recipientAccount = frame.getWorldUpdater().get(this.recipientAddress); - this.recipientAccountBefore = - AccountSnapshot.fromAccount( - recipientAccount, - this.recipientIncomingWarmth, - this.recipientIncomingDeploymentNumber, - this.recipientIncomingDeploymentStatus); + // final recipientAccount = frame.getWorldUpdater().get(this.recipientAddress); + this.recipientAccountBefore = AccountSnapshot.canonical(hub, this.recipientAddress); // SelfdestructScenarioFragment selfdestructScenarioFragment = new SelfdestructScenarioFragment(); @@ -127,7 +100,6 @@ public SelfdestructSection(Hub hub) { .make( this.accountBefore, this.accountBefore, - // this.accountAddress, no need to explicitly pass the address? DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); // TODO: check if the account has balance or not From 95ecc8057742fc78a781efabf251111d734cd874 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 18 Jul 2024 23:17:24 +0200 Subject: [PATCH 237/461] feat(selfdestruct): managed part before transaction is completed --- .../zktracer/module/hub/AccountSnapshot.java | 4 +- .../hub/section/TxInitializationSection.java | 2 +- .../hub/section/halt/SelfdestructSection.java | 41 ++++++++++++++++--- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index e3844039f0..f3a32e6c43 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -163,12 +163,12 @@ public AccountSnapshot deployByteCode(Bytecode code) { this.address, this.nonce, this.balance, true, code, this.deploymentNumber, false); } - public AccountSnapshot credit(Wei value, boolean isWarm) { + public AccountSnapshot credit(Wei value) { return new AccountSnapshot( this.address, this.nonce, this.balance.add(value), - isWarm, + this.isWarm, this.code, this.deploymentNumber, this.deploymentStatus); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 2ebbec4e97..65f0556fcf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -86,7 +86,7 @@ public TxInitializationSection(Hub hub, WorldView world) { isDeployment ? recipientBeforeValueTransfer.initiateDeployment( value, initBytecode, deploymentInfo.getDeploymentNumber(toAddress)) - : recipientBeforeValueTransfer.credit(value, true); + : recipientBeforeValueTransfer.credit(value).turnOnWarmth(); final DomSubStampsSubFragment recipientDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 1); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 43bad73171..e0ad93db59 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -40,16 +40,19 @@ public class SelfdestructSection extends TraceSection final Address address; AccountSnapshot accountBefore; - // AccountSnapshot accountAfter; + AccountSnapshot accountAfter; final Bytes recipientRawAddress; final Address recipientAddress; AccountSnapshot recipientAccountBefore; - // AccountSnapshot recipientAccountAfter; + AccountSnapshot recipientAccountAfter; AccountFragment selfDestroyerFirstAccountFragment; AccountFragment recipientFirstAccountFragment; + AccountFragment selfDestroyerSecondAccountFragment; + AccountFragment recipientSecondAccountFragment; + public SelfdestructSection(Hub hub) { // up to 8 = 1 + 7 rows super(hub, (short) 8); @@ -102,8 +105,6 @@ public SelfdestructSection(Hub hub) { this.accountBefore, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); - // TODO: check if the account has balance or not - this.addFragment(selfDestroyerFirstAccountFragment); // i+2 // ACC fragment (2) @@ -134,6 +135,36 @@ public SelfdestructSection(Hub hub) { // - The recipient address will become warm (i+3) // * recipientFirstAccountFragment + // Here we complete the SELFDESTRUCT without knowing yet if it will be reverted yet (not yet + // marked case?) + // ACC fragment (?) + this.accountAfter = this.accountBefore.debit(this.accountBefore.balance()); + selfDestroyerSecondAccountFragment = + hub.factories() + .accountFragment() + .make( + this.accountBefore, + this.accountAfter, + DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); + this.addFragment(selfDestroyerSecondAccountFragment); + + // ACC fragment (?) + this.recipientAccountAfter = + !recipientAddress.equals(address) + ? this.recipientAccountBefore.credit(this.accountBefore.balance()) + : this.recipientAccountBefore.debit( + this.recipientAccountBefore + .balance()); // NOTE: in the second case account is equal to recipientAccount + this.recipientAccountAfter = this.recipientAccountAfter.turnOnWarmth(); + recipientSecondAccountFragment = + hub.factories() + .accountFragment() + .make( + this.recipientAccountBefore, + this.recipientAccountAfter, + DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); + this.addFragment(recipientSecondAccountFragment); + // take a look at EXTCODECOPY, RETURN, ACCOUNT for reference } @@ -141,7 +172,7 @@ public SelfdestructSection(Hub hub) { public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { /* willRevert case undo the modifications we applied to selfDestroyerFirstAccountFragment and recipientFirstAccountFragment - this will add account rows + this will add account rows. Shall we basically go back from after to before? */ } From 5dd36b4317cb789515aa897da7f0661580c2b9ea Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 19 Jul 2024 10:52:36 +0530 Subject: [PATCH 238/461] feat(hub): done with exceptional, aborting, failure, emptyInit CREATE(s) --- .../hub/fragment/DomSubStampsSubFragment.java | 16 ++++++++++ .../hub/fragment/account/AccountFragment.java | 4 ++- .../fragment/account/RlpAddrSubFragment.java | 31 +++++++++++++------ .../hub/section/create/CreateSection.java | 26 ++++++++++++++-- .../create/FailureOrEmptyInitCreate.java | 13 +++++--- .../hub/section/create/FillCreateSection.java | 4 +++ .../create/NonEmptyInitCodeCreate.java | 17 ++++++++++ zkevm-constraints | 2 +- 8 files changed, 94 insertions(+), 19 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java index 390707f182..ab4b914854 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java @@ -39,6 +39,7 @@ public enum DomSubType { final int childRevertStamp; final int transactionEndStamp; + // TODO: to be use with care, as stamps might have changed public static DomSubStampsSubFragment standardDomSubStamps(final Hub hub, final int domOffset) { return new DomSubStampsSubFragment(DomSubType.STANDARD, hub.stamp(), domOffset, 0, 0, 0, 0); } @@ -47,6 +48,7 @@ public static DomSubStampsSubFragment standardDomSubStamps(final int h, final in return new DomSubStampsSubFragment(DomSubType.STANDARD, h, domOffset, 0, 0, 0, 0); } + // TODO: to be use with care, as stamps might have changed public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( final Hub hub, final int subOffset) { return new DomSubStampsSubFragment( @@ -59,12 +61,26 @@ public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( 0); } + public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( + final int h, final int revertStamp, final int subOffset) { + return new DomSubStampsSubFragment( + DomSubType.REVERTS_WITH_CURRENT, h, 0, subOffset, revertStamp, 0, 0); + } + + // TODO: to be use with care, as stamps might have changed public static DomSubStampsSubFragment revertsWithChildDomSubStamps( final Hub hub, final CallFrame child, final int subOffset) { return new DomSubStampsSubFragment( DomSubType.REVERTS_WITH_CHILD, hub.stamp(), 0, subOffset, 0, child.revertStamp(), 0); } + public static DomSubStampsSubFragment revertsWithChildDomSubStamps( + final int h, final int childRevertStamp, final int subOffset) { + return new DomSubStampsSubFragment( + DomSubType.REVERTS_WITH_CHILD, h, 0, subOffset, 0, childRevertStamp, 0); + } + + // TODO: to be use with care, as stamps might have changed public static DomSubStampsSubFragment selfdestructDomSubStamps(final Hub hub) { return new DomSubStampsSubFragment( DomSubType.SELFDESTRUCT, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 7b5615f143..eb65c3eb8b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -108,7 +108,9 @@ public Trace trace(Trace trace) { // tracing this.domSubStampsSubFragment.trace(trace); - this.rlpAddrSubFragment.trace(trace); + if (rlpAddrSubFragment != null) { + this.rlpAddrSubFragment.trace(trace); + } return trace .peekAtAccount(true) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java index d7eb7aa137..81343d8f79 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java @@ -20,9 +20,14 @@ import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; +import net.consensys.linea.zktracer.module.hub.transients.OperationAncillaries; +import net.consensys.linea.zktracer.opcode.OpCode; +import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.crypto.Hash; import org.hyperledger.besu.datatypes.Address; @RequiredArgsConstructor @@ -32,21 +37,29 @@ public class RlpAddrSubFragment implements TraceSubFragment { private final Bytes32 salt; private final Bytes32 keccak; - public static RlpAddrSubFragment rlpAddrSubFragmentForCreate2( - final Address depAddress, final Bytes32 Salt, final Bytes32 Keccak) { - return new RlpAddrSubFragment((short) 2, depAddress, Salt, Keccak); - } - - public static RlpAddrSubFragment rlpAddrSubFragmentForCreate(final Address depAddress) { - return new RlpAddrSubFragment( - (short) 1, depAddress, (Bytes32) Bytes32.EMPTY, (Bytes32) Bytes32.EMPTY); + public static RlpAddrSubFragment makeFragment(Hub hub, Address createdAddress) { + final OpCode currentOpCode = hub.opCode(); + switch (currentOpCode) { + case CREATE2 -> { + final Bytes32 salt = Bytes32.leftPad(hub.currentFrame().frame().getStackItem(3)); + final Bytes initCode = OperationAncillaries.callData(hub.currentFrame().frame()); + final Bytes32 hash = + Hash.keccak256(initCode); // TODO: could be done better, we compute the HASH two times + return new RlpAddrSubFragment((short) 2, createdAddress, salt, hash); + } + case CREATE -> { + return new RlpAddrSubFragment( + (short) 1, createdAddress, (Bytes32) Bytes32.EMPTY, (Bytes32) Bytes32.EMPTY); + } + default -> throw new IllegalStateException("Unexpected value: " + currentOpCode); + } } @Override public Trace trace(Trace trace) { return trace .pAccountRlpaddrFlag(true) - .pAccountRlpaddrRecipe(recipe == 2) + .pAccountRlpaddrRecipe(recipe == 2) // TODO: regenerate Trace.java and update it .pAccountRlpaddrDepAddrHi(highPart(depAddress)) .pAccountRlpaddrDepAddrLo(lowPart(depAddress)) .pAccountRlpaddrSaltHi(salt.slice(0, LLARGE)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 812c43a09d..5d4f7e635d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -25,6 +25,7 @@ import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; @@ -62,7 +63,10 @@ public class CreateSection implements PostExecDefer, ReEnterContextDefer, PostTr private AccountSnapshot newCreatorSnapshot; private AccountSnapshot newCreatedSnapshot; - private boolean createSuccessful; + private RlpAddrSubFragment rlpAddrSubFragment; + + /* true if the CREATE was successful **/ + private boolean createSuccessful = false; /* true if the putatively created account already has code **/ private boolean targetHasCode() { @@ -134,6 +138,8 @@ public CreateSection(Hub hub) { hub.defers().reEntry(this); hub.defers().schedulePostTransaction(this); + this.creatorContextId = hub.currentFrame().id(); + final Address createdAddress = getCreateAddress(frame); final Account createdAccount = frame.getWorldUpdater().get(createdAddress); oldCreatedSnapshot = @@ -143,6 +149,8 @@ public CreateSection(Hub hub) { hub.transients().conflation().deploymentInfo().number(createdAddress), hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createdAddress); + failure = hub.pch().failureConditions().any(); emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); @@ -188,7 +196,7 @@ public void resolvePostExecution( @Override public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { - this.createSuccessful = !frame.getStackItem(0).isZero(); + this.createSuccessful = !frame.getStackItem(0).isZero(); // TODO: are we sure it's working ?? final Address creatorAddress = oldCreatorSnapshot.address(); this.newCreatorSnapshot = @@ -210,12 +218,14 @@ public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (this.mmuCall != null) { this.imcFragment.callMmu(this.mmuCall); } this.createSection.fillAccountFragment( hub, + rlpAddrSubFragment, oldCreatorSnapshot, midCreatorSnapshot, newCreatorSnapshot, @@ -223,9 +233,19 @@ public void resolvePostTransaction( midCreatedSnapshot, newCreatedSnapshot); - if (hub.callStack().getById(this.creatorContextId).hasReverted()) { + final CallFrame createCallFrame = hub.callStack().getById(this.creatorContextId); + if (createCallFrame.hasReverted()) { + final int childRevertStamp = + createCallFrame.childFrames().isEmpty() + ? 0 + : hub.callStack() + .getById(createCallFrame.childFrames().getFirst()) + .revertStamp(); // TODO: not sure about this + final int currentRevertStamp = createCallFrame.revertStamp(); this.createSection.fillReverting( hub, + childRevertStamp, + currentRevertStamp, oldCreatorSnapshot, midCreatorSnapshot, newCreatorSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java index b6a9141db1..7d5ca6cf1f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -24,6 +24,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; @@ -51,6 +52,7 @@ public FailureOrEmptyInitCreate( @Override public void fillAccountFragment( Hub hub, + RlpAddrSubFragment rlpAddrSubFragment, AccountSnapshot oldCreatorSnapshot, AccountSnapshot midCreatorSnapshot, AccountSnapshot newCreatorSnapshot, @@ -64,8 +66,8 @@ public void fillAccountFragment( accountFragmentFactory.make( oldCreatorSnapshot, newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps( - hubStamp, 0)); // TODO: RLP_ADDR subFragment + DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 0)); + creatorAccountFragment.rlpAddrSubFragment(rlpAddrSubFragment); final AccountFragment createdAccountFragment = accountFragmentFactory.make( @@ -79,6 +81,8 @@ public void fillAccountFragment( @Override public void fillReverting( Hub hub, + int childRevertStamp, + int currentRevertStamp, AccountSnapshot oldCreatorSnapshot, AccountSnapshot midCreatorSnapshot, AccountSnapshot newCreatorSnapshot, @@ -98,13 +102,12 @@ public void fillReverting( accountFragmentFactory.make( newCreatorSnapshot, oldCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 0)); // TODO domsub - + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, currentRevertStamp, 2)); final AccountFragment undoCreatedAccountFragment = accountFragmentFactory.make( newCreatedSnapshot, oldCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 1)); // TODO domsub + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, currentRevertStamp, 3)); this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java index 9fb28b0781..7f65f5f577 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java @@ -18,10 +18,12 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; public interface FillCreateSection { void fillAccountFragment( final Hub hub, + final RlpAddrSubFragment rlpAddrSubFragment, final AccountSnapshot oldCreatorSnapshot, final AccountSnapshot midCreatorSnapshot, final AccountSnapshot newCreatorSnapshot, @@ -31,6 +33,8 @@ void fillAccountFragment( void fillReverting( final Hub hub, + final int childRevertStamp, + final int currentRevertStamp, final AccountSnapshot oldCreatorSnapshot, final AccountSnapshot midCreatorSnapshot, final AccountSnapshot newCreatorSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index df9465be5b..b0b2a81c1e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -18,6 +18,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; @@ -31,10 +32,26 @@ public NonEmptyInitCodeCreate( @Override public void fillAccountFragment( Hub hub, + RlpAddrSubFragment rlpAddrSubFragment, AccountSnapshot oldCreatorSnapshot, AccountSnapshot midCreatorSnapshot, AccountSnapshot newCreatorSnapshot, AccountSnapshot oldCreatedSnapshot, AccountSnapshot midCreatedSnapshot, AccountSnapshot newCreatedSnapshot) {} + + @Override + public void fillReverting( + Hub hub, + int childRevertStamp, + int currentRevertStamp, + AccountSnapshot oldCreatorSnapshot, + AccountSnapshot midCreatorSnapshot, + AccountSnapshot newCreatorSnapshot, + AccountSnapshot oldCreatedSnapshot, + AccountSnapshot midCreatedSnapshot, + AccountSnapshot newCreatedSnapshot) {} + + @Override + public void fillContextFragment(ContextFragment contextFragment) {} } diff --git a/zkevm-constraints b/zkevm-constraints index 29b10da4cd..03e1cadacb 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 29b10da4cd96cfbe8bf12d84020fb4df177021db +Subproject commit 03e1cadacba51ac1e36eb6816cc370b2f24fc2b3 From 67e83296c8f33bfeafa3848978216b2daeae6ade Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 19 Jul 2024 11:08:18 +0530 Subject: [PATCH 239/461] fix(hub): regenerate Trace.java --- .../linea/zktracer/module/hub/Trace.java | 1364 +++++++++-------- .../fragment/account/RlpAddrSubFragment.java | 2 +- gradle/trace-files.gradle | 2 +- 3 files changed, 689 insertions(+), 679 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 72df3effbb..9563c7b142 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -79,6 +79,7 @@ public class Trace { private final MappedByteBuffer contextWillRevert; private final MappedByteBuffer counterNsr; private final MappedByteBuffer counterTli; + private final MappedByteBuffer createFailureConditionWillRevertXorHashInfoFlag; private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; @@ -195,10 +196,10 @@ public class Trace { rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew; private final MappedByteBuffer rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo; private final MappedByteBuffer rlpaddrKecLoXorMmuTgtOffsetLo; - private final MappedByteBuffer rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4; + private final MappedByteBuffer rlpaddrRecipe; private final MappedByteBuffer rlpaddrSaltHiXorMxpGasMxp; private final MappedByteBuffer rlpaddrSaltLoXorMxpOffset1Hi; - private final MappedByteBuffer romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag; + private final MappedByteBuffer romlexFlagXorStpOogxXorCreateAbortXorDecFlag4; private final MappedByteBuffer selfdestructExceptionXorStackItemPop4; private final MappedByteBuffer selfdestructWillRevertXorStaticx; private final MappedByteBuffer selfdestructWontRevertAlreadyMarkedXorStaticFlag; @@ -229,7 +230,7 @@ public class Trace { private final MappedByteBuffer subStamp; private final MappedByteBuffer sux; private final MappedByteBuffer swapFlag; - private final MappedByteBuffer trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag; + private final MappedByteBuffer trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag; private final MappedByteBuffer trmRawAddressHiXorMxpOffset1Lo; private final MappedByteBuffer twoLineInstruction; private final MappedByteBuffer txExec; @@ -238,8 +239,8 @@ public class Trace { private final MappedByteBuffer txSkip; private final MappedByteBuffer txWarm; private final MappedByteBuffer txnFlag; - private final MappedByteBuffer warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag; - private final MappedByteBuffer warmthXorCreateExceptionXorHaltFlag; + private final MappedByteBuffer warmthNewXorCreateExceptionXorHaltFlag; + private final MappedByteBuffer warmthXorCreateEmptyInitCodeWontRevertXorExtFlag; private final MappedByteBuffer wcpFlag; static List headers(int length) { @@ -302,6 +303,7 @@ static List headers(int length) { new ColumnHeader("hub.CONTEXT_WILL_REVERT", 1, length), new ColumnHeader("hub.COUNTER_NSR", 1, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), + new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), new ColumnHeader( "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), @@ -458,14 +460,10 @@ static List headers(int length) { length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 16, length), new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO", 16, length), - new ColumnHeader( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), + new ColumnHeader("hub.RLPADDR_RECIPE", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 16, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 16, length), - new ColumnHeader( - "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", - 1, - length), + new ColumnHeader("hub.ROMLEX_FLAG_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), @@ -497,7 +495,9 @@ static List headers(int length) { new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), new ColumnHeader( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + "hub.TRM_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", + 1, + length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 16, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -506,11 +506,9 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), + new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", - 1, - length), - new ColumnHeader("hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), + "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -560,170 +558,171 @@ public Trace(List buffers) { this.contextWillRevert = buffers.get(30); this.counterNsr = buffers.get(31); this.counterTli = buffers.get(32); - this.createFailureConditionWontRevertXorIcpx = buffers.get(33); - this.createNonemptyInitCodeFailureWillRevertXorInvalidFlag = buffers.get(34); - this.createNonemptyInitCodeFailureWontRevertXorJumpx = buffers.get(35); - this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(36); - this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(37); - this.delta = buffers.get(38); + this.createFailureConditionWillRevertXorHashInfoFlag = buffers.get(33); + this.createFailureConditionWontRevertXorIcpx = buffers.get(34); + this.createNonemptyInitCodeFailureWillRevertXorInvalidFlag = buffers.get(35); + this.createNonemptyInitCodeFailureWontRevertXorJumpx = buffers.get(36); + this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(37); + this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(38); + this.delta = buffers.get(39); this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = - buffers.get(39); - this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(40); + buffers.get(40); + this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(41); this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = - buffers.get(41); + buffers.get(42); this .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment = - buffers.get(42); + buffers.get(43); this .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 = - buffers.get(43); + buffers.get(44); this .deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd = - buffers.get(44); - this.domStamp = buffers.get(45); - this.exceptionAhoy = buffers.get(46); + buffers.get(45); + this.domStamp = buffers.get(46); + this.exceptionAhoy = buffers.get(47); this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode = - buffers.get(47); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = buffers.get(48); - this.gasActual = buffers.get(49); - this.gasCost = buffers.get(50); - this.gasExpected = buffers.get(51); - this.gasLimit = buffers.get(52); - this.gasNext = buffers.get(53); - this.gasPrice = buffers.get(54); + this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = + buffers.get(49); + this.gasActual = buffers.get(50); + this.gasCost = buffers.get(51); + this.gasExpected = buffers.get(52); + this.gasLimit = buffers.get(53); + this.gasNext = buffers.get(54); + this.gasPrice = buffers.get(55); this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig = - buffers.get(55); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr = buffers.get(56); - this.hashInfoStamp = buffers.get(57); - this.height = buffers.get(58); - this.heightNew = buffers.get(59); - this.hubStamp = buffers.get(60); - this.hubStampTransactionEnd = buffers.get(61); - this.instruction = buffers.get(62); + this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr = + buffers.get(57); + this.hashInfoStamp = buffers.get(58); + this.height = buffers.get(59); + this.heightNew = buffers.get(60); + this.hubStamp = buffers.get(61); + this.hubStampTransactionEnd = buffers.get(62); + this.instruction = buffers.get(63); this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero = - buffers.get(63); - this.logInfoStamp = buffers.get(64); + buffers.get(64); + this.logInfoStamp = buffers.get(65); this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth = - buffers.get(65); + buffers.get(66); this .markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero = - buffers.get(66); - this.mmuStamp = buffers.get(67); - this.mxpOffset2Hi = buffers.get(68); - this.mxpOffset2Lo = buffers.get(69); - this.mxpSize1Hi = buffers.get(70); - this.mxpSize1Lo = buffers.get(71); - this.mxpSize2Hi = buffers.get(72); - this.mxpSize2Lo = buffers.get(73); - this.mxpStamp = buffers.get(74); - this.mxpWords = buffers.get(75); - this.nbAdded = buffers.get(76); - this.nbRemoved = buffers.get(77); - this.nonStackRows = buffers.get(78); - this.nonce = buffers.get(79); - this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(80); - this.nonceXorStpGasMxpXorBasefee = buffers.get(81); - this.oobData1 = buffers.get(82); - this.oobData2 = buffers.get(83); - this.oobData3 = buffers.get(84); - this.oobData4 = buffers.get(85); - this.oobData5 = buffers.get(86); - this.oobData6 = buffers.get(87); - this.oobData7 = buffers.get(88); - this.oobData8 = buffers.get(89); - this.peekAtAccount = buffers.get(90); - this.peekAtContext = buffers.get(91); - this.peekAtMiscellaneous = buffers.get(92); - this.peekAtScenario = buffers.get(93); - this.peekAtStack = buffers.get(94); - this.peekAtStorage = buffers.get(95); - this.peekAtTransaction = buffers.get(96); - this.prcBlake2FXorKecFlag = buffers.get(97); - this.prcEcaddXorLogFlag = buffers.get(98); - this.prcEcmulXorLogInfoFlag = buffers.get(99); - this.prcEcpairingXorMachineStateFlag = buffers.get(100); - this.prcEcrecoverXorMaxcsx = buffers.get(101); - this.prcFailureKnownToHubXorModFlag = buffers.get(102); - this.prcFailureKnownToRamXorMulFlag = buffers.get(103); - this.prcIdentityXorMxpx = buffers.get(104); - this.prcModexpXorMxpFlag = buffers.get(105); - this.prcRipemd160XorOogx = buffers.get(106); - this.prcSha2256XorOpcx = buffers.get(107); - this.prcSuccessCallerWillRevertXorPushpopFlag = buffers.get(108); - this.prcSuccessCallerWontRevertXorRdcx = buffers.get(109); - this.priorityFeePerGas = buffers.get(110); - this.programCounter = buffers.get(111); - this.programCounterNew = buffers.get(112); - this.refundCounter = buffers.get(113); - this.refundCounterInfinity = buffers.get(114); - this.refundCounterNew = buffers.get(115); - this.refundEffective = buffers.get(116); - this.returnAtCapacityXorMxpInst = buffers.get(117); - this.returnAtOffsetXorOobInst = buffers.get(118); - this.returnDataContextNumberXorStpGasStipend = buffers.get(119); - this.returnDataOffsetXorStpInstruction = buffers.get(120); - this.returnDataSize = buffers.get(121); - this.returnExceptionXorShfFlag = buffers.get(122); - this.returnFromDeploymentEmptyCodeWillRevertXorSox = buffers.get(123); - this.returnFromDeploymentEmptyCodeWontRevertXorSstorex = buffers.get(124); - this.returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag = buffers.get(125); - this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1 = buffers.get(126); - this.returnFromMessageCallWillTouchRamXorStackItemPop2 = buffers.get(127); - this.returnFromMessageCallWontTouchRamXorStackItemPop3 = buffers.get(128); - this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(129); - this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi = buffers.get(130); + buffers.get(67); + this.mmuStamp = buffers.get(68); + this.mxpOffset2Hi = buffers.get(69); + this.mxpOffset2Lo = buffers.get(70); + this.mxpSize1Hi = buffers.get(71); + this.mxpSize1Lo = buffers.get(72); + this.mxpSize2Hi = buffers.get(73); + this.mxpSize2Lo = buffers.get(74); + this.mxpStamp = buffers.get(75); + this.mxpWords = buffers.get(76); + this.nbAdded = buffers.get(77); + this.nbRemoved = buffers.get(78); + this.nonStackRows = buffers.get(79); + this.nonce = buffers.get(80); + this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(81); + this.nonceXorStpGasMxpXorBasefee = buffers.get(82); + this.oobData1 = buffers.get(83); + this.oobData2 = buffers.get(84); + this.oobData3 = buffers.get(85); + this.oobData4 = buffers.get(86); + this.oobData5 = buffers.get(87); + this.oobData6 = buffers.get(88); + this.oobData7 = buffers.get(89); + this.oobData8 = buffers.get(90); + this.peekAtAccount = buffers.get(91); + this.peekAtContext = buffers.get(92); + this.peekAtMiscellaneous = buffers.get(93); + this.peekAtScenario = buffers.get(94); + this.peekAtStack = buffers.get(95); + this.peekAtStorage = buffers.get(96); + this.peekAtTransaction = buffers.get(97); + this.prcBlake2FXorKecFlag = buffers.get(98); + this.prcEcaddXorLogFlag = buffers.get(99); + this.prcEcmulXorLogInfoFlag = buffers.get(100); + this.prcEcpairingXorMachineStateFlag = buffers.get(101); + this.prcEcrecoverXorMaxcsx = buffers.get(102); + this.prcFailureKnownToHubXorModFlag = buffers.get(103); + this.prcFailureKnownToRamXorMulFlag = buffers.get(104); + this.prcIdentityXorMxpx = buffers.get(105); + this.prcModexpXorMxpFlag = buffers.get(106); + this.prcRipemd160XorOogx = buffers.get(107); + this.prcSha2256XorOpcx = buffers.get(108); + this.prcSuccessCallerWillRevertXorPushpopFlag = buffers.get(109); + this.prcSuccessCallerWontRevertXorRdcx = buffers.get(110); + this.priorityFeePerGas = buffers.get(111); + this.programCounter = buffers.get(112); + this.programCounterNew = buffers.get(113); + this.refundCounter = buffers.get(114); + this.refundCounterInfinity = buffers.get(115); + this.refundCounterNew = buffers.get(116); + this.refundEffective = buffers.get(117); + this.returnAtCapacityXorMxpInst = buffers.get(118); + this.returnAtOffsetXorOobInst = buffers.get(119); + this.returnDataContextNumberXorStpGasStipend = buffers.get(120); + this.returnDataOffsetXorStpInstruction = buffers.get(121); + this.returnDataSize = buffers.get(122); + this.returnExceptionXorShfFlag = buffers.get(123); + this.returnFromDeploymentEmptyCodeWillRevertXorSox = buffers.get(124); + this.returnFromDeploymentEmptyCodeWontRevertXorSstorex = buffers.get(125); + this.returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag = buffers.get(126); + this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1 = buffers.get(127); + this.returnFromMessageCallWillTouchRamXorStackItemPop2 = buffers.get(128); + this.returnFromMessageCallWontTouchRamXorStackItemPop3 = buffers.get(129); + this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(130); + this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi = buffers.get(131); this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew = - buffers.get(131); - this.rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo = buffers.get(132); - this.rlpaddrKecLoXorMmuTgtOffsetLo = buffers.get(133); - this.rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4 = buffers.get(134); - this.rlpaddrSaltHiXorMxpGasMxp = buffers.get(135); - this.rlpaddrSaltLoXorMxpOffset1Hi = buffers.get(136); - this.romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag = buffers.get(137); - this.selfdestructExceptionXorStackItemPop4 = buffers.get(138); - this.selfdestructWillRevertXorStaticx = buffers.get(139); - this.selfdestructWontRevertAlreadyMarkedXorStaticFlag = buffers.get(140); - this.selfdestructWontRevertNotYetMarkedXorStoFlag = buffers.get(141); - this.stackItemHeight1 = buffers.get(142); - this.stackItemHeight2 = buffers.get(143); - this.stackItemHeight3 = buffers.get(144); - this.stackItemHeight4 = buffers.get(145); - this.stackItemStamp1 = buffers.get(146); - this.stackItemStamp2 = buffers.get(147); - this.stackItemStamp3 = buffers.get(148); - this.stackItemStamp4 = buffers.get(149); - this.stackItemValueHi1 = buffers.get(150); - this.stackItemValueHi2 = buffers.get(151); - this.stackItemValueHi3 = buffers.get(152); - this.stackItemValueHi4 = buffers.get(153); - this.stackItemValueLo1 = buffers.get(154); - this.stackItemValueLo2 = buffers.get(155); - this.stackItemValueLo3 = buffers.get(156); - this.stackItemValueLo4 = buffers.get(157); - this.stoFinal = buffers.get(158); - this.stoFirst = buffers.get(159); - this.stpGasHi = buffers.get(160); - this.stpGasLo = buffers.get(161); - this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(162); - this.stpValueHi = buffers.get(163); - this.stpValueLo = buffers.get(164); - this.subStamp = buffers.get(165); - this.sux = buffers.get(166); - this.swapFlag = buffers.get(167); - this.trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag = buffers.get(168); - this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(169); - this.twoLineInstruction = buffers.get(170); - this.txExec = buffers.get(171); - this.txFinl = buffers.get(172); - this.txInit = buffers.get(173); - this.txSkip = buffers.get(174); - this.txWarm = buffers.get(175); - this.txnFlag = buffers.get(176); - this.warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag = buffers.get(177); - this.warmthXorCreateExceptionXorHaltFlag = buffers.get(178); - this.wcpFlag = buffers.get(179); + buffers.get(132); + this.rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo = buffers.get(133); + this.rlpaddrKecLoXorMmuTgtOffsetLo = buffers.get(134); + this.rlpaddrRecipe = buffers.get(135); + this.rlpaddrSaltHiXorMxpGasMxp = buffers.get(136); + this.rlpaddrSaltLoXorMxpOffset1Hi = buffers.get(137); + this.romlexFlagXorStpOogxXorCreateAbortXorDecFlag4 = buffers.get(138); + this.selfdestructExceptionXorStackItemPop4 = buffers.get(139); + this.selfdestructWillRevertXorStaticx = buffers.get(140); + this.selfdestructWontRevertAlreadyMarkedXorStaticFlag = buffers.get(141); + this.selfdestructWontRevertNotYetMarkedXorStoFlag = buffers.get(142); + this.stackItemHeight1 = buffers.get(143); + this.stackItemHeight2 = buffers.get(144); + this.stackItemHeight3 = buffers.get(145); + this.stackItemHeight4 = buffers.get(146); + this.stackItemStamp1 = buffers.get(147); + this.stackItemStamp2 = buffers.get(148); + this.stackItemStamp3 = buffers.get(149); + this.stackItemStamp4 = buffers.get(150); + this.stackItemValueHi1 = buffers.get(151); + this.stackItemValueHi2 = buffers.get(152); + this.stackItemValueHi3 = buffers.get(153); + this.stackItemValueHi4 = buffers.get(154); + this.stackItemValueLo1 = buffers.get(155); + this.stackItemValueLo2 = buffers.get(156); + this.stackItemValueLo3 = buffers.get(157); + this.stackItemValueLo4 = buffers.get(158); + this.stoFinal = buffers.get(159); + this.stoFirst = buffers.get(160); + this.stpGasHi = buffers.get(161); + this.stpGasLo = buffers.get(162); + this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(163); + this.stpValueHi = buffers.get(164); + this.stpValueLo = buffers.get(165); + this.subStamp = buffers.get(166); + this.sux = buffers.get(167); + this.swapFlag = buffers.get(168); + this.trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag = buffers.get(169); + this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(170); + this.twoLineInstruction = buffers.get(171); + this.txExec = buffers.get(172); + this.txFinl = buffers.get(173); + this.txInit = buffers.get(174); + this.txSkip = buffers.get(175); + this.txWarm = buffers.get(176); + this.txnFlag = buffers.get(177); + this.warmthNewXorCreateExceptionXorHaltFlag = buffers.get(178); + this.warmthXorCreateEmptyInitCodeWontRevertXorExtFlag = buffers.get(179); + this.wcpFlag = buffers.get(180); } public int size() { @@ -1244,10 +1243,10 @@ public Trace nonStackRows(final long b) { } public Trace pAccountAddressHi(final long b) { - if (filled.get(106)) { + if (filled.get(107)) { throw new IllegalStateException("hub.account/ADDRESS_HI already set"); } else { - filled.set(106); + filled.set(107); } if (b >= 4294967296L) { @@ -1269,10 +1268,10 @@ public Trace pAccountAddressHi(final long b) { } public Trace pAccountAddressLo(final Bytes b) { - if (filled.get(131)) { + if (filled.get(132)) { throw new IllegalStateException("hub.account/ADDRESS_LO already set"); } else { - filled.set(131); + filled.set(132); } // Trim array to size @@ -1299,10 +1298,10 @@ public Trace pAccountAddressLo(final Bytes b) { } public Trace pAccountBalance(final Bytes b) { - if (filled.get(132)) { + if (filled.get(133)) { throw new IllegalStateException("hub.account/BALANCE already set"); } else { - filled.set(132); + filled.set(133); } // Trim array to size @@ -1329,10 +1328,10 @@ public Trace pAccountBalance(final Bytes b) { } public Trace pAccountBalanceNew(final Bytes b) { - if (filled.get(133)) { + if (filled.get(134)) { throw new IllegalStateException("hub.account/BALANCE_NEW already set"); } else { - filled.set(133); + filled.set(134); } // Trim array to size @@ -1359,10 +1358,10 @@ public Trace pAccountBalanceNew(final Bytes b) { } public Trace pAccountCodeFragmentIndex(final long b) { - if (filled.get(107)) { + if (filled.get(108)) { throw new IllegalStateException("hub.account/CODE_FRAGMENT_INDEX already set"); } else { - filled.set(107); + filled.set(108); } if (b >= 4294967296L) { @@ -1384,10 +1383,10 @@ public Trace pAccountCodeFragmentIndex(final long b) { } public Trace pAccountCodeHashHi(final Bytes b) { - if (filled.get(134)) { + if (filled.get(135)) { throw new IllegalStateException("hub.account/CODE_HASH_HI already set"); } else { - filled.set(134); + filled.set(135); } // Trim array to size @@ -1412,10 +1411,10 @@ public Trace pAccountCodeHashHi(final Bytes b) { } public Trace pAccountCodeHashHiNew(final Bytes b) { - if (filled.get(135)) { + if (filled.get(136)) { throw new IllegalStateException("hub.account/CODE_HASH_HI_NEW already set"); } else { - filled.set(135); + filled.set(136); } // Trim array to size @@ -1440,10 +1439,10 @@ public Trace pAccountCodeHashHiNew(final Bytes b) { } public Trace pAccountCodeHashLo(final Bytes b) { - if (filled.get(136)) { + if (filled.get(137)) { throw new IllegalStateException("hub.account/CODE_HASH_LO already set"); } else { - filled.set(136); + filled.set(137); } // Trim array to size @@ -1466,10 +1465,10 @@ public Trace pAccountCodeHashLo(final Bytes b) { } public Trace pAccountCodeHashLoNew(final Bytes b) { - if (filled.get(137)) { + if (filled.get(138)) { throw new IllegalStateException("hub.account/CODE_HASH_LO_NEW already set"); } else { - filled.set(137); + filled.set(138); } // Trim array to size @@ -1492,10 +1491,10 @@ public Trace pAccountCodeHashLoNew(final Bytes b) { } public Trace pAccountCodeSize(final long b) { - if (filled.get(108)) { + if (filled.get(109)) { throw new IllegalStateException("hub.account/CODE_SIZE already set"); } else { - filled.set(108); + filled.set(109); } if (b >= 4294967296L) { @@ -1517,10 +1516,10 @@ public Trace pAccountCodeSize(final long b) { } public Trace pAccountCodeSizeNew(final long b) { - if (filled.get(109)) { + if (filled.get(110)) { throw new IllegalStateException("hub.account/CODE_SIZE_NEW already set"); } else { - filled.set(109); + filled.set(110); } if (b >= 4294967296L) { @@ -1541,10 +1540,10 @@ public Trace pAccountCodeSizeNew(final long b) { } public Trace pAccountDeploymentNumber(final long b) { - if (filled.get(110)) { + if (filled.get(111)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER already set"); } else { - filled.set(110); + filled.set(111); } if (b >= 4294967296L) { @@ -1565,10 +1564,10 @@ public Trace pAccountDeploymentNumber(final long b) { } public Trace pAccountDeploymentNumberInfty(final long b) { - if (filled.get(111)) { + if (filled.get(112)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(111); + filled.set(112); } if (b >= 4294967296L) { @@ -1590,10 +1589,10 @@ public Trace pAccountDeploymentNumberInfty(final long b) { } public Trace pAccountDeploymentNumberNew(final long b) { - if (filled.get(112)) { + if (filled.get(113)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_NEW already set"); } else { - filled.set(112); + filled.set(113); } if (b >= 4294967296L) { @@ -1741,10 +1740,10 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { } public Trace pAccountNonce(final Bytes b) { - if (filled.get(122)) { + if (filled.get(123)) { throw new IllegalStateException("hub.account/NONCE already set"); } else { - filled.set(122); + filled.set(123); } // Trim array to size @@ -1767,10 +1766,10 @@ public Trace pAccountNonce(final Bytes b) { } public Trace pAccountNonceNew(final Bytes b) { - if (filled.get(123)) { + if (filled.get(124)) { throw new IllegalStateException("hub.account/NONCE_NEW already set"); } else { - filled.set(123); + filled.set(124); } // Trim array to size @@ -1795,10 +1794,10 @@ public Trace pAccountNonceNew(final Bytes b) { } public Trace pAccountRlpaddrDepAddrHi(final long b) { - if (filled.get(113)) { + if (filled.get(114)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_HI already set"); } else { - filled.set(113); + filled.set(114); } if (b >= 4294967296L) { @@ -1814,10 +1813,10 @@ public Trace pAccountRlpaddrDepAddrHi(final long b) { } public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { - if (filled.get(138)) { + if (filled.get(139)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_LO already set"); } else { - filled.set(138); + filled.set(139); } // Trim array to size @@ -1855,10 +1854,10 @@ public Trace pAccountRlpaddrFlag(final Boolean b) { } public Trace pAccountRlpaddrKecHi(final Bytes b) { - if (filled.get(139)) { + if (filled.get(140)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_HI already set"); } else { - filled.set(139); + filled.set(140); } // Trim array to size @@ -1883,10 +1882,10 @@ public Trace pAccountRlpaddrKecHi(final Bytes b) { } public Trace pAccountRlpaddrKecLo(final Bytes b) { - if (filled.get(140)) { + if (filled.get(141)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_LO already set"); } else { - filled.set(140); + filled.set(141); } // Trim array to size @@ -1908,23 +1907,26 @@ public Trace pAccountRlpaddrKecLo(final Bytes b) { return this; } - public Trace pAccountRlpaddrRecipe(final Boolean b) { - if (filled.get(63)) { + public Trace pAccountRlpaddrRecipe(final long b) { + if (filled.get(105)) { throw new IllegalStateException("hub.account/RLPADDR_RECIPE already set"); } else { - filled.set(63); + filled.set(105); } - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + if (b >= 256L) { + throw new IllegalArgumentException("rlpaddrRecipe has invalid value (" + b + ")"); + } + rlpaddrRecipe.put((byte) b); return this; } public Trace pAccountRlpaddrSaltHi(final Bytes b) { - if (filled.get(141)) { + if (filled.get(142)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_HI already set"); } else { - filled.set(141); + filled.set(142); } // Trim array to size @@ -1947,10 +1949,10 @@ public Trace pAccountRlpaddrSaltHi(final Bytes b) { } public Trace pAccountRlpaddrSaltLo(final Bytes b) { - if (filled.get(142)) { + if (filled.get(143)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_LO already set"); } else { - filled.set(142); + filled.set(143); } // Trim array to size @@ -1973,34 +1975,34 @@ public Trace pAccountRlpaddrSaltLo(final Bytes b) { } public Trace pAccountRomlexFlag(final Boolean b) { - if (filled.get(64)) { + if (filled.get(63)) { throw new IllegalStateException("hub.account/ROMLEX_FLAG already set"); } else { - filled.set(64); + filled.set(63); } - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountTrmFlag(final Boolean b) { - if (filled.get(65)) { + if (filled.get(64)) { throw new IllegalStateException("hub.account/TRM_FLAG already set"); } else { - filled.set(65); + filled.set(64); } - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountTrmRawAddressHi(final Bytes b) { - if (filled.get(143)) { + if (filled.get(144)) { throw new IllegalStateException("hub.account/TRM_RAW_ADDRESS_HI already set"); } else { - filled.set(143); + filled.set(144); } // Trim array to size @@ -2023,34 +2025,34 @@ public Trace pAccountTrmRawAddressHi(final Bytes b) { } public Trace pAccountWarmth(final Boolean b) { - if (filled.get(66)) { + if (filled.get(65)) { throw new IllegalStateException("hub.account/WARMTH already set"); } else { - filled.set(66); + filled.set(65); } - warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountWarmthNew(final Boolean b) { - if (filled.get(67)) { + if (filled.get(66)) { throw new IllegalStateException("hub.account/WARMTH_NEW already set"); } else { - filled.set(67); + filled.set(66); } - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pContextAccountAddressHi(final long b) { - if (filled.get(106)) { + if (filled.get(107)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_HI already set"); } else { - filled.set(106); + filled.set(107); } if (b >= 4294967296L) { @@ -2072,10 +2074,10 @@ public Trace pContextAccountAddressHi(final long b) { } public Trace pContextAccountAddressLo(final Bytes b) { - if (filled.get(131)) { + if (filled.get(132)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_LO already set"); } else { - filled.set(131); + filled.set(132); } // Trim array to size @@ -2102,10 +2104,10 @@ public Trace pContextAccountAddressLo(final Bytes b) { } public Trace pContextAccountDeploymentNumber(final long b) { - if (filled.get(107)) { + if (filled.get(108)) { throw new IllegalStateException("hub.context/ACCOUNT_DEPLOYMENT_NUMBER already set"); } else { - filled.set(107); + filled.set(108); } if (b >= 4294967296L) { @@ -2127,10 +2129,10 @@ public Trace pContextAccountDeploymentNumber(final long b) { } public Trace pContextByteCodeAddressHi(final long b) { - if (filled.get(108)) { + if (filled.get(109)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_HI already set"); } else { - filled.set(108); + filled.set(109); } if (b >= 4294967296L) { @@ -2152,10 +2154,10 @@ public Trace pContextByteCodeAddressHi(final long b) { } public Trace pContextByteCodeAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(133)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(133); } // Trim array to size @@ -2182,10 +2184,10 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { } public Trace pContextByteCodeCodeFragmentIndex(final long b) { - if (filled.get(109)) { + if (filled.get(110)) { throw new IllegalStateException("hub.context/BYTE_CODE_CODE_FRAGMENT_INDEX already set"); } else { - filled.set(109); + filled.set(110); } if (b >= 4294967296L) { @@ -2206,10 +2208,10 @@ public Trace pContextByteCodeCodeFragmentIndex(final long b) { } public Trace pContextByteCodeDeploymentNumber(final long b) { - if (filled.get(110)) { + if (filled.get(111)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_NUMBER already set"); } else { - filled.set(110); + filled.set(111); } if (b >= 4294967296L) { @@ -2230,10 +2232,10 @@ public Trace pContextByteCodeDeploymentNumber(final long b) { } public Trace pContextByteCodeDeploymentStatus(final long b) { - if (filled.get(111)) { + if (filled.get(112)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_STATUS already set"); } else { - filled.set(111); + filled.set(112); } if (b >= 4294967296L) { @@ -2255,10 +2257,10 @@ public Trace pContextByteCodeDeploymentStatus(final long b) { } public Trace pContextCallDataContextNumber(final long b) { - if (filled.get(113)) { + if (filled.get(114)) { throw new IllegalStateException("hub.context/CALL_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(113); + filled.set(114); } if (b >= 4294967296L) { @@ -2274,10 +2276,10 @@ public Trace pContextCallDataContextNumber(final long b) { } public Trace pContextCallDataOffset(final long b) { - if (filled.get(114)) { + if (filled.get(115)) { throw new IllegalStateException("hub.context/CALL_DATA_OFFSET already set"); } else { - filled.set(114); + filled.set(115); } if (b >= 4294967296L) { @@ -2292,10 +2294,10 @@ public Trace pContextCallDataOffset(final long b) { } public Trace pContextCallDataSize(final long b) { - if (filled.get(115)) { + if (filled.get(116)) { throw new IllegalStateException("hub.context/CALL_DATA_SIZE already set"); } else { - filled.set(115); + filled.set(116); } if (b >= 4294967296L) { @@ -2310,10 +2312,10 @@ public Trace pContextCallDataSize(final long b) { } public Trace pContextCallStackDepth(final long b) { - if (filled.get(105)) { + if (filled.get(106)) { throw new IllegalStateException("hub.context/CALL_STACK_DEPTH already set"); } else { - filled.set(105); + filled.set(106); } if (b >= 2048L) { @@ -2326,10 +2328,10 @@ public Trace pContextCallStackDepth(final long b) { } public Trace pContextCallValue(final Bytes b) { - if (filled.get(134)) { + if (filled.get(135)) { throw new IllegalStateException("hub.context/CALL_VALUE already set"); } else { - filled.set(134); + filled.set(135); } // Trim array to size @@ -2354,10 +2356,10 @@ public Trace pContextCallValue(final Bytes b) { } public Trace pContextCallerAddressHi(final long b) { - if (filled.get(112)) { + if (filled.get(113)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_HI already set"); } else { - filled.set(112); + filled.set(113); } if (b >= 4294967296L) { @@ -2375,10 +2377,10 @@ public Trace pContextCallerAddressHi(final long b) { } public Trace pContextCallerAddressLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(134)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_LO already set"); } else { - filled.set(133); + filled.set(134); } // Trim array to size @@ -2405,10 +2407,10 @@ public Trace pContextCallerAddressLo(final Bytes b) { } public Trace pContextContextNumber(final long b) { - if (filled.get(116)) { + if (filled.get(117)) { throw new IllegalStateException("hub.context/CONTEXT_NUMBER already set"); } else { - filled.set(116); + filled.set(117); } if (b >= 4294967296L) { @@ -2449,10 +2451,10 @@ public Trace pContextIsStatic(final Boolean b) { } public Trace pContextReturnAtCapacity(final long b) { - if (filled.get(117)) { + if (filled.get(118)) { throw new IllegalStateException("hub.context/RETURN_AT_CAPACITY already set"); } else { - filled.set(117); + filled.set(118); } if (b >= 4294967296L) { @@ -2468,10 +2470,10 @@ public Trace pContextReturnAtCapacity(final long b) { } public Trace pContextReturnAtOffset(final long b) { - if (filled.get(118)) { + if (filled.get(119)) { throw new IllegalStateException("hub.context/RETURN_AT_OFFSET already set"); } else { - filled.set(118); + filled.set(119); } if (b >= 4294967296L) { @@ -2486,10 +2488,10 @@ public Trace pContextReturnAtOffset(final long b) { } public Trace pContextReturnDataContextNumber(final long b) { - if (filled.get(119)) { + if (filled.get(120)) { throw new IllegalStateException("hub.context/RETURN_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(119); + filled.set(120); } if (b >= 4294967296L) { @@ -2505,10 +2507,10 @@ public Trace pContextReturnDataContextNumber(final long b) { } public Trace pContextReturnDataOffset(final long b) { - if (filled.get(120)) { + if (filled.get(121)) { throw new IllegalStateException("hub.context/RETURN_DATA_OFFSET already set"); } else { - filled.set(120); + filled.set(121); } if (b >= 4294967296L) { @@ -2524,10 +2526,10 @@ public Trace pContextReturnDataOffset(final long b) { } public Trace pContextReturnDataSize(final long b) { - if (filled.get(121)) { + if (filled.get(122)) { throw new IllegalStateException("hub.context/RETURN_DATA_SIZE already set"); } else { - filled.set(121); + filled.set(122); } if (b >= 4294967296L) { @@ -2555,10 +2557,10 @@ public Trace pContextUpdate(final Boolean b) { } public Trace pMiscCcrsStamp(final long b) { - if (filled.get(106)) { + if (filled.get(107)) { throw new IllegalStateException("hub.misc/CCRS_STAMP already set"); } else { - filled.set(106); + filled.set(107); } if (b >= 4294967296L) { @@ -2593,10 +2595,10 @@ public Trace pMiscCcsrFlag(final Boolean b) { } public Trace pMiscExpData1(final Bytes b) { - if (filled.get(131)) { + if (filled.get(132)) { throw new IllegalStateException("hub.misc/EXP_DATA_1 already set"); } else { - filled.set(131); + filled.set(132); } // Trim array to size @@ -2623,10 +2625,10 @@ public Trace pMiscExpData1(final Bytes b) { } public Trace pMiscExpData2(final Bytes b) { - if (filled.get(132)) { + if (filled.get(133)) { throw new IllegalStateException("hub.misc/EXP_DATA_2 already set"); } else { - filled.set(132); + filled.set(133); } // Trim array to size @@ -2653,10 +2655,10 @@ public Trace pMiscExpData2(final Bytes b) { } public Trace pMiscExpData3(final Bytes b) { - if (filled.get(133)) { + if (filled.get(134)) { throw new IllegalStateException("hub.misc/EXP_DATA_3 already set"); } else { - filled.set(133); + filled.set(134); } // Trim array to size @@ -2683,10 +2685,10 @@ public Trace pMiscExpData3(final Bytes b) { } public Trace pMiscExpData4(final Bytes b) { - if (filled.get(134)) { + if (filled.get(135)) { throw new IllegalStateException("hub.misc/EXP_DATA_4 already set"); } else { - filled.set(134); + filled.set(135); } // Trim array to size @@ -2711,10 +2713,10 @@ public Trace pMiscExpData4(final Bytes b) { } public Trace pMiscExpData5(final Bytes b) { - if (filled.get(135)) { + if (filled.get(136)) { throw new IllegalStateException("hub.misc/EXP_DATA_5 already set"); } else { - filled.set(135); + filled.set(136); } // Trim array to size @@ -2752,10 +2754,10 @@ public Trace pMiscExpFlag(final Boolean b) { } public Trace pMiscExpInst(final long b) { - if (filled.get(107)) { + if (filled.get(108)) { throw new IllegalStateException("hub.misc/EXP_INST already set"); } else { - filled.set(107); + filled.set(108); } if (b >= 4294967296L) { @@ -2777,10 +2779,10 @@ public Trace pMiscExpInst(final long b) { } public Trace pMiscMmuAuxId(final long b) { - if (filled.get(108)) { + if (filled.get(109)) { throw new IllegalStateException("hub.misc/MMU_AUX_ID already set"); } else { - filled.set(108); + filled.set(109); } if (b >= 4294967296L) { @@ -2802,10 +2804,10 @@ public Trace pMiscMmuAuxId(final long b) { } public Trace pMiscMmuExoSum(final long b) { - if (filled.get(109)) { + if (filled.get(110)) { throw new IllegalStateException("hub.misc/MMU_EXO_SUM already set"); } else { - filled.set(109); + filled.set(110); } if (b >= 4294967296L) { @@ -2839,10 +2841,10 @@ public Trace pMiscMmuFlag(final Boolean b) { } public Trace pMiscMmuInst(final long b) { - if (filled.get(110)) { + if (filled.get(111)) { throw new IllegalStateException("hub.misc/MMU_INST already set"); } else { - filled.set(110); + filled.set(111); } if (b >= 4294967296L) { @@ -2863,10 +2865,10 @@ public Trace pMiscMmuInst(final long b) { } public Trace pMiscMmuLimb1(final Bytes b) { - if (filled.get(136)) { + if (filled.get(137)) { throw new IllegalStateException("hub.misc/MMU_LIMB_1 already set"); } else { - filled.set(136); + filled.set(137); } // Trim array to size @@ -2889,10 +2891,10 @@ public Trace pMiscMmuLimb1(final Bytes b) { } public Trace pMiscMmuLimb2(final Bytes b) { - if (filled.get(137)) { + if (filled.get(138)) { throw new IllegalStateException("hub.misc/MMU_LIMB_2 already set"); } else { - filled.set(137); + filled.set(138); } // Trim array to size @@ -2915,10 +2917,10 @@ public Trace pMiscMmuLimb2(final Bytes b) { } public Trace pMiscMmuPhase(final long b) { - if (filled.get(111)) { + if (filled.get(112)) { throw new IllegalStateException("hub.misc/MMU_PHASE already set"); } else { - filled.set(111); + filled.set(112); } if (b >= 4294967296L) { @@ -2940,10 +2942,10 @@ public Trace pMiscMmuPhase(final long b) { } public Trace pMiscMmuRefOffset(final long b) { - if (filled.get(112)) { + if (filled.get(113)) { throw new IllegalStateException("hub.misc/MMU_REF_OFFSET already set"); } else { - filled.set(112); + filled.set(113); } if (b >= 4294967296L) { @@ -2961,10 +2963,10 @@ public Trace pMiscMmuRefOffset(final long b) { } public Trace pMiscMmuRefSize(final long b) { - if (filled.get(113)) { + if (filled.get(114)) { throw new IllegalStateException("hub.misc/MMU_REF_SIZE already set"); } else { - filled.set(113); + filled.set(114); } if (b >= 4294967296L) { @@ -2980,10 +2982,10 @@ public Trace pMiscMmuRefSize(final long b) { } public Trace pMiscMmuSize(final long b) { - if (filled.get(114)) { + if (filled.get(115)) { throw new IllegalStateException("hub.misc/MMU_SIZE already set"); } else { - filled.set(114); + filled.set(115); } if (b >= 4294967296L) { @@ -2998,10 +3000,10 @@ public Trace pMiscMmuSize(final long b) { } public Trace pMiscMmuSrcId(final long b) { - if (filled.get(115)) { + if (filled.get(116)) { throw new IllegalStateException("hub.misc/MMU_SRC_ID already set"); } else { - filled.set(115); + filled.set(116); } if (b >= 4294967296L) { @@ -3016,10 +3018,10 @@ public Trace pMiscMmuSrcId(final long b) { } public Trace pMiscMmuSrcOffsetHi(final Bytes b) { - if (filled.get(138)) { + if (filled.get(139)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_HI already set"); } else { - filled.set(138); + filled.set(139); } // Trim array to size @@ -3044,10 +3046,10 @@ public Trace pMiscMmuSrcOffsetHi(final Bytes b) { } public Trace pMiscMmuSrcOffsetLo(final Bytes b) { - if (filled.get(139)) { + if (filled.get(140)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_LO already set"); } else { - filled.set(139); + filled.set(140); } // Trim array to size @@ -3085,10 +3087,10 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { } public Trace pMiscMmuTgtId(final long b) { - if (filled.get(116)) { + if (filled.get(117)) { throw new IllegalStateException("hub.misc/MMU_TGT_ID already set"); } else { - filled.set(116); + filled.set(117); } if (b >= 4294967296L) { @@ -3103,10 +3105,10 @@ public Trace pMiscMmuTgtId(final long b) { } public Trace pMiscMmuTgtOffsetLo(final Bytes b) { - if (filled.get(140)) { + if (filled.get(141)) { throw new IllegalStateException("hub.misc/MMU_TGT_OFFSET_LO already set"); } else { - filled.set(140); + filled.set(141); } // Trim array to size @@ -3155,10 +3157,10 @@ public Trace pMiscMxpFlag(final Boolean b) { } public Trace pMiscMxpGasMxp(final Bytes b) { - if (filled.get(141)) { + if (filled.get(142)) { throw new IllegalStateException("hub.misc/MXP_GAS_MXP already set"); } else { - filled.set(141); + filled.set(142); } // Trim array to size @@ -3181,10 +3183,10 @@ public Trace pMiscMxpGasMxp(final Bytes b) { } public Trace pMiscMxpInst(final long b) { - if (filled.get(117)) { + if (filled.get(118)) { throw new IllegalStateException("hub.misc/MXP_INST already set"); } else { - filled.set(117); + filled.set(118); } if (b >= 4294967296L) { @@ -3226,10 +3228,10 @@ public Trace pMiscMxpMxpx(final Boolean b) { } public Trace pMiscMxpOffset1Hi(final Bytes b) { - if (filled.get(142)) { + if (filled.get(143)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_HI already set"); } else { - filled.set(142); + filled.set(143); } // Trim array to size @@ -3252,10 +3254,10 @@ public Trace pMiscMxpOffset1Hi(final Bytes b) { } public Trace pMiscMxpOffset1Lo(final Bytes b) { - if (filled.get(143)) { + if (filled.get(144)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_LO already set"); } else { - filled.set(143); + filled.set(144); } // Trim array to size @@ -3278,10 +3280,10 @@ public Trace pMiscMxpOffset1Lo(final Bytes b) { } public Trace pMiscMxpOffset2Hi(final Bytes b) { - if (filled.get(144)) { + if (filled.get(145)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_HI already set"); } else { - filled.set(144); + filled.set(145); } // Trim array to size @@ -3304,10 +3306,10 @@ public Trace pMiscMxpOffset2Hi(final Bytes b) { } public Trace pMiscMxpOffset2Lo(final Bytes b) { - if (filled.get(145)) { + if (filled.get(146)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_LO already set"); } else { - filled.set(145); + filled.set(146); } // Trim array to size @@ -3330,10 +3332,10 @@ public Trace pMiscMxpOffset2Lo(final Bytes b) { } public Trace pMiscMxpSize1Hi(final Bytes b) { - if (filled.get(146)) { + if (filled.get(147)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_HI already set"); } else { - filled.set(146); + filled.set(147); } // Trim array to size @@ -3356,10 +3358,10 @@ public Trace pMiscMxpSize1Hi(final Bytes b) { } public Trace pMiscMxpSize1Lo(final Bytes b) { - if (filled.get(147)) { + if (filled.get(148)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_LO already set"); } else { - filled.set(147); + filled.set(148); } // Trim array to size @@ -3382,10 +3384,10 @@ public Trace pMiscMxpSize1Lo(final Bytes b) { } public Trace pMiscMxpSize2Hi(final Bytes b) { - if (filled.get(148)) { + if (filled.get(149)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_HI already set"); } else { - filled.set(148); + filled.set(149); } // Trim array to size @@ -3408,10 +3410,10 @@ public Trace pMiscMxpSize2Hi(final Bytes b) { } public Trace pMiscMxpSize2Lo(final Bytes b) { - if (filled.get(149)) { + if (filled.get(150)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_LO already set"); } else { - filled.set(149); + filled.set(150); } // Trim array to size @@ -3434,10 +3436,10 @@ public Trace pMiscMxpSize2Lo(final Bytes b) { } public Trace pMiscMxpWords(final Bytes b) { - if (filled.get(150)) { + if (filled.get(151)) { throw new IllegalStateException("hub.misc/MXP_WORDS already set"); } else { - filled.set(150); + filled.set(151); } // Trim array to size @@ -3459,10 +3461,10 @@ public Trace pMiscMxpWords(final Bytes b) { } public Trace pMiscOobData1(final Bytes b) { - if (filled.get(151)) { + if (filled.get(152)) { throw new IllegalStateException("hub.misc/OOB_DATA_1 already set"); } else { - filled.set(151); + filled.set(152); } // Trim array to size @@ -3484,10 +3486,10 @@ public Trace pMiscOobData1(final Bytes b) { } public Trace pMiscOobData2(final Bytes b) { - if (filled.get(152)) { + if (filled.get(153)) { throw new IllegalStateException("hub.misc/OOB_DATA_2 already set"); } else { - filled.set(152); + filled.set(153); } // Trim array to size @@ -3509,10 +3511,10 @@ public Trace pMiscOobData2(final Bytes b) { } public Trace pMiscOobData3(final Bytes b) { - if (filled.get(153)) { + if (filled.get(154)) { throw new IllegalStateException("hub.misc/OOB_DATA_3 already set"); } else { - filled.set(153); + filled.set(154); } // Trim array to size @@ -3534,10 +3536,10 @@ public Trace pMiscOobData3(final Bytes b) { } public Trace pMiscOobData4(final Bytes b) { - if (filled.get(154)) { + if (filled.get(155)) { throw new IllegalStateException("hub.misc/OOB_DATA_4 already set"); } else { - filled.set(154); + filled.set(155); } // Trim array to size @@ -3559,10 +3561,10 @@ public Trace pMiscOobData4(final Bytes b) { } public Trace pMiscOobData5(final Bytes b) { - if (filled.get(155)) { + if (filled.get(156)) { throw new IllegalStateException("hub.misc/OOB_DATA_5 already set"); } else { - filled.set(155); + filled.set(156); } // Trim array to size @@ -3584,10 +3586,10 @@ public Trace pMiscOobData5(final Bytes b) { } public Trace pMiscOobData6(final Bytes b) { - if (filled.get(156)) { + if (filled.get(157)) { throw new IllegalStateException("hub.misc/OOB_DATA_6 already set"); } else { - filled.set(156); + filled.set(157); } // Trim array to size @@ -3609,10 +3611,10 @@ public Trace pMiscOobData6(final Bytes b) { } public Trace pMiscOobData7(final Bytes b) { - if (filled.get(157)) { + if (filled.get(158)) { throw new IllegalStateException("hub.misc/OOB_DATA_7 already set"); } else { - filled.set(157); + filled.set(158); } // Trim array to size @@ -3634,10 +3636,10 @@ public Trace pMiscOobData7(final Bytes b) { } public Trace pMiscOobData8(final Bytes b) { - if (filled.get(158)) { + if (filled.get(159)) { throw new IllegalStateException("hub.misc/OOB_DATA_8 already set"); } else { - filled.set(158); + filled.set(159); } // Trim array to size @@ -3672,10 +3674,10 @@ public Trace pMiscOobFlag(final Boolean b) { } public Trace pMiscOobInst(final long b) { - if (filled.get(118)) { + if (filled.get(119)) { throw new IllegalStateException("hub.misc/OOB_INST already set"); } else { - filled.set(118); + filled.set(119); } if (b >= 4294967296L) { @@ -3716,10 +3718,10 @@ public Trace pMiscStpFlag(final Boolean b) { } public Trace pMiscStpGasHi(final Bytes b) { - if (filled.get(159)) { + if (filled.get(160)) { throw new IllegalStateException("hub.misc/STP_GAS_HI already set"); } else { - filled.set(159); + filled.set(160); } // Trim array to size @@ -3741,10 +3743,10 @@ public Trace pMiscStpGasHi(final Bytes b) { } public Trace pMiscStpGasLo(final Bytes b) { - if (filled.get(160)) { + if (filled.get(161)) { throw new IllegalStateException("hub.misc/STP_GAS_LO already set"); } else { - filled.set(160); + filled.set(161); } // Trim array to size @@ -3766,10 +3768,10 @@ public Trace pMiscStpGasLo(final Bytes b) { } public Trace pMiscStpGasMxp(final Bytes b) { - if (filled.get(122)) { + if (filled.get(123)) { throw new IllegalStateException("hub.misc/STP_GAS_MXP already set"); } else { - filled.set(122); + filled.set(123); } // Trim array to size @@ -3792,10 +3794,10 @@ public Trace pMiscStpGasMxp(final Bytes b) { } public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { - if (filled.get(123)) { + if (filled.get(124)) { throw new IllegalStateException("hub.misc/STP_GAS_PAID_OUT_OF_POCKET already set"); } else { - filled.set(123); + filled.set(124); } // Trim array to size @@ -3820,10 +3822,10 @@ public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { } public Trace pMiscStpGasStipend(final long b) { - if (filled.get(119)) { + if (filled.get(120)) { throw new IllegalStateException("hub.misc/STP_GAS_STIPEND already set"); } else { - filled.set(119); + filled.set(120); } if (b >= 4294967296L) { @@ -3839,10 +3841,10 @@ public Trace pMiscStpGasStipend(final long b) { } public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { - if (filled.get(124)) { + if (filled.get(125)) { throw new IllegalStateException("hub.misc/STP_GAS_UPFRONT_GAS_COST already set"); } else { - filled.set(124); + filled.set(125); } // Trim array to size @@ -3865,10 +3867,10 @@ public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { } public Trace pMiscStpInstruction(final long b) { - if (filled.get(120)) { + if (filled.get(121)) { throw new IllegalStateException("hub.misc/STP_INSTRUCTION already set"); } else { - filled.set(120); + filled.set(121); } if (b >= 4294967296L) { @@ -3890,16 +3892,16 @@ public Trace pMiscStpOogx(final Boolean b) { filled.set(63); } - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscStpValueHi(final Bytes b) { - if (filled.get(161)) { + if (filled.get(162)) { throw new IllegalStateException("hub.misc/STP_VALUE_HI already set"); } else { - filled.set(161); + filled.set(162); } // Trim array to size @@ -3922,10 +3924,10 @@ public Trace pMiscStpValueHi(final Bytes b) { } public Trace pMiscStpValueLo(final Bytes b) { - if (filled.get(162)) { + if (filled.get(163)) { throw new IllegalStateException("hub.misc/STP_VALUE_LO already set"); } else { - filled.set(162); + filled.set(163); } // Trim array to size @@ -3954,7 +3956,7 @@ public Trace pMiscStpWarmth(final Boolean b) { filled.set(64); } - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4117,7 +4119,7 @@ public Trace pScenarioCreateAbort(final Boolean b) { filled.set(63); } - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } @@ -4130,7 +4132,7 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { filled.set(64); } - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4143,7 +4145,7 @@ public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { filled.set(65); } - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4155,7 +4157,7 @@ public Trace pScenarioCreateException(final Boolean b) { filled.set(66); } - warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4168,7 +4170,7 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { filled.set(67); } - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); + createFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4252,10 +4254,10 @@ public Trace pScenarioPrcBlake2F(final Boolean b) { } public Trace pScenarioPrcCalleeGas(final long b) { - if (filled.get(106)) { + if (filled.get(107)) { throw new IllegalStateException("hub.scenario/PRC_CALLEE_GAS already set"); } else { - filled.set(106); + filled.set(107); } if (b >= 4294967296L) { @@ -4277,10 +4279,10 @@ public Trace pScenarioPrcCalleeGas(final long b) { } public Trace pScenarioPrcCallerGas(final long b) { - if (filled.get(107)) { + if (filled.get(108)) { throw new IllegalStateException("hub.scenario/PRC_CALLER_GAS already set"); } else { - filled.set(107); + filled.set(108); } if (b >= 4294967296L) { @@ -4302,10 +4304,10 @@ public Trace pScenarioPrcCallerGas(final long b) { } public Trace pScenarioPrcCdo(final long b) { - if (filled.get(108)) { + if (filled.get(109)) { throw new IllegalStateException("hub.scenario/PRC_CDO already set"); } else { - filled.set(108); + filled.set(109); } if (b >= 4294967296L) { @@ -4327,10 +4329,10 @@ public Trace pScenarioPrcCdo(final long b) { } public Trace pScenarioPrcCds(final long b) { - if (filled.get(109)) { + if (filled.get(110)) { throw new IllegalStateException("hub.scenario/PRC_CDS already set"); } else { - filled.set(109); + filled.set(110); } if (b >= 4294967296L) { @@ -4447,10 +4449,10 @@ public Trace pScenarioPrcModexp(final Boolean b) { } public Trace pScenarioPrcRac(final long b) { - if (filled.get(110)) { + if (filled.get(111)) { throw new IllegalStateException("hub.scenario/PRC_RAC already set"); } else { - filled.set(110); + filled.set(111); } if (b >= 4294967296L) { @@ -4471,10 +4473,10 @@ public Trace pScenarioPrcRac(final long b) { } public Trace pScenarioPrcRao(final long b) { - if (filled.get(111)) { + if (filled.get(112)) { throw new IllegalStateException("hub.scenario/PRC_RAO already set"); } else { - filled.set(111); + filled.set(112); } if (b >= 4294967296L) { @@ -4496,10 +4498,10 @@ public Trace pScenarioPrcRao(final long b) { } public Trace pScenarioPrcReturnGas(final long b) { - if (filled.get(112)) { + if (filled.get(113)) { throw new IllegalStateException("hub.scenario/PRC_RETURN_GAS already set"); } else { - filled.set(112); + filled.set(113); } if (b >= 4294967296L) { @@ -4866,7 +4868,7 @@ public Trace pStackDecFlag4(final Boolean b) { filled.set(63); } - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } @@ -4890,7 +4892,7 @@ public Trace pStackDupFlag(final Boolean b) { filled.set(64); } - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4902,7 +4904,7 @@ public Trace pStackExtFlag(final Boolean b) { filled.set(65); } - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4914,7 +4916,7 @@ public Trace pStackHaltFlag(final Boolean b) { filled.set(66); } - warmthXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4926,16 +4928,16 @@ public Trace pStackHashInfoFlag(final Boolean b) { filled.set(67); } - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); + createFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pStackHashInfoKeccakHi(final Bytes b) { - if (filled.get(131)) { + if (filled.get(132)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_HI already set"); } else { - filled.set(131); + filled.set(132); } // Trim array to size @@ -4962,10 +4964,10 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { } public Trace pStackHashInfoKeccakLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(133)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_LO already set"); } else { - filled.set(132); + filled.set(133); } // Trim array to size @@ -5004,10 +5006,10 @@ public Trace pStackIcpx(final Boolean b) { } public Trace pStackInstruction(final Bytes b) { - if (filled.get(163)) { + if (filled.get(164)) { throw new IllegalStateException("hub.stack/INSTRUCTION already set"); } else { - filled.set(163); + filled.set(164); } // Trim array to size @@ -5235,10 +5237,10 @@ public Trace pStackOpcx(final Boolean b) { } public Trace pStackPushValueHi(final Bytes b) { - if (filled.get(133)) { + if (filled.get(134)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_HI already set"); } else { - filled.set(133); + filled.set(134); } // Trim array to size @@ -5265,10 +5267,10 @@ public Trace pStackPushValueHi(final Bytes b) { } public Trace pStackPushValueLo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(135)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_LO already set"); } else { - filled.set(134); + filled.set(135); } // Trim array to size @@ -5353,10 +5355,10 @@ public Trace pStackSstorex(final Boolean b) { } public Trace pStackStackItemHeight1(final Bytes b) { - if (filled.get(164)) { + if (filled.get(165)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_1 already set"); } else { - filled.set(164); + filled.set(165); } // Trim array to size @@ -5379,10 +5381,10 @@ public Trace pStackStackItemHeight1(final Bytes b) { } public Trace pStackStackItemHeight2(final Bytes b) { - if (filled.get(165)) { + if (filled.get(166)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_2 already set"); } else { - filled.set(165); + filled.set(166); } // Trim array to size @@ -5405,10 +5407,10 @@ public Trace pStackStackItemHeight2(final Bytes b) { } public Trace pStackStackItemHeight3(final Bytes b) { - if (filled.get(166)) { + if (filled.get(167)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_3 already set"); } else { - filled.set(166); + filled.set(167); } // Trim array to size @@ -5431,10 +5433,10 @@ public Trace pStackStackItemHeight3(final Bytes b) { } public Trace pStackStackItemHeight4(final Bytes b) { - if (filled.get(167)) { + if (filled.get(168)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_4 already set"); } else { - filled.set(167); + filled.set(168); } // Trim array to size @@ -5505,10 +5507,10 @@ public Trace pStackStackItemPop4(final Boolean b) { } public Trace pStackStackItemStamp1(final Bytes b) { - if (filled.get(168)) { + if (filled.get(169)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_1 already set"); } else { - filled.set(168); + filled.set(169); } // Trim array to size @@ -5531,10 +5533,10 @@ public Trace pStackStackItemStamp1(final Bytes b) { } public Trace pStackStackItemStamp2(final Bytes b) { - if (filled.get(169)) { + if (filled.get(170)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_2 already set"); } else { - filled.set(169); + filled.set(170); } // Trim array to size @@ -5557,10 +5559,10 @@ public Trace pStackStackItemStamp2(final Bytes b) { } public Trace pStackStackItemStamp3(final Bytes b) { - if (filled.get(170)) { + if (filled.get(171)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_3 already set"); } else { - filled.set(170); + filled.set(171); } // Trim array to size @@ -5583,10 +5585,10 @@ public Trace pStackStackItemStamp3(final Bytes b) { } public Trace pStackStackItemStamp4(final Bytes b) { - if (filled.get(171)) { + if (filled.get(172)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_4 already set"); } else { - filled.set(171); + filled.set(172); } // Trim array to size @@ -5609,10 +5611,10 @@ public Trace pStackStackItemStamp4(final Bytes b) { } public Trace pStackStackItemValueHi1(final Bytes b) { - if (filled.get(172)) { + if (filled.get(173)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_1 already set"); } else { - filled.set(172); + filled.set(173); } // Trim array to size @@ -5635,10 +5637,10 @@ public Trace pStackStackItemValueHi1(final Bytes b) { } public Trace pStackStackItemValueHi2(final Bytes b) { - if (filled.get(173)) { + if (filled.get(174)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_2 already set"); } else { - filled.set(173); + filled.set(174); } // Trim array to size @@ -5661,10 +5663,10 @@ public Trace pStackStackItemValueHi2(final Bytes b) { } public Trace pStackStackItemValueHi3(final Bytes b) { - if (filled.get(174)) { + if (filled.get(175)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_3 already set"); } else { - filled.set(174); + filled.set(175); } // Trim array to size @@ -5687,10 +5689,10 @@ public Trace pStackStackItemValueHi3(final Bytes b) { } public Trace pStackStackItemValueHi4(final Bytes b) { - if (filled.get(175)) { + if (filled.get(176)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_4 already set"); } else { - filled.set(175); + filled.set(176); } // Trim array to size @@ -5713,10 +5715,10 @@ public Trace pStackStackItemValueHi4(final Bytes b) { } public Trace pStackStackItemValueLo1(final Bytes b) { - if (filled.get(176)) { + if (filled.get(177)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_1 already set"); } else { - filled.set(176); + filled.set(177); } // Trim array to size @@ -5739,10 +5741,10 @@ public Trace pStackStackItemValueLo1(final Bytes b) { } public Trace pStackStackItemValueLo2(final Bytes b) { - if (filled.get(177)) { + if (filled.get(178)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_2 already set"); } else { - filled.set(177); + filled.set(178); } // Trim array to size @@ -5765,10 +5767,10 @@ public Trace pStackStackItemValueLo2(final Bytes b) { } public Trace pStackStackItemValueLo3(final Bytes b) { - if (filled.get(178)) { + if (filled.get(179)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_3 already set"); } else { - filled.set(178); + filled.set(179); } // Trim array to size @@ -5791,10 +5793,10 @@ public Trace pStackStackItemValueLo3(final Bytes b) { } public Trace pStackStackItemValueLo4(final Bytes b) { - if (filled.get(179)) { + if (filled.get(180)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_4 already set"); } else { - filled.set(179); + filled.set(180); } // Trim array to size @@ -5841,10 +5843,10 @@ public Trace pStackStaticFlag(final Boolean b) { } public Trace pStackStaticGas(final long b) { - if (filled.get(106)) { + if (filled.get(107)) { throw new IllegalStateException("hub.stack/STATIC_GAS already set"); } else { - filled.set(106); + filled.set(107); } if (b >= 4294967296L) { @@ -5938,10 +5940,10 @@ public Trace pStackWcpFlag(final Boolean b) { } public Trace pStorageAddressHi(final long b) { - if (filled.get(106)) { + if (filled.get(107)) { throw new IllegalStateException("hub.storage/ADDRESS_HI already set"); } else { - filled.set(106); + filled.set(107); } if (b >= 4294967296L) { @@ -5963,10 +5965,10 @@ public Trace pStorageAddressHi(final long b) { } public Trace pStorageAddressLo(final Bytes b) { - if (filled.get(131)) { + if (filled.get(132)) { throw new IllegalStateException("hub.storage/ADDRESS_LO already set"); } else { - filled.set(131); + filled.set(132); } // Trim array to size @@ -5993,10 +5995,10 @@ public Trace pStorageAddressLo(final Bytes b) { } public Trace pStorageDeploymentNumber(final long b) { - if (filled.get(107)) { + if (filled.get(108)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER already set"); } else { - filled.set(107); + filled.set(108); } if (b >= 4294967296L) { @@ -6018,10 +6020,10 @@ public Trace pStorageDeploymentNumber(final long b) { } public Trace pStorageDeploymentNumberInfty(final long b) { - if (filled.get(108)) { + if (filled.get(109)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(108); + filled.set(109); } if (b >= 4294967296L) { @@ -6043,10 +6045,10 @@ public Trace pStorageDeploymentNumberInfty(final long b) { } public Trace pStorageStorageKeyHi(final Bytes b) { - if (filled.get(132)) { + if (filled.get(133)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_HI already set"); } else { - filled.set(132); + filled.set(133); } // Trim array to size @@ -6073,10 +6075,10 @@ public Trace pStorageStorageKeyHi(final Bytes b) { } public Trace pStorageStorageKeyLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(134)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_LO already set"); } else { - filled.set(133); + filled.set(134); } // Trim array to size @@ -6142,10 +6144,10 @@ public Trace pStorageValueCurrChanges(final Boolean b) { } public Trace pStorageValueCurrHi(final Bytes b) { - if (filled.get(134)) { + if (filled.get(135)) { throw new IllegalStateException("hub.storage/VALUE_CURR_HI already set"); } else { - filled.set(134); + filled.set(135); } // Trim array to size @@ -6196,10 +6198,10 @@ public Trace pStorageValueCurrIsZero(final Boolean b) { } public Trace pStorageValueCurrLo(final Bytes b) { - if (filled.get(135)) { + if (filled.get(136)) { throw new IllegalStateException("hub.storage/VALUE_CURR_LO already set"); } else { - filled.set(135); + filled.set(136); } // Trim array to size @@ -6224,10 +6226,10 @@ public Trace pStorageValueCurrLo(final Bytes b) { } public Trace pStorageValueNextHi(final Bytes b) { - if (filled.get(136)) { + if (filled.get(137)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_HI already set"); } else { - filled.set(136); + filled.set(137); } // Trim array to size @@ -6289,10 +6291,10 @@ public Trace pStorageValueNextIsZero(final Boolean b) { } public Trace pStorageValueNextLo(final Bytes b) { - if (filled.get(137)) { + if (filled.get(138)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_LO already set"); } else { - filled.set(137); + filled.set(138); } // Trim array to size @@ -6315,10 +6317,10 @@ public Trace pStorageValueNextLo(final Bytes b) { } public Trace pStorageValueOrigHi(final Bytes b) { - if (filled.get(138)) { + if (filled.get(139)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_HI already set"); } else { - filled.set(138); + filled.set(139); } // Trim array to size @@ -6356,10 +6358,10 @@ public Trace pStorageValueOrigIsZero(final Boolean b) { } public Trace pStorageValueOrigLo(final Bytes b) { - if (filled.get(139)) { + if (filled.get(140)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_LO already set"); } else { - filled.set(139); + filled.set(140); } // Trim array to size @@ -6410,10 +6412,10 @@ public Trace pStorageWarmthNew(final Boolean b) { } public Trace pTransactionBasefee(final Bytes b) { - if (filled.get(122)) { + if (filled.get(123)) { throw new IllegalStateException("hub.transaction/BASEFEE already set"); } else { - filled.set(122); + filled.set(123); } // Trim array to size @@ -6436,10 +6438,10 @@ public Trace pTransactionBasefee(final Bytes b) { } public Trace pTransactionBatchNum(final long b) { - if (filled.get(106)) { + if (filled.get(107)) { throw new IllegalStateException("hub.transaction/BATCH_NUM already set"); } else { - filled.set(106); + filled.set(107); } if (b >= 4294967296L) { @@ -6461,10 +6463,10 @@ public Trace pTransactionBatchNum(final long b) { } public Trace pTransactionCallDataSize(final long b) { - if (filled.get(107)) { + if (filled.get(108)) { throw new IllegalStateException("hub.transaction/CALL_DATA_SIZE already set"); } else { - filled.set(107); + filled.set(108); } if (b >= 4294967296L) { @@ -6486,10 +6488,10 @@ public Trace pTransactionCallDataSize(final long b) { } public Trace pTransactionCoinbaseAddressHi(final long b) { - if (filled.get(108)) { + if (filled.get(109)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_HI already set"); } else { - filled.set(108); + filled.set(109); } if (b >= 4294967296L) { @@ -6511,10 +6513,10 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { } public Trace pTransactionCoinbaseAddressLo(final Bytes b) { - if (filled.get(131)) { + if (filled.get(132)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_LO already set"); } else { - filled.set(131); + filled.set(132); } // Trim array to size @@ -6554,10 +6556,10 @@ public Trace pTransactionCopyTxcd(final Boolean b) { } public Trace pTransactionFromAddressHi(final long b) { - if (filled.get(109)) { + if (filled.get(110)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_HI already set"); } else { - filled.set(109); + filled.set(110); } if (b >= 4294967296L) { @@ -6578,10 +6580,10 @@ public Trace pTransactionFromAddressHi(final long b) { } public Trace pTransactionFromAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(133)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(133); } // Trim array to size @@ -6608,10 +6610,10 @@ public Trace pTransactionFromAddressLo(final Bytes b) { } public Trace pTransactionGasInitiallyAvailable(final Bytes b) { - if (filled.get(123)) { + if (filled.get(124)) { throw new IllegalStateException("hub.transaction/GAS_INITIALLY_AVAILABLE already set"); } else { - filled.set(123); + filled.set(124); } // Trim array to size @@ -6636,10 +6638,10 @@ public Trace pTransactionGasInitiallyAvailable(final Bytes b) { } public Trace pTransactionGasLeftover(final Bytes b) { - if (filled.get(124)) { + if (filled.get(125)) { throw new IllegalStateException("hub.transaction/GAS_LEFTOVER already set"); } else { - filled.set(124); + filled.set(125); } // Trim array to size @@ -6662,10 +6664,10 @@ public Trace pTransactionGasLeftover(final Bytes b) { } public Trace pTransactionGasLimit(final Bytes b) { - if (filled.get(125)) { + if (filled.get(126)) { throw new IllegalStateException("hub.transaction/GAS_LIMIT already set"); } else { - filled.set(125); + filled.set(126); } // Trim array to size @@ -6687,10 +6689,10 @@ public Trace pTransactionGasLimit(final Bytes b) { } public Trace pTransactionGasPrice(final Bytes b) { - if (filled.get(126)) { + if (filled.get(127)) { throw new IllegalStateException("hub.transaction/GAS_PRICE already set"); } else { - filled.set(126); + filled.set(127); } // Trim array to size @@ -6712,10 +6714,10 @@ public Trace pTransactionGasPrice(final Bytes b) { } public Trace pTransactionInitCodeSize(final long b) { - if (filled.get(110)) { + if (filled.get(111)) { throw new IllegalStateException("hub.transaction/INIT_CODE_SIZE already set"); } else { - filled.set(110); + filled.set(111); } if (b >= 4294967296L) { @@ -6736,10 +6738,10 @@ public Trace pTransactionInitCodeSize(final long b) { } public Trace pTransactionInitialBalance(final Bytes b) { - if (filled.get(133)) { + if (filled.get(134)) { throw new IllegalStateException("hub.transaction/INITIAL_BALANCE already set"); } else { - filled.set(133); + filled.set(134); } // Trim array to size @@ -6792,10 +6794,10 @@ public Trace pTransactionIsType2(final Boolean b) { } public Trace pTransactionNonce(final Bytes b) { - if (filled.get(127)) { + if (filled.get(128)) { throw new IllegalStateException("hub.transaction/NONCE already set"); } else { - filled.set(127); + filled.set(128); } // Trim array to size @@ -6817,10 +6819,10 @@ public Trace pTransactionNonce(final Bytes b) { } public Trace pTransactionPriorityFeePerGas(final Bytes b) { - if (filled.get(128)) { + if (filled.get(129)) { throw new IllegalStateException("hub.transaction/PRIORITY_FEE_PER_GAS already set"); } else { - filled.set(128); + filled.set(129); } // Trim array to size @@ -6843,10 +6845,10 @@ public Trace pTransactionPriorityFeePerGas(final Bytes b) { } public Trace pTransactionRefundCounterInfinity(final Bytes b) { - if (filled.get(129)) { + if (filled.get(130)) { throw new IllegalStateException("hub.transaction/REFUND_COUNTER_INFINITY already set"); } else { - filled.set(129); + filled.set(130); } // Trim array to size @@ -6869,10 +6871,10 @@ public Trace pTransactionRefundCounterInfinity(final Bytes b) { } public Trace pTransactionRefundEffective(final Bytes b) { - if (filled.get(130)) { + if (filled.get(131)) { throw new IllegalStateException("hub.transaction/REFUND_EFFECTIVE already set"); } else { - filled.set(130); + filled.set(131); } // Trim array to size @@ -6921,10 +6923,10 @@ public Trace pTransactionStatusCode(final Boolean b) { } public Trace pTransactionToAddressHi(final long b) { - if (filled.get(111)) { + if (filled.get(112)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_HI already set"); } else { - filled.set(111); + filled.set(112); } if (b >= 4294967296L) { @@ -6946,10 +6948,10 @@ public Trace pTransactionToAddressHi(final long b) { } public Trace pTransactionToAddressLo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(135)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_LO already set"); } else { - filled.set(134); + filled.set(135); } // Trim array to size @@ -6974,10 +6976,10 @@ public Trace pTransactionToAddressLo(final Bytes b) { } public Trace pTransactionValue(final Bytes b) { - if (filled.get(135)) { + if (filled.get(136)) { throw new IllegalStateException("hub.transaction/VALUE already set"); } else { - filled.set(135); + filled.set(136); } // Trim array to size @@ -7284,12 +7286,12 @@ public Trace validateRow() { throw new IllegalStateException("hub.acc_FIRST has not been filled"); } - if (!filled.get(106)) { + if (!filled.get(107)) { throw new IllegalStateException( "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_BATCH_NUM has not been filled"); } - if (!filled.get(131)) { + if (!filled.get(132)) { throw new IllegalStateException( "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } @@ -7298,12 +7300,12 @@ public Trace validateRow() { throw new IllegalStateException("hub.ALPHA has not been filled"); } - if (!filled.get(133)) { + if (!filled.get(134)) { throw new IllegalStateException( "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } - if (!filled.get(132)) { + if (!filled.get(133)) { throw new IllegalStateException( "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } @@ -7312,15 +7314,15 @@ public Trace validateRow() { throw new IllegalStateException("hub.BATCH_NUMBER has not been filled"); } - if (!filled.get(114)) { + if (!filled.get(115)) { throw new IllegalStateException("hub.CALL_DATA_OFFSET_xor_MMU_SIZE has not been filled"); } - if (!filled.get(115)) { + if (!filled.get(116)) { throw new IllegalStateException("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID has not been filled"); } - if (!filled.get(105)) { + if (!filled.get(106)) { throw new IllegalStateException("hub.CALL_STACK_DEPTH has not been filled"); } @@ -7332,37 +7334,37 @@ public Trace validateRow() { throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX has not been filled"); } - if (!filled.get(107)) { + if (!filled.get(108)) { throw new IllegalStateException( "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_CALL_DATA_SIZE has not been filled"); } - if (!filled.get(135)) { + if (!filled.get(136)) { throw new IllegalStateException( "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } - if (!filled.get(134)) { + if (!filled.get(135)) { throw new IllegalStateException( "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } - if (!filled.get(137)) { + if (!filled.get(138)) { throw new IllegalStateException( "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_VALUE_NEXT_LO has not been filled"); } - if (!filled.get(136)) { + if (!filled.get(137)) { throw new IllegalStateException( "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_VALUE_NEXT_HI has not been filled"); } - if (!filled.get(109)) { + if (!filled.get(110)) { throw new IllegalStateException( "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_FROM_ADDRESS_HI has not been filled"); } - if (!filled.get(108)) { + if (!filled.get(109)) { throw new IllegalStateException( "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_COINBASE_ADDRESS_HI has not been filled"); } @@ -7391,7 +7393,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.CONTEXT_NUMBER_NEW has not been filled"); } - if (!filled.get(116)) { + if (!filled.get(117)) { throw new IllegalStateException("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID has not been filled"); } @@ -7415,6 +7417,11 @@ public Trace validateRow() { throw new IllegalStateException("hub.COUNTER_TLI has not been filled"); } + if (!filled.get(67)) { + throw new IllegalStateException( + "hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + } + if (!filled.get(68)) { throw new IllegalStateException( "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); @@ -7444,17 +7451,17 @@ public Trace validateRow() { throw new IllegalStateException("hub.DELTA has not been filled"); } - if (!filled.get(111)) { + if (!filled.get(112)) { throw new IllegalStateException( "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI has not been filled"); } - if (!filled.get(112)) { + if (!filled.get(113)) { throw new IllegalStateException( "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } - if (!filled.get(110)) { + if (!filled.get(111)) { throw new IllegalStateException( "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_INIT_CODE_SIZE has not been filled"); } @@ -7504,7 +7511,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_EXPECTED has not been filled"); } - if (!filled.get(125)) { + if (!filled.get(126)) { throw new IllegalStateException("hub.GAS_LIMIT has not been filled"); } @@ -7512,7 +7519,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_NEXT has not been filled"); } - if (!filled.get(126)) { + if (!filled.get(127)) { throw new IllegalStateException("hub.GAS_PRICE has not been filled"); } @@ -7546,7 +7553,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.HUB_STAMP_TRANSACTION_END has not been filled"); } - if (!filled.get(163)) { + if (!filled.get(164)) { throw new IllegalStateException("hub.INSTRUCTION has not been filled"); } @@ -7573,27 +7580,27 @@ public Trace validateRow() { throw new IllegalStateException("hub.MMU_STAMP has not been filled"); } - if (!filled.get(144)) { + if (!filled.get(145)) { throw new IllegalStateException("hub.MXP_OFFSET_2_HI has not been filled"); } - if (!filled.get(145)) { + if (!filled.get(146)) { throw new IllegalStateException("hub.MXP_OFFSET_2_LO has not been filled"); } - if (!filled.get(146)) { + if (!filled.get(147)) { throw new IllegalStateException("hub.MXP_SIZE_1_HI has not been filled"); } - if (!filled.get(147)) { + if (!filled.get(148)) { throw new IllegalStateException("hub.MXP_SIZE_1_LO has not been filled"); } - if (!filled.get(148)) { + if (!filled.get(149)) { throw new IllegalStateException("hub.MXP_SIZE_2_HI has not been filled"); } - if (!filled.get(149)) { + if (!filled.get(150)) { throw new IllegalStateException("hub.MXP_SIZE_2_LO has not been filled"); } @@ -7601,7 +7608,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.MXP_STAMP has not been filled"); } - if (!filled.get(150)) { + if (!filled.get(151)) { throw new IllegalStateException("hub.MXP_WORDS has not been filled"); } @@ -7617,48 +7624,48 @@ public Trace validateRow() { throw new IllegalStateException("hub.NON_STACK_ROWS has not been filled"); } - if (!filled.get(127)) { + if (!filled.get(128)) { throw new IllegalStateException("hub.NONCE has not been filled"); } - if (!filled.get(123)) { + if (!filled.get(124)) { throw new IllegalStateException( "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } - if (!filled.get(122)) { + if (!filled.get(123)) { throw new IllegalStateException("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE has not been filled"); } - if (!filled.get(151)) { + if (!filled.get(152)) { throw new IllegalStateException("hub.OOB_DATA_1 has not been filled"); } - if (!filled.get(152)) { + if (!filled.get(153)) { throw new IllegalStateException("hub.OOB_DATA_2 has not been filled"); } - if (!filled.get(153)) { + if (!filled.get(154)) { throw new IllegalStateException("hub.OOB_DATA_3 has not been filled"); } - if (!filled.get(154)) { + if (!filled.get(155)) { throw new IllegalStateException("hub.OOB_DATA_4 has not been filled"); } - if (!filled.get(155)) { + if (!filled.get(156)) { throw new IllegalStateException("hub.OOB_DATA_5 has not been filled"); } - if (!filled.get(156)) { + if (!filled.get(157)) { throw new IllegalStateException("hub.OOB_DATA_6 has not been filled"); } - if (!filled.get(157)) { + if (!filled.get(158)) { throw new IllegalStateException("hub.OOB_DATA_7 has not been filled"); } - if (!filled.get(158)) { + if (!filled.get(159)) { throw new IllegalStateException("hub.OOB_DATA_8 has not been filled"); } @@ -7747,7 +7754,7 @@ public Trace validateRow() { "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); } - if (!filled.get(128)) { + if (!filled.get(129)) { throw new IllegalStateException("hub.PRIORITY_FEE_PER_GAS has not been filled"); } @@ -7763,7 +7770,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER has not been filled"); } - if (!filled.get(129)) { + if (!filled.get(130)) { throw new IllegalStateException("hub.REFUND_COUNTER_INFINITY has not been filled"); } @@ -7771,29 +7778,29 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER_NEW has not been filled"); } - if (!filled.get(130)) { + if (!filled.get(131)) { throw new IllegalStateException("hub.REFUND_EFFECTIVE has not been filled"); } - if (!filled.get(117)) { + if (!filled.get(118)) { throw new IllegalStateException("hub.RETURN_AT_CAPACITY_xor_MXP_INST has not been filled"); } - if (!filled.get(118)) { + if (!filled.get(119)) { throw new IllegalStateException("hub.RETURN_AT_OFFSET_xor_OOB_INST has not been filled"); } - if (!filled.get(119)) { + if (!filled.get(120)) { throw new IllegalStateException( "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } - if (!filled.get(120)) { + if (!filled.get(121)) { throw new IllegalStateException( "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } - if (!filled.get(121)) { + if (!filled.get(122)) { throw new IllegalStateException("hub.RETURN_DATA_SIZE has not been filled"); } @@ -7831,12 +7838,12 @@ public Trace validateRow() { "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } - if (!filled.get(113)) { + if (!filled.get(114)) { throw new IllegalStateException( "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } - if (!filled.get(138)) { + if (!filled.get(139)) { throw new IllegalStateException( "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI has not been filled"); } @@ -7846,33 +7853,32 @@ public Trace validateRow() { "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW has not been filled"); } - if (!filled.get(139)) { + if (!filled.get(140)) { throw new IllegalStateException( "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO has not been filled"); } - if (!filled.get(140)) { + if (!filled.get(141)) { throw new IllegalStateException( "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO has not been filled"); } - if (!filled.get(63)) { - throw new IllegalStateException( - "hub.RLPADDR_RECIPE_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); + if (!filled.get(105)) { + throw new IllegalStateException("hub.RLPADDR_RECIPE has not been filled"); } - if (!filled.get(141)) { + if (!filled.get(142)) { throw new IllegalStateException("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP has not been filled"); } - if (!filled.get(142)) { + if (!filled.get(143)) { throw new IllegalStateException( "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI has not been filled"); } - if (!filled.get(64)) { + if (!filled.get(63)) { throw new IllegalStateException( - "hub.ROMLEX_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + "hub.ROMLEX_FLAG_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); } if (!filled.get(93)) { @@ -7895,67 +7901,67 @@ public Trace validateRow() { "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); } - if (!filled.get(164)) { + if (!filled.get(165)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_1 has not been filled"); } - if (!filled.get(165)) { + if (!filled.get(166)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_2 has not been filled"); } - if (!filled.get(166)) { + if (!filled.get(167)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_3 has not been filled"); } - if (!filled.get(167)) { + if (!filled.get(168)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_4 has not been filled"); } - if (!filled.get(168)) { + if (!filled.get(169)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_1 has not been filled"); } - if (!filled.get(169)) { + if (!filled.get(170)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_2 has not been filled"); } - if (!filled.get(170)) { + if (!filled.get(171)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_3 has not been filled"); } - if (!filled.get(171)) { + if (!filled.get(172)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_4 has not been filled"); } - if (!filled.get(172)) { + if (!filled.get(173)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_1 has not been filled"); } - if (!filled.get(173)) { + if (!filled.get(174)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_2 has not been filled"); } - if (!filled.get(174)) { + if (!filled.get(175)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_3 has not been filled"); } - if (!filled.get(175)) { + if (!filled.get(176)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_HI_4 has not been filled"); } - if (!filled.get(176)) { + if (!filled.get(177)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_1 has not been filled"); } - if (!filled.get(177)) { + if (!filled.get(178)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_2 has not been filled"); } - if (!filled.get(178)) { + if (!filled.get(179)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_3 has not been filled"); } - if (!filled.get(179)) { + if (!filled.get(180)) { throw new IllegalStateException("hub.STACK_ITEM_VALUE_LO_4 has not been filled"); } @@ -7967,24 +7973,24 @@ public Trace validateRow() { throw new IllegalStateException("hub.sto_FIRST has not been filled"); } - if (!filled.get(159)) { + if (!filled.get(160)) { throw new IllegalStateException("hub.STP_GAS_HI has not been filled"); } - if (!filled.get(160)) { + if (!filled.get(161)) { throw new IllegalStateException("hub.STP_GAS_LO has not been filled"); } - if (!filled.get(124)) { + if (!filled.get(125)) { throw new IllegalStateException( "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } - if (!filled.get(161)) { + if (!filled.get(162)) { throw new IllegalStateException("hub.STP_VALUE_HI has not been filled"); } - if (!filled.get(162)) { + if (!filled.get(163)) { throw new IllegalStateException("hub.STP_VALUE_LO has not been filled"); } @@ -8000,12 +8006,12 @@ public Trace validateRow() { throw new IllegalStateException("hub.SWAP_FLAG has not been filled"); } - if (!filled.get(65)) { + if (!filled.get(64)) { throw new IllegalStateException( - "hub.TRM_FLAG_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + "hub.TRM_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); } - if (!filled.get(143)) { + if (!filled.get(144)) { throw new IllegalStateException( "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } @@ -8038,14 +8044,14 @@ public Trace validateRow() { throw new IllegalStateException("hub.TXN_FLAG has not been filled"); } - if (!filled.get(67)) { + if (!filled.get(66)) { throw new IllegalStateException( - "hub.WARMTH_NEW_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + "hub.WARMTH_NEW_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); } - if (!filled.get(66)) { + if (!filled.get(65)) { throw new IllegalStateException( - "hub.WARMTH_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); } if (!filled.get(100)) { @@ -8071,7 +8077,7 @@ public Trace fillAndValidateRow() { accFirst.position(accFirst.position() + 1); } - if (!filled.get(106)) { + if (!filled.get(107)) { addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum .position( addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorBatchNum @@ -8079,7 +8085,7 @@ public Trace fillAndValidateRow() { + 4); } - if (!filled.get(131)) { + if (!filled.get(132)) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .position( addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo @@ -8091,7 +8097,7 @@ public Trace fillAndValidateRow() { alpha.position(alpha.position() + 1); } - if (!filled.get(133)) { + if (!filled.get(134)) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance .position( balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance @@ -8099,7 +8105,7 @@ public Trace fillAndValidateRow() { + 16); } - if (!filled.get(132)) { + if (!filled.get(133)) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo .position( balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo @@ -8111,15 +8117,15 @@ public Trace fillAndValidateRow() { batchNumber.position(batchNumber.position() + 2); } - if (!filled.get(114)) { + if (!filled.get(115)) { callDataOffsetXorMmuSize.position(callDataOffsetXorMmuSize.position() + 4); } - if (!filled.get(115)) { + if (!filled.get(116)) { callDataSizeXorMmuSrcId.position(callDataSizeXorMmuSrcId.position() + 4); } - if (!filled.get(105)) { + if (!filled.get(106)) { callStackDepth.position(callStackDepth.position() + 2); } @@ -8131,7 +8137,7 @@ public Trace fillAndValidateRow() { codeFragmentIndex.position(codeFragmentIndex.position() + 4); } - if (!filled.get(107)) { + if (!filled.get(108)) { codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize .position( codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCallDataSize @@ -8139,34 +8145,34 @@ public Trace fillAndValidateRow() { + 4); } - if (!filled.get(135)) { + if (!filled.get(136)) { codeHashHiNewXorExpData5XorValueCurrLoXorValue.position( codeHashHiNewXorExpData5XorValueCurrLoXorValue.position() + 16); } - if (!filled.get(134)) { + if (!filled.get(135)) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 16); } - if (!filled.get(137)) { + if (!filled.get(138)) { codeHashLoNewXorMmuLimb2XorValueNextLo.position( codeHashLoNewXorMmuLimb2XorValueNextLo.position() + 16); } - if (!filled.get(136)) { + if (!filled.get(137)) { codeHashLoXorMmuLimb1XorValueNextHi.position( codeHashLoXorMmuLimb1XorValueNextHi.position() + 16); } - if (!filled.get(109)) { + if (!filled.get(110)) { codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position( codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorFromAddressHi.position() + 4); } - if (!filled.get(108)) { + if (!filled.get(109)) { codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi .position( codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorCoinbaseAddressHi @@ -8198,7 +8204,7 @@ public Trace fillAndValidateRow() { contextNumberNew.position(contextNumberNew.position() + 4); } - if (!filled.get(116)) { + if (!filled.get(117)) { contextNumberXorMmuTgtId.position(contextNumberXorMmuTgtId.position() + 4); } @@ -8222,6 +8228,11 @@ public Trace fillAndValidateRow() { counterTli.position(counterTli.position() + 1); } + if (!filled.get(67)) { + createFailureConditionWillRevertXorHashInfoFlag.position( + createFailureConditionWillRevertXorHashInfoFlag.position() + 1); + } + if (!filled.get(68)) { createFailureConditionWontRevertXorIcpx.position( createFailureConditionWontRevertXorIcpx.position() + 1); @@ -8251,19 +8262,19 @@ public Trace fillAndValidateRow() { delta.position(delta.position() + 1); } - if (!filled.get(111)) { + if (!filled.get(112)) { deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi.position( deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi .position() + 4); } - if (!filled.get(112)) { + if (!filled.get(113)) { deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 4); } - if (!filled.get(110)) { + if (!filled.get(111)) { deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position( deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize.position() + 4); @@ -8328,7 +8339,7 @@ public Trace fillAndValidateRow() { gasExpected.position(gasExpected.position() + 4); } - if (!filled.get(125)) { + if (!filled.get(126)) { gasLimit.position(gasLimit.position() + 8); } @@ -8336,7 +8347,7 @@ public Trace fillAndValidateRow() { gasNext.position(gasNext.position() + 4); } - if (!filled.get(126)) { + if (!filled.get(127)) { gasPrice.position(gasPrice.position() + 8); } @@ -8373,7 +8384,7 @@ public Trace fillAndValidateRow() { hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 4); } - if (!filled.get(163)) { + if (!filled.get(164)) { instruction.position(instruction.position() + 32); } @@ -8409,27 +8420,27 @@ public Trace fillAndValidateRow() { mmuStamp.position(mmuStamp.position() + 4); } - if (!filled.get(144)) { + if (!filled.get(145)) { mxpOffset2Hi.position(mxpOffset2Hi.position() + 16); } - if (!filled.get(145)) { + if (!filled.get(146)) { mxpOffset2Lo.position(mxpOffset2Lo.position() + 16); } - if (!filled.get(146)) { + if (!filled.get(147)) { mxpSize1Hi.position(mxpSize1Hi.position() + 16); } - if (!filled.get(147)) { + if (!filled.get(148)) { mxpSize1Lo.position(mxpSize1Lo.position() + 16); } - if (!filled.get(148)) { + if (!filled.get(149)) { mxpSize2Hi.position(mxpSize2Hi.position() + 16); } - if (!filled.get(149)) { + if (!filled.get(150)) { mxpSize2Lo.position(mxpSize2Lo.position() + 16); } @@ -8437,7 +8448,7 @@ public Trace fillAndValidateRow() { mxpStamp.position(mxpStamp.position() + 4); } - if (!filled.get(150)) { + if (!filled.get(151)) { mxpWords.position(mxpWords.position() + 16); } @@ -8453,48 +8464,48 @@ public Trace fillAndValidateRow() { nonStackRows.position(nonStackRows.position() + 1); } - if (!filled.get(127)) { + if (!filled.get(128)) { nonce.position(nonce.position() + 8); } - if (!filled.get(123)) { + if (!filled.get(124)) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 8); } - if (!filled.get(122)) { + if (!filled.get(123)) { nonceXorStpGasMxpXorBasefee.position(nonceXorStpGasMxpXorBasefee.position() + 8); } - if (!filled.get(151)) { + if (!filled.get(152)) { oobData1.position(oobData1.position() + 16); } - if (!filled.get(152)) { + if (!filled.get(153)) { oobData2.position(oobData2.position() + 16); } - if (!filled.get(153)) { + if (!filled.get(154)) { oobData3.position(oobData3.position() + 16); } - if (!filled.get(154)) { + if (!filled.get(155)) { oobData4.position(oobData4.position() + 16); } - if (!filled.get(155)) { + if (!filled.get(156)) { oobData5.position(oobData5.position() + 16); } - if (!filled.get(156)) { + if (!filled.get(157)) { oobData6.position(oobData6.position() + 16); } - if (!filled.get(157)) { + if (!filled.get(158)) { oobData7.position(oobData7.position() + 16); } - if (!filled.get(158)) { + if (!filled.get(159)) { oobData8.position(oobData8.position() + 16); } @@ -8579,7 +8590,7 @@ public Trace fillAndValidateRow() { prcSuccessCallerWontRevertXorRdcx.position(prcSuccessCallerWontRevertXorRdcx.position() + 1); } - if (!filled.get(128)) { + if (!filled.get(129)) { priorityFeePerGas.position(priorityFeePerGas.position() + 8); } @@ -8595,7 +8606,7 @@ public Trace fillAndValidateRow() { refundCounter.position(refundCounter.position() + 4); } - if (!filled.get(129)) { + if (!filled.get(130)) { refundCounterInfinity.position(refundCounterInfinity.position() + 8); } @@ -8603,28 +8614,28 @@ public Trace fillAndValidateRow() { refundCounterNew.position(refundCounterNew.position() + 4); } - if (!filled.get(130)) { + if (!filled.get(131)) { refundEffective.position(refundEffective.position() + 8); } - if (!filled.get(117)) { + if (!filled.get(118)) { returnAtCapacityXorMxpInst.position(returnAtCapacityXorMxpInst.position() + 4); } - if (!filled.get(118)) { + if (!filled.get(119)) { returnAtOffsetXorOobInst.position(returnAtOffsetXorOobInst.position() + 4); } - if (!filled.get(119)) { + if (!filled.get(120)) { returnDataContextNumberXorStpGasStipend.position( returnDataContextNumberXorStpGasStipend.position() + 4); } - if (!filled.get(120)) { + if (!filled.get(121)) { returnDataOffsetXorStpInstruction.position(returnDataOffsetXorStpInstruction.position() + 4); } - if (!filled.get(121)) { + if (!filled.get(122)) { returnDataSize.position(returnDataSize.position() + 4); } @@ -8662,12 +8673,12 @@ public Trace fillAndValidateRow() { returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); } - if (!filled.get(113)) { + if (!filled.get(114)) { rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 4); } - if (!filled.get(138)) { + if (!filled.get(139)) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position( rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi.position() + 16); } @@ -8678,31 +8689,30 @@ public Trace fillAndValidateRow() { + 1); } - if (!filled.get(139)) { + if (!filled.get(140)) { rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position( rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo.position() + 16); } - if (!filled.get(140)) { + if (!filled.get(141)) { rlpaddrKecLoXorMmuTgtOffsetLo.position(rlpaddrKecLoXorMmuTgtOffsetLo.position() + 16); } - if (!filled.get(63)) { - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position( - rlpaddrRecipeXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); + if (!filled.get(105)) { + rlpaddrRecipe.position(rlpaddrRecipe.position() + 1); } - if (!filled.get(141)) { + if (!filled.get(142)) { rlpaddrSaltHiXorMxpGasMxp.position(rlpaddrSaltHiXorMxpGasMxp.position() + 16); } - if (!filled.get(142)) { + if (!filled.get(143)) { rlpaddrSaltLoXorMxpOffset1Hi.position(rlpaddrSaltLoXorMxpOffset1Hi.position() + 16); } - if (!filled.get(64)) { - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( - romlexFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + if (!filled.get(63)) { + romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.position( + romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); } if (!filled.get(93)) { @@ -8724,67 +8734,67 @@ public Trace fillAndValidateRow() { selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); } - if (!filled.get(164)) { + if (!filled.get(165)) { stackItemHeight1.position(stackItemHeight1.position() + 32); } - if (!filled.get(165)) { + if (!filled.get(166)) { stackItemHeight2.position(stackItemHeight2.position() + 32); } - if (!filled.get(166)) { + if (!filled.get(167)) { stackItemHeight3.position(stackItemHeight3.position() + 32); } - if (!filled.get(167)) { + if (!filled.get(168)) { stackItemHeight4.position(stackItemHeight4.position() + 32); } - if (!filled.get(168)) { + if (!filled.get(169)) { stackItemStamp1.position(stackItemStamp1.position() + 32); } - if (!filled.get(169)) { + if (!filled.get(170)) { stackItemStamp2.position(stackItemStamp2.position() + 32); } - if (!filled.get(170)) { + if (!filled.get(171)) { stackItemStamp3.position(stackItemStamp3.position() + 32); } - if (!filled.get(171)) { + if (!filled.get(172)) { stackItemStamp4.position(stackItemStamp4.position() + 32); } - if (!filled.get(172)) { + if (!filled.get(173)) { stackItemValueHi1.position(stackItemValueHi1.position() + 32); } - if (!filled.get(173)) { + if (!filled.get(174)) { stackItemValueHi2.position(stackItemValueHi2.position() + 32); } - if (!filled.get(174)) { + if (!filled.get(175)) { stackItemValueHi3.position(stackItemValueHi3.position() + 32); } - if (!filled.get(175)) { + if (!filled.get(176)) { stackItemValueHi4.position(stackItemValueHi4.position() + 32); } - if (!filled.get(176)) { + if (!filled.get(177)) { stackItemValueLo1.position(stackItemValueLo1.position() + 32); } - if (!filled.get(177)) { + if (!filled.get(178)) { stackItemValueLo2.position(stackItemValueLo2.position() + 32); } - if (!filled.get(178)) { + if (!filled.get(179)) { stackItemValueLo3.position(stackItemValueLo3.position() + 32); } - if (!filled.get(179)) { + if (!filled.get(180)) { stackItemValueLo4.position(stackItemValueLo4.position() + 32); } @@ -8796,24 +8806,24 @@ public Trace fillAndValidateRow() { stoFirst.position(stoFirst.position() + 1); } - if (!filled.get(159)) { + if (!filled.get(160)) { stpGasHi.position(stpGasHi.position() + 16); } - if (!filled.get(160)) { + if (!filled.get(161)) { stpGasLo.position(stpGasLo.position() + 16); } - if (!filled.get(124)) { + if (!filled.get(125)) { stpGasUpfrontGasCostXorGasLeftover.position( stpGasUpfrontGasCostXorGasLeftover.position() + 8); } - if (!filled.get(161)) { + if (!filled.get(162)) { stpValueHi.position(stpValueHi.position() + 16); } - if (!filled.get(162)) { + if (!filled.get(163)) { stpValueLo.position(stpValueLo.position() + 16); } @@ -8829,12 +8839,12 @@ public Trace fillAndValidateRow() { swapFlag.position(swapFlag.position() + 1); } - if (!filled.get(65)) { - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position( - trmFlagXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + if (!filled.get(64)) { + trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( + trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); } - if (!filled.get(143)) { + if (!filled.get(144)) { trmRawAddressHiXorMxpOffset1Lo.position(trmRawAddressHiXorMxpOffset1Lo.position() + 16); } @@ -8866,14 +8876,14 @@ public Trace fillAndValidateRow() { txnFlag.position(txnFlag.position() + 1); } - if (!filled.get(67)) { - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position( - warmthNewXorCreateFailureConditionWillRevertXorHashInfoFlag.position() + 1); + if (!filled.get(66)) { + warmthNewXorCreateExceptionXorHaltFlag.position( + warmthNewXorCreateExceptionXorHaltFlag.position() + 1); } - if (!filled.get(66)) { - warmthXorCreateExceptionXorHaltFlag.position( - warmthXorCreateExceptionXorHaltFlag.position() + 1); + if (!filled.get(65)) { + warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.position( + warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); } if (!filled.get(100)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java index 81343d8f79..ed0c23728a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java @@ -59,7 +59,7 @@ public static RlpAddrSubFragment makeFragment(Hub hub, Address createdAddress) { public Trace trace(Trace trace) { return trace .pAccountRlpaddrFlag(true) - .pAccountRlpaddrRecipe(recipe == 2) // TODO: regenerate Trace.java and update it + .pAccountRlpaddrRecipe(recipe) .pAccountRlpaddrDepAddrHi(highPart(depAddress)) .pAccountRlpaddrDepAddrLo(lowPart(depAddress)) .pAccountRlpaddrSaltHi(salt.slice(0, LLARGE)) diff --git a/gradle/trace-files.gradle b/gradle/trace-files.gradle index ef5d865e6c..49f7e47480 100644 --- a/gradle/trace-files.gradle +++ b/gradle/trace-files.gradle @@ -29,7 +29,7 @@ // tasks.register("hub", TraceFilesTask) { group "Trace files generation" - dependsOn corsetExists + // dependsOn corsetExists module = 'hub' files = ['hub/constants.lisp', 'hub/columns/account.lisp', 'hub/columns/context.lisp', 'hub/columns/shared.lisp', 'hub/columns/stack.lisp', From f4638793a71a50e382accff75ff04217b7237dd9 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 19 Jul 2024 14:07:36 +0530 Subject: [PATCH 240/461] feat(hub): CREATE ready for testing and debuging --- .../linea/zktracer/module/hub/Hub.java | 28 +----- .../module/hub/fragment/imc/ImcFragment.java | 4 +- .../fragment/imc/call/mmu/opcode/Create.java | 7 ++ .../hub/section/create/CreateSection.java | 24 +++-- .../create/FailureOrEmptyInitCreate.java | 4 +- .../hub/section/create/FillCreateSection.java | 4 +- .../create/NonEmptyInitCodeCreate.java | 94 ++++++++++++++++++- 7 files changed, 120 insertions(+), 45 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 78385fecee..a26670a54f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -18,7 +18,6 @@ import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.*; import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; -import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; import java.nio.MappedByteBuffer; import java.util.HashMap; @@ -1151,32 +1150,7 @@ void traceOperation(MessageFrame frame) { } } - case CREATE -> { - new CreateSection(this); - - final Address myAddress = this.currentFrame().accountAddress(); - final Account myAccount = frame.getWorldUpdater().get(myAddress); - AccountSnapshot myAccountSnapshot = - AccountSnapshot.fromAccount( - myAccount, - frame.isAddressWarm(myAddress), - this.transients.conflation().deploymentInfo().number(myAddress), - this.transients.conflation().deploymentInfo().isDeploying(myAddress)); - - final Address createdAddress = getCreateAddress(frame); - final Account createdAccount = frame.getWorldUpdater().get(createdAddress); - AccountSnapshot createdAccountSnapshot = - AccountSnapshot.fromAccount( - createdAccount, - frame.isAddressWarm(createdAddress), - this.transients.conflation().deploymentInfo().number(createdAddress), - this.transients.conflation().deploymentInfo().isDeploying(createdAddress)); - - CreateSectionOld createSection = - new CreateSectionOld(this, myAccountSnapshot, createdAccountSnapshot); - this.addTraceSection(createSection); - this.currentFrame().needsUnlatchingAtReEntry(createSection); - } + case CREATE -> new CreateSection(this); case CALL -> { final Address myAddress = this.currentFrame().accountAddress(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index fff3350b1a..c5e24bdcc8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -192,13 +192,13 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { // case MSTORE -> r.callMmu(MmuCall.mstore(hub)); // case MSTORE8 -> r.callMmu(MmuCall.mstore8(hub)); // case LOG0, LOG1, LOG2, LOG3, LOG4 -> r.callMmu(MmuCall.log(hub)); - case CREATE -> r.callMmu(MmuCall.create(hub)); + // case CREATE -> r.callMmu(MmuCall.create(hub)); case RETURN -> r.callMmu( hub.currentFrame().isDeployment() ? MmuCall.returnFromDeployment( hub) // TODO Add a MMU call to MMU_INST_INVALID_CODE8PREFIX : MmuCall.returnFromCall(hub)); - case CREATE2 -> r.callMmu(MmuCall.create2(hub)); + // case CREATE2 -> r.callMmu(MmuCall.create2(hub)); case REVERT -> r.callMmu(MmuCall.revert(hub)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java index 3f249dc42b..09f8281450 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java @@ -17,6 +17,8 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING; +import java.util.Optional; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; @@ -38,6 +40,11 @@ public Create(final Hub hub) { this.hub.romLex().createDefers().register(this); this.sourceId(hub.currentFrame().contextNumber()) + .sourceRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(2))) .referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(2))) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 5d4f7e635d..3ec25a91ed 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -77,13 +77,13 @@ private boolean targetHasCode() { private final ImcFragment imcFragment; private MmuCall mmuCall; - // row i+ ? + // row i+? private ContextFragment lastContextFragment; public CreateSection(Hub hub) { final short exception = hub.pch().exceptions(); - // row i +1 + // row i + 1 final ContextFragment commonContext = ContextFragment.readCurrentContextData(hub); imcFragment = ImcFragment.empty(hub); @@ -167,6 +167,8 @@ public CreateSection(Hub hub) { // Finally, non-exceptional, non-aborting, non-failing, non-emptyInitCode create this.createSection = new NonEmptyInitCodeCreate(hub, commonContext, imcFragment); + this.mmuCall = hub.opCode() == OpCode.CREATE2 ? MmuCall.create2(hub) : MmuCall.create(hub); + this.lastContextFragment = ContextFragment.initializeExecutionContext(hub); } @Override @@ -223,8 +225,17 @@ public void resolvePostTransaction( this.imcFragment.callMmu(this.mmuCall); } + final CallFrame createCallFrame = hub.callStack().getById(this.creatorContextId); + final int childRevertStamp = + createCallFrame.childFrames().isEmpty() + ? 0 + : hub.callStack() + .getById(createCallFrame.childFrames().getFirst()) + .revertStamp(); // TODO: not sure about this this.createSection.fillAccountFragment( hub, + createSuccessful, + childRevertStamp, rlpAddrSubFragment, oldCreatorSnapshot, midCreatorSnapshot, @@ -233,18 +244,11 @@ public void resolvePostTransaction( midCreatedSnapshot, newCreatedSnapshot); - final CallFrame createCallFrame = hub.callStack().getById(this.creatorContextId); if (createCallFrame.hasReverted()) { - final int childRevertStamp = - createCallFrame.childFrames().isEmpty() - ? 0 - : hub.callStack() - .getById(createCallFrame.childFrames().getFirst()) - .revertStamp(); // TODO: not sure about this final int currentRevertStamp = createCallFrame.revertStamp(); this.createSection.fillReverting( hub, - childRevertStamp, + createSuccessful, currentRevertStamp, oldCreatorSnapshot, midCreatorSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java index 7d5ca6cf1f..cc54a6eb12 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -52,6 +52,8 @@ public FailureOrEmptyInitCreate( @Override public void fillAccountFragment( Hub hub, + boolean createSuccess, + int childRevertStamp, RlpAddrSubFragment rlpAddrSubFragment, AccountSnapshot oldCreatorSnapshot, AccountSnapshot midCreatorSnapshot, @@ -81,7 +83,7 @@ public void fillAccountFragment( @Override public void fillReverting( Hub hub, - int childRevertStamp, + boolean createSuccess, int currentRevertStamp, AccountSnapshot oldCreatorSnapshot, AccountSnapshot midCreatorSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java index 7f65f5f577..b09d6ba33f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java @@ -23,6 +23,8 @@ public interface FillCreateSection { void fillAccountFragment( final Hub hub, + final boolean createSuccess, + final int childRevertStamp, final RlpAddrSubFragment rlpAddrSubFragment, final AccountSnapshot oldCreatorSnapshot, final AccountSnapshot midCreatorSnapshot, @@ -33,7 +35,7 @@ void fillAccountFragment( void fillReverting( final Hub hub, - final int childRevertStamp, + final boolean createSuccess, final int currentRevertStamp, final AccountSnapshot oldCreatorSnapshot, final AccountSnapshot midCreatorSnapshot, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index b0b2a81c1e..ee8e284095 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -15,43 +15,129 @@ package net.consensys.linea.zktracer.module.hub.section.create; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT; + import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class NonEmptyInitCodeCreate extends TraceSection implements FillCreateSection { + final int hubStamp; + final CreateScenarioFragment scenarioFragment; + public NonEmptyInitCodeCreate( final Hub hub, final ContextFragment commonContext, final ImcFragment imcFragment) { super(hub, (short) 11); hub.addTraceSection(this); + + this.hubStamp = hub.stamp(); + this.scenarioFragment = new CreateScenarioFragment(); + + this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); } @Override public void fillAccountFragment( Hub hub, + boolean createSuccess, + int childRevertStamp, RlpAddrSubFragment rlpAddrSubFragment, AccountSnapshot oldCreatorSnapshot, AccountSnapshot midCreatorSnapshot, AccountSnapshot newCreatorSnapshot, AccountSnapshot oldCreatedSnapshot, AccountSnapshot midCreatedSnapshot, - AccountSnapshot newCreatedSnapshot) {} + AccountSnapshot newCreatedSnapshot) { + final ScenarioEnum scenario = + createSuccess + ? CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT + : CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; + this.scenarioFragment.setScenario(scenario); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final AccountFragment oldToMidCreatorAccountFragment = + accountFragmentFactory.make( + oldCreatorSnapshot, + midCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 0)); + oldToMidCreatorAccountFragment.rlpAddrSubFragment(rlpAddrSubFragment); + + final AccountFragment oldToMidCreatedAccountFragment = + accountFragmentFactory.make( + oldCreatedSnapshot, + midCreatedSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 1)); + + this.addFragmentsWithoutStack(oldToMidCreatorAccountFragment, oldToMidCreatedAccountFragment); + + if (!createSuccess) { + final AccountFragment midToNewCreatorAccountFragment = + accountFragmentFactory.make( + midCreatorSnapshot, + newCreatorSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps(hubStamp, childRevertStamp, 2)); + + final AccountFragment midToNewCreatedAccountFragment = + accountFragmentFactory.make( + midCreatedSnapshot, + newCreatedSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps(hubStamp, childRevertStamp, 3)); + + this.addFragmentsWithoutStack(midToNewCreatorAccountFragment, midToNewCreatedAccountFragment); + } + } @Override public void fillReverting( Hub hub, - int childRevertStamp, + boolean createSuccess, int currentRevertStamp, AccountSnapshot oldCreatorSnapshot, AccountSnapshot midCreatorSnapshot, AccountSnapshot newCreatorSnapshot, AccountSnapshot oldCreatedSnapshot, AccountSnapshot midCreatedSnapshot, - AccountSnapshot newCreatedSnapshot) {} + AccountSnapshot newCreatedSnapshot) { + + final ScenarioEnum newScenario = + createSuccess + ? CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT + : CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; + this.scenarioFragment.setScenario(newScenario); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final AccountFragment undoCreatorAccountFragment = + accountFragmentFactory.make( + createSuccess ? midCreatorSnapshot : newCreatorSnapshot, + oldCreatorSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + hubStamp, currentRevertStamp, createSuccess ? 2 : 4)); + final AccountFragment undoCreatedAccountFragment = + accountFragmentFactory.make( + createSuccess ? midCreatedSnapshot : newCreatedSnapshot, + oldCreatedSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + hubStamp, currentRevertStamp, createSuccess ? 3 : 5)); + + this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); + } @Override - public void fillContextFragment(ContextFragment contextFragment) {} + public void fillContextFragment(ContextFragment contextFragment) { + this.addFragment(contextFragment); + } } From 115bd734b01eb9d94a2c6a3d8ed6879694104bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 19 Jul 2024 12:12:56 +0200 Subject: [PATCH 241/461] ras --- .../hub/section/copy/ExtCodeCopySection.java | 7 +- .../hub/section/halt/ReturnSection.java | 30 +++++++- limits.md | 77 +++++++++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 limits.md diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 5c9f3fbede..a68299aa88 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -70,9 +70,10 @@ public ExtCodeCopySection(Hub hub) { hub.transients().conflation().deploymentInfo().isDeploying(this.address); this.incomingWarmth = frame.isAddressWarm(this.address); this.exceptions = hub.pch().exceptions(); + this.miscFragment = ImcFragment.empty(hub); - miscFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, miscFragment); + this.addStack(hub); + this.addFragment(this.miscFragment); // triggerExp = false // triggerOob = false @@ -80,7 +81,7 @@ public ExtCodeCopySection(Hub hub) { // triggerMxp = true final MxpCall mxpCall = new MxpCall(hub); - miscFragment.callMxp(mxpCall); + this.miscFragment.callMxp(mxpCall); Preconditions.checkArgument( mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 5611ff2726..66fbcab72a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -17,6 +17,8 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.RETURN_EXCEPTION; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -26,9 +28,13 @@ import net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.worldstate.WorldView; public class ReturnSection - extends TraceSection { // implements PostTransactionDefer, PostRollbackDefer { + extends TraceSection implements PostTransactionDefer, PostRollbackDefer { final short exceptions; final ImcFragment imcFragment; @@ -37,6 +43,7 @@ public class ReturnSection boolean triggerOob = false; boolean triggerHashInfo = false; boolean messageCallTouchesRam = false; + boolean returnFromDeployment; public ReturnSection(Hub hub) { // 5 = 1 + 4 @@ -57,6 +64,9 @@ public ReturnSection(Hub hub) { this.addFragment(currentContextFragment); this.addFragment(imcFragment); + // Exceptional RETURN's + /////////////////////// + if (Exceptions.any(exceptions)) { returnScenarioFragment.setScenario(RETURN_EXCEPTION); } @@ -75,12 +85,28 @@ public ReturnSection(Hub hub) { final boolean triggerMmuForInvalidCodePrefix = Exceptions.invalidCodePrefix(exceptions); if (triggerMmuForInvalidCodePrefix) { - // mmuCall = MmuCall.invalidCodePrefix(); TODO: + // TODO: @françois: invalidCodePrefix currently unavailable + // mmuCall = MmuCall.invalidCodePrefix(); } + // Unexceptional RETURN's + ///////////////////////// + final boolean triggerOobForNonemptyDeployments = Exceptions.none(exceptions) && hub.currentFrame().isDeployment() && mxpCall.isMayTriggerNonTrivialMmuOperation(); + + // returnFromDeployment = + } + + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + + } + + @Override + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + } } diff --git a/limits.md b/limits.md new file mode 100644 index 0000000000..ad36d345f3 --- /dev/null +++ b/limits.md @@ -0,0 +1,77 @@ +# Limits for ECDATA precompiles + +- line limits for ECDATA as a standard module + - [ ] for all precompiles and their row-space in the ECDATA module + - [ ] specify the upper limit for ECDATA +- specialized limits + - [x] ECPAIRING 'talliers' + - [x] PRECOMPILE_ECPAIRING_MILLER_LOOPS + - [x] PRECOMPILE_ECPAIRING_FINAL_EXPONENTIATIONS + - [x] PRECOMPILE_ECPAIRING_G2_MEMBERSHIP_TESTS + - [x] ECRECOVER 'tallier' + - [x] ECADD 'tallier' + - [x] ECMUL 'tallier' + + +How large can the ECDATA trace get +- ECRECOVER: 128 * 10 = 1280 +- ECADD: 16384 * 12 = 196608 +- ECMUL: 32 * 10 = 320 +- ECPAIRING (unexceptional, nontrivial): 16 * (4 * 12 + 2) = 800 +- sum total = 199008 + + +Number of pairs of points: +========================== +- 0 ⇐ shouldn't trigger anything in ECDATA +- 1 ⇐ strange edgecase which is permitted by the EVM +- 2 or more ⇐ canonical case + +1 point: +======== + +- ICP fail / success + - Failure cases: 2 * 2 * 2 - 1 = 7 ways to fail; + - Success: 1 way to succeed + - well-formedness of pair of points: + - Failure: 2 ways to fail ( B not on C2 ? on C2 but not on G2 ?) + - Success: 4 ways of succeeding: + + | small point A | ≡ ∞ | ≠ ∞ | + | large point B | ≡ ∞ | ≠ ∞ | + + ( ★ ) case analysis: + - [B ≡ ∞]: should trigger nothing (CS_ECPAIRING = 0, CS_G2_MEMBERSHIP = 0) + - [B ≠ ∞] ∧ [A ≡ ∞]: should trigger nothing (CS_ECPAIRING = 0, CS_G2_MEMBERSHIP = 1) + - [B ≠ ∞] ∧ [A ≠ ∞]: should trigger nothing (CS_ECPAIRING = 1, CS_G2_MEMBERSHIP = 0) + +FAILURE_KNOWN_TO_RAM: 7 + 2 test scenarios +RAM_SUCCESS: 3 cases (or 4 is we include the distinction on [A ≡ ∞ ?] in the first case) + +n points: +========= + +n = number of pairs of points (n = 2, 3, 4 for the extensive tests; and maybe some larger thing to test GNARK's ability to chain the Miller loops) + +- ICP failure: +- ICP success: + - one or more of the B_k are malformed [check with 1 malformed and also with 2 or more]: + - expect to see: (SUCCESS_BIT = 0, CS_ECPAIRING = 0, CS_G2_MEMBERSHIP = 1 @ first malformed k) + - we have 2 ways to be malformed but we can be malformed (1) more than once (2) for different reasons + - all of the B_k are wellformed + - expect to see: (SUCCESS_BIT = 1) + - if TRIVIAL_PAIRING = 1 case (all B_k's are infinity) then the arithmetization sets the RESULT to 1 + the arithmetization sets the SUCCESS_BIT = 1) + - it TRIVIAL_PAIRING = 0 + - k by k we have the same analysis as in the 1 point case ( ★ ) + + +FAILURE_KNOWN_TO_RAM: +- 7 + (2 * n + 4 * n(n-1)/2 + ...) = 7 + (1 + 2)^n test scenarios (the same as before + we have a choice for where it fails, how often, several failure conditions at once etc ...) 2 * n ≡ 2 ways to fail at a position 1 ≤ k ≤ n, 4 * n(n-1)/2 ways to fail at 2 positions etc ... + +RAM_SUCCESS test cases we want to test: +- TRIVIAL_PAIRING = 1 + - all the B_k's are ∞, and we can freely select the A_k's to be a mixture of ∞'s and nontrivial points + - 2 ^ n choices for (which of the A_k are ≡ ∞) +- TRIVIAL_PAIRING = 0 + - all of the pairs of points are ACCEPTABLE_PAIR_OF_POINTS + - only some are and we require CS_G2_MEMBERSHIP_TEST From a360bb5586997bf5135cf1505b999e763c1fff27 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 19 Jul 2024 17:26:02 +0530 Subject: [PATCH 242/461] test: add CREATE test --- .../hub/section/halt/ReturnSection.java | 12 +- .../module/rlpaddr/TestRlpAddress.java | 202 ++++++++---------- 2 files changed, 98 insertions(+), 116 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 66fbcab72a..e9e7752f1e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -33,8 +33,7 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; -public class ReturnSection - extends TraceSection implements PostTransactionDefer, PostRollbackDefer { +public class ReturnSection extends TraceSection implements PostTransactionDefer, PostRollbackDefer { final short exceptions; final ImcFragment imcFragment; @@ -101,12 +100,9 @@ public ReturnSection(Hub hub) { } @Override - public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - - } + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) {} @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - - } + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index 27e247b986..4f58d056ab 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -15,14 +15,9 @@ package net.consensys.linea.zktracer.module.rlpaddr; -import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randBigInt; import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randData; import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randLong; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; import java.util.Random; import net.consensys.linea.zktracer.opcode.OpCode; @@ -40,126 +35,117 @@ import org.hyperledger.besu.datatypes.TransactionType; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @ExtendWith(EvmExtension.class) public class TestRlpAddress { - private static final int TEST_TX_COUNT = 30; private final Random rnd = new Random(666); @Test - @Disabled - void test() { - ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); - List txList = new ArrayList<>(); - - for (int i = 0; i < TEST_TX_COUNT; i++) { - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount senderAccount = randSenderAccount(senderAddress); - - Bytes initCode = randData(true); - int initCodeSize = initCode.size(); - - int trigger = rnd.nextInt(0, 3); - ToyAccount receiverAccount; - switch (trigger) { - case 0 -> { // create with tx.To = null - world.account(senderAccount); - txList.add( - ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .transactionType(TransactionType.FRONTIER) - .gasLimit(rnd.nextLong(21000, 0xffffL)) - .payload(initCode) - .build()); - } - case 1 -> { // Create OpCode - receiverAccount = randCreate(initCodeSize); - world.account(senderAccount).account(receiverAccount); - txList.add( - ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .to(receiverAccount) - .transactionType(TransactionType.FRONTIER) - .gasLimit(rnd.nextLong(21000, 0xffffL)) - .build()); - } - case 2 -> { // Create2 OpCode - receiverAccount = randCreateTwo(initCodeSize); - world.account(senderAccount).account(receiverAccount); - txList.add( - ToyTransaction.builder() - .sender(senderAccount) - .keyPair(keyPair) - .to(receiverAccount) - .transactionType(TransactionType.FRONTIER) - .gasLimit(rnd.nextLong(21000, 0xffffL)) - .build()); - } - } - } + void randDeployment() { + final ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); + + final KeyPair keyPair = new SECP256K1().generateKeyPair(); + final Address senderAddress = + Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount = + ToyAccount.builder() + .balance(Wei.of(100000000)) + .nonce(randLong()) + .address(senderAddress) + .build(); + ; + + final Bytes initCode = randData(true); + + world.account(senderAccount); + + final Transaction tx = + ToyTransaction.builder() + .sender(senderAccount) + .keyPair(keyPair) + .transactionType(TransactionType.FRONTIER) + .gasLimit(rnd.nextLong(21000, 0xffffL)) + .payload(initCode) + .build(); ToyExecutionEnvironment.builder() .toyWorld(world.build()) - .transactions(txList) + .transaction(tx) .testValidator(x -> {}) .build() .run(); } - private ToyAccount randCreate(int initCodeSize) { - byte[] value = bigIntegerToBytes(BigInteger.valueOf(randLong())).toArray(); - return ToyAccount.builder() - .balance(Wei.fromEth(1000)) - .nonce(randLong()) - .address(Address.wrap(Bytes.repeat((byte) 0x01, 20))) - .code( - BytecodeCompiler.newProgram() - .push(initCodeSize) - .push(1) - .push(1) - .op(OpCode.CALLDATACOPY) - .push(initCodeSize) - .push(1) - .push(value.length, value) - .op(OpCode.CREATE) - .compile()) - .build(); - } + @Test + void create() { + final ToyWorld.ToyWorldBuilder world = ToyWorld.builder(); - private ToyAccount randCreateTwo(int initCodeSize) { - byte[] salt = bigIntegerToBytes(randBigInt(false)).toArray(); - byte[] value = bigIntegerToBytes(BigInteger.valueOf(randLong())).toArray(); - - return ToyAccount.builder() - .balance(Wei.fromEth(1000)) - .nonce(randLong()) - .address(Address.wrap(Bytes.repeat((byte) 0x02, 20))) - .code( - BytecodeCompiler.newProgram() - .push(initCodeSize) - .push(1) - .push(1) - .op(OpCode.CALLDATACOPY) - .push(salt.length, salt) - .push(1) - .push(1) - .push(value.length, value) - .op(OpCode.CREATE2) - .compile()) - .build(); - } + final KeyPair keyPair = new SECP256K1().generateKeyPair(); + final Address senderAddress = + Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + + final ToyAccount senderAccount = + ToyAccount.builder() + .balance(Wei.of(100000000)) + .nonce(randLong()) + .address(senderAddress) + .build(); + world.account(senderAccount); + + final Address contractAddress = Address.fromHexString("0x000bad000000b077000"); + final ToyAccount contractAccount = + ToyAccount.builder() + .balance(Wei.of(10000000)) + .nonce(10) + .address(contractAddress) + .code( + BytecodeCompiler.newProgram() - final ToyAccount randSenderAccount(Address senderAddress) { - return ToyAccount.builder() - .balance(Wei.of(randBigInt(true))) - .nonce(randLong()) - .address(senderAddress) - .build(); + // copy the entirety of the call data to RAM + .op(OpCode.CALLDATASIZE) + .push(0) + .push(0) + .op(OpCode.CALLDATACOPY) + .op(OpCode.CALLDATASIZE) + .push(0) + .push(rnd.nextInt(0, 50000)) // value + .op(OpCode.CREATE) + .op(OpCode.STOP) + .compile()) + .build(); + world.account(contractAccount); + + final Bytes initCodeReturnContractCode = + BytecodeCompiler.newProgram() + .push(contractAddress) + .op(OpCode.EXTCODESIZE) + .op(OpCode.DUP1) + .push(0) + .push(0) + .op(OpCode.DUP5) + .op(OpCode.EXTCODECOPY) + .push(0) + .push(0) + .op(OpCode.RETURN) + .compile(); + + final Transaction tx = + ToyTransaction.builder() + .sender(senderAccount) + .to(contractAccount) + .keyPair(keyPair) + .transactionType(TransactionType.FRONTIER) + .gasLimit(rnd.nextLong(21000, 0xffffL)) + .payload(initCodeReturnContractCode) + .build(); + + ToyExecutionEnvironment.builder() + .toyWorld(world.build()) + .transaction(tx) + .testValidator(x -> {}) + .build() + .run(); } } From af398e2448f41f66e574c7c115fde3f4f1056f49 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 19 Jul 2024 15:12:27 +0200 Subject: [PATCH 243/461] feat(selfdestruct): managed will revert case --- .../hub/section/halt/SelfdestructSection.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index e0ad93db59..4e6a81db39 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -174,6 +174,22 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undo the modifications we applied to selfDestroyerFirstAccountFragment and recipientFirstAccountFragment this will add account rows. Shall we basically go back from after to before? */ + // TODO: check if we can we use the same AccountSnapshot objects to revert the changes? + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.accountAfter, + this.accountBefore, + DomSubStampsSubFragment.selfdestructDomSubStamps(hub))); + + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.recipientAccountAfter, + this.recipientAccountBefore, + DomSubStampsSubFragment.selfdestructDomSubStamps(hub))); } @Override From 36b5e0f0c1b40e2a55c63750acb08aa58c09c917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 22 Jul 2024 00:08:18 +0200 Subject: [PATCH 244/461] feat(return): wip --- .../module/hub/fragment/ContextFragment.java | 4 +- .../hub/section/halt/ReturnSection.java | 154 +++++++++++++++--- 2 files changed, 135 insertions(+), 23 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 3f25342b26..9b83335dcb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -129,8 +129,10 @@ public static ContextFragment providesReturnData( callStack, Either.right(receiverContextNumber), providerContextNumber, - callStack.current().latestReturnDataSource().snapshot(), // TODO: is this what we want ? + callStack.current().latestReturnDataSource().snapshot(), true); + // TODO: is this what we want ? + // also: will the latestReturnData have been updated ? } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index e9e7752f1e..987223445e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -14,8 +14,8 @@ */ package net.consensys.linea.zktracer.module.hub.section.halt; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.RETURN_EXCEPTION; - +import com.google.common.base.Preconditions; +import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; @@ -33,16 +33,22 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; + +@Getter public class ReturnSection extends TraceSection implements PostTransactionDefer, PostRollbackDefer { final short exceptions; - final ImcFragment imcFragment; - MmuCall mmuCall; - boolean triggerMmu = false; - boolean triggerOob = false; - boolean triggerHashInfo = false; - boolean messageCallTouchesRam = false; - boolean returnFromDeployment; + final boolean returnFromDeployment; + final boolean returnFromMessageCall; // not stricly speaking necessary + ReturnScenarioFragment returnScenarioFragment; + final ImcFragment firstImcFragment; + MmuCall firstMmuCall; + MmuCall secondMmuCall; + + ContextFragment squashCreatorReturnData; + @Getter public boolean emptyDeployment; + @Getter public boolean deploymentWasReverted = false; public ReturnSection(Hub hub) { // 5 = 1 + 4 @@ -51,58 +57,162 @@ public ReturnSection(Hub hub) { hub.addTraceSection(this); exceptions = hub.pch().exceptions(); + returnFromMessageCall = hub.currentFrame().isMessageCall(); + returnFromDeployment = hub.currentFrame().isDeployment(); + firstImcFragment = ImcFragment.empty(hub); - final ReturnScenarioFragment returnScenarioFragment = new ReturnScenarioFragment(); + returnScenarioFragment = new ReturnScenarioFragment(); final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); - imcFragment = ImcFragment.empty(hub); final MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); + firstImcFragment.callMxp(mxpCall); this.addStack(hub); this.addFragment(returnScenarioFragment); this.addFragment(currentContextFragment); - this.addFragment(imcFragment); + this.addFragment(firstImcFragment); // Exceptional RETURN's /////////////////////// + /////////////////////// if (Exceptions.any(exceptions)) { returnScenarioFragment.setScenario(RETURN_EXCEPTION); } + // Memory expansion exception (MXPX) + // Out of gas exception (OOGX) + //////////////////////////////////// if (Exceptions.memoryExpansionException(exceptions) || Exceptions.outOfGasException(exceptions)) { + // Note: the context fragment will be added elsewhere return; } + + // Max code size exception (MAXCSX) + /////////////////////////////////// boolean triggerOobForMaxCodeSizeException = Exceptions.codeSizeOverflow(exceptions); if (triggerOobForMaxCodeSizeException) { + Preconditions.checkArgument(hub.currentFrame().isDeployment()); OobCall oobCall = new XCallOobCall(); - imcFragment.callOob(oobCall); + firstImcFragment.callOob(oobCall); return; } + // Invalid code prefix exception (ICPX) + /////////////////////////////////////// final boolean triggerMmuForInvalidCodePrefix = Exceptions.invalidCodePrefix(exceptions); if (triggerMmuForInvalidCodePrefix) { + Preconditions.checkArgument(hub.currentFrame().isDeployment()); // TODO: @françois: invalidCodePrefix currently unavailable - // mmuCall = MmuCall.invalidCodePrefix(); + // TODO: @olivier: hub.defers().schedulePostTransaction(hub); + // firstMmuCall = MmuCall.invalidCodePrefix(); + return; } + Preconditions.checkArgument(Exceptions.none(exceptions)); + // Unexceptional RETURN's - ///////////////////////// + // (we have exceptions ≡ ∅ by the checkArgument) + //////////////////////////////////////////////// + //////////////////////////////////////////////// + + final boolean nontrivialMmOperation = mxpCall.isMayTriggerNonTrivialMmuOperation(); + + // RETURN_FROM_MESSAGE_CALL cases + ///////////////////////////////// + ///////////////////////////////// + if (returnFromMessageCall) { + // TODO: remove final long returnAtCapacity = hub.currentFrame().requestedReturnDataTarget().length(); + final boolean messageCallReturnTouchesRam = + !hub.currentFrame().isRoot() + && nontrivialMmOperation // [size ≠ 0] ∧ ¬MXPX + && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); // [r@c ≠ 0] + + returnScenarioFragment.setScenario( + messageCallReturnTouchesRam + ? RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM + : RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM); + + if (messageCallReturnTouchesRam) { + firstMmuCall = MmuCall.returnFromCall(hub); + hub.defers().schedulePostTransaction(this); + } else { + // TODO: should we add the following ? It shouldn't be necessary ... + // mmuCall = MmuCall.nop(); + // hub.defers().schedulePostTransaction(this); + } + + ContextFragment updateCallerReturnData = ContextFragment.providesReturnData( + hub, + hub.callStack().getById(hub.currentFrame().parentFrame()).contextNumber(), + hub.currentFrame().contextNumber()); + this.addFragment(updateCallerReturnData); + + + return; + } + + // RETURN_FROM_DEPLOYMENT cases + /////////////////////////////// + /////////////////////////////// + if (returnFromDeployment) { + + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + final boolean triggerOobForNonemptyDeployments = + mxpCall.isMayTriggerNonTrivialMmuOperation(); + + final long byteCodeSize = hub.messageFrame().getStackItem(1).toLong(); + final boolean emptyDeployment = byteCodeSize == 0; + + if (emptyDeployment) { + return; + } + + // TODO: + // firstMmuCall = MmuCall.invalidCodePrefix(); + + // TODO: we need to implement the mechanism that will append the + // context row which will squash the creator's return data after + // any and all account-rows. + // + // TODO: make sure this works if the current context is the root + // context (deployment transaction) in particular the following + // ``Either.left(callStack.parent().id())'' + squashCreatorReturnData = ContextFragment.executionProvidesEmptyReturnData(hub); + } - final boolean triggerOobForNonemptyDeployments = - Exceptions.none(exceptions) - && hub.currentFrame().isDeployment() - && mxpCall.isMayTriggerNonTrivialMmuOperation(); // returnFromDeployment = } @Override - public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) {} + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + // TODO + Preconditions.checkArgument(returnFromDeployment); + returnScenarioFragment.setScenario( + emptyDeployment + ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT + : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT); + + this.addFragment(squashCreatorReturnData); + + deploymentWasReverted = true; + } @Override public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + // TODO + + if (returnFromDeployment && !deploymentWasReverted) { + returnScenarioFragment.setScenario( + emptyDeployment + ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT + : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); + } + + firstImcFragment.callMmu(firstMmuCall); + this.addFragment(squashCreatorReturnData); + } } From 721dc9da89118d764504fee12089deea95376e97 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 22 Jul 2024 13:32:38 +0530 Subject: [PATCH 245/461] feat(return): implement mmu call invalid code prefix --- .../hub/fragment/imc/call/mmu/MmuCall.java | 14 ++++ .../hub/section/halt/ReturnSection.java | 84 ++++++++++--------- 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index b41b070943..0fc5555781 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -30,6 +30,7 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_ANY_TO_RAM_WITH_PADDING; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_BLAKE; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_EXO_TO_RAM_TRANSPLANTS; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_INVALID_CODE_PREFIX; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MLOAD; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MODEXP_DATA; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MODEXP_ZERO; @@ -79,6 +80,7 @@ import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.LogInvocation; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; @@ -273,6 +275,18 @@ public static MmuCall create2(final Hub hub) { return new Create2(hub); } + public static MmuCall invalidCodePrefix(final Hub hub) { + return new MmuCall(MMU_INST_INVALID_CODE_PREFIX) + .sourceId(hub.currentFrame().contextNumber()) + .sourceRamBytes( + Optional.of( + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) + .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) + .successBit(Exceptions.any(hub.pch().exceptions())); + } + public static MmuCall revert(final Hub hub) { return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(hub.currentFrame().contextNumber()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 987223445e..ae9b610c36 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -14,6 +14,8 @@ */ package net.consensys.linea.zktracer.module.hub.section.halt; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; + import com.google.common.base.Preconditions; import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; @@ -33,15 +35,13 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; - @Getter public class ReturnSection extends TraceSection implements PostTransactionDefer, PostRollbackDefer { final short exceptions; final boolean returnFromDeployment; final boolean returnFromMessageCall; // not stricly speaking necessary - ReturnScenarioFragment returnScenarioFragment; + final ReturnScenarioFragment returnScenarioFragment; final ImcFragment firstImcFragment; MmuCall firstMmuCall; MmuCall secondMmuCall; @@ -88,7 +88,6 @@ public ReturnSection(Hub hub) { return; } - // Max code size exception (MAXCSX) /////////////////////////////////// boolean triggerOobForMaxCodeSizeException = Exceptions.codeSizeOverflow(exceptions); @@ -104,9 +103,8 @@ public ReturnSection(Hub hub) { final boolean triggerMmuForInvalidCodePrefix = Exceptions.invalidCodePrefix(exceptions); if (triggerMmuForInvalidCodePrefix) { Preconditions.checkArgument(hub.currentFrame().isDeployment()); - // TODO: @françois: invalidCodePrefix currently unavailable - // TODO: @olivier: hub.defers().schedulePostTransaction(hub); - // firstMmuCall = MmuCall.invalidCodePrefix(); + firstMmuCall = MmuCall.invalidCodePrefix(hub); + hub.defers().schedulePostTransaction(this); return; } @@ -123,34 +121,35 @@ public ReturnSection(Hub hub) { ///////////////////////////////// ///////////////////////////////// if (returnFromMessageCall) { - // TODO: remove final long returnAtCapacity = hub.currentFrame().requestedReturnDataTarget().length(); + // TODO: remove final long returnAtCapacity = + // hub.currentFrame().requestedReturnDataTarget().length(); final boolean messageCallReturnTouchesRam = - !hub.currentFrame().isRoot() - && nontrivialMmOperation // [size ≠ 0] ∧ ¬MXPX - && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); // [r@c ≠ 0] + !hub.currentFrame().isRoot() + && nontrivialMmOperation // [size ≠ 0] ∧ ¬MXPX + && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); // [r@c ≠ 0] returnScenarioFragment.setScenario( - messageCallReturnTouchesRam + messageCallReturnTouchesRam ? RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM : RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM); - if (messageCallReturnTouchesRam) { - firstMmuCall = MmuCall.returnFromCall(hub); - hub.defers().schedulePostTransaction(this); - } else { - // TODO: should we add the following ? It shouldn't be necessary ... - // mmuCall = MmuCall.nop(); - // hub.defers().schedulePostTransaction(this); - } - - ContextFragment updateCallerReturnData = ContextFragment.providesReturnData( - hub, - hub.callStack().getById(hub.currentFrame().parentFrame()).contextNumber(), - hub.currentFrame().contextNumber()); - this.addFragment(updateCallerReturnData); + if (messageCallReturnTouchesRam) { + firstMmuCall = MmuCall.returnFromCall(hub); + hub.defers().schedulePostTransaction(this); + } else { + // TODO: should we add the following ? It shouldn't be necessary ... @FB: no, no need. + // mmuCall = MmuCall.nop(); + // hub.defers().schedulePostTransaction(this); + } + ContextFragment updateCallerReturnData = + ContextFragment.providesReturnData( + hub, + hub.callStack().getById(hub.currentFrame().parentFrame()).contextNumber(), + hub.currentFrame().contextNumber()); + this.addFragment(updateCallerReturnData); - return; + return; } // RETURN_FROM_DEPLOYMENT cases @@ -159,8 +158,8 @@ public ReturnSection(Hub hub) { if (returnFromDeployment) { hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - final boolean triggerOobForNonemptyDeployments = - mxpCall.isMayTriggerNonTrivialMmuOperation(); + + final boolean triggerOobForNonemptyDeployments = mxpCall.isMayTriggerNonTrivialMmuOperation(); final long byteCodeSize = hub.messageFrame().getStackItem(1).toLong(); final boolean emptyDeployment = byteCodeSize == 0; @@ -169,8 +168,8 @@ public ReturnSection(Hub hub) { return; } - // TODO: - // firstMmuCall = MmuCall.invalidCodePrefix(); + hub.defers().schedulePostTransaction(this); + firstMmuCall = MmuCall.invalidCodePrefix(hub); // TODO: we need to implement the mechanism that will append the // context row which will squash the creator's return data after @@ -182,7 +181,6 @@ public ReturnSection(Hub hub) { squashCreatorReturnData = ContextFragment.executionProvidesEmptyReturnData(hub); } - // returnFromDeployment = } @@ -191,9 +189,9 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca // TODO Preconditions.checkArgument(returnFromDeployment); returnScenarioFragment.setScenario( - emptyDeployment - ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT - : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT); + emptyDeployment + ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT + : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT); this.addFragment(squashCreatorReturnData); @@ -202,17 +200,23 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { // TODO if (returnFromDeployment && !deploymentWasReverted) { returnScenarioFragment.setScenario( - emptyDeployment - ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT - : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); + emptyDeployment + ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT + : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); } - firstImcFragment.callMmu(firstMmuCall); + if (firstMmuCall != null) { + firstImcFragment.callMmu(firstMmuCall); + } + // TODO: + // if (secondMmuCall != null) { + // secondImcFragment.callMmu(secondMmuCall); + // } this.addFragment(squashCreatorReturnData); } } From 962736ea9b31da9b8fc4740dada3cc64b90be2b9 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 22 Jul 2024 18:23:12 +0200 Subject: [PATCH 246/461] feat(selfdestruct): review and complete will revert case --- .../zktracer/module/hub/AccountSnapshot.java | 12 ++++ .../module/hub/fragment/ContextFragment.java | 2 +- .../hub/section/halt/SelfdestructSection.java | 72 +++++++++++-------- .../zktracer/runtime/callstack/CallStack.java | 20 ++++-- 4 files changed, 73 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index f3a32e6c43..fce06d1335 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -173,4 +173,16 @@ public AccountSnapshot credit(Wei value) { this.deploymentNumber, this.deploymentStatus); } + + // TODO: confirm with Tsvetan if this creates a proper deep copy + public AccountSnapshot deepCopy() { + return new AccountSnapshot( + this.address, + this.nonce, + this.balance, + this.isWarm, + this.code, + this.deploymentNumber, + this.deploymentStatus); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 9b83335dcb..c1ffb3d3cd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -139,7 +139,7 @@ public static ContextFragment providesReturnData( public Trace trace(Trace trace) { final CallFrame callFrame = this.callFrameReference.map(this.callStack::getById, this.callStack::getByContextNumber); - final CallFrame parent = callStack.getParentOf(callFrame.id()); + final CallFrame parent = callStack.getParentCallFrameById(callFrame.id()); final Address address = callFrame.accountAddress(); final Address codeAddress = callFrame.byteCodeAddress(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 4e6a81db39..bd9bb4c01a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section.halt; import com.google.common.base.Preconditions; +import lombok.Getter; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; @@ -36,22 +37,24 @@ public class SelfdestructSection extends TraceSection implements PostRollbackDefer, PostTransactionDefer { + final int hubStamp; final short exceptions; + SelfdestructScenarioFragment selfdestructScenarioFragment; + final Address address; AccountSnapshot accountBefore; AccountSnapshot accountAfter; final Bytes recipientRawAddress; final Address recipientAddress; - AccountSnapshot recipientAccountBefore; - AccountSnapshot recipientAccountAfter; - AccountFragment selfDestroyerFirstAccountFragment; AccountFragment recipientFirstAccountFragment; + AccountSnapshot recipientAccountBefore; + AccountSnapshot recipientAccountAfter; - AccountFragment selfDestroyerSecondAccountFragment; - AccountFragment recipientSecondAccountFragment; + final boolean selfDestructTagetsItself; + @Getter boolean selfDestructWasReverted = false; public SelfdestructSection(Hub hub) { // up to 8 = 1 + 7 rows @@ -59,6 +62,7 @@ public SelfdestructSection(Hub hub) { hub.addTraceSection(this); // Init + hubStamp = hub.stamp(); this.exceptions = hub.pch().exceptions(); final MessageFrame frame = hub.messageFrame(); @@ -72,10 +76,15 @@ public SelfdestructSection(Hub hub) { this.recipientRawAddress = frame.getStackItem(0); this.recipientAddress = Address.extract((Bytes32) this.recipientRawAddress); // final recipientAccount = frame.getWorldUpdater().get(this.recipientAddress); - this.recipientAccountBefore = AccountSnapshot.canonical(hub, this.recipientAddress); - // - SelfdestructScenarioFragment selfdestructScenarioFragment = new SelfdestructScenarioFragment(); + this.selfDestructTagetsItself = this.address.equals(this.recipientAddress); + + this.recipientAccountBefore = + selfDestructTagetsItself + ? this.accountAfter.deepCopy() + : AccountSnapshot.canonical(hub, this.recipientAddress); + + selfdestructScenarioFragment = new SelfdestructScenarioFragment(); // SCN fragment this.addFragment(selfdestructScenarioFragment); if (Exceptions.any(exceptions)) { @@ -122,7 +131,7 @@ public SelfdestructSection(Hub hub) { return; } - // Unexceptional case (add CON row in the end manually in any case) + // Unexceptional case hub.defers().scheduleForPostRollback(this, hub.currentFrame()); hub.defers().schedulePostTransaction(this); @@ -135,37 +144,31 @@ public SelfdestructSection(Hub hub) { // - The recipient address will become warm (i+3) // * recipientFirstAccountFragment - // Here we complete the SELFDESTRUCT without knowing yet if it will be reverted yet (not yet - // marked case?) - // ACC fragment (?) this.accountAfter = this.accountBefore.debit(this.accountBefore.balance()); - selfDestroyerSecondAccountFragment = + selfDestroyerFirstAccountFragment = hub.factories() .accountFragment() .make( this.accountBefore, this.accountAfter, DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); - this.addFragment(selfDestroyerSecondAccountFragment); + this.addFragment(selfDestroyerFirstAccountFragment); - // ACC fragment (?) this.recipientAccountAfter = - !recipientAddress.equals(address) - ? this.recipientAccountBefore.credit(this.accountBefore.balance()) - : this.recipientAccountBefore.debit( - this.recipientAccountBefore + this.selfDestructTagetsItself + ? this.accountAfter.deepCopy() + : this.recipientAccountBefore.credit( + this.accountBefore .balance()); // NOTE: in the second case account is equal to recipientAccount this.recipientAccountAfter = this.recipientAccountAfter.turnOnWarmth(); - recipientSecondAccountFragment = + recipientFirstAccountFragment = hub.factories() .accountFragment() .make( this.recipientAccountBefore, this.recipientAccountAfter, DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); - this.addFragment(recipientSecondAccountFragment); - - // take a look at EXTCODECOPY, RETURN, ACCOUNT for reference + this.addFragment(recipientFirstAccountFragment); } @Override @@ -174,22 +177,35 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undo the modifications we applied to selfDestroyerFirstAccountFragment and recipientFirstAccountFragment this will add account rows. Shall we basically go back from after to before? */ - // TODO: check if we can we use the same AccountSnapshot objects to revert the changes? - this.addFragment( + final AccountFragment selfDestroyerUndoingAccountFragment = hub.factories() .accountFragment() .make( this.accountAfter, this.accountBefore, - DomSubStampsSubFragment.selfdestructDomSubStamps(hub))); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + hubStamp, callFrame.revertStamp(), 2)); + this.addFragment(selfDestroyerUndoingAccountFragment); - this.addFragment( + final AccountFragment recipientUndoingAccountFragment = hub.factories() .accountFragment() .make( this.recipientAccountAfter, this.recipientAccountBefore, - DomSubStampsSubFragment.selfdestructDomSubStamps(hub))); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + hubStamp, callFrame.revertStamp(), 3)); + this.addFragment(recipientUndoingAccountFragment); + + ContextFragment squashParentContextReturnData = + ContextFragment.executionProvidesEmptyReturnData( + hub, hub.callStack().getParentContextNumberById(callFrame.id())); + this.addFragment(squashParentContextReturnData); + + selfDestructWasReverted = true; + + selfdestructScenarioFragment.setScenario( + SelfdestructScenarioFragment.SelfdestructScenario.SELFDESTRUCT_WILL_REVERT); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 7359ef9590..8d50c3eca2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -339,16 +339,28 @@ public CallFrame getByContextNumber(final long i) { /** * Returns the parent of the ith {@link CallFrame} in this call stack. * - * @param i ID of the call frame whose parent to fetch + * @param id ID of the call frame whose parent to fetch * @return the ith call frame parent * @throws IndexOutOfBoundsException if the index is out of range */ - public CallFrame getParentOf(int i) { + public CallFrame getParentCallFrameById(int id) { if (this.frames.isEmpty()) { return CallFrame.EMPTY; } - return this.getById(this.frames.get(i).parentFrame()); + return this.getById(this.frames.get(id).parentFrame()); + } + + /** + * Retrieves the context number of the parent {@link CallFrame} for a given call frame ID. + * + * @param id the ID of the call frame whose parent's context number is to be retrieved. + * @return the context number of the parent call frame. If the call frame has no parent, or if the + * specified ID does not correspond to a valid call frame, this method returns the context + * number of the {@link CallFrame#EMPTY} which is typically 0. + */ + public int getParentContextNumberById(int id) { + return this.getParentCallFrameById(id).contextNumber(); } public void revert(int stamp) { @@ -358,7 +370,7 @@ public void revert(int stamp) { public String pretty() { StringBuilder r = new StringBuilder(2000); for (CallFrame c : this.frames) { - final CallFrame parent = this.getParentOf(c.id()); + final CallFrame parent = this.getParentCallFrameById(c.id()); r.append(" ".repeat(c.depth())); r.append( "%d/%d (<- %d/%d): %s" From 2fe118fd4cc37c8f6e1d13fdfe69a0924cec2e54 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 22 Jul 2024 19:06:04 +0200 Subject: [PATCH 247/461] feat(selfdestruct): added comments --- .../hub/fragment/account/AccountFragment.java | 14 +++++++- .../hub/section/halt/SelfdestructSection.java | 33 ++++++++++--------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index eb65c3eb8b..a93f0759ff 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -57,6 +57,11 @@ public final class AccountFragment private final DomSubStampsSubFragment domSubStampsSubFragment; @Setter private RlpAddrSubFragment rlpAddrSubFragment; + // TODO: will be needed to properly compute MARKED_FOR_SELFDESTRUCT + // and to have the correct value of the hub stamp for the subordinate + // stamp of any reverting scenario. @Olivier @Francois @Lorenzo + // final int hubStamp; + /** * {@link AccountFragment} creation requires access to a {@link DeferRegistry} for post-conflation * data gathering, which is provided by this factory. @@ -98,7 +103,12 @@ public AccountFragment( this.addressToTrim = addressToTrim; this.domSubStampsSubFragment = domSubStampsSubFragment; + // This allows us to properly fill EXISTS_INFTY, DEPLOYMENT_NUMBER_INFTY and CODE_FRAGMENT_INDEX defers.schedulePostConflation(this); + + // This allows us to properly fill MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW, + // among other things + defers.schedulePostTransaction(this); } @Override @@ -155,7 +165,9 @@ public Trace trace(Trace trace) { @Override public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + // TODO + } @Override public void resolvePostConflation(Hub hub, WorldView world) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index bd9bb4c01a..0ccf5751fa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -37,6 +37,7 @@ public class SelfdestructSection extends TraceSection implements PostRollbackDefer, PostTransactionDefer { + final int id; final int hubStamp; final short exceptions; @@ -53,7 +54,7 @@ public class SelfdestructSection extends TraceSection AccountSnapshot recipientAccountBefore; AccountSnapshot recipientAccountAfter; - final boolean selfDestructTagetsItself; + final boolean selfDestructTargetsItself; @Getter boolean selfDestructWasReverted = false; public SelfdestructSection(Hub hub) { @@ -62,6 +63,7 @@ public SelfdestructSection(Hub hub) { hub.addTraceSection(this); // Init + this.id = hub.currentFrame().id(); hubStamp = hub.stamp(); this.exceptions = hub.pch().exceptions(); @@ -69,18 +71,16 @@ public SelfdestructSection(Hub hub) { // Account this.address = frame.getSenderAddress(); - // final Account accountAccount = frame.getWorldUpdater().get(this.address); this.accountBefore = AccountSnapshot.canonical(hub, this.address); // Recipient this.recipientRawAddress = frame.getStackItem(0); this.recipientAddress = Address.extract((Bytes32) this.recipientRawAddress); - // final recipientAccount = frame.getWorldUpdater().get(this.recipientAddress); - this.selfDestructTagetsItself = this.address.equals(this.recipientAddress); + this.selfDestructTargetsItself = this.address.equals(this.recipientAddress); this.recipientAccountBefore = - selfDestructTagetsItself + selfDestructTargetsItself ? this.accountAfter.deepCopy() : AccountSnapshot.canonical(hub, this.recipientAddress); @@ -105,7 +105,6 @@ public SelfdestructSection(Hub hub) { if (Exceptions.any(exceptions)) { Preconditions.checkArgument(exceptions == Exceptions.OUT_OF_GAS_EXCEPTION); - // ACC fragment (1) selfDestroyerFirstAccountFragment = hub.factories() .accountFragment() @@ -114,9 +113,8 @@ public SelfdestructSection(Hub hub) { this.accountBefore, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); - this.addFragment(selfDestroyerFirstAccountFragment); // i+2 + this.addFragment(selfDestroyerFirstAccountFragment); - // ACC fragment (2) recipientFirstAccountFragment = hub.factories() .accountFragment() @@ -126,7 +124,7 @@ public SelfdestructSection(Hub hub) { this.recipientRawAddress, DomSubStampsSubFragment.standardDomSubStamps(hub, 1)); - this.addFragment(recipientFirstAccountFragment); // i+3 + this.addFragment(recipientFirstAccountFragment); return; } @@ -155,7 +153,7 @@ public SelfdestructSection(Hub hub) { this.addFragment(selfDestroyerFirstAccountFragment); this.recipientAccountAfter = - this.selfDestructTagetsItself + this.selfDestructTargetsItself ? this.accountAfter.deepCopy() : this.recipientAccountBefore.credit( this.accountBefore @@ -173,10 +171,8 @@ public SelfdestructSection(Hub hub) { @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - /* willRevert case - undo the modifications we applied to selfDestroyerFirstAccountFragment and recipientFirstAccountFragment - this will add account rows. Shall we basically go back from after to before? - */ + // Undo the modifications we applied to selfDestroyerFirstAccountFragment and + // recipientFirstAccountFragment final AccountFragment selfDestroyerUndoingAccountFragment = hub.factories() .accountFragment() @@ -199,7 +195,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca ContextFragment squashParentContextReturnData = ContextFragment.executionProvidesEmptyReturnData( - hub, hub.callStack().getParentContextNumberById(callFrame.id())); + hub, hub.callStack().getParentContextNumberById(this.id)); this.addFragment(squashParentContextReturnData); selfDestructWasReverted = true; @@ -211,6 +207,13 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + // if selfDestructWasReverted = false then we are in the WONT_REVERT case + // We still need to understand in which of the below cases we are: + // selfdestructScenarioFragment.setScenario( + // SelfdestructScenarioFragment.SelfdestructScenario.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED); + // selfdestructScenarioFragment.setScenario( + // SelfdestructScenarioFragment.SelfdestructScenario.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED); + // will not revert (subcases: already marked, not yet marked) // - not yet marked corresponds to when SELFDESTRUCT produces no exceptions, will not be // reverted From ea70c7dc4a8ccaf01e86aab2a7f5bd751248d892 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 22 Jul 2024 19:22:19 +0200 Subject: [PATCH 248/461] ras --- .../hub/section/halt/SelfdestructSection.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 0ccf5751fa..566fe1eeca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -218,33 +218,42 @@ public void resolvePostTransaction( // - not yet marked corresponds to when SELFDESTRUCT produces no exceptions, will not be // reverted // ,and it is the first time this account will be successful in self-destructing + // - already marked corresponds to when SELFDESTRUCT produces no exceptions, will not be // reverted // ,and it is not the first time this account will be successful in self-destructing + // mark for self-destructing is associated to an address and a deployment number - // use a maps that keeps track the (hub stamp, call frame) of all the unexceptional + // use a maps that keeps track of the (hub stamp, call frame) of all the unexceptional // SELFDESTRUCT for a given (address, deployment number) + // at the end of the transaction we have that map + // we analyse that map: // for every (address, deployment number) we walk through the list of [(hub stamp, call frame), // ...] + // for every call frame we know if it was reverted or not + // the first time (selfDestructTime) we find a call frame that has not been reverted, we // remember the hub stamp + // this produces a new map (address, deployment number) -> selfDestructTime (of the first // successful and un-reverted // SELFDESTRUCT) - // we know have a map of all (address, deployment number) that have been successful in + + // we now have a map of all (address, deployment number) that have been successful in // self-destructing // and the hub stamp in which it happened + // for every account row in the entire trace, we can now decide what to write in the - // MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW columns + // MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW columns: // MARKED_FOR_SELFDESTRUCT = [hub stamp < selfDestructTime] // MARKED_FOR_SELFDESTRUCT_NEW = [hub stamp >= selfDestructTime] // This will only be triggered at the hub stamp = selfDestructTime - // i+4 for not yet marked case - // we wipe the entire account + // we wipe the entire account in the "not yet marked" case (precisely when not yet marked + // transitions from false to true) (see row i+4 of not yet marked case) // in the already marked case we know that this action has already been scheduled for the future // every transaction should start with an empty map From 15088abb03b9f32c2992e51bf2ffcfa2565f8763 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 22 Jul 2024 23:46:22 +0530 Subject: [PATCH 249/461] clean stuff --- .../linea/zktracer/module/hub/Hub.java | 13 +- .../fragment/scenario/ScenarioFragment.java | 15 +- .../module/hub/section/CreateSectionOld.java | 360 ------------------ .../module/hub/signals/FailureConditions.java | 34 +- .../hub/signals/PlatformController.java | 2 +- .../zktracer/module/hub/signals/Signals.java | 83 +--- 6 files changed, 18 insertions(+), 489 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a26670a54f..2eb8da2cdf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -924,7 +924,9 @@ void triggerModules(MessageFrame frame) { if (this.pch.signals().hashInfo()) { // TODO: this.hashInfo.tracePreOpcode(frame); } - if (this.pch.signals().ecData()) { + if (this.pch + .signals() + .ecData()) { // TODO why do we have this ? Shouldn't it be triggered by a precompileLimits ? this.ecData.tracePreOpcode(frame); } if (this.pch.signals().blockhash()) { @@ -983,15 +985,6 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { .value(result); } } - - // TODO: this seems useless now - // if (this.pch.exceptions().none()) { - // for (TraceSection.TraceLine line : section.fragments()) { - // if (line.specific() instanceof StackFragment stackFragment) { - // stackFragment.feedHashedValue(frame); - // } - // } - // } } void processStateExec(MessageFrame frame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index e460d4e60c..1cdde1adbc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -72,25 +72,12 @@ public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { hub.callStack().futureId(), Exceptions.any(hub.pch().exceptions()), hub.pch().abortingConditions().any(), - hub.pch().failureConditions().any(), + false, Exceptions.invalidCodePrefix(hub.pch().exceptions())); hub.defers().schedulePostTransaction(r); return r; } - public static ScenarioFragment forCreate(final Hub hub, boolean targetHasCode) { - return new ScenarioFragment( - Optional.empty(), - ScenarioEnum.CREATE_EXCEPTION, // this is wrong, but all will be deleted - targetHasCode, - hub.currentFrame().id(), - hub.callStack().futureId(), - Exceptions.any(hub.pch().exceptions()), - hub.pch().abortingConditions().any(), - hub.pch().failureConditions().any(), - Exceptions.invalidCodePrefix(hub.pch().exceptions())); - } - public static ScenarioFragment forSmartContractCallSection( final Hub hub, int calledFrameId, int callerFrameId) { final ScenarioFragment r = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java deleted file mode 100644 index f09b63ad72..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSectionOld.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section; - -import net.consensys.linea.zktracer.module.constants.GlobalConstants; -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.NextContextDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; -import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.module.hub.signals.FailureConditions; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.opcode.gas.projector.GasProjection; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class CreateSectionOld extends TraceSection - implements PostExecDefer, NextContextDefer, PostTransactionDefer, ReEnterContextDefer { - private final int creatorContextId; - private final boolean emptyInitCode; - private final OpCode opCode; - private final long initialGas; - private final AbortingConditions aborts; - private final short exceptions; - private final FailureConditions failures; - - // Just before create - private final AccountSnapshot oldCreatorSnapshot; - private final AccountSnapshot oldCreatedSnapshot; - - // Just after create but before entering child frame - private AccountSnapshot midCreatorSnapshot; - private AccountSnapshot midCreatedSnapshot; - - // After return from child-context - private AccountSnapshot newCreatorSnapshot; - private AccountSnapshot newCreatedSnapshot; - - private boolean createSuccessful; - - /* true if the putatively created account already has code **/ - private boolean targetHasCode() { - return !oldCreatedSnapshot.code().isEmpty(); - } - - public CreateSectionOld( - Hub hub, AccountSnapshot oldCreatorSnapshot, AccountSnapshot oldCreatedSnapshot) { - super(hub); - this.creatorContextId = hub.currentFrame().id(); - this.opCode = hub.opCode(); - this.emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); - this.initialGas = hub.messageFrame().getRemainingGas(); - this.aborts = hub.pch().abortingConditions().snapshot(); - this.exceptions = hub.pch().exceptions(); - this.failures = hub.pch().failureConditions().snapshot(); - - this.oldCreatorSnapshot = oldCreatorSnapshot; - this.oldCreatedSnapshot = oldCreatedSnapshot; - - // this.scenarioFragment = ScenarioFragment.forCreate(hub, this.targetHasCode()); - - this.addStack(hub); - - // Will be traced in one (and only one!) of these depending on the hubSuccess of - // the operation - hub.defers().schedulePostExecution(this); - hub.defers().scheduleForContextReEntry(this, hub.currentFrame().id()); - hub.defers().reEntry(this); - } - - @Override - public void resolvePostExecution( - Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - Address creatorAddress = oldCreatorSnapshot.address(); - this.midCreatorSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(creatorAddress), - true, - hub.transients().conflation().deploymentInfo().number(creatorAddress), - hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); - - Address createdAddress = oldCreatedSnapshot.address(); - this.midCreatedSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(createdAddress), - true, - hub.transients().conflation().deploymentInfo().number(createdAddress), - hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); - // Pre-emptively set new* snapshots in case we never enter the child frame. - // Will be overwritten if we enter the child frame and runNextContext is explicitly called by - // the defer registry. - this.resolveAtContextReEntry(hub, frame); - } - - @Override - public void resolveWithNextContext(Hub hub, MessageFrame frame) {} - - @Override - public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { - this.createSuccessful = !frame.getStackItem(0).isZero(); - - Address creatorAddress = oldCreatorSnapshot.address(); - this.newCreatorSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(creatorAddress), - true, - hub.transients().conflation().deploymentInfo().number(creatorAddress), - hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); - - Address createdAddress = oldCreatedSnapshot.address(); - this.newCreatedSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(createdAddress), - true, - hub.transients().conflation().deploymentInfo().number(createdAddress), - hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); - } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - final boolean creatorWillRevert = hub.callStack().getById(this.creatorContextId).hasReverted(); - final GasProjection projection = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()); - final long upfrontCost = - projection.memoryExpansion() - + projection.linearPerWord() - + GlobalConstants.GAS_CONST_G_TX_CREATE; - - final ImcFragment commonImcFragment = - ImcFragment.empty(hub).callOob(new CreateOobCall()).callMxp(MxpCall.build(hub)) - // .callStp( - // new StpCall( - // this.opCode.byteValue(), - // EWord.of(this.initialGas), - // EWord.ZERO, - // false, - // oldCreatedSnapshot.isWarm(), - // this.exceptions.outOfGasException(), - // upfrontCost, - // allButOneSixtyFourth(this.initialGas - upfrontCost), - // 0)) - ; - - // this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); - // this.addFragmentsWithoutStack(scenarioFragment); - if (Exceptions.staticFault(this.exceptions)) { - this.addFragmentsWithoutStack( - ImcFragment.empty(hub), - ContextFragment.readCurrentContextData(hub), - ContextFragment.executionProvidesEmptyReturnData(hub)); - } else if (Exceptions.memoryExpansionException(this.exceptions)) { - this.addFragmentsWithoutStack( - ImcFragment.empty(hub).callMxp(MxpCall.build(hub)), - ContextFragment.executionProvidesEmptyReturnData(hub)); - } else if (Exceptions.outOfGasException(this.exceptions)) { - this.addFragmentsWithoutStack( - commonImcFragment, ContextFragment.executionProvidesEmptyReturnData(hub)); - } else if (this.aborts.any()) { - this.addFragmentsWithoutStack( - commonImcFragment, - ContextFragment.readCurrentContextData(hub), - accountFragmentFactory.make( - oldCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - ContextFragment.nonExecutionEmptyReturnData(hub)); - } else if (this.failures.any()) { - if (creatorWillRevert) { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - accountFragmentFactory.make( - newCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), - accountFragmentFactory.make( - newCreatedSnapshot, - oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3)), - ContextFragment.nonExecutionEmptyReturnData(hub)); - } else { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - ContextFragment.nonExecutionEmptyReturnData(hub)); - } - } else { - // entry into the CREATE operation - if (this.emptyInitCode) { - if (creatorWillRevert) { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - accountFragmentFactory.make( - newCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), - accountFragmentFactory.make( - newCreatedSnapshot, - oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3)), - ContextFragment.nonExecutionEmptyReturnData(hub)); - } else { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - ContextFragment.nonExecutionEmptyReturnData(hub)); - } - } else { - // non empty code - final int createeContextId = hub.callStack().futureId(); - if (this.createSuccessful) { - if (creatorWillRevert) { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - midCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - midCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - accountFragmentFactory.make( - midCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), - accountFragmentFactory.make( - midCreatedSnapshot, - oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3)), - ContextFragment.initializeExecutionContext(hub)); - - } else { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - midCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - midCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - ContextFragment.initializeExecutionContext(hub)); - } - } else { - if (creatorWillRevert) { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - midCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - midCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - accountFragmentFactory.make( - midCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps( - hub, hub.callStack().getById(createeContextId), 2)), - accountFragmentFactory.make( - midCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps( - hub, hub.callStack().getById(createeContextId), 3)), - accountFragmentFactory.make( - newCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 4)), - accountFragmentFactory.make( - newCreatedSnapshot, - oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 5)), - ContextFragment.initializeExecutionContext(hub)); - } else { - this.addFragmentsWithoutStack( - commonImcFragment, - accountFragmentFactory.make( - oldCreatorSnapshot, - midCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), - accountFragmentFactory.make( - oldCreatedSnapshot, - midCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), - accountFragmentFactory.make( - midCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps( - hub, hub.callStack().getById(createeContextId), 2)), - accountFragmentFactory.make( - midCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps( - hub, hub.callStack().getById(createeContextId), 3)), - ContextFragment.initializeExecutionContext(hub)); - } - } - } - } - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java index fefb7ea9f5..fad8dc1858 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java @@ -15,12 +15,12 @@ package net.consensys.linea.zktracer.module.hub.signals; +import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; + import java.util.Optional; import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.AddressUtils; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountState; @@ -28,36 +28,22 @@ @RequiredArgsConstructor public final class FailureConditions { - private final Hub hub; private boolean deploymentAddressHasNonZeroNonce; private boolean deploymentAddressHasNonEmptyCode; - public FailureConditions snapshot() { - final FailureConditions r = new FailureConditions(null); - r.deploymentAddressHasNonZeroNonce = this.deploymentAddressHasNonZeroNonce; - r.deploymentAddressHasNonEmptyCode = this.deploymentAddressHasNonEmptyCode; - return r; - } - public void reset() { this.deploymentAddressHasNonEmptyCode = false; this.deploymentAddressHasNonZeroNonce = false; } public void prepare(MessageFrame frame) { - final OpCode instruction = this.hub.opCode(); - Address deploymentAddress; - switch (instruction) { - case CREATE -> { - deploymentAddress = AddressUtils.getCreateAddress(frame); - } - case CREATE2 -> { - deploymentAddress = AddressUtils.getCreate2Address(frame); - } - default -> { - return; - } + final OpCode instruction = OpCode.of(frame.getCurrentOperation().getOpcode()); + + if (!instruction.isCreate()) { + return; } + final Address deploymentAddress = getDeploymentAddress(frame); + final Optional deploymentAccount = Optional.ofNullable(frame.getWorldUpdater().get(deploymentAddress)); deploymentAddressHasNonZeroNonce = deploymentAccount.map(a -> a.getNonce() != 0).orElse(false); @@ -67,8 +53,4 @@ public void prepare(MessageFrame frame) { public boolean any() { return deploymentAddressHasNonEmptyCode || deploymentAddressHasNonZeroNonce; } - - public boolean none() { - return !any(); - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java index 09aac2781c..0a2d5b0a8b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java @@ -44,7 +44,7 @@ public PlatformController(final Hub hub) { this.exceptions = Exceptions.NONE; this.abortingConditions = new AbortingConditions(); this.signals = new Signals(this); - this.failureConditions = new FailureConditions(hub); + this.failureConditions = new FailureConditions(); } /** Reset all information */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index 164610c1d1..acddef45a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -57,7 +57,6 @@ public class Signals { @Getter private boolean shf; @Getter private boolean gas; - @Getter private boolean mmu; // TODO: SHOULD DIE @Getter private boolean mxp; @Getter private boolean oob; @Getter private boolean stp; @@ -81,7 +80,6 @@ public void reset() { this.shf = false; this.gas = false; - this.mmu = false; this.mxp = false; this.oob = false; this.stp = false; @@ -105,7 +103,6 @@ public Signals snapshot() { r.shf = this.shf; r.gas = this.gas; - r.mmu = this.mmu; r.mxp = this.mxp; r.oob = this.oob; r.stp = this.stp; @@ -141,55 +138,6 @@ public void prepare(MessageFrame frame, PlatformController platformController, H } switch (opCode) { - case CALLDATACOPY, CODECOPY -> { - this.mxp = - Exceptions.memoryExpansionException(ex) - || Exceptions.outOfGasException(ex) - || Exceptions.none(ex); - this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); - } - - case RETURNDATACOPY -> { - this.oob = Exceptions.none(ex) || Exceptions.returnDataCopyFault(ex); - this.mxp = - Exceptions.none(ex) - || Exceptions.memoryExpansionException(ex) - || Exceptions.outOfGasException(ex); - this.mmu = Exceptions.none(ex) && !frame.getStackItem(2).isZero(); - } - - case EXTCODECOPY -> { - final boolean nonzeroSize = !frame.getStackItem(3).isZero(); - this.mxp = - Exceptions.memoryExpansionException(ex) - || Exceptions.outOfGasException(ex) - || Exceptions.none(ex); - this.trm = Exceptions.outOfGasException(ex) || Exceptions.none(ex); - this.mmu = Exceptions.none(ex) && nonzeroSize; - - final Address address = Words.toAddress(frame.getStackItem(0)); - final boolean targetAddressHasCode = - Optional.ofNullable(frame.getWorldUpdater().get(address)) - .map(AccountState::hasCode) - .orElse(false); - - this.romLex = Exceptions.none(ex) && nonzeroSize && targetAddressHasCode; - } - - case LOG0, LOG1, LOG2, LOG3, LOG4 -> { - this.mxp = - Exceptions.memoryExpansionException(ex) - || Exceptions.outOfGasException(ex) - || Exceptions.none(ex); - this.mmu = - Exceptions.none(ex) - && !frame - .getStackItem(1) - .isZero(); // TODO do not trigger the MMU if the context is going to revert and - // check the HUB does increment or not the MMU stamp for reverted LOG - // logInfo and logData are triggered via rlpRcpt at the end of the tx - } - case CALL, DELEGATECALL, STATICCALL, CALLCODE -> { this.mxp = !Exceptions.staticFault(ex); this.stp = Exceptions.outOfGasException(ex) || Exceptions.none(ex); @@ -237,19 +185,12 @@ public void prepare(MessageFrame frame, PlatformController platformController, H && !triggersAbortingCondition && nonzeroSize && !triggersFailureCondition; - this.mmu = this.hashInfo || this.romLex; } - case REVERT -> { - this.mxp = - Exceptions.memoryExpansionException(ex) - || Exceptions.outOfGasException(ex) - || Exceptions.none(ex); - this.mmu = - Exceptions.none(ex) - && !frame.getStackItem(1).isZero() - && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); - } + case REVERT -> this.mxp = + Exceptions.memoryExpansionException(ex) + || Exceptions.outOfGasException(ex) + || Exceptions.none(ex); case RETURN -> { final boolean isDeployment = frame.getType() == MessageFrame.Type.CONTRACT_CREATION; @@ -262,13 +203,6 @@ public void prepare(MessageFrame frame, PlatformController platformController, H || Exceptions.invalidCodePrefix(ex) || Exceptions.none(ex); this.oob = isDeployment && (Exceptions.codeSizeOverflow(ex) || Exceptions.none(ex)); - this.mmu = - (isDeployment && Exceptions.invalidCodePrefix(ex)) - || (isDeployment && Exceptions.none(ex) && sizeNonZero) - || (!isDeployment - && Exceptions.none(ex) - && sizeNonZero - && !hub.currentFrame().requestedReturnDataTarget().isEmpty()); this.romLex = this.hashInfo = isDeployment && Exceptions.none(ex) && sizeNonZero; } @@ -288,19 +222,12 @@ public void prepare(MessageFrame frame, PlatformController platformController, H case SHA3 -> { this.mxp = true; this.hashInfo = Exceptions.none(ex) && !frame.getStackItem(1).isZero(); - this.mmu = this.hashInfo; } case BALANCE, EXTCODESIZE, EXTCODEHASH, SELFDESTRUCT -> this.trm = true; case MLOAD, MSTORE, MSTORE8 -> { this.mxp = true; - this.mmu = Exceptions.none(ex); - } - case CALLDATALOAD -> { - this.oob = true; - this.mmu = - Exceptions.none(ex) - && frame.getInputData().size() > Words.clampedToLong(frame.getStackItem(0)); } + case CALLDATALOAD -> this.oob = true; case SLOAD -> {} case SSTORE, JUMP, JUMPI -> this.oob = true; case MSIZE -> this.mxp = Exceptions.none(ex); From a6e2be98d820eda01e699e8589aea38708efb2a3 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 22 Jul 2024 20:29:10 +0200 Subject: [PATCH 250/461] feat(selfdestruct): started implementing self destruct map --- .../hub/section/halt/SelfdestructSection.java | 35 +++++++++++++++++++ .../types/TransactionProcessingMetadata.java | 11 ++++++ 2 files changed, 46 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 566fe1eeca..3e32ff56f8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -14,6 +14,9 @@ */ package net.consensys.linea.zktracer.module.hub.section.halt; +import java.util.List; +import java.util.Map; + import com.google.common.base.Preconditions; import lombok.Getter; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; @@ -27,6 +30,8 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.AddressDeploymentNumberPair; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.HubStampCallFramePair; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; @@ -130,6 +135,25 @@ public SelfdestructSection(Hub hub) { } // Unexceptional case + Map> unexceptionalSelfDestructMap = + hub.txStack().current().getUnexceptionalSelfDestructMap(); + + AddressDeploymentNumberPair addressDeploymentNumberPair = + new AddressDeploymentNumberPair(this.address, this.accountBefore.deploymentNumber()); + + if (unexceptionalSelfDestructMap.containsKey(addressDeploymentNumberPair)) { + List hubStampCallFramePairs = + unexceptionalSelfDestructMap.get(addressDeploymentNumberPair); + hubStampCallFramePairs.add(new HubStampCallFramePair(hubStamp, hub.currentFrame())); + // TODO: double check that re-adding the list to the map is not necessary, as the list is a + // reference + // unexceptionalSelfDestructMap.put(addressDeploymentNumberPair, hubStampCallFramePairs); + } else { + unexceptionalSelfDestructMap.put( + new AddressDeploymentNumberPair(this.address, this.accountBefore.deploymentNumber()), + List.of(new HubStampCallFramePair(hubStamp, hub.currentFrame()))); + } + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); hub.defers().schedulePostTransaction(this); @@ -227,6 +251,17 @@ public void resolvePostTransaction( // use a maps that keeps track of the (hub stamp, call frame) of all the unexceptional // SELFDESTRUCT for a given (address, deployment number) + // we need the callFrame in order to tell us, when we walk through this map at the end of the + // transaction (transactionEnd), + // if the SELFDESTRUCT took place in a frame that will be reverted/roll back (in this case, we + // can ignore it) + // later this information will be used to filter out the reverted SELFDESTRUCT + // once we have this filtered map, for every pair (address, deploymentNumber), + // we can compute its selfDestructTime = the first hubStamp such that is successful and not + // reverted + // these SELFDESTRUCT will be finished at the end of the transaction by wiping the corresponding + // accounts + // at the end of the transaction we have that map // we analyse that map: diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 22001de1a2..712d71c333 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -21,6 +21,7 @@ import java.math.BigInteger; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; @@ -33,6 +34,7 @@ import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; @@ -111,6 +113,15 @@ public class TransactionProcessingMetadata { @Setter Set destructedAccountsSnapshot; + @Getter + Map> unexceptionalSelfDestructMap; + + public record AddressDeploymentNumberPair(Address address, int deploymentNumber) {} + ; + + public record HubStampCallFramePair(int hubStamp, CallFrame callFrame) {} + ; + public TransactionProcessingMetadata( final WorldView world, final Transaction transaction, From 809ce42bc677454ea6979d1aa1cd4188a9f8631c Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 22 Jul 2024 22:54:14 +0200 Subject: [PATCH 251/461] feat(selfdestruct): rename components of the map --- .../hub/section/halt/SelfdestructSection.java | 24 +++++++++---------- .../types/TransactionProcessingMetadata.java | 6 ++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 3e32ff56f8..b0deef5ab7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -30,8 +30,8 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.AddressDeploymentNumberPair; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.HubStampCallFramePair; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.AddressDeploymentNumberKey; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.HubStampCallFrameValue; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; @@ -135,23 +135,23 @@ public SelfdestructSection(Hub hub) { } // Unexceptional case - Map> unexceptionalSelfDestructMap = + Map> unexceptionalSelfDestructMap = hub.txStack().current().getUnexceptionalSelfDestructMap(); - AddressDeploymentNumberPair addressDeploymentNumberPair = - new AddressDeploymentNumberPair(this.address, this.accountBefore.deploymentNumber()); + AddressDeploymentNumberKey addressDeploymentNumberKey = + new AddressDeploymentNumberKey(this.address, this.accountBefore.deploymentNumber()); - if (unexceptionalSelfDestructMap.containsKey(addressDeploymentNumberPair)) { - List hubStampCallFramePairs = - unexceptionalSelfDestructMap.get(addressDeploymentNumberPair); - hubStampCallFramePairs.add(new HubStampCallFramePair(hubStamp, hub.currentFrame())); + if (unexceptionalSelfDestructMap.containsKey(addressDeploymentNumberKey)) { + List hubStampCallFrameValues = + unexceptionalSelfDestructMap.get(addressDeploymentNumberKey); + hubStampCallFrameValues.add(new HubStampCallFrameValue(hubStamp, hub.currentFrame())); // TODO: double check that re-adding the list to the map is not necessary, as the list is a // reference - // unexceptionalSelfDestructMap.put(addressDeploymentNumberPair, hubStampCallFramePairs); + // unexceptionalSelfDestructMap.put(addressDeploymentNumberKey, hubStampCallFrameValues); } else { unexceptionalSelfDestructMap.put( - new AddressDeploymentNumberPair(this.address, this.accountBefore.deploymentNumber()), - List.of(new HubStampCallFramePair(hubStamp, hub.currentFrame()))); + new AddressDeploymentNumberKey(this.address, this.accountBefore.deploymentNumber()), + List.of(new HubStampCallFrameValue(hubStamp, hub.currentFrame()))); } hub.defers().scheduleForPostRollback(this, hub.currentFrame()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 712d71c333..74aa93dd5b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -114,12 +114,12 @@ public class TransactionProcessingMetadata { @Setter Set destructedAccountsSnapshot; @Getter - Map> unexceptionalSelfDestructMap; + Map> unexceptionalSelfDestructMap; - public record AddressDeploymentNumberPair(Address address, int deploymentNumber) {} + public record AddressDeploymentNumberKey(Address address, int deploymentNumber) {} ; - public record HubStampCallFramePair(int hubStamp, CallFrame callFrame) {} + public record HubStampCallFrameValue(int hubStamp, CallFrame callFrame) {} ; public TransactionProcessingMetadata( From 5709e8a1ba42e89e6e41af0d50c8d2d1d43a28b7 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 22 Jul 2024 23:08:07 +0200 Subject: [PATCH 252/461] feat(selfdestruct): implement resolvePostTransaction --- .../hub/section/halt/SelfdestructSection.java | 32 +++++++++++++++++++ .../types/TransactionProcessingMetadata.java | 2 ++ 2 files changed, 34 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index b0deef5ab7..944c917e1d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -292,5 +292,37 @@ public void resolvePostTransaction( // in the already marked case we know that this action has already been scheduled for the future // every transaction should start with an empty map + + // TODO: review and comment the code below + + for (Map.Entry> entry : + hub.txStack().current().getUnexceptionalSelfDestructMap().entrySet()) { + + AddressDeploymentNumberKey addressDeploymentNumberKey = entry.getKey(); + List hubStampCallFrameValues = entry.getValue(); + + int selfDestructTime = -1; + for (HubStampCallFrameValue hubStampCallFrameValue : hubStampCallFrameValues) { + if (hubStampCallFrameValue.callFrame().revertStamp() == -1) { + selfDestructTime = hubStampCallFrameValue.hubStamp(); + hub.txStack() + .current() + .getEffectiveSelfDestructMap() + .put(addressDeploymentNumberKey, selfDestructTime); + break; + } + } + + if (selfDestructTime != -1) { + AccountFragment accountFragment = + hub.factories() + .accountFragment() + .make( + this.accountAfter, + AccountSnapshot.empty(false, 0, false), + DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); + this.addFragment(accountFragment); + } + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 74aa93dd5b..966513790b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -116,6 +116,8 @@ public class TransactionProcessingMetadata { @Getter Map> unexceptionalSelfDestructMap; + @Getter Map effectiveSelfDestructMap; + public record AddressDeploymentNumberKey(Address address, int deploymentNumber) {} ; From 4b88891f4c741f84aa31a755043ce385972e72c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 22 Jul 2024 19:29:39 +0200 Subject: [PATCH 253/461] ras --- .../hub/section/halt/ReturnSection.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index ae9b610c36..6dce8d07da 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -18,6 +18,7 @@ import com.google.common.base.Preconditions; import lombok.Getter; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; @@ -31,6 +32,7 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -46,7 +48,7 @@ public class ReturnSection extends TraceSection implements PostTransactionDefer, MmuCall firstMmuCall; MmuCall secondMmuCall; - ContextFragment squashCreatorReturnData; + ContextFragment squashParentContextReturnData; @Getter public boolean emptyDeployment; @Getter public boolean deploymentWasReverted = false; @@ -84,7 +86,7 @@ public ReturnSection(Hub hub) { //////////////////////////////////// if (Exceptions.memoryExpansionException(exceptions) || Exceptions.outOfGasException(exceptions)) { - // Note: the context fragment will be added elsewhere + // Note: the missing context fragment is added elsewhere return; } @@ -121,8 +123,6 @@ public ReturnSection(Hub hub) { ///////////////////////////////// ///////////////////////////////// if (returnFromMessageCall) { - // TODO: remove final long returnAtCapacity = - // hub.currentFrame().requestedReturnDataTarget().length(); final boolean messageCallReturnTouchesRam = !hub.currentFrame().isRoot() && nontrivialMmOperation // [size ≠ 0] ∧ ¬MXPX @@ -136,11 +136,8 @@ public ReturnSection(Hub hub) { if (messageCallReturnTouchesRam) { firstMmuCall = MmuCall.returnFromCall(hub); hub.defers().schedulePostTransaction(this); - } else { - // TODO: should we add the following ? It shouldn't be necessary ... @FB: no, no need. - // mmuCall = MmuCall.nop(); - // hub.defers().schedulePostTransaction(this); } + // no need for the else case (and a nop) as per @François ContextFragment updateCallerReturnData = ContextFragment.providesReturnData( @@ -156,15 +153,19 @@ public ReturnSection(Hub hub) { /////////////////////////////// /////////////////////////////// if (returnFromDeployment) { - hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - final boolean triggerOobForNonemptyDeployments = mxpCall.isMayTriggerNonTrivialMmuOperation(); - final long byteCodeSize = hub.messageFrame().getStackItem(1).toLong(); final boolean emptyDeployment = byteCodeSize == 0; + final boolean triggerOobForNonemptyDeployments = mxpCall.isMayTriggerNonTrivialMmuOperation(); + Preconditions.checkArgument(triggerOobForNonemptyDeployments == !emptyDeployment); + + Address deploymentAddress = hub.messageFrame().getRecipientAddress(); + AccountSnapshot accountBeforeDeployment = AccountSnapshot.canonical(hub, deploymentAddress); + AccountSnapshot accountAfterDeployment = AccountSnapshot.canonical(hub, deploymentAddress); if (emptyDeployment) { + return; } @@ -178,7 +179,7 @@ public ReturnSection(Hub hub) { // TODO: make sure this works if the current context is the root // context (deployment transaction) in particular the following // ``Either.left(callStack.parent().id())'' - squashCreatorReturnData = ContextFragment.executionProvidesEmptyReturnData(hub); + squashParentContextReturnData = ContextFragment.executionProvidesEmptyReturnData(hub); } // returnFromDeployment = @@ -193,7 +194,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT); - this.addFragment(squashCreatorReturnData); + this.addFragment(squashParentContextReturnData); deploymentWasReverted = true; } @@ -217,6 +218,6 @@ public void resolvePostTransaction( // if (secondMmuCall != null) { // secondImcFragment.callMmu(secondMmuCall); // } - this.addFragment(squashCreatorReturnData); + this.addFragment(squashParentContextReturnData); } } From f86f88f8c04cc5b7db3d2950f7006c13f320f3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 23 Jul 2024 00:44:29 +0200 Subject: [PATCH 254/461] feat(return): progress but some TODO's --- .../zktracer/module/hub/AccountSnapshot.java | 13 +++- .../module/hub/fragment/imc/ImcFragment.java | 2 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 2 +- .../hub/section/halt/ReturnSection.java | 63 +++++++++++++++---- 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index fce06d1335..a501c7a687 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -22,6 +22,7 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.types.Bytecode; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; @@ -32,7 +33,6 @@ @Setter @Accessors(fluent = true) public class AccountSnapshot { - // TODO: we require a MARKED_FOR_SELFDESTRUCT boolean private Address address; private long nonce; private Wei balance; @@ -40,6 +40,17 @@ public class AccountSnapshot { private Bytecode code; private int deploymentNumber; private boolean deploymentStatus; + // TODO: we require a MARKED_FOR_SELFDESTRUCT boolean + // The implementation will be + // 1. is (address, deploymentNumber) ∈ effectiveSelfdestructsMap Then + // - get the relevant selfDestructTime + // - MARKED_FOR_SELFDESTRUCT = [hubStamp > selfDestructTime] + // - MARKED_FOR_SELFDESTRUCT_NEW = hubStamp ≥ selfDestructTime + + // public enum AccountRowType { + // STANDARD, + // DEFERRED, + // } public static AccountSnapshot canonical(Hub hub, Address address) { final Account account = hub.messageFrame().getWorldUpdater().getAccount(address); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index c5e24bdcc8..3e248d0e2a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -197,7 +197,7 @@ public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { hub.currentFrame().isDeployment() ? MmuCall.returnFromDeployment( hub) // TODO Add a MMU call to MMU_INST_INVALID_CODE8PREFIX - : MmuCall.returnFromCall(hub)); + : MmuCall.returnFromMessageCall(hub)); // case CREATE2 -> r.callMmu(MmuCall.create2(hub)); case REVERT -> r.callMmu(MmuCall.revert(hub)); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 0fc5555781..efbbc74e53 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -267,7 +267,7 @@ public static MmuCall returnFromDeployment(final Hub hub) { return new ReturnFromDeployment(hub); } - public static MmuCall returnFromCall(final Hub hub) { + public static MmuCall returnFromMessageCall(final Hub hub) { return MmuCall.revert(hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 6dce8d07da..093e49e797 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -23,6 +23,8 @@ import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; @@ -32,6 +34,7 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.types.Bytecode; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -40,11 +43,16 @@ @Getter public class ReturnSection extends TraceSection implements PostTransactionDefer, PostRollbackDefer { + final int hubStamp; + final CallFrame currentFrame; final short exceptions; final boolean returnFromDeployment; final boolean returnFromMessageCall; // not stricly speaking necessary final ReturnScenarioFragment returnScenarioFragment; final ImcFragment firstImcFragment; + ImcFragment secondImcFragment; + AccountFragment deploymentFragment; + AccountFragment undoingDeploymentAccountFragment; MmuCall firstMmuCall; MmuCall secondMmuCall; @@ -58,6 +66,8 @@ public ReturnSection(Hub hub) { super(hub, Exceptions.any(hub.pch().exceptions()) ? (short) 5 : (short) 8); hub.addTraceSection(this); + hubStamp = hub.stamp(); + currentFrame = hub.currentFrame(); exceptions = hub.pch().exceptions(); returnFromMessageCall = hub.currentFrame().isMessageCall(); returnFromDeployment = hub.currentFrame().isDeployment(); @@ -134,7 +144,8 @@ public ReturnSection(Hub hub) { : RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM); if (messageCallReturnTouchesRam) { - firstMmuCall = MmuCall.returnFromCall(hub); + firstMmuCall = MmuCall.returnFromMessageCall(hub); + Preconditions.checkArgument(!firstMmuCall.successBit()); hub.defers().schedulePostTransaction(this); } // no need for the else case (and a nop) as per @François @@ -162,15 +173,40 @@ public ReturnSection(Hub hub) { Address deploymentAddress = hub.messageFrame().getRecipientAddress(); AccountSnapshot accountBeforeDeployment = AccountSnapshot.canonical(hub, deploymentAddress); - AccountSnapshot accountAfterDeployment = AccountSnapshot.canonical(hub, deploymentAddress); + // Empty deployments + //////////////////// if (emptyDeployment) { + AccountSnapshot accountAfterEmptyDeployment = accountBeforeDeployment.deployByteCode(Bytecode.EMPTY); + AccountFragment emptyDeploymentAccountFragment = hub.factories().accountFragment().make( + accountBeforeDeployment, + accountAfterEmptyDeployment, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0) + ); + this.addFragment(emptyDeploymentAccountFragment); + + // Note: + // - triggerHASHINFO isn't required; + // - triggerROMLEX isn't required either; + return; } + // Nonempty deployments + /////////////////////// hub.defers().schedulePostTransaction(this); + firstMmuCall = MmuCall.invalidCodePrefix(hub); + Preconditions.checkArgument(firstMmuCall.successBit()); + + secondImcFragment = ImcFragment.empty(hub); + secondMmuCall = MmuCall.returnFromDeployment(hub); + this.addFragment(secondImcFragment); + + // TODO: we require the + // - triggerHashInfo stuff on the first stack row + // - triggerROMLEX on the deploymentAccountFragment row // TODO: we need to implement the mechanism that will append the // context row which will squash the creator's return data after @@ -194,8 +230,17 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT); - this.addFragment(squashParentContextReturnData); - + // TODO: do we account for updates to + // - deploymentNumber and status ? Presumably, but if so by coincidence + // - MARKED_FOR_SELF_DESTRUCT(_NEW) ? No + // - + undoingDeploymentAccountFragment = hub.factories().accountFragment().make( + deploymentFragment.newState(), + deploymentFragment.oldState(), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, hub.currentFrame().revertStamp(), 1) + ); + + this.addFragment(undoingDeploymentAccountFragment); deploymentWasReverted = true; } @@ -211,13 +256,9 @@ public void resolvePostTransaction( : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); } - if (firstMmuCall != null) { - firstImcFragment.callMmu(firstMmuCall); - } - // TODO: - // if (secondMmuCall != null) { - // secondImcFragment.callMmu(secondMmuCall); - // } + if (firstMmuCall != null) firstImcFragment.callMmu(firstMmuCall); + if (secondMmuCall != null) secondImcFragment.callMmu(secondMmuCall); + this.addFragment(squashParentContextReturnData); } } From c811307bd1c6869c5a3ef35bbbb8c4aa50663f0c Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 12:16:34 +0530 Subject: [PATCH 255/461] delete the failure signals, delete romLex signals, triggers romLex for CREATE, seal sections for CN/CNnew --- .../zktracer/module/hub/AccountSnapshot.java | 2 +- .../linea/zktracer/module/hub/Hub.java | 70 +----------- .../fragment/common/CommonFragmentValues.java | 4 +- .../module/hub/fragment/imc/ImcFragment.java | 100 ------------------ .../module/hub/section/TraceSection.java | 15 +++ .../hub/section/create/CreateSection.java | 21 ++-- .../create/NonEmptyInitCodeCreate.java | 2 + .../hub/section/halt/ReturnSection.java | 28 +++-- .../hub/section/halt/SelfdestructSection.java | 2 +- .../module/hub/signals/FailureConditions.java | 56 ---------- .../hub/signals/PlatformController.java | 7 -- .../zktracer/module/hub/signals/Signals.java | 31 ------ .../linea/zktracer/module/romlex/RomLex.java | 44 ++++---- 13 files changed, 75 insertions(+), 307 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index a501c7a687..4157ada32c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -22,7 +22,6 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.types.Bytecode; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; @@ -40,6 +39,7 @@ public class AccountSnapshot { private Bytecode code; private int deploymentNumber; private boolean deploymentStatus; + // TODO: we require a MARKED_FOR_SELFDESTRUCT boolean // The implementation will be // 1. is (address, deploymentNumber) ∈ effectiveSelfdestructsMap Then diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 2eb8da2cdf..feb52104ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; import com.google.common.base.Preconditions; @@ -800,67 +799,6 @@ public CallFrame currentFrame() { return this.callStack.current(); } - public int contextNumberNew(CallFrame frame) { - switch (this.state.getProcessingPhase()) { - case TX_SKIP, TX_WARM, TX_FINAL -> { - return 0; - } - case TX_INIT -> { - return newChildContextNumber(); - } - case TX_EXEC -> { - final OpCode opCode = this.opCode(); - - if (Exceptions.any(pch.exceptions()) - || opCode.getData().instructionFamily().equals(InstructionFamily.HALT) - || opCode.getData().instructionFamily().equals(InstructionFamily.INVALID)) { - return this.callStack.depth() == 0 ? 0 : this.callStack().caller().contextNumber(); - } - - final int currentContextNumber = this.callStack().current().contextNumber(); - - if (opCode.isCall()) { - if (pch().abortingConditions().any()) { - return currentContextNumber; - } - - final Address calleeAddress = - Words.toAddress(this.currentFrame().frame().getStackItem(1)); - - AtomicInteger newContext = new AtomicInteger(currentContextNumber); - - Optional.ofNullable(frame.frame().getWorldUpdater().get(calleeAddress)) - .map(AccountState::getCode) - .ifPresent( - byteCode -> { - if (!byteCode.isEmpty()) { - newContext.set(newChildContextNumber()); - } - }); - return newContext.get(); - } - - if (opCode.isCreate()) { - if (pch().abortingConditions().any() || pch().failureConditions().any()) { - return currentContextNumber; - } - final int initCodeSize = this.currentFrame().frame().getStackItem(2).toInt(); - if (initCodeSize != 0) { - return newChildContextNumber(); - } - } - - return currentContextNumber; - } - default -> { - { - throw new IllegalStateException( - String.format("Hub can't be in the state %s", this.state.getProcessingPhase())); - } - } - } - } - public MessageFrame messageFrame() { MessageFrame frame = this.callStack.current().frame(); return frame; @@ -879,9 +817,6 @@ void triggerModules(MessageFrame frame) { } } - if (this.pch.signals().romLex()) { - this.romLex.tracePreOpcode(frame); - } if (this.pch.signals().add()) { this.add.tracePreOpcode(frame); } @@ -1086,7 +1021,7 @@ void traceOperation(MessageFrame frame) { } else { parentFrame.latestReturnData(Bytes.EMPTY); } - final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); // TODO finish it + // final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); // TODO finish it } case REVERT -> { new RevertSection(this); @@ -1228,7 +1163,8 @@ void traceOperation(MessageFrame frame) { ContextFragment.nonExecutionEmptyReturnData(this)); this.addTraceSection(abortedSection); } else { - final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); + final ImcFragment imcFragment = /* ImcFragment.forOpcode(this, frame)*/ + ImcFragment.empty(this); if (hasCode) { final SmartContractCallSection section = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java index aeeaacb105..70e159231c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java @@ -44,7 +44,7 @@ public class CommonFragmentValues { @Setter public int logStamp = -1; @Getter final CallFrame callFrame; public final boolean exceptionAhoy; - public final int contextNumberNew; + @Setter public int contextNumberNew; public final int cnRevertStamp; public final int pc; public final int pcNew; @@ -73,7 +73,7 @@ public CommonFragmentValues(Hub hub) { this.stamps = hub.state().stamps(); this.callFrame = hub.currentFrame(); this.exceptionAhoy = Exceptions.any(hub.pch().exceptions()); - this.contextNumberNew = hub.contextNumberNew(callFrame); + // this.contextNumberNew = hub.contextNumberNew(callFrame); this.cnRevertStamp = 0; // TODO this.pc = hubProcessingPhase == TX_EXEC ? hub.currentFrame().pc() : 0; this.pcNew = computePcNew(hub, pc, noStackException, hub.state.getProcessingPhase() == TX_EXEC); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 3e248d0e2a..f75559648c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -30,10 +30,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; @@ -41,7 +37,6 @@ import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; /** @@ -55,7 +50,6 @@ public class ImcFragment implements TraceFragment { private final Hub hub; private boolean expIsSet = false; - private boolean modExpIsSet = false; private boolean oobIsSet = false; private boolean mxpIsSet = false; private boolean mmuIsSet = false; @@ -160,74 +154,6 @@ public static ImcFragment forCall( return r; } - // TODO: should be deleted - public static ImcFragment forOpcode(Hub hub, MessageFrame frame) { - final ImcFragment r = new ImcFragment(hub); - - /* TODO: this has been commented out since signals will die - if (hub.pch().signals().mxp()) { - r.callMxp(MxpCall.build(hub)); - } - - - if (hub.pch().signals().exp()) { - r.callExp(new ExplogExpCall()); - } - */ - - if (hub.pch().signals().exp() && !Exceptions.stackException(hub.pch().exceptions())) { - hub.exp().tracePreOpcode(frame); - } - - if (hub.pch().signals().mmu()) { - switch (hub.opCode()) { - // commented instruction are done elsewhere, everything should be deleted - // case SHA3 -> r.callMmu(MmuCall.sha3(hub)); - // case CALLDATALOAD -> r.callMmu(MmuCall.callDataLoad(hub)); - // case CALLDATACOPY -> r.callMmu(MmuCall.callDataCopy(hub)); - // case CODECOPY -> r.callMmu(MmuCall.codeCopy(hub)); - // case EXTCODECOPY -> r.callMmu(MmuCall.extCodeCopy(hub)); - // case RETURNDATACOPY -> r.callMmu(MmuCall.returnDataCopy(hub)); - // case MLOAD -> r.callMmu(MmuCall.mload(hub)); - // case MSTORE -> r.callMmu(MmuCall.mstore(hub)); - // case MSTORE8 -> r.callMmu(MmuCall.mstore8(hub)); - // case LOG0, LOG1, LOG2, LOG3, LOG4 -> r.callMmu(MmuCall.log(hub)); - // case CREATE -> r.callMmu(MmuCall.create(hub)); - case RETURN -> r.callMmu( - hub.currentFrame().isDeployment() - ? MmuCall.returnFromDeployment( - hub) // TODO Add a MMU call to MMU_INST_INVALID_CODE8PREFIX - : MmuCall.returnFromMessageCall(hub)); - // case CREATE2 -> r.callMmu(MmuCall.create2(hub)); - case REVERT -> r.callMmu(MmuCall.revert(hub)); - } - } - - if (hub.pch().signals().oob()) { - switch (hub.opCode()) { - case JUMP -> r.callOob(new JumpOobCall()); - case JUMPI -> r.callOob(new JumpiOobCall()); - // case CALLDATALOAD -> r.callOob(new CallDataLoadOobCall()); - case SSTORE -> r.callOob(new SstoreOobCall()); - case CALL, CALLCODE -> { - r.callOob(new CallOobCall()); - } - case DELEGATECALL, STATICCALL -> { - r.callOob(new CallOobCall()); - } - case RETURN -> { - if (hub.currentFrame().isDeployment()) { - r.callOob(new DeploymentOobCall()); - } - } - default -> throw new IllegalArgumentException( - "unexpected opcode for OoB %s".formatted(hub.opCode())); - } - } - - return r; - } - public ImcFragment callOob(OobCall f) { if (oobIsSet) { throw new IllegalStateException("OOB already called"); @@ -264,32 +190,6 @@ public ImcFragment callExp(ExpCall f) { return this; } - /* - public ImcFragment callExp(ExplogExpCall f) { - if (expIsSet) { - throw new IllegalStateException("EXP already called"); - } else { - expIsSet = true; - } - this.hub.exp().callExpLogCall(f); - this.moduleCalls.add(f); - return this; - } - */ - - /* - public ImcFragment callExp(ModexplogExpCall f) { - if (modExpIsSet) { - throw new IllegalStateException("MODEXP already called"); - } else { - modExpIsSet = true; - } - this.hub.exp().callModExpLogCall(f); - this.moduleCalls.add(f); - return this; - } - */ - public ImcFragment callMxp(MxpCall f) { if (mxpIsSet) { throw new IllegalStateException("MXP already called"); 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 f947e4c97c..c59b4aceda 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 @@ -16,6 +16,9 @@ package net.consensys.linea.zktracer.module.hub.section; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; import java.util.ArrayList; import java.util.List; @@ -26,6 +29,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.DeploymentExceptions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.TxTrace; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; @@ -124,6 +128,7 @@ public void seal() { this.commonValues.callFrame().codeDeploymentNumber(), this.commonValues.callFrame().isDeployment()) : 0); + commonValues.contextNumberNew(computeContextNumberNew()); /* If the logStamp hasn't been set (either by being first section of the tx, or by the LogSection), set it to the previous section logStamp */ if (commonValues.logStamp == -1) { @@ -131,6 +136,16 @@ public void seal() { } } + private int computeContextNumberNew() { + final HubProcessingPhase currentPhase = this.commonValues.hubProcessingPhase; + if (currentPhase == TX_WARM || currentPhase == TX_FINAL || currentPhase == TX_SKIP) { + return 0; + } + return this.nextSection.commonValues.hubProcessingPhase == TX_EXEC + ? this.nextSection.commonValues.callFrame().contextNumber() + : 0; + } + public final boolean hasReverted() { return this.commonValues.callFrame().hasReverted(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 3ec25a91ed..55856ea35e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -19,6 +19,8 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT; import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; +import java.util.Optional; + import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; @@ -40,16 +42,15 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldView; public class CreateSection implements PostExecDefer, ReEnterContextDefer, PostTransactionDefer { private FillCreateSection createSection; - private boolean failure; private int creatorContextId; - private boolean emptyInitCode; // Just before create private AccountSnapshot oldCreatorSnapshot; @@ -68,11 +69,6 @@ public class CreateSection implements PostExecDefer, ReEnterContextDefer, PostTr /* true if the CREATE was successful **/ private boolean createSuccessful = false; - /* true if the putatively created account already has code **/ - private boolean targetHasCode() { - return !oldCreatedSnapshot.code().isEmpty(); - } - // row i+2 private final ImcFragment imcFragment; private MmuCall mmuCall; @@ -151,8 +147,15 @@ public CreateSection(Hub hub) { rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createdAddress); - failure = hub.pch().failureConditions().any(); - emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); + final Optional deploymentAccount = + Optional.ofNullable(frame.getWorldUpdater().get(createdAddress)); + final boolean createdAddressHasNonZeroNonce = + deploymentAccount.map(a -> a.getNonce() != 0).orElse(false); + final boolean createdAddressHasNonEmptyCode = + deploymentAccount.map(AccountState::hasCode).orElse(false); + + final boolean failure = createdAddressHasNonZeroNonce || createdAddressHasNonEmptyCode; + final boolean emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); if (failure || emptyInitCode) { final ScenarioEnum scenario = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index ee8e284095..22f01e7107 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -44,6 +44,7 @@ public NonEmptyInitCodeCreate( this.scenarioFragment = new CreateScenarioFragment(); this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); + hub.romLex().triggerRomLex(hub.messageFrame()); } @Override @@ -79,6 +80,7 @@ public void fillAccountFragment( oldCreatedSnapshot, midCreatedSnapshot, DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 1)); + oldToMidCreatedAccountFragment.requiresRomlex(true); this.addFragmentsWithoutStack(oldToMidCreatorAccountFragment, oldToMidCreatedAccountFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 093e49e797..be2bdecaec 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -178,12 +178,15 @@ public ReturnSection(Hub hub) { //////////////////// if (emptyDeployment) { - AccountSnapshot accountAfterEmptyDeployment = accountBeforeDeployment.deployByteCode(Bytecode.EMPTY); - AccountFragment emptyDeploymentAccountFragment = hub.factories().accountFragment().make( - accountBeforeDeployment, - accountAfterEmptyDeployment, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0) - ); + AccountSnapshot accountAfterEmptyDeployment = + accountBeforeDeployment.deployByteCode(Bytecode.EMPTY); + AccountFragment emptyDeploymentAccountFragment = + hub.factories() + .accountFragment() + .make( + accountBeforeDeployment, + accountAfterEmptyDeployment, + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); this.addFragment(emptyDeploymentAccountFragment); // Note: @@ -234,11 +237,14 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca // - deploymentNumber and status ? Presumably, but if so by coincidence // - MARKED_FOR_SELF_DESTRUCT(_NEW) ? No // - - undoingDeploymentAccountFragment = hub.factories().accountFragment().make( - deploymentFragment.newState(), - deploymentFragment.oldState(), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, hub.currentFrame().revertStamp(), 1) - ); + undoingDeploymentAccountFragment = + hub.factories() + .accountFragment() + .make( + deploymentFragment.newState(), + deploymentFragment.oldState(), + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + hubStamp, hub.currentFrame().revertStamp(), 1)); this.addFragment(undoingDeploymentAccountFragment); deploymentWasReverted = true; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 944c917e1d..a3f1475cca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -294,7 +294,7 @@ public void resolvePostTransaction( // every transaction should start with an empty map // TODO: review and comment the code below - + for (Map.Entry> entry : hub.txStack().current().getUnexceptionalSelfDestructMap().entrySet()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java deleted file mode 100644 index fad8dc1858..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/FailureConditions.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.signals; - -import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; - -import java.util.Optional; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.account.AccountState; -import org.hyperledger.besu.evm.frame.MessageFrame; - -@RequiredArgsConstructor -public final class FailureConditions { - private boolean deploymentAddressHasNonZeroNonce; - private boolean deploymentAddressHasNonEmptyCode; - - public void reset() { - this.deploymentAddressHasNonEmptyCode = false; - this.deploymentAddressHasNonZeroNonce = false; - } - - public void prepare(MessageFrame frame) { - final OpCode instruction = OpCode.of(frame.getCurrentOperation().getOpcode()); - - if (!instruction.isCreate()) { - return; - } - final Address deploymentAddress = getDeploymentAddress(frame); - - final Optional deploymentAccount = - Optional.ofNullable(frame.getWorldUpdater().get(deploymentAddress)); - deploymentAddressHasNonZeroNonce = deploymentAccount.map(a -> a.getNonce() != 0).orElse(false); - deploymentAddressHasNonEmptyCode = deploymentAccount.map(AccountState::hasCode).orElse(false); - } - - public boolean any() { - return deploymentAddressHasNonEmptyCode || deploymentAddressHasNonZeroNonce; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java index 0a2d5b0a8b..7c06aa8a9c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java @@ -37,14 +37,11 @@ public class PlatformController { /** The aborting conditions raised during the execution of the current operation */ @Getter private final AbortingConditions abortingConditions; - @Getter private final FailureConditions failureConditions; - public PlatformController(final Hub hub) { this.hub = hub; this.exceptions = Exceptions.NONE; this.abortingConditions = new AbortingConditions(); this.signals = new Signals(this); - this.failureConditions = new FailureConditions(); } /** Reset all information */ @@ -52,7 +49,6 @@ public void reset() { this.signals.reset(); this.exceptions = Exceptions.NONE; this.abortingConditions.reset(); - this.failureConditions.reset(); } /** @@ -67,9 +63,6 @@ public void setup(MessageFrame frame) { this.exceptions |= Exceptions.fromFrame(hub, frame); if (Exceptions.none(this.exceptions)) { this.abortingConditions.prepare(hub); - if (abortingConditions.none()) { - this.failureConditions.prepare(frame); - } } this.signals.prepare(frame, this, this.hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index acddef45a1..e7845315b1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -63,7 +63,6 @@ public class Signals { @Getter private boolean exp; @Getter private boolean trm; @Getter private boolean hashInfo; - @Getter private boolean romLex; @Getter private boolean rlpAddr; @Getter private boolean ecData; @@ -86,7 +85,6 @@ public void reset() { this.exp = false; this.trm = false; this.hashInfo = false; - this.romLex = false; this.rlpAddr = false; this.ecData = false; } @@ -109,7 +107,6 @@ public Signals snapshot() { r.exp = this.exp; r.trm = this.trm; r.hashInfo = this.hashInfo; - r.romLex = this.romLex; r.rlpAddr = this.rlpAddr; r.ecData = this.ecData; @@ -153,8 +150,6 @@ public void prepare(MessageFrame frame, PlatformController platformController, H .map(AccountState::hasCode) .orElse(false); - this.romLex = - Exceptions.none(ex) && !triggersAbortingCondition && targetAddressHasNonEmptyCode; this.ecData = Exceptions.none(ex) && EC_PRECOMPILES.contains(target); this.exp = Exceptions.none(ex) @@ -162,31 +157,6 @@ public void prepare(MessageFrame frame, PlatformController platformController, H && target.equals(Address.MODEXP); } - case CREATE, CREATE2 -> { - boolean triggersAbortingCondition = - Exceptions.none(ex) && this.platformController.abortingConditions().any(); - - boolean triggersFailureCondition = false; - if (Exceptions.none(ex) && this.platformController.abortingConditions().none()) { - triggersFailureCondition = this.platformController.failureConditions().any(); - } - - final boolean nonzeroSize = !frame.getStackItem(2).isZero(); - final boolean isCreate2 = opCode == OpCode.CREATE2; - - this.mxp = !Exceptions.staticFault(ex); - this.stp = Exceptions.outOfGasException(ex) || Exceptions.none(ex); - this.oob = Exceptions.none(ex); - this.rlpAddr = Exceptions.none(ex) && !triggersAbortingCondition; - this.hashInfo = - Exceptions.none(ex) && !triggersAbortingCondition && nonzeroSize && isCreate2; - this.romLex = - Exceptions.none(ex) - && !triggersAbortingCondition - && nonzeroSize - && !triggersFailureCondition; - } - case REVERT -> this.mxp = Exceptions.memoryExpansionException(ex) || Exceptions.outOfGasException(ex) @@ -203,7 +173,6 @@ public void prepare(MessageFrame frame, PlatformController platformController, H || Exceptions.invalidCodePrefix(ex) || Exceptions.none(ex); this.oob = isDeployment && (Exceptions.codeSizeOverflow(ex) || Exceptions.none(ex)); - this.romLex = this.hashInfo = isDeployment && Exceptions.none(ex) && sizeNonZero; } case EXP -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index b532e2440e..e276bda75f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -26,12 +26,15 @@ import java.util.Map; import java.util.Optional; +import com.google.common.base.Preconditions; import lombok.Getter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; +import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; @@ -40,10 +43,11 @@ import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true) -public class RomLex implements Module { +public class RomLex implements Module, PostExecDefer { private static final RomChunkComparator ROM_CHUNK_COMPARATOR = new RomChunkComparator(); private final Hub hub; @@ -148,16 +152,17 @@ public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMe }); } - @Override - public void tracePreOpcode(MessageFrame frame) { - switch (this.hub.opCode()) { + public void triggerRomLex(final MessageFrame frame) { + switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { case CREATE -> { + hub.defers().schedulePostExecution(this); this.byteCode = this.hub.transients().op().callData(); if (!this.byteCode.isEmpty()) { this.address = getCreateAddress(frame); } } case CREATE2 -> { + hub.defers().schedulePostExecution(this); this.byteCode = this.hub.transients().op().callData(); if (!this.byteCode.isEmpty()) { this.address = getCreate2Address(frame); @@ -240,24 +245,19 @@ public void tracePreOpcode(MessageFrame frame) { } @Override - public void tracePostOpcode(MessageFrame frame) { - if (byteCode.isEmpty()) { - return; - } - switch (hub.opCode()) { - case CREATE, CREATE2 -> { - final int depNumber = hub.transients().conflation().deploymentInfo().number(this.address); - final boolean depStatus = - hub.transients().conflation().deploymentInfo().isDeploying(this.address); - final ContractMetadata contractMetadata = - ContractMetadata.make(this.address, depNumber, depStatus); - - final RomChunk chunk = new RomChunk(contractMetadata, true, false, this.byteCode); - this.chunks.add(chunk); - this.createDefers.trigger(contractMetadata); - this.addressRomChunkMap.put(this.address, chunk); - } - } + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + Preconditions.checkArgument(hub.opCode().isCreate()); + final int depNumber = hub.transients().conflation().deploymentInfo().number(this.address); + final boolean depStatus = + hub.transients().conflation().deploymentInfo().isDeploying(this.address); + final ContractMetadata contractMetadata = + ContractMetadata.make(this.address, depNumber, depStatus); + + final RomChunk chunk = new RomChunk(contractMetadata, true, false, this.byteCode); + this.chunks.add(chunk); + this.createDefers.trigger(contractMetadata); + this.addressRomChunkMap.put(this.address, chunk); } // This is the tracing for ROMLEX module From e4e9b4d9621e7536895e1a84d8bb2664423f99fa Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 12:47:09 +0530 Subject: [PATCH 256/461] merge arith-dev --- .../linea/zktracer/module/exp/ExpLogOperation.java | 1 + .../consensys/linea/zktracer/module/exp/ExpOperation.java | 4 ++-- .../linea/zktracer/module/exp/ModexpLogOperation.java | 1 + .../net/consensys/linea/zktracer/module/hub/TxTrace.java | 6 +++--- .../main/java/net/consensys/linea/zktracer/types/Utils.java | 2 +- .../linea/continoustracing/ContinuousTracerTest.java | 2 -- .../test/java/net/consensys/linea/zktracer/ReplayTests.java | 3 --- .../java/net/consensys/linea/zktracer/ZkTracerTest.java | 3 --- .../instructionprocessing/ContractModifyingStorageTest.java | 3 --- .../instructionprocessing/JumpDestinationVettingTest.java | 3 --- .../linea/zktracer/instructionprocessing/JumpTest.java | 3 --- .../linea/zktracer/instructionprocessing/JumpiTest.java | 3 --- .../linea/zktracer/instructionprocessing/StpTests.java | 3 --- .../linea/zktracer/module/hub/SimpleStorageConsistency.java | 3 --- .../net/consensys/linea/zktracer/module/hub/TxSkip.java | 3 --- .../linea/zktracer/module/rlpaddr/TestRlpAddress.java | 1 - .../consensys/linea/zktracer/module/rlptxrcpt/LogTest.java | 3 --- 17 files changed, 8 insertions(+), 39 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java index e69de29bb2..8b13789179 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java @@ -0,0 +1 @@ + diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index afa6a2e7ac..553afd3bbe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -23,12 +23,12 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_MODEXPLOG; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGEPO; -import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Utils.leftPadTo; import static net.consensys.linea.zktracer.module.exp.Trace.CT_MAX_CMPTN_EXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.CT_MAX_CMPTN_MODEXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.CT_MAX_PRPRC_EXP_LOG; import static net.consensys.linea.zktracer.module.exp.Trace.CT_MAX_PRPRC_MODEXP_LOG; +import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import static net.consensys.linea.zktracer.types.Utils.leftPadTo; import java.math.BigInteger; import java.math.RoundingMode; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java index e69de29bb2..8b13789179 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java @@ -0,0 +1 @@ + diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index d7a5f1a46d..696acbd82e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -85,9 +85,9 @@ public void add(TraceSection section) { public long refundCounter() { if (this.trace.size() >= PARALLELIZATION_THRESHOLD) { return this.trace.parallelStream() - .filter(section -> !section.hasReverted()) - .mapToLong(TraceSection::refundDelta) - .sum(); + .filter(section -> !section.hasReverted()) + .mapToLong(TraceSection::refundDelta) + .sum(); } else { if (this.refundCounter == -1) { this.refundCounter = 0; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java index 5f570045d9..e6a423ccae 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Utils.java @@ -15,8 +15,8 @@ package net.consensys.linea.zktracer.types; -import java.math.BigInteger; import java.io.IOException; +import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; diff --git a/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java index 671183026c..05d4fe3b17 100644 --- a/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/continoustracing/ContinuousTracerTest.java @@ -28,7 +28,6 @@ import net.consensys.linea.plugins.exception.InvalidBlockTraceException; import net.consensys.linea.plugins.exception.TraceVerificationException; import net.consensys.linea.zktracer.ZkTracer; -import net.consensys.linea.zktracer.testing.EvmExtension; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.plugin.data.BlockTraceResult; import org.hyperledger.besu.plugin.data.TransactionTraceResult; @@ -42,7 +41,6 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -@ExtendWith(EvmExtension.class) public class ContinuousTracerTest { private static final Hash BLOCK_HASH = Hash.fromHexString("0x0000000000000000000000000000000000000000000000000000000000000042"); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java index 8516b16c0b..aa8dc45eff 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java @@ -24,10 +24,8 @@ import java.util.zip.GZIPInputStream; import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; /** * Replays are captured on a fully (not snapshot) synchronized Besu node running the plugin: @@ -46,7 +44,6 @@ * One can run this command: scripts/capture.pl --start xxx --end yyy --output my-test-case.json.gz */ @Slf4j -@ExtendWith(EvmExtension.class) public class ReplayTests { /** * Loads a .json or .json.gz replay file generated by the {@link diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java index 095877bfbb..1ac111f012 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ZkTracerTest.java @@ -17,11 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import net.consensys.linea.zktracer.testing.EvmExtension; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -@ExtendWith(EvmExtension.class) public class ZkTracerTest { @Test diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index b350d76ad2..2b06531338 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -21,7 +21,6 @@ import java.util.Random; import com.google.common.base.Preconditions; -import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyAccount; import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import net.consensys.linea.zktracer.testing.ToyTransaction; @@ -37,9 +36,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -@ExtendWith(EvmExtension.class) public class ContractModifyingStorageTest { /* diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java index d74ac9559a..a7cd6ba292 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpDestinationVettingTest.java @@ -23,14 +23,11 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.EvmExtension; import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -@ExtendWith(EvmExtension.class) public class JumpDestinationVettingTest { final Random random = new Random(1); final int N_JUMPS = 3; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTest.java index a419a23a7b..fbe9e60786 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpTest.java @@ -19,14 +19,11 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.EvmExtension; import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -@ExtendWith(EvmExtension.class) public class JumpTest { // NOTE: the bytecode we propose will at time use the following offsets (unless pcNew is large) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java index 221c1f2f48..176a70af82 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java @@ -24,14 +24,11 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.EvmExtension; import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -@ExtendWith(EvmExtension.class) public class JumpiTest { // NOTE: the bytecode we propose will at time use the following offsets (unless pcNew is large) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java index bacf550a2c..ec0ac5acf3 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StpTests.java @@ -16,12 +16,9 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.EvmExtension; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.junit.jupiter.api.extension.ExtendWith; -@ExtendWith(EvmExtension.class) public class StpTests { private void forceWarmRecipient( diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java index 0a4fb79285..c526e2c322 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/SimpleStorageConsistency.java @@ -19,7 +19,6 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyAccount; import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import net.consensys.linea.zktracer.testing.ToyTransaction; @@ -34,9 +33,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -@ExtendWith(EvmExtension.class) public class SimpleStorageConsistency { private final Address receiverAddress = diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java index e075eccb72..9ea52b2974 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TxSkip.java @@ -19,7 +19,6 @@ import java.util.List; -import net.consensys.linea.zktracer.testing.EvmExtension; import net.consensys.linea.zktracer.testing.ToyAccount; import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; import net.consensys.linea.zktracer.testing.ToyTransaction; @@ -34,9 +33,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -@ExtendWith(EvmExtension.class) public class TxSkip { final int nbOfRowsTxSkip = 4; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index 00f45d6755..38ba85dc1e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -35,7 +35,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; public class TestRlpAddress { private final Random rnd = new Random(666); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java index cbde941b45..5c75f5c331 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/LogTest.java @@ -18,12 +18,9 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.EvmExtension; import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -@ExtendWith(EvmExtension.class) public class LogTest { @Test void log2Test() { From 9bc92576106ee831d918001f57acdf9c45ef5f9e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 13:59:15 +0530 Subject: [PATCH 257/461] rm void file --- .../net/consensys/linea/zktracer/module/exp/ExpLogOperation.java | 1 - .../consensys/linea/zktracer/module/exp/ModexpLogOperation.java | 1 - 2 files changed, 2 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java deleted file mode 100644 index 8b13789179..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpLogOperation.java +++ /dev/null @@ -1 +0,0 @@ - diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java deleted file mode 100644 index 8b13789179..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ModexpLogOperation.java +++ /dev/null @@ -1 +0,0 @@ - From 99192b7ad7892538e2393af239d2a18d3a85377d Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 23 Jul 2024 11:11:57 +0200 Subject: [PATCH 258/461] feat(selfdestruct): cleaned code --- .../linea/zktracer/module/add/Trace.java | 164 +++++------------- .../hub/section/halt/SelfdestructSection.java | 6 +- 2 files changed, 47 insertions(+), 123 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java index b1df4b1234..191bd1c6a0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java @@ -52,21 +52,21 @@ public class Trace { static List headers(int length) { return List.of( - new ColumnHeader("add.ACC_1", 16, length), - new ColumnHeader("add.ACC_2", 16, length), - new ColumnHeader("add.ARG_1_HI", 16, length), - new ColumnHeader("add.ARG_1_LO", 16, length), - new ColumnHeader("add.ARG_2_HI", 16, length), - new ColumnHeader("add.ARG_2_LO", 16, length), + new ColumnHeader("add.ACC_1", 32, length), + new ColumnHeader("add.ACC_2", 32, length), + new ColumnHeader("add.ARG_1_HI", 32, length), + new ColumnHeader("add.ARG_1_LO", 32, length), + new ColumnHeader("add.ARG_2_HI", 32, length), + new ColumnHeader("add.ARG_2_LO", 32, length), new ColumnHeader("add.BYTE_1", 1, length), new ColumnHeader("add.BYTE_2", 1, length), new ColumnHeader("add.CT", 1, length), new ColumnHeader("add.CT_MAX", 1, length), new ColumnHeader("add.INST", 1, length), new ColumnHeader("add.OVERFLOW", 1, length), - new ColumnHeader("add.RES_HI", 16, length), - new ColumnHeader("add.RES_LO", 16, length), - new ColumnHeader("add.STAMP", 4, length)); + new ColumnHeader("add.RES_HI", 32, length), + new ColumnHeader("add.RES_LO", 32, length), + new ColumnHeader("add.STAMP", 8, length)); } public Trace(List buffers) { @@ -102,20 +102,11 @@ public Trace acc1(final Bytes b) { filled.set(0); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { acc1.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - acc1.put(bs.get(j)); - } + acc1.put(b.toArrayUnsafe()); return this; } @@ -127,20 +118,11 @@ public Trace acc2(final Bytes b) { filled.set(1); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { acc2.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - acc2.put(bs.get(j)); - } + acc2.put(b.toArrayUnsafe()); return this; } @@ -152,20 +134,11 @@ public Trace arg1Hi(final Bytes b) { filled.set(2); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { arg1Hi.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg1Hi.put(bs.get(j)); - } + arg1Hi.put(b.toArrayUnsafe()); return this; } @@ -177,20 +150,11 @@ public Trace arg1Lo(final Bytes b) { filled.set(3); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { arg1Lo.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg1Lo.put(bs.get(j)); - } + arg1Lo.put(b.toArrayUnsafe()); return this; } @@ -202,20 +166,11 @@ public Trace arg2Hi(final Bytes b) { filled.set(4); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { arg2Hi.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg2Hi.put(bs.get(j)); - } + arg2Hi.put(b.toArrayUnsafe()); return this; } @@ -227,20 +182,11 @@ public Trace arg2Lo(final Bytes b) { filled.set(5); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { arg2Lo.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg2Lo.put(bs.get(j)); - } + arg2Lo.put(b.toArrayUnsafe()); return this; } @@ -324,20 +270,11 @@ public Trace resHi(final Bytes b) { filled.set(12); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { resHi.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - resHi.put(bs.get(j)); - } + resHi.put(b.toArrayUnsafe()); return this; } @@ -349,20 +286,11 @@ public Trace resLo(final Bytes b) { filled.set(13); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { + final byte[] bs = b.toArrayUnsafe(); + for (int i = bs.length; i < 32; i++) { resLo.put((byte) 0); } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - resLo.put(bs.get(j)); - } + resLo.put(b.toArrayUnsafe()); return this; } @@ -374,13 +302,7 @@ public Trace stamp(final long b) { filled.set(14); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); - } - stamp.put((byte) (b >> 24)); - stamp.put((byte) (b >> 16)); - stamp.put((byte) (b >> 8)); - stamp.put((byte) b); + stamp.putLong(b); return this; } @@ -454,27 +376,27 @@ public Trace validateRow() { public Trace fillAndValidateRow() { if (!filled.get(0)) { - acc1.position(acc1.position() + 16); + acc1.position(acc1.position() + 32); } if (!filled.get(1)) { - acc2.position(acc2.position() + 16); + acc2.position(acc2.position() + 32); } if (!filled.get(2)) { - arg1Hi.position(arg1Hi.position() + 16); + arg1Hi.position(arg1Hi.position() + 32); } if (!filled.get(3)) { - arg1Lo.position(arg1Lo.position() + 16); + arg1Lo.position(arg1Lo.position() + 32); } if (!filled.get(4)) { - arg2Hi.position(arg2Hi.position() + 16); + arg2Hi.position(arg2Hi.position() + 32); } if (!filled.get(5)) { - arg2Lo.position(arg2Lo.position() + 16); + arg2Lo.position(arg2Lo.position() + 32); } if (!filled.get(6)) { @@ -502,15 +424,15 @@ public Trace fillAndValidateRow() { } if (!filled.get(12)) { - resHi.position(resHi.position() + 16); + resHi.position(resHi.position() + 32); } if (!filled.get(13)) { - resLo.position(resLo.position() + 16); + resLo.position(resLo.position() + 32); } if (!filled.get(14)) { - stamp.position(stamp.position() + 4); + stamp.position(stamp.position() + 8); } filled.clear(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index a3f1475cca..9108e674c3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -293,14 +293,15 @@ public void resolvePostTransaction( // every transaction should start with an empty map - // TODO: review and comment the code below - for (Map.Entry> entry : hub.txStack().current().getUnexceptionalSelfDestructMap().entrySet()) { AddressDeploymentNumberKey addressDeploymentNumberKey = entry.getKey(); List hubStampCallFrameValues = entry.getValue(); + // For each address, deployment number, we find selfDestructTime as + // the time in which the first unexceptional and un-reverted SELFDESTRUCT occurs + // Then we add this value in a new map int selfDestructTime = -1; for (HubStampCallFrameValue hubStampCallFrameValue : hubStampCallFrameValues) { if (hubStampCallFrameValue.callFrame().revertStamp() == -1) { @@ -313,6 +314,7 @@ public void resolvePostTransaction( } } + // We modify the account fragment to reflect the self-destruct time if (selfDestructTime != -1) { AccountFragment accountFragment = hub.factories() From ce4101ac0798a3ea9807626cf95c3c036b936e8f Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 11:26:18 +0200 Subject: [PATCH 259/461] fix resolve defers after triggering module at endTx --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f60f787f38..08f3b8a025 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -385,6 +385,7 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.exp, this.rlpAddr, this.rlpTxn, + this.rlpTxnRcpt, this.rom, this.romLex, this.shakiraData, @@ -393,9 +394,7 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.trm, this.wcp, /* WARN: must be called BEFORE txnData */ this.txnData, - this.blockdata, /* WARN: must be called AFTER txnData */ - this - .rlpTxnRcpt /* WARN: must be called AFTER txnData TODO: is it still the case ? */), + this.blockdata /* WARN: must be called AFTER txnData */), this.precompileLimitModules.stream()) .toList(); } @@ -508,11 +507,11 @@ public void traceEndTransaction( this.state.stamps().incrementHubStamp(); } - this.defers.resolvePostTransaction(this, world, tx, isSuccessful); - for (Module m : this.modules) { m.traceEndTx(txStack.current()); } + + this.defers.resolvePostTransaction(this, world, tx, isSuccessful); } @Override From 39d1312a595d6473f25c8db0b83eec272b479a80 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 14:34:06 +0200 Subject: [PATCH 260/461] fix: need to do two rounds of defersPostTx --- .../linea/zktracer/module/hub/Hub.java | 6 ++---- .../linea/zktracer/module/hub/TxTrace.java | 9 +-------- .../module/hub/defer/DeferRegistry.java | 6 ++++++ .../hub/fragment/TransactionFragment.java | 9 +-------- ...xDefer.java => TxFinalizationSection.java} | 19 ++++++++++--------- .../hub/section/TxInitializationSection.java | 1 - 6 files changed, 20 insertions(+), 30 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{TxFinalizationPostTxDefer.java => TxFinalizationSection.java} (95%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 08f3b8a025..5577e7ed2c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -48,7 +48,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.section.*; -import net.consensys.linea.zktracer.module.hub.section.TxFinalizationPostTxDefer; +import net.consensys.linea.zktracer.module.hub.section.TxFinalizationSection; import net.consensys.linea.zktracer.module.hub.section.TxPreWarmingMacroSection; import net.consensys.linea.zktracer.module.hub.section.TxSkippedSectionDefers; import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; @@ -455,7 +455,6 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { this.pch.reset(); this.state.enter(); this.txStack.enterTransaction(world, tx, transients.block()); - this.defers.schedulePostTransaction(this.state.currentTxTrace()); this.enterTransaction(); @@ -674,8 +673,7 @@ public void traceContextExit(MessageFrame frame) { this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); if (this.state.getProcessingPhase() != TX_SKIP) { this.state.setProcessingPhase(TX_FINAL); - this.defers.schedulePostTransaction( - new TxFinalizationPostTxDefer(this, frame.getWorldUpdater())); + new TxFinalizationSection(this, frame.getWorldUpdater()); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 696acbd82e..9138e0a0b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -20,17 +20,14 @@ import lombok.Getter; import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; /** * Stores all the trace sections associated to the same transaction, stored in chronological order * of creation. */ @Accessors(fluent = true) -public class TxTrace implements PostTransactionDefer { +public class TxTrace { /** The {@link TraceSection} of which this transaction trace is made of */ @Getter private final List trace = new ArrayList<>(); @@ -101,10 +98,6 @@ public long refundCounter() { } } - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} - /** * Generate the final numeric trace from the accumulated information. * diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index fe34b9e8d5..2caa950bd6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -118,6 +118,12 @@ public void resolveWithNextContext(Hub hub, MessageFrame frame) { @Override public void resolvePostTransaction( Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { + final List postTransactionDefersFirstRound = + new ArrayList<>(this.postTransactionDefers); + this.postTransactionDefers.clear(); + for (PostTransactionDefer defer : postTransactionDefersFirstRound) { + defer.resolvePostTransaction(hub, world, tx, isSuccessful); + } for (PostTransactionDefer defer : this.postTransactionDefers) { defer.resolvePostTransaction(hub, world, tx, isSuccessful); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java index d602dbcc1d..fbd963ec48 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/TransactionFragment.java @@ -20,18 +20,15 @@ import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import lombok.Setter; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.evm.worldstate.WorldView; -public final class TransactionFragment implements TraceFragment, PostTransactionDefer { +public final class TransactionFragment implements TraceFragment { private final TransactionProcessingMetadata transactionProcessingMetadata; @Setter private TraceSection parentSection; @@ -85,8 +82,4 @@ public Trace trace(Trace trace) { .pTransactionCoinbaseAddressHi(highPart(miner)) .pTransactionCoinbaseAddressLo(lowPart(miner)); } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 8e36783ce4..570c135b89 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationPostTxDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -29,7 +29,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.worldstate.WorldView; -public class TxFinalizationPostTxDefer implements PostTransactionDefer { +public class TxFinalizationSection implements PostTransactionDefer { private final TransactionProcessingMetadata txMetadata; private final AccountSnapshot fromAccountBeforeTxFinalization; private final AccountSnapshot toAccountBeforeTxFinalization; @@ -38,7 +38,7 @@ public class TxFinalizationPostTxDefer implements PostTransactionDefer { private @Setter AccountSnapshot toAccountAfterTxFinalization; private @Setter AccountSnapshot minerAccountAfterTxFinalization; - public TxFinalizationPostTxDefer(Hub hub, WorldView world) { + public TxFinalizationSection(Hub hub, WorldView world) { this.txMetadata = hub.txStack().current(); final DeploymentInfo depInfo = hub.transients().conflation().deploymentInfo(); @@ -66,6 +66,8 @@ public TxFinalizationPostTxDefer(Hub hub, WorldView world) { txMetadata.isMinerWarmAtEndTx(), depInfo.number(minerAddress), depInfo.isDeploying(minerAddress)); + + hub.defers().schedulePostTransaction(this); } @Override @@ -104,7 +106,7 @@ public void resolvePostTransaction( private void successfulFinalization(Hub hub) { if (!senderIsMiner()) { hub.addTraceSection( - new TxFinalizationSection( + new FinalizationSection( hub, hub.factories() .accountFragment() @@ -122,7 +124,7 @@ private void successfulFinalization(Hub hub) { } else { // TODO: verify it works hub.addTraceSection( - new TxFinalizationSection( + new FinalizationSection( hub, hub.factories() .accountFragment() @@ -142,10 +144,9 @@ private void successfulFinalization(Hub hub) { } private void unsuccessfulFinalization(Hub hub) { - if (noAccountCollision()) { hub.addTraceSection( - new TxFinalizationSection( + new FinalizationSection( hub, hub.factories() .accountFragment() @@ -169,7 +170,7 @@ private void unsuccessfulFinalization(Hub hub) { } else { // TODO: test this hub.addTraceSection( - new TxFinalizationSection( + new FinalizationSection( hub, hub.factories() .accountFragment() @@ -225,8 +226,8 @@ private boolean noAccountCollision() { return !senderIsMiner() && !senderIsTo() && !toIsMiner(); } - public class TxFinalizationSection extends TraceSection { - public TxFinalizationSection(Hub hub, TraceFragment... fragments) { + public class FinalizationSection extends TraceSection { + public FinalizationSection(Hub hub, TraceFragment... fragments) { super(hub, (short) (txMetadata.statusCode() ? 3 : 4)); this.addFragmentsWithoutStack(fragments); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 65f0556fcf..d186d9b0d4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -91,7 +91,6 @@ public TxInitializationSection(Hub hub, WorldView world) { DomSubStampsSubFragment.standardDomSubStamps(hub, 1); final TransactionFragment txFragment = TransactionFragment.prepare(tx); - hub.defers().schedulePostTransaction(txFragment); final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); From 938927ae59ae37c85c325f4688f1f7111942aaf1 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 15:14:10 +0200 Subject: [PATCH 261/461] extcodecopy triggers RomLex --- .../module/hub/section/copy/ExtCodeCopySection.java | 1 + .../java/net/consensys/linea/zktracer/ReplayTests.java | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index a68299aa88..3ba76159bb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -140,6 +140,7 @@ public ExtCodeCopySection(Hub hub) { .makeWithTrm(this.accountBefore, this.accountAfter, this.rawAddress, doingDomSubStamps); accountDoingFragment.requiresRomlex(triggerCfi); this.addFragment(accountDoingFragment); + hub.romLex().triggerRomLex(hub.messageFrame()); // an EXTCODECOPY section is only scheduled // for rollback if it is unexceptional diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java index 266885477f..b0a0421af2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java @@ -80,10 +80,10 @@ void fatMxp() { replay("2492975-2492977.json.gz"); } - @Test - void leoFailingRange() { - replay("5389571-5389577.json.gz"); - } + @Test + void leoFailingRange() { + replay("5389571-5389577.json.gz"); + } @Test void failingMmuModexp() { From 7027263d531b4bff97f803b212a2e5b9d1ccbbeb Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 23 Jul 2024 16:13:27 +0200 Subject: [PATCH 262/461] feat(selfdestruct): fixed resolvePostTransaction --- .../zktracer/module/hub/AccountSnapshot.java | 5 + .../hub/section/halt/SelfdestructSection.java | 161 ++++++------------ .../zktracer/runtime/callstack/CallFrame.java | 7 +- .../types/TransactionProcessingMetadata.java | 37 +++- 4 files changed, 99 insertions(+), 111 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 4157ada32c..0b272f52ce 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -196,4 +196,9 @@ public AccountSnapshot deepCopy() { this.deploymentNumber, this.deploymentStatus); } + + public AccountSnapshot wipe() { + return new AccountSnapshot( + this.address, 0, Wei.of(0), this.isWarm, Bytecode.EMPTY, this.deploymentNumber + 1, false); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 9108e674c3..dbbbc072f6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -30,8 +30,9 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.AddressDeploymentNumberKey; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.HubStampCallFrameValue; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.AttemptedSelfDestruct; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.EphemeralAccount; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; @@ -62,11 +63,15 @@ public class SelfdestructSection extends TraceSection final boolean selfDestructTargetsItself; @Getter boolean selfDestructWasReverted = false; + final TransactionProcessingMetadata transactionProcessingMetadata; + public SelfdestructSection(Hub hub) { // up to 8 = 1 + 7 rows super(hub, (short) 8); hub.addTraceSection(this); + this.transactionProcessingMetadata = hub.txStack().current(); + // Init this.id = hub.currentFrame().id(); hubStamp = hub.stamp(); @@ -135,23 +140,23 @@ public SelfdestructSection(Hub hub) { } // Unexceptional case - Map> unexceptionalSelfDestructMap = + Map> unexceptionalSelfDestructMap = hub.txStack().current().getUnexceptionalSelfDestructMap(); - AddressDeploymentNumberKey addressDeploymentNumberKey = - new AddressDeploymentNumberKey(this.address, this.accountBefore.deploymentNumber()); + EphemeralAccount ephemeralAccount = + new EphemeralAccount(this.address, this.accountBefore.deploymentNumber()); - if (unexceptionalSelfDestructMap.containsKey(addressDeploymentNumberKey)) { - List hubStampCallFrameValues = - unexceptionalSelfDestructMap.get(addressDeploymentNumberKey); - hubStampCallFrameValues.add(new HubStampCallFrameValue(hubStamp, hub.currentFrame())); + if (unexceptionalSelfDestructMap.containsKey(ephemeralAccount)) { + List attemptedSelfDestructs = + unexceptionalSelfDestructMap.get(ephemeralAccount); + attemptedSelfDestructs.add(new AttemptedSelfDestruct(hubStamp, hub.currentFrame())); // TODO: double check that re-adding the list to the map is not necessary, as the list is a // reference // unexceptionalSelfDestructMap.put(addressDeploymentNumberKey, hubStampCallFrameValues); } else { unexceptionalSelfDestructMap.put( - new AddressDeploymentNumberKey(this.address, this.accountBefore.deploymentNumber()), - List.of(new HubStampCallFrameValue(hubStamp, hub.currentFrame()))); + new EphemeralAccount(this.address, this.accountBefore.deploymentNumber()), + List.of(new AttemptedSelfDestruct(hubStamp, hub.currentFrame()))); } hub.defers().scheduleForPostRollback(this, hub.currentFrame()); @@ -231,100 +236,46 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - // if selfDestructWasReverted = false then we are in the WONT_REVERT case - // We still need to understand in which of the below cases we are: - // selfdestructScenarioFragment.setScenario( - // SelfdestructScenarioFragment.SelfdestructScenario.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED); - // selfdestructScenarioFragment.setScenario( - // SelfdestructScenarioFragment.SelfdestructScenario.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED); - - // will not revert (subcases: already marked, not yet marked) - // - not yet marked corresponds to when SELFDESTRUCT produces no exceptions, will not be - // reverted - // ,and it is the first time this account will be successful in self-destructing - - // - already marked corresponds to when SELFDESTRUCT produces no exceptions, will not be - // reverted - // ,and it is not the first time this account will be successful in self-destructing - - // mark for self-destructing is associated to an address and a deployment number - // use a maps that keeps track of the (hub stamp, call frame) of all the unexceptional - // SELFDESTRUCT for a given (address, deployment number) - - // we need the callFrame in order to tell us, when we walk through this map at the end of the - // transaction (transactionEnd), - // if the SELFDESTRUCT took place in a frame that will be reverted/roll back (in this case, we - // can ignore it) - // later this information will be used to filter out the reverted SELFDESTRUCT - // once we have this filtered map, for every pair (address, deploymentNumber), - // we can compute its selfDestructTime = the first hubStamp such that is successful and not - // reverted - // these SELFDESTRUCT will be finished at the end of the transaction by wiping the corresponding - // accounts - - // at the end of the transaction we have that map - - // we analyse that map: - // for every (address, deployment number) we walk through the list of [(hub stamp, call frame), - // ...] - - // for every call frame we know if it was reverted or not - - // the first time (selfDestructTime) we find a call frame that has not been reverted, we - // remember the hub stamp - - // this produces a new map (address, deployment number) -> selfDestructTime (of the first - // successful and un-reverted - // SELFDESTRUCT) - - // we now have a map of all (address, deployment number) that have been successful in - // self-destructing - // and the hub stamp in which it happened - - // for every account row in the entire trace, we can now decide what to write in the - // MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW columns: - // MARKED_FOR_SELFDESTRUCT = [hub stamp < selfDestructTime] - // MARKED_FOR_SELFDESTRUCT_NEW = [hub stamp >= selfDestructTime] - - // This will only be triggered at the hub stamp = selfDestructTime - // we wipe the entire account in the "not yet marked" case (precisely when not yet marked - // transitions from false to true) (see row i+4 of not yet marked case) - // in the already marked case we know that this action has already been scheduled for the future - - // every transaction should start with an empty map - - for (Map.Entry> entry : - hub.txStack().current().getUnexceptionalSelfDestructMap().entrySet()) { - - AddressDeploymentNumberKey addressDeploymentNumberKey = entry.getKey(); - List hubStampCallFrameValues = entry.getValue(); - - // For each address, deployment number, we find selfDestructTime as - // the time in which the first unexceptional and un-reverted SELFDESTRUCT occurs - // Then we add this value in a new map - int selfDestructTime = -1; - for (HubStampCallFrameValue hubStampCallFrameValue : hubStampCallFrameValues) { - if (hubStampCallFrameValue.callFrame().revertStamp() == -1) { - selfDestructTime = hubStampCallFrameValue.hubStamp(); - hub.txStack() - .current() - .getEffectiveSelfDestructMap() - .put(addressDeploymentNumberKey, selfDestructTime); - break; - } - } - - // We modify the account fragment to reflect the self-destruct time - if (selfDestructTime != -1) { - AccountFragment accountFragment = - hub.factories() - .accountFragment() - .make( - this.accountAfter, - AccountSnapshot.empty(false, 0, false), - DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); - this.addFragment(accountFragment); - } + if (selfDestructWasReverted) { + return; + } + + Map effectiveSelfDestructMap = + this.transactionProcessingMetadata.getEffectiveSelfDestructMap(); + EphemeralAccount ephemeralAccount = + new EphemeralAccount(this.address, this.accountAfter.deploymentNumber()); + + Preconditions.checkArgument(effectiveSelfDestructMap.containsKey(ephemeralAccount)); + + // We modify the account fragment to reflect the self-destruct time + + int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); + + Preconditions.checkArgument(this.hubStamp >= selfDestructTime); + + AccountSnapshot accountBeforeSelfDestruct = + this.transactionProcessingMetadata.getDestructedAccountsSnapshot().stream() + .filter(accountSnapshot -> accountSnapshot.address().equals(this.address)) + .findFirst() + .orElseThrow(() -> new IllegalStateException("Account not found")); + + if (this.hubStamp == selfDestructTime) { + selfdestructScenarioFragment.setScenario( + SelfdestructScenarioFragment.SelfdestructScenario + .SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED); + + AccountFragment accountWipingFragment = + hub.factories() + .accountFragment() + .make( + accountBeforeSelfDestruct, + this.accountAfter.wipe(), + DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); + this.addFragment(accountWipingFragment); + } else { + selfdestructScenarioFragment.setScenario( + SelfdestructScenarioFragment.SelfdestructScenario + .SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 1cfd52edb4..d9e71a691b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -142,7 +142,12 @@ public int getCodeFragmentIndex(Hub hub) { @Getter @Setter private boolean selfReverts = false; @Getter @Setter private boolean getsReverted = false; - @Getter @Setter private int revertStamp = 0; + + @Getter @Setter + private int revertStamp = + 0; // the hub stamp at which this frame reverts (0 means it does not revert) + + // TODO: create an enum with WILL_REVERT, WONT_REVERT /** this frame {@link Stack}. */ @Getter private final Stack stack = new Stack(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 966513790b..692c6cf6de 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -20,6 +20,7 @@ import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import java.math.BigInteger; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -32,6 +33,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -42,7 +44,7 @@ import org.hyperledger.besu.evm.worldstate.WorldView; @Getter -public class TransactionProcessingMetadata { +public class TransactionProcessingMetadata implements PostTransactionDefer { final int absoluteTransactionNumber; final int relativeTransactionNumber; @@ -114,14 +116,16 @@ public class TransactionProcessingMetadata { @Setter Set destructedAccountsSnapshot; @Getter - Map> unexceptionalSelfDestructMap; + Map> unexceptionalSelfDestructMap = new HashMap<>(); - @Getter Map effectiveSelfDestructMap; + @Getter Map effectiveSelfDestructMap = new HashMap<>(); - public record AddressDeploymentNumberKey(Address address, int deploymentNumber) {} + // Ephermeral accounts are both accounts that have been deployed on-chain + // and accounts that live for a limited time + public record EphemeralAccount(Address address, int deploymentNumber) {} ; - public record HubStampCallFrameValue(int hubStamp, CallFrame callFrame) {} + public record AttemptedSelfDestruct(int hubStamp, CallFrame callFrame) {} ; public TransactionProcessingMetadata( @@ -163,6 +167,7 @@ public void setPreFinalisationValues( final long refundCounterMax, final boolean minerIsWarmAtFinalisation, final int accumulatedGasUsedInBlockAtStartTx) { + this.isMinerWarmAtEndTx(minerIsWarmAtFinalisation); this.refundCounterMax = refundCounterMax; this.setLeftoverGas(leftOverGas); @@ -300,4 +305,26 @@ public int numberWarmedKey() { .sum() : 0; } + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + for (Map.Entry> entry : + this.unexceptionalSelfDestructMap.entrySet()) { + + EphemeralAccount ephemeralAccount = entry.getKey(); + List attemptedSelfDestructs = entry.getValue(); + + // For each address, deployment number, we find selfDestructTime as + // the time in which the first unexceptional and un-reverted SELFDESTRUCT occurs + // Then we add this value in a new map + for (AttemptedSelfDestruct attemptedSelfDestruct : attemptedSelfDestructs) { + if (attemptedSelfDestruct.callFrame().revertStamp() == 0) { + int selfDestructTime = attemptedSelfDestruct.hubStamp(); + this.effectiveSelfDestructMap.put(ephemeralAccount, selfDestructTime); + break; + } + } + } + } } From 90d2df20cf36e498ac2d64feb3ed733043841cb2 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 16:41:12 +0200 Subject: [PATCH 263/461] fix(return): triggers ROMLEX --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../hub/section/halt/ReturnSection.java | 29 +++++++++++++++---- zkevm-constraints | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 5577e7ed2c..a3ee1e5c4b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1020,7 +1020,7 @@ void traceOperation(MessageFrame frame) { } else { parentFrame.latestReturnData(Bytes.EMPTY); } - // final ImcFragment imcFragment = ImcFragment.forOpcode(this, frame); // TODO finish it + // TODO add returnSection } case REVERT -> { new RevertSection(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index be2bdecaec..6eebf7e2f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section.halt; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; +import static org.hyperledger.besu.evm.internal.Words.clampedToLong; import com.google.common.base.Preconditions; import lombok.Getter; @@ -150,7 +151,7 @@ public ReturnSection(Hub hub) { } // no need for the else case (and a nop) as per @François - ContextFragment updateCallerReturnData = + final ContextFragment updateCallerReturnData = ContextFragment.providesReturnData( hub, hub.callStack().getById(hub.currentFrame().parentFrame()).contextNumber(), @@ -171,16 +172,17 @@ public ReturnSection(Hub hub) { final boolean triggerOobForNonemptyDeployments = mxpCall.isMayTriggerNonTrivialMmuOperation(); Preconditions.checkArgument(triggerOobForNonemptyDeployments == !emptyDeployment); - Address deploymentAddress = hub.messageFrame().getRecipientAddress(); - AccountSnapshot accountBeforeDeployment = AccountSnapshot.canonical(hub, deploymentAddress); + final Address deploymentAddress = hub.messageFrame().getRecipientAddress(); + final AccountSnapshot accountBeforeDeployment = + AccountSnapshot.canonical(hub, deploymentAddress); // Empty deployments //////////////////// if (emptyDeployment) { - AccountSnapshot accountAfterEmptyDeployment = + final AccountSnapshot accountAfterEmptyDeployment = accountBeforeDeployment.deployByteCode(Bytecode.EMPTY); - AccountFragment emptyDeploymentAccountFragment = + final AccountFragment emptyDeploymentAccountFragment = hub.factories() .accountFragment() .make( @@ -207,9 +209,24 @@ public ReturnSection(Hub hub) { secondMmuCall = MmuCall.returnFromDeployment(hub); this.addFragment(secondImcFragment); + final long offset = clampedToLong(hub.messageFrame().getStackItem(0)); + final Bytecode deploymentCode = + new Bytecode(hub.messageFrame().shadowReadMemory(offset, byteCodeSize)); + // TODO: we require the // - triggerHashInfo stuff on the first stack row - // - triggerROMLEX on the deploymentAccountFragment row + // - triggerROMLEX on the deploymentAccountFragment row (done) + final AccountFragment nonemptyDeploymentAccountFragment = + hub.factories() + .accountFragment() + .make( + accountBeforeDeployment, + accountBeforeDeployment.deployByteCode(deploymentCode), + DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + nonemptyDeploymentAccountFragment.requiresRomlex(true); + hub.romLex().triggerRomLex(hub.messageFrame()); + + this.addFragment(nonemptyDeploymentAccountFragment); // TODO: we need to implement the mechanism that will append the // context row which will squash the creator's return data after diff --git a/zkevm-constraints b/zkevm-constraints index 03e1cadacb..66cf5cf54f 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 03e1cadacba51ac1e36eb6816cc370b2f24fc2b3 +Subproject commit 66cf5cf54f2e7d3a11dd740e44cf1eb9771e0e17 From a392785edff8804af893b73079ba86194f9a414a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 23 Jul 2024 16:59:34 +0200 Subject: [PATCH 264/461] fix(stuff): various --- .../module/hub/fragment/StackFragment.java | 2 +- .../fragment/common/CommonFragmentValues.java | 2 +- .../module/hub/section/AccountSection.java | 24 ++++++- .../module/hub/section/SloadSection.java | 12 +++- .../module/hub/section/SstoreSection.java | 9 ++- .../module/hub/section/TraceSection.java | 4 ++ .../hub/section/copy/ExtCodeCopySection.java | 67 ++++++++++--------- .../create/FailureOrEmptyInitCreate.java | 11 ++- .../create/NonEmptyInitCodeCreate.java | 14 ++-- .../module/hub/section/halt/StopSection.java | 7 +- .../linea/zktracer/opcode/OpCode.java | 4 ++ 11 files changed, 96 insertions(+), 60 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 68dcec9ab9..6c3296980a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -52,8 +52,8 @@ public final class StackFragment implements TraceFragment { private final short exceptions; @Setter private DeploymentExceptions contextExceptions; private final long staticGas; - private EWord hashInfoKeccak = EWord.ZERO; @Setter public boolean hashInfoFlag; + private EWord hashInfoKeccak = EWord.ZERO; @Setter public Bytes hash; @Getter private final OpCode opCode; @Setter private boolean jumpDestinationVettingRequired; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java index 70e159231c..133017cd86 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java @@ -68,7 +68,7 @@ public CommonFragmentValues(Hub hub) { this.txMetadata = hub.txStack().current(); this.hubProcessingPhase = hub.state().getProcessingPhase(); - this.hubStamp = hub.state().stamps().hub(); + this.hubStamp = hub.stamp(); this.callStack = hub.callStack(); this.stamps = hub.state().stamps(); this.callFrame = hub.currentFrame(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 01357f82da..34949b33dd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -15,12 +15,15 @@ package net.consensys.linea.zktracer.module.hub.section; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; @@ -31,6 +34,7 @@ public class AccountSection extends TraceSection implements PostRollbackDefer { + final short exceptions; final Bytes rawTargetAddress; final Address targetAddress; final boolean intialWarmth; @@ -65,10 +69,24 @@ public void appendToTrace(Hub hub) { this.addFragment(doingAccountFragment); } + private static short maxNumberOfRows(Hub hub) { + OpCode opCode = hub.opCode(); + + if (opCode.isAnyOf(OpCode.BALANCE, OpCode.EXTCODESIZE, OpCode.EXTCODEHASH)) { + return (short) (opCode.numberOfStackRows() + 3); + } + + return (short) (opCode.numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) + ? 1 + : 2)); + } + public AccountSection(Hub hub) { - super(hub); + super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); - this.addFragmentsAndStack(hub); + this.addStack(hub); + + exceptions = hub.pch().exceptions(); final MessageFrame frame = hub.messageFrame(); this.rawTargetAddress = @@ -106,7 +124,7 @@ private Account getTargetAccount(Hub hub) { public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), hub.currentFrame().revertStamp(), 0); final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(targetAddress); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 23059fb8b3..ba640863c1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -33,17 +33,21 @@ @Getter public class SloadSection extends TraceSection implements PostRollbackDefer { + + final WorldView world; final Address address; final int deploymentNumber; final Bytes32 storageKey; final boolean incomingWarmth; final EWord valueOriginal; final EWord valueCurrent; - final WorldView world; final short exceptions; public SloadSection(Hub hub, WorldView world) { - super(hub); + // exceptional case: 1 (stack row) + 5 (non stack rows) + // unexceptional case: 1 (stack row) + 4 (non stack rows) + super(hub, (short) (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); + this.world = world; this.address = hub.messageFrame().getRecipientAddress(); this.deploymentNumber = hub.currentFrame().accountDeploymentNumber(); @@ -90,8 +94,10 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca return; } + // TODO: make sure that the "current" execution context is the one that is being rolled back + // so that we can use its revert stamp () final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), hub.callStack().current().revertStamp(), 0); final StorageFragment undoingSloadStorageFragment = new StorageFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index df4e06ac5c..5738f5564b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -35,6 +35,8 @@ @Getter public class SstoreSection extends TraceSection implements PostRollbackDefer { + + final WorldView world; final Address address; final int deploymentNumber; final Bytes32 storageKey; @@ -42,11 +44,12 @@ public class SstoreSection extends TraceSection implements PostRollbackDefer { final EWord valueOriginal; final EWord valueCurrent; final EWord valueNext; - final WorldView world; final short exceptions; + // TODO: there should be a better way to public SstoreSection(Hub hub, WorldView world) { - super(hub); + super(hub, (short) (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); + this.world = world; this.address = hub.messageFrame().getRecipientAddress(); this.deploymentNumber = hub.currentFrame().accountDeploymentNumber(); @@ -110,7 +113,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca } final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 0); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), hub.callStack().current().revertStamp(), 0); final StorageFragment undoingSstoreStorageFragment = new StorageFragment( 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 c59b4aceda..9762a49313 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 @@ -238,4 +238,8 @@ public void trace(Trace hubTrace) { hubTrace.fillAndValidateRow(); } } + + public int hubStamp() { + return commonValues.hubStamp; + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 3ba76159bb..f6d1155653 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -42,6 +42,7 @@ public class ExtCodeCopySection extends TraceSection implements PostRollbackDefer, PostTransactionDefer { + final int hubStamp; final Bytes rawAddress; final Address address; final int incomingDeploymentNumber; @@ -62,26 +63,26 @@ public ExtCodeCopySection(Hub hub) { hub.addTraceSection(this); final MessageFrame frame = hub.messageFrame(); - this.rawAddress = frame.getStackItem(0); - this.address = Address.extract((Bytes32) this.rawAddress); - this.incomingDeploymentNumber = - hub.transients().conflation().deploymentInfo().number(this.address); - this.incomingDeploymentStatus = - hub.transients().conflation().deploymentInfo().isDeploying(this.address); - this.incomingWarmth = frame.isAddressWarm(this.address); - this.exceptions = hub.pch().exceptions(); - this.miscFragment = ImcFragment.empty(hub); + hubStamp = hub.stamp(); + rawAddress = frame.getStackItem(0); + address = Address.extract((Bytes32) rawAddress); + incomingDeploymentNumber = + hub.transients().conflation().deploymentInfo().number(address); + incomingDeploymentStatus = + hub.transients().conflation().deploymentInfo().isDeploying(address); + incomingWarmth = frame.isAddressWarm(address); + exceptions = hub.pch().exceptions(); + miscFragment = ImcFragment.empty(hub); this.addStack(hub); - this.addFragment(this.miscFragment); + this.addFragment(miscFragment); // triggerExp = false // triggerOob = false // triggerStp = false - // triggerMxp = true final MxpCall mxpCall = new MxpCall(hub); - this.miscFragment.callMxp(mxpCall); + miscFragment.callMxp(mxpCall); Preconditions.checkArgument( mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); @@ -97,22 +98,22 @@ public ExtCodeCopySection(Hub hub) { this.accountBefore = AccountSnapshot.fromAccount( foreignAccount, - this.incomingWarmth, - this.incomingDeploymentNumber, - this.incomingDeploymentStatus); + incomingWarmth, + incomingDeploymentNumber, + incomingDeploymentStatus); final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 0); // The OOGX case //////////////// - if (outOfGasException(this.exceptions)) { + if (outOfGasException(exceptions)) { // the last context row will be added automatically final AccountFragment accountReadingFragment = hub.factories() .accountFragment() .makeWithTrm( - this.accountBefore, this.accountBefore, this.rawAddress, doingDomSubStamps); + accountBefore, accountBefore, rawAddress, doingDomSubStamps); this.addFragment(accountReadingFragment); return; @@ -120,7 +121,7 @@ public ExtCodeCopySection(Hub hub) { // The unexceptional case ///////////////////////// - triggerMmu = none(this.exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; + triggerMmu = none(exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { mmuCall = MmuCall.extCodeCopy(hub); hub.defers().schedulePostTransaction(this); @@ -132,12 +133,12 @@ public ExtCodeCopySection(Hub hub) { this.accountAfter = AccountSnapshot.fromAccount( - foreignAccount, true, this.incomingDeploymentNumber, this.incomingDeploymentStatus); + foreignAccount, true, incomingDeploymentNumber, incomingDeploymentStatus); final AccountFragment accountDoingFragment = hub.factories() .accountFragment() - .makeWithTrm(this.accountBefore, this.accountAfter, this.rawAddress, doingDomSubStamps); + .makeWithTrm(accountBefore, accountAfter, rawAddress, doingDomSubStamps); accountDoingFragment.requiresRomlex(triggerCfi); this.addFragment(accountDoingFragment); hub.romLex().triggerRomLex(hub.messageFrame()); @@ -151,32 +152,32 @@ public ExtCodeCopySection(Hub hub) { public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { final int deploymentNumberAtRollback = - hub.transients().conflation().deploymentInfo().number(this.address); + hub.transients().conflation().deploymentInfo().number(address); final boolean deploymentStatusAtRollback = - hub.transients().conflation().deploymentInfo().isDeploying(this.address); + hub.transients().conflation().deploymentInfo().isDeploying(address); final AccountSnapshot revertFromSnapshot = new AccountSnapshot( - this.accountAfter.address(), - this.accountAfter.nonce(), - this.accountAfter.balance(), - this.accountAfter.isWarm(), - this.accountAfter.code(), + accountAfter.address(), + accountAfter.nonce(), + accountAfter.balance(), + accountAfter.isWarm(), + accountAfter.code(), deploymentNumberAtRollback, deploymentStatusAtRollback); final AccountSnapshot revertToSnapshot = new AccountSnapshot( - this.accountBefore.address(), - this.accountBefore.nonce(), - this.accountBefore.balance(), - this.accountBefore.isWarm(), - this.accountBefore.code(), + accountBefore.address(), + accountBefore.nonce(), + accountBefore.balance(), + accountBefore.isWarm(), + accountBefore.code(), deploymentNumberAtRollback, deploymentStatusAtRollback); final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, callFrame.revertStamp(), 1); final AccountFragment undoingAccountFragment = hub.factories() .accountFragment() diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java index cc54a6eb12..a33642d5e8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -31,7 +31,6 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class FailureOrEmptyInitCreate extends TraceSection implements FillCreateSection { - private final int hubStamp; final CreateScenarioFragment scenarioFragment; public FailureOrEmptyInitCreate( @@ -42,8 +41,6 @@ public FailureOrEmptyInitCreate( super(hub, (short) 10); hub.addTraceSection(this); - this.hubStamp = hub.stamp(); - this.scenarioFragment = new CreateScenarioFragment(scenario); this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); @@ -68,14 +65,14 @@ public void fillAccountFragment( accountFragmentFactory.make( oldCreatorSnapshot, newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); creatorAccountFragment.rlpAddrSubFragment(rlpAddrSubFragment); final AccountFragment createdAccountFragment = accountFragmentFactory.make( oldCreatedSnapshot, newCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 1)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); this.addFragmentsWithoutStack(creatorAccountFragment, createdAccountFragment); } @@ -104,12 +101,12 @@ public void fillReverting( accountFragmentFactory.make( newCreatorSnapshot, oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, currentRevertStamp, 2)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), currentRevertStamp, 2)); final AccountFragment undoCreatedAccountFragment = accountFragmentFactory.make( newCreatedSnapshot, oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, currentRevertStamp, 3)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), currentRevertStamp, 3)); this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index 22f01e7107..d8363db4a7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -32,7 +32,6 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class NonEmptyInitCodeCreate extends TraceSection implements FillCreateSection { - final int hubStamp; final CreateScenarioFragment scenarioFragment; public NonEmptyInitCodeCreate( @@ -40,7 +39,6 @@ public NonEmptyInitCodeCreate( super(hub, (short) 11); hub.addTraceSection(this); - this.hubStamp = hub.stamp(); this.scenarioFragment = new CreateScenarioFragment(); this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); @@ -72,14 +70,14 @@ public void fillAccountFragment( accountFragmentFactory.make( oldCreatorSnapshot, midCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); oldToMidCreatorAccountFragment.rlpAddrSubFragment(rlpAddrSubFragment); final AccountFragment oldToMidCreatedAccountFragment = accountFragmentFactory.make( oldCreatedSnapshot, midCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hubStamp, 1)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); oldToMidCreatedAccountFragment.requiresRomlex(true); this.addFragmentsWithoutStack(oldToMidCreatorAccountFragment, oldToMidCreatedAccountFragment); @@ -89,13 +87,13 @@ public void fillAccountFragment( accountFragmentFactory.make( midCreatorSnapshot, newCreatorSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(hubStamp, childRevertStamp, 2)); + DomSubStampsSubFragment.revertsWithChildDomSubStamps(this.hubStamp(), childRevertStamp, 2)); final AccountFragment midToNewCreatedAccountFragment = accountFragmentFactory.make( midCreatedSnapshot, newCreatedSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(hubStamp, childRevertStamp, 3)); + DomSubStampsSubFragment.revertsWithChildDomSubStamps(this.hubStamp(), childRevertStamp, 3)); this.addFragmentsWithoutStack(midToNewCreatorAccountFragment, midToNewCreatedAccountFragment); } @@ -127,13 +125,13 @@ public void fillReverting( createSuccess ? midCreatorSnapshot : newCreatorSnapshot, oldCreatorSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - hubStamp, currentRevertStamp, createSuccess ? 2 : 4)); + this.hubStamp(), currentRevertStamp, createSuccess ? 2 : 4)); final AccountFragment undoCreatedAccountFragment = accountFragmentFactory.make( createSuccess ? midCreatedSnapshot : newCreatedSnapshot, oldCreatedSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - hubStamp, currentRevertStamp, createSuccess ? 3 : 5)); + this.hubStamp(), currentRevertStamp, createSuccess ? 3 : 5)); this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index 4c82026801..3bb19a5a2f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -36,6 +36,7 @@ public class StopSection extends TraceSection implements PostRollbackDefer, PostTransactionDefer { + final int hubStamp; final Address address; final int deploymentNumber; final boolean deploymentStatus; @@ -49,6 +50,7 @@ public StopSection(Hub hub) { hub.addTraceSection(this); hub.defers().schedulePostTransaction(this); // always + hubStamp = hub.stamp(); address = hub.currentFrame().accountAddress(); contextNumber = hub.currentFrame().contextNumber(); { @@ -105,7 +107,9 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca } Preconditions.checkArgument(this.fragments().getLast() instanceof AccountFragment); + AccountFragment lastAccountFragment = (AccountFragment) this.fragments().getLast(); + DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, hub.callStack().current().revertStamp(), 1); this.addFragmentsWithoutStack( hub.factories() @@ -113,7 +117,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca .make( lastAccountFragment.newState(), lastAccountFragment.oldState(), - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 1))); + undoingDomSubStamps + )); } /** 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 cdb125e306..3a837c08d1 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 @@ -262,4 +262,8 @@ public boolean isAnyOf(OpCode... opCodes) { return false; } + + public short numberOfStackRows() { + return (short) (this.getData().stackSettings().twoLineInstruction() ? 2 : 1); + } } From f784b76f2406a5b606be658fa2aee73a4f3134e4 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 17:17:02 +0200 Subject: [PATCH 265/461] spotless + clean --- .../module/hub/section/AccountSection.java | 9 +++------ .../zktracer/module/hub/section/SloadSection.java | 8 ++++++-- .../zktracer/module/hub/section/SstoreSection.java | 9 ++++++--- .../hub/section/copy/ExtCodeCopySection.java | 14 ++++---------- .../section/create/FailureOrEmptyInitCreate.java | 6 ++++-- .../hub/section/create/NonEmptyInitCodeCreate.java | 6 ++++-- .../module/hub/section/halt/StopSection.java | 7 ++++--- .../linea/zktracer/module/hub/signals/Signals.java | 13 ------------- 8 files changed, 31 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 34949b33dd..db66a65daf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.hub.section; -import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; @@ -23,7 +22,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.opcode.InstructionFamily; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; @@ -76,9 +74,7 @@ private static short maxNumberOfRows(Hub hub) { return (short) (opCode.numberOfStackRows() + 3); } - return (short) (opCode.numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) - ? 1 - : 2)); + return (short) (opCode.numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 1 : 2)); } public AccountSection(Hub hub) { @@ -124,7 +120,8 @@ private Account getTargetAccount(Hub hub) { public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), hub.currentFrame().revertStamp(), 0); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), hub.currentFrame().revertStamp(), 0); final int deploymentNumberAtRollback = hub.transients().conflation().deploymentInfo().number(targetAddress); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index ba640863c1..96a2efdc5b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -46,7 +46,10 @@ public class SloadSection extends TraceSection implements PostRollbackDefer { public SloadSection(Hub hub, WorldView world) { // exceptional case: 1 (stack row) + 5 (non stack rows) // unexceptional case: 1 (stack row) + 4 (non stack rows) - super(hub, (short) (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); + super( + hub, + (short) + (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); this.world = world; this.address = hub.messageFrame().getRecipientAddress(); @@ -97,7 +100,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca // TODO: make sure that the "current" execution context is the one that is being rolled back // so that we can use its revert stamp () final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), hub.callStack().current().revertStamp(), 0); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), hub.callStack().current().revertStamp(), 0); final StorageFragment undoingSloadStorageFragment = new StorageFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 5738f5564b..c28ef4b2b4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -46,9 +46,11 @@ public class SstoreSection extends TraceSection implements PostRollbackDefer { final EWord valueNext; final short exceptions; - // TODO: there should be a better way to public SstoreSection(Hub hub, WorldView world) { - super(hub, (short) (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); + super( + hub, + (short) + (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); this.world = world; this.address = hub.messageFrame().getRecipientAddress(); @@ -113,7 +115,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca } final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), hub.callStack().current().revertStamp(), 0); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), hub.callStack().current().revertStamp(), 0); final StorageFragment undoingSstoreStorageFragment = new StorageFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index f6d1155653..9e2f6d7a82 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -66,10 +66,8 @@ public ExtCodeCopySection(Hub hub) { hubStamp = hub.stamp(); rawAddress = frame.getStackItem(0); address = Address.extract((Bytes32) rawAddress); - incomingDeploymentNumber = - hub.transients().conflation().deploymentInfo().number(address); - incomingDeploymentStatus = - hub.transients().conflation().deploymentInfo().isDeploying(address); + incomingDeploymentNumber = hub.transients().conflation().deploymentInfo().number(address); + incomingDeploymentStatus = hub.transients().conflation().deploymentInfo().isDeploying(address); incomingWarmth = frame.isAddressWarm(address); exceptions = hub.pch().exceptions(); miscFragment = ImcFragment.empty(hub); @@ -97,10 +95,7 @@ public ExtCodeCopySection(Hub hub) { this.accountBefore = AccountSnapshot.fromAccount( - foreignAccount, - incomingWarmth, - incomingDeploymentNumber, - incomingDeploymentStatus); + foreignAccount, incomingWarmth, incomingDeploymentNumber, incomingDeploymentStatus); final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(hub, 0); @@ -112,8 +107,7 @@ public ExtCodeCopySection(Hub hub) { final AccountFragment accountReadingFragment = hub.factories() .accountFragment() - .makeWithTrm( - accountBefore, accountBefore, rawAddress, doingDomSubStamps); + .makeWithTrm(accountBefore, accountBefore, rawAddress, doingDomSubStamps); this.addFragment(accountReadingFragment); return; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java index a33642d5e8..dc5fb559b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -101,12 +101,14 @@ public void fillReverting( accountFragmentFactory.make( newCreatorSnapshot, oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), currentRevertStamp, 2)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), currentRevertStamp, 2)); final AccountFragment undoCreatedAccountFragment = accountFragmentFactory.make( newCreatedSnapshot, oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), currentRevertStamp, 3)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), currentRevertStamp, 3)); this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index d8363db4a7..354b119a8b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -87,13 +87,15 @@ public void fillAccountFragment( accountFragmentFactory.make( midCreatorSnapshot, newCreatorSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(this.hubStamp(), childRevertStamp, 2)); + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + this.hubStamp(), childRevertStamp, 2)); final AccountFragment midToNewCreatedAccountFragment = accountFragmentFactory.make( midCreatedSnapshot, newCreatedSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(this.hubStamp(), childRevertStamp, 3)); + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + this.hubStamp(), childRevertStamp, 3)); this.addFragmentsWithoutStack(midToNewCreatorAccountFragment, midToNewCreatedAccountFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index 3bb19a5a2f..eb88659c24 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -109,7 +109,9 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca Preconditions.checkArgument(this.fragments().getLast() instanceof AccountFragment); AccountFragment lastAccountFragment = (AccountFragment) this.fragments().getLast(); - DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, hub.callStack().current().revertStamp(), 1); + DomSubStampsSubFragment undoingDomSubStamps = + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + hubStamp, hub.callStack().current().revertStamp(), 1); this.addFragmentsWithoutStack( hub.factories() @@ -117,8 +119,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca .make( lastAccountFragment.newState(), lastAccountFragment.oldState(), - undoingDomSubStamps - )); + undoingDomSubStamps)); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index e7845315b1..1fd3d8bbdf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -162,19 +162,6 @@ public void prepare(MessageFrame frame, PlatformController platformController, H || Exceptions.outOfGasException(ex) || Exceptions.none(ex); - case RETURN -> { - final boolean isDeployment = frame.getType() == MessageFrame.Type.CONTRACT_CREATION; - final boolean sizeNonZero = !frame.getStackItem(1).isZero(); - - // WARN: Static part, other modules may be dynamically requested in the hub - this.mxp = - Exceptions.memoryExpansionException(ex) - || Exceptions.outOfGasException(ex) - || Exceptions.invalidCodePrefix(ex) - || Exceptions.none(ex); - this.oob = isDeployment && (Exceptions.codeSizeOverflow(ex) || Exceptions.none(ex)); - } - case EXP -> { this.exp = true; // TODO: use expCall instead this.mul = !Exceptions.outOfGasException(ex); From 4e1934aaeee3624e571fa3ea0ecc06c584b46d30 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 23 Jul 2024 17:27:01 +0200 Subject: [PATCH 266/461] feat(account fragment): implemented marked for selfdestruct --- .../linea/zktracer/module/hub/Factories.java | 2 +- .../hub/fragment/account/AccountFragment.java | 33 ++++++++++++++----- .../hub/section/halt/SelfdestructSection.java | 8 ++--- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java index 792c68dafe..7c36a6e921 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Factories.java @@ -25,6 +25,6 @@ public class Factories { @Getter private final AccountFragment.AccountFragmentFactory accountFragment; public Factories(final Hub hub) { - this.accountFragment = new AccountFragment.AccountFragmentFactory(hub.defers()); + this.accountFragment = new AccountFragment.AccountFragmentFactory(hub); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index a93f0759ff..3969718094 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -19,6 +19,7 @@ import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; +import java.util.Map; import java.util.Optional; import com.google.common.base.Preconditions; @@ -36,6 +37,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; @@ -56,6 +58,9 @@ public final class AccountFragment private final Optional addressToTrim; private final DomSubStampsSubFragment domSubStampsSubFragment; @Setter private RlpAddrSubFragment rlpAddrSubFragment; + private boolean markedForSelfDestruct; + final int hubStamp; + final TransactionProcessingMetadata transactionProcessingMetadata; // TODO: will be needed to properly compute MARKED_FOR_SELFDESTRUCT // and to have the correct value of the hub stamp for the subordinate @@ -68,14 +73,14 @@ public final class AccountFragment */ @RequiredArgsConstructor public static class AccountFragmentFactory { - private final DeferRegistry defers; + private final Hub hub; public AccountFragment make( AccountSnapshot oldState, AccountSnapshot newState, DomSubStampsSubFragment domSubStampsSubFragment) { return new AccountFragment( - this.defers, oldState, newState, Optional.empty(), domSubStampsSubFragment); + hub, oldState, newState, Optional.empty(), domSubStampsSubFragment); } public AccountFragment makeWithTrm( @@ -84,18 +89,21 @@ public AccountFragment makeWithTrm( Bytes toTrim, DomSubStampsSubFragment domSubStampsSubFragment) { return new AccountFragment( - this.defers, oldState, newState, Optional.of(toTrim), domSubStampsSubFragment); + hub, oldState, newState, Optional.of(toTrim), domSubStampsSubFragment); } } public AccountFragment( - final DeferRegistry defers, + Hub hub, AccountSnapshot oldState, AccountSnapshot newState, Optional addressToTrim, DomSubStampsSubFragment domSubStampsSubFragment) { Preconditions.checkArgument(oldState.address().equals(newState.address())); + this.transactionProcessingMetadata = hub.txStack().current(); + this.hubStamp = hub.stamp(); + this.oldState = oldState; this.newState = newState; this.deploymentNumber = newState.deploymentNumber(); @@ -104,11 +112,11 @@ public AccountFragment( this.domSubStampsSubFragment = domSubStampsSubFragment; // This allows us to properly fill EXISTS_INFTY, DEPLOYMENT_NUMBER_INFTY and CODE_FRAGMENT_INDEX - defers.schedulePostConflation(this); + hub.defers().schedulePostConflation(this); // This allows us to properly fill MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW, // among other things - defers.schedulePostTransaction(this); + hub.defers().schedulePostTransaction(this); } @Override @@ -150,8 +158,8 @@ public Trace trace(Trace trace) { || !newState.balance().isZero()) .pAccountWarmth(oldState.isWarm()) .pAccountWarmthNew(newState.isWarm()) - .pAccountMarkedForSelfdestruct(false) // TODO - .pAccountMarkedForSelfdestructNew(false) // TODO + .pAccountMarkedForSelfdestruct(markedForSelfDestruct) + .pAccountMarkedForSelfdestructNew(!markedForSelfDestruct) .pAccountDeploymentNumber(oldState.deploymentNumber()) .pAccountDeploymentNumberNew(newState.deploymentNumber()) .pAccountDeploymentStatus(oldState.deploymentStatus()) @@ -166,7 +174,14 @@ public Trace trace(Trace trace) { @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - // TODO + Map effectiveSelfDestructMap = + this.transactionProcessingMetadata.getEffectiveSelfDestructMap(); + TransactionProcessingMetadata.EphemeralAccount ephemeralAccount = + new TransactionProcessingMetadata.EphemeralAccount( + this.newState.address(), this.newState.deploymentNumber()); + Preconditions.checkArgument(effectiveSelfDestructMap.containsKey(ephemeralAccount)); + int selfDestructStamp = effectiveSelfDestructMap.get(ephemeralAccount); + this.markedForSelfDestruct = this.hubStamp == selfDestructStamp; } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index dbbbc072f6..4c2d78716a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -45,6 +45,7 @@ public class SelfdestructSection extends TraceSection final int id; final int hubStamp; + final TransactionProcessingMetadata transactionProcessingMetadata; final short exceptions; SelfdestructScenarioFragment selfdestructScenarioFragment; @@ -63,18 +64,15 @@ public class SelfdestructSection extends TraceSection final boolean selfDestructTargetsItself; @Getter boolean selfDestructWasReverted = false; - final TransactionProcessingMetadata transactionProcessingMetadata; - public SelfdestructSection(Hub hub) { // up to 8 = 1 + 7 rows super(hub, (short) 8); hub.addTraceSection(this); - this.transactionProcessingMetadata = hub.txStack().current(); - // Init this.id = hub.currentFrame().id(); - hubStamp = hub.stamp(); + this.transactionProcessingMetadata = hub.txStack().current(); + this.hubStamp = hub.stamp(); this.exceptions = hub.pch().exceptions(); final MessageFrame frame = hub.messageFrame(); From 34c55b402b501659b66252d898ca822f60d619fc Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 23 Jul 2024 17:37:23 +0200 Subject: [PATCH 267/461] fix(self destruct time): renaming --- .../zktracer/module/hub/fragment/account/AccountFragment.java | 4 ++-- .../zktracer/module/hub/section/halt/SelfdestructSection.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 3969718094..57d6896ca4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -180,8 +180,8 @@ public void resolvePostTransaction( new TransactionProcessingMetadata.EphemeralAccount( this.newState.address(), this.newState.deploymentNumber()); Preconditions.checkArgument(effectiveSelfDestructMap.containsKey(ephemeralAccount)); - int selfDestructStamp = effectiveSelfDestructMap.get(ephemeralAccount); - this.markedForSelfDestruct = this.hubStamp == selfDestructStamp; + final int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); + this.markedForSelfDestruct = this.hubStamp == selfDestructTime; } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 4c2d78716a..258361279f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -247,7 +247,7 @@ public void resolvePostTransaction( // We modify the account fragment to reflect the self-destruct time - int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); + final int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); Preconditions.checkArgument(this.hubStamp >= selfDestructTime); From 4edce051b8b41517b1f1776d84df51ea49707f71 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 23 Jul 2024 17:46:49 +0200 Subject: [PATCH 268/461] fix(account fragment): fix account fragment resolve post transaction --- .../hub/fragment/account/AccountFragment.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 57d6896ca4..96edc90065 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -59,6 +59,7 @@ public final class AccountFragment private final DomSubStampsSubFragment domSubStampsSubFragment; @Setter private RlpAddrSubFragment rlpAddrSubFragment; private boolean markedForSelfDestruct; + private boolean markedForSelfDestructNew; final int hubStamp; final TransactionProcessingMetadata transactionProcessingMetadata; @@ -159,7 +160,7 @@ public Trace trace(Trace trace) { .pAccountWarmth(oldState.isWarm()) .pAccountWarmthNew(newState.isWarm()) .pAccountMarkedForSelfdestruct(markedForSelfDestruct) - .pAccountMarkedForSelfdestructNew(!markedForSelfDestruct) + .pAccountMarkedForSelfdestructNew(markedForSelfDestructNew) .pAccountDeploymentNumber(oldState.deploymentNumber()) .pAccountDeploymentNumberNew(newState.deploymentNumber()) .pAccountDeploymentStatus(oldState.deploymentStatus()) @@ -178,10 +179,15 @@ public void resolvePostTransaction( this.transactionProcessingMetadata.getEffectiveSelfDestructMap(); TransactionProcessingMetadata.EphemeralAccount ephemeralAccount = new TransactionProcessingMetadata.EphemeralAccount( - this.newState.address(), this.newState.deploymentNumber()); - Preconditions.checkArgument(effectiveSelfDestructMap.containsKey(ephemeralAccount)); - final int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); - this.markedForSelfDestruct = this.hubStamp == selfDestructTime; + this.oldState.address(), this.oldState.deploymentNumber()); + if (effectiveSelfDestructMap.containsKey(ephemeralAccount)) { + final int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); + this.markedForSelfDestruct = this.hubStamp < selfDestructTime; + this.markedForSelfDestructNew = this.hubStamp >= selfDestructTime; + } else { + this.markedForSelfDestruct = false; + this.markedForSelfDestructNew = false; + } } @Override From c719e09b2d9ff44c8d125769c1e62fb34ca8111e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 23 Jul 2024 18:06:51 +0200 Subject: [PATCH 269/461] feat: implement the refund business --- .../module/hub/HubProcessingPhase.java | 6 ++-- .../linea/zktracer/module/hub/TxTrace.java | 25 ------------- .../fragment/common/CommonFragmentValues.java | 8 ++--- .../module/hub/section/SstoreSection.java | 36 ++++++++++--------- .../module/hub/section/TraceSection.java | 17 ++++++--- 5 files changed, 38 insertions(+), 54 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java index 0a2ac67536..1e8f5aa832 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java @@ -16,9 +16,9 @@ package net.consensys.linea.zktracer.module.hub; public enum HubProcessingPhase { - TX_EXEC, - TX_FINAL, - TX_INIT, TX_SKIP, TX_WARM, + TX_INIT, + TX_EXEC, + TX_FINAL } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 9138e0a0b9..767079e206 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -34,12 +34,6 @@ public class TxTrace { /** A cache for the line count of this transaction */ private int cachedLineCount = 0; - private long refundCounter = -1; - @Getter private long leftoverGas = -1; - @Getter private long gasRefundFinalCounter = 0; // TODO: - - private static final int PARALLELIZATION_THRESHOLD = 10_000; - public int size() { return this.trace.size(); } @@ -79,25 +73,6 @@ public void add(TraceSection section) { this.trace.add(section); } - public long refundCounter() { - if (this.trace.size() >= PARALLELIZATION_THRESHOLD) { - return this.trace.parallelStream() - .filter(section -> !section.hasReverted()) - .mapToLong(TraceSection::refundDelta) - .sum(); - } else { - if (this.refundCounter == -1) { - this.refundCounter = 0; - for (TraceSection section : this.trace) { - if (!section.hasReverted()) { - this.refundCounter += section.refundDelta(); - } - } - } - return this.refundCounter; - } - } - /** * Generate the final numeric trace from the accumulated information. * diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java index 133017cd86..fb2dd3adab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java @@ -55,9 +55,9 @@ public class CommonFragmentValues { public final boolean contextMayChange; @Setter long gasCost; // Set at Post Execution @Setter long gasNext; // Set at Post Execution - @Getter public final long refundDelta; - @Setter public long gasRefund; // TODO - @Setter public long gasRefundNew; /* TODO gasRefund + (willRevert ? 0 : refundDelta) */ + @Setter public long refundDelta = 0; // 0 is default Value, can be modified only by SSTORE section + @Setter public long gasRefund; // Set at commit time + @Setter public long gasRefundNew; // Set at commit time @Setter public int numberOfNonStackRows; @Setter public boolean TLI; @Setter public int codeFragmentIndex = -1; @@ -79,8 +79,6 @@ public CommonFragmentValues(Hub hub) { this.pcNew = computePcNew(hub, pc, noStackException, hub.state.getProcessingPhase() == TX_EXEC); this.height = (short) callFrame.stack().getHeight(); this.heightNew = (short) callFrame.stack().getHeightNew(); - this.refundDelta = - noStackException ? Hub.GAS_PROJECTOR.of(callFrame.frame(), hub.opCode()).refund() : 0; // TODO: partial solution, will not work in general this.gasExpected = hub.expectedGas(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index c28ef4b2b4..a648c5a3fd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section; +import com.google.common.base.Preconditions; import lombok.Getter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; @@ -44,7 +45,6 @@ public class SstoreSection extends TraceSection implements PostRollbackDefer { final EWord valueOriginal; final EWord valueCurrent; final EWord valueNext; - final short exceptions; public SstoreSection(Hub hub, WorldView world) { super( @@ -61,16 +61,15 @@ public SstoreSection(Hub hub, WorldView world) { EWord.of(world.get(address).getOriginalStorageValue(UInt256.fromBytes(storageKey))); this.valueCurrent = EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); this.valueNext = EWord.of(hub.messageFrame().getStackItem(1)); - this.exceptions = hub.pch().exceptions(); + final short exceptions = hub.pch().exceptions(); hub.addTraceSection(this); - hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - final boolean staticContextException = Exceptions.staticFault(this.exceptions); - final boolean sstoreException = Exceptions.outOfSStore(this.exceptions); + final boolean staticContextException = Exceptions.staticFault(exceptions); + final boolean sstoreException = Exceptions.outOfSStore(exceptions); // CONTEXT fragment - ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); + final ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); this.addFragmentsAndStack(hub, readCurrentContext); if (staticContextException) { @@ -78,7 +77,7 @@ public SstoreSection(Hub hub, WorldView world) { } // MISC fragment - ImcFragment miscForSstore = ImcFragment.empty(hub); + final ImcFragment miscForSstore = ImcFragment.empty(hub); this.addFragment(miscForSstore); miscForSstore.callOob(new SstoreOobCall()); @@ -87,9 +86,20 @@ public SstoreSection(Hub hub, WorldView world) { return; } + Preconditions.checkArgument( + Exceptions.outOfGasException(exceptions) || Exceptions.none(exceptions)); + + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + // STORAGE fragment (for doing) - StorageFragment doingSstore = this.doingSstore(hub); + final StorageFragment doingSstore = this.doingSstore(hub); this.addFragment(doingSstore); + + // set the refundDelta + this.commonValues.refundDelta( + Hub.GAS_PROJECTOR + .of(hub.currentFrame().frame(), hub.opCode()) + .refund()); // TODO should use Besu's value } private StorageFragment doingSstore(Hub hub) { @@ -109,11 +119,6 @@ private StorageFragment doingSstore(Hub hub) { @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - - if (!this.undoingRequired()) { - return; - } - final DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), hub.callStack().current().revertStamp(), 0); @@ -132,9 +137,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca hub.state.firstAndLastStorageSlotOccurrences.size()); this.addFragment(undoingSstoreStorageFragment); - } - private boolean undoingRequired() { - return Exceptions.outOfGasException(this.exceptions) || Exceptions.none(this.exceptions); + // undo the refund + this.commonValues.refundDelta(0); } } 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 9762a49313..018249f2dc 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 @@ -17,6 +17,7 @@ import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; @@ -117,19 +118,29 @@ public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { /** This method is called at commit time, to build required information post-hoc. */ public void seal() { + final HubProcessingPhase currentPhase = this.commonValues.hubProcessingPhase; + commonValues.numberOfNonStackRows( (int) this.fragments.stream().filter(l -> !(l instanceof StackFragment)).count()); commonValues.TLI( (int) this.fragments.stream().filter(l -> (l instanceof StackFragment)).count() == 2); + commonValues.codeFragmentIndex( - this.commonValues.hubProcessingPhase == TX_EXEC + currentPhase == TX_EXEC ? this.hub.getCfiByMetaData( this.commonValues.callFrame().byteCodeAddress(), this.commonValues.callFrame().codeDeploymentNumber(), this.commonValues.callFrame().isDeployment()) : 0); + commonValues.contextNumberNew(computeContextNumberNew()); + commonValues.gasRefund( + currentPhase == TX_SKIP || currentPhase == TX_WARM || currentPhase == TX_INIT + ? 0 + : this.previousSection.commonValues.gasRefundNew); + commonValues.gasRefundNew(commonValues.gasRefund + commonValues.refundDelta); + /* If the logStamp hasn't been set (either by being first section of the tx, or by the LogSection), set it to the previous section logStamp */ if (commonValues.logStamp == -1) { commonValues.logStamp(this.previousSection.commonValues.logStamp); @@ -150,10 +161,6 @@ public final boolean hasReverted() { return this.commonValues.callFrame().hasReverted(); } - public final long refundDelta() { - return this.commonValues.refundDelta(); - } - /** * Update the stack fragments of the section with the provided {@link DeploymentExceptions}. * From 7458e4b186bdfb834f03e18f044a975e234660e9 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 23 Jul 2024 22:20:45 +0200 Subject: [PATCH 270/461] feat(selfdestruct): added draft of contracts for testing --- .../selfDestruct/SelfDestructCalle.sol | 20 ++++++++++++ .../selfDestruct/SelfDestructCaller.sol | 32 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol create mode 100644 arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol diff --git a/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol new file mode 100644 index 0000000000..8d40807761 --- /dev/null +++ b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract SelfDestructCallee { + bool public selfDestructInvoked = false; + + function invokeSelfDestruct() external { + selfDestructInvoked = true; + emit Bye(selfDestructInvoked); + + selfdestruct(payable(msg.sender)); + + // assembly { + // Execute the STOP opcode + // stop() + // } + } + + event Bye(bool selfDestructInvoked); +} \ No newline at end of file diff --git a/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol new file mode 100644 index 0000000000..64a15c1cbf --- /dev/null +++ b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract SelfDestructCaller { + + function staticCallToBWhenWarm(address bAddress) external { + // Get the balance of contract B to warm it + uint256 balance = address(bAddress).balance; + emit BalanceOfB(balance); + + uint256 size; + assembly { + size := extcodesize(bAddress) + } + emit ExtCodeSize(size); + + // Perform the STATICCALL + (bool success, ) = bAddress.call(abi.encodeWithSignature("invokeSelfDestruct()")); + emit CallSuccess(success); + + assembly { + size := extcodesize(bAddress) + } + emit ExtCodeSize(size); + } + + event BalanceOfB(uint256 balance); + + event CallSuccess(bool success); + + event ExtCodeSize(uint256 size); +} From e1c47b9f843d5dce05c0a6fb047712f5182f68c9 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 24 Jul 2024 09:55:03 +0200 Subject: [PATCH 271/461] fix(OOB:RDC): typo in StackArg --- .../zktracer/module/oob/OobOperation.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index bb80fb7a95..2f01d6aebc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -19,6 +19,13 @@ import static java.lang.Byte.toUnsignedInt; import static java.lang.Math.max; import static java.lang.Math.min; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_ADD; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_DIV; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_EQ; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_GT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_ISZERO; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_LT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_MOD; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.GAS_CONST_G_CALL_STIPEND; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; @@ -71,6 +78,7 @@ import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBoolean; import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; +import static net.consensys.linea.zktracer.types.Utils.rightPadTo; import java.math.BigInteger; import java.math.RoundingMode; @@ -381,8 +389,8 @@ private void populateColumns(final MessageFrame frame) { setJumpi(jumpiOobCall); } else if (isRdc) { ReturnDataCopyOobCall rdcOobCall = (ReturnDataCopyOobCall) oobCall; - rdcOobCall.setOffset(EWord.of(frame.getStackItem(0))); - rdcOobCall.setSize(EWord.of(frame.getStackItem(1))); + rdcOobCall.setOffset(EWord.of(frame.getStackItem(1))); + rdcOobCall.setSize(EWord.of(frame.getStackItem(2))); rdcOobCall.setRds(BigInteger.valueOf(frame.getReturnData().size())); setRdc(rdcOobCall); } else if (isCdl) { @@ -487,9 +495,7 @@ private void populateColumns(final MessageFrame frame) { final Bytes unpaddedCallData = frame.shadowReadMemory(argsOffset, cds.longValue()); // pad unpaddedCallData to 96 final Bytes paddedCallData = - cds.intValue() < 96 - ? Bytes.concatenate(unpaddedCallData, Bytes.repeat((byte) 0, 96 - cds.intValue())) - : unpaddedCallData; + cds.intValue() < 96 ? rightPadTo(unpaddedCallData, 96) : unpaddedCallData; // cds and the data below can be int when compared (after size check) final BigInteger bbs = paddedCallData.slice(0, 32).toUnsignedBigInteger(); @@ -506,9 +512,7 @@ private void populateColumns(final MessageFrame frame) { // pad paddedCallData to 96 + bbs + ebs final Bytes doublePaddedCallData = cds.intValue() < 96 + bbs.intValue() + ebs.intValue() - ? Bytes.concatenate( - paddedCallData, - Bytes.repeat((byte) 0, 96 + bbs.intValue() + ebs.intValue() - cds.intValue())) + ? rightPadTo(paddedCallData, 96 + bbs.intValue() + ebs.intValue()) : paddedCallData; final BigInteger leadingBytesOfExponent = @@ -621,7 +625,7 @@ private void callToADD( addFlag[k] = true; modFlag[k] = false; wcpFlag[k] = false; - outgoingInst[k] = UnsignedByte.of(OpCode.ADD.byteValue()); + outgoingInst[k] = UnsignedByte.of(EVM_INST_ADD); outgoingData1[k] = arg1Hi; outgoingData2[k] = arg1Lo; outgoingData3[k] = arg2Hi; @@ -644,7 +648,7 @@ private BigInteger callToDIV( addFlag[k] = false; modFlag[k] = true; wcpFlag[k] = false; - outgoingInst[k] = UnsignedByte.of(OpCode.DIV.byteValue()); + outgoingInst[k] = UnsignedByte.of(EVM_INST_DIV); outgoingData1[k] = arg1Hi; outgoingData2[k] = arg1Lo; outgoingData3[k] = arg2Hi; @@ -664,7 +668,7 @@ private BigInteger callToMOD( addFlag[k] = false; modFlag[k] = true; wcpFlag[k] = false; - outgoingInst[k] = UnsignedByte.of(OpCode.MOD.byteValue()); + outgoingInst[k] = UnsignedByte.of(EVM_INST_MOD); outgoingData1[k] = arg1Hi; outgoingData2[k] = arg1Lo; outgoingData3[k] = arg2Hi; @@ -684,7 +688,7 @@ private boolean callToLT( addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; - outgoingInst[k] = UnsignedByte.of(OpCode.LT.byteValue()); + outgoingInst[k] = UnsignedByte.of(EVM_INST_LT); outgoingData1[k] = arg1Hi; outgoingData2[k] = arg1Lo; outgoingData3[k] = arg2Hi; @@ -705,7 +709,7 @@ private boolean callToGT( addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; - outgoingInst[k] = UnsignedByte.of(OpCode.GT.byteValue()); + outgoingInst[k] = UnsignedByte.of(EVM_INST_GT); outgoingData1[k] = arg1Hi; outgoingData2[k] = arg1Lo; outgoingData3[k] = arg2Hi; @@ -722,7 +726,7 @@ private boolean callToISZERO(final int k, final BigInteger arg1Hi, final BigInte addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; - outgoingInst[k] = UnsignedByte.of(OpCode.ISZERO.byteValue()); + outgoingInst[k] = UnsignedByte.of(EVM_INST_ISZERO); outgoingData1[k] = arg1Hi; outgoingData2[k] = arg1Lo; outgoingData3[k] = BigInteger.ZERO; @@ -743,7 +747,7 @@ private boolean callToEQ( addFlag[k] = false; modFlag[k] = false; wcpFlag[k] = true; - outgoingInst[k] = UnsignedByte.of(OpCode.EQ.byteValue()); + outgoingInst[k] = UnsignedByte.of(EVM_INST_EQ); outgoingData1[k] = arg1Hi; outgoingData2[k] = arg1Lo; outgoingData3[k] = arg2Hi; From 3cb9c42b86c2bb5610516b60329afc3a3d75f374 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 24 Jul 2024 11:14:29 +0200 Subject: [PATCH 272/461] typo --- .../zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index efbbc74e53..b19e2e7e9e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -240,7 +240,7 @@ public static MmuCall extCodeCopy(final Hub hub) { public static MmuCall returnDataCopy(final Hub hub) { final MemorySpan returnDataSegment = hub.currentFrame().latestReturnDataSource(); final CallFrame returnerFrame = - hub.callStack().getById(hub.currentFrame().returnDataContextNumber()); + hub.callStack().getByContextNumber(hub.currentFrame().returnDataContextNumber()); return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) .sourceId(returnerFrame.contextNumber()) .sourceRamBytes( From 98ee0952c7d331c48050b163f67601a99113f82e Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 24 Jul 2024 12:49:27 +0200 Subject: [PATCH 273/461] feat(selfdestruct): fixed contracts for testing using 0.8.0+commit.c7dfd78e compiler version and VM London Environment --- .../selfDestruct/SelfDestructCalle.sol | 20 --------- .../selfDestruct/SelfDestructCallee.sol | 13 ++++++ .../selfDestruct/SelfDestructCaller.sol | 41 ++++++++++++++----- 3 files changed, 43 insertions(+), 31 deletions(-) delete mode 100644 arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol create mode 100644 arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCallee.sol diff --git a/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol deleted file mode 100644 index 8d40807761..0000000000 --- a/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCalle.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -contract SelfDestructCallee { - bool public selfDestructInvoked = false; - - function invokeSelfDestruct() external { - selfDestructInvoked = true; - emit Bye(selfDestructInvoked); - - selfdestruct(payable(msg.sender)); - - // assembly { - // Execute the STOP opcode - // stop() - // } - } - - event Bye(bool selfDestructInvoked); -} \ No newline at end of file diff --git a/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCallee.sol b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCallee.sol new file mode 100644 index 0000000000..d2dc1114cb --- /dev/null +++ b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCallee.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract SelfDestructCallee { + constructor() payable {} + + function invokeSelfDestruct() external { + emit SelfDestruct(); + selfdestruct(payable(msg.sender)); + } + + event SelfDestruct(); +} diff --git a/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol index 64a15c1cbf..5472ce8877 100644 --- a/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol +++ b/arithmetization/src/test/resources/contracts/selfDestruct/SelfDestructCaller.sol @@ -2,31 +2,50 @@ pragma solidity ^0.8.0; contract SelfDestructCaller { - - function staticCallToBWhenWarm(address bAddress) external { - // Get the balance of contract B to warm it - uint256 balance = address(bAddress).balance; - emit BalanceOfB(balance); + function callSelfDestructCalleeWhenWarm(address selfDestructCalleeAddress) + external + { + // Get the balance of SelfDestructCallee to warm it + emit Balance(address(selfDestructCalleeAddress).balance); + // Get the codesize of SelfDestructCallee uint256 size; assembly { - size := extcodesize(bAddress) + size := extcodesize(selfDestructCalleeAddress) } emit ExtCodeSize(size); // Perform the STATICCALL - (bool success, ) = bAddress.call(abi.encodeWithSignature("invokeSelfDestruct()")); + // (bool success, ) = selfDestructCalleeAddress.staticcall(abi.encodeWithSignature("invokeSelfDestruct()")); // fails + // emit CallSuccess(success); + + // Perform the CALL + (bool success, ) = selfDestructCalleeAddress.call( + abi.encodeWithSignature("invokeSelfDestruct()") + ); // succeed emit CallSuccess(success); + // here codesize of SelfDestructCallee is not 0 yet + } + + function verifyBalanceAndCodesizeOfSelfDestructCallee( + address selfDestructCalleeAddress + ) external { + // here codesize of SelfDestructCallee is 0 after invoking callSelfDestructCalleeWhenWarm + // Get the balance of SelfDestructCallee + emit Balance(address(selfDestructCalleeAddress).balance); + + // Get the codesize of SelfDestructCallee + uint256 size; assembly { - size := extcodesize(bAddress) + size := extcodesize(selfDestructCalleeAddress) } emit ExtCodeSize(size); } - event BalanceOfB(uint256 balance); - - event CallSuccess(bool success); + event Balance(uint256 balance); event ExtCodeSize(uint256 size); + + event CallSuccess(bool success); } From 9e368e710eb87ba8e454f428755a71446f44df3e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 24 Jul 2024 16:12:56 +0200 Subject: [PATCH 274/461] fix(hub): return data + halting instruction fixes and refactoring --- .../linea/zktracer/module/hub/Hub.java | 126 +++++++++++------- .../module/hub/defer/DeferRegistry.java | 2 +- .../module/hub/fragment/ContextFragment.java | 14 +- .../hub/fragment/common/CommonFragment.java | 2 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 8 +- .../fragment/scenario/ScenarioFragment.java | 14 +- .../hub/section/halt/ReturnSection.java | 4 +- .../hub/section/halt/RevertSection.java | 2 +- .../hub/transients/OperationAncillaries.java | 45 ++++--- .../zktracer/module/mmio/CallStackReader.java | 2 +- .../linea/zktracer/module/romlex/RomLex.java | 6 +- .../zktracer/runtime/callstack/CallFrame.java | 73 +++++----- .../zktracer/runtime/callstack/CallStack.java | 12 +- 13 files changed, 174 insertions(+), 136 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index a3ee1e5c4b..c5c3e6be93 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -15,7 +15,10 @@ package net.consensys.linea.zktracer.module.hub; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.*; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; @@ -42,21 +45,42 @@ import net.consensys.linea.zktracer.module.exp.Exp; import net.consensys.linea.zktracer.module.ext.Ext; import net.consensys.linea.zktracer.module.gas.Gas; -import net.consensys.linea.zktracer.module.hub.defer.*; -import net.consensys.linea.zktracer.module.hub.fragment.*; +import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.hub.section.*; +import net.consensys.linea.zktracer.module.hub.section.AccountSection; +import net.consensys.linea.zktracer.module.hub.section.CallDataLoadSection; +import net.consensys.linea.zktracer.module.hub.section.ContextSection; +import net.consensys.linea.zktracer.module.hub.section.ExpSection; +import net.consensys.linea.zktracer.module.hub.section.JumpSection; +import net.consensys.linea.zktracer.module.hub.section.KeccakSection; +import net.consensys.linea.zktracer.module.hub.section.LogSection; +import net.consensys.linea.zktracer.module.hub.section.SloadSection; +import net.consensys.linea.zktracer.module.hub.section.SstoreSection; +import net.consensys.linea.zktracer.module.hub.section.StackOnlySection; +import net.consensys.linea.zktracer.module.hub.section.StackRamSection; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.section.TransactionSection; import net.consensys.linea.zktracer.module.hub.section.TxFinalizationSection; +import net.consensys.linea.zktracer.module.hub.section.TxInitializationSection; import net.consensys.linea.zktracer.module.hub.section.TxPreWarmingMacroSection; import net.consensys.linea.zktracer.module.hub.section.TxSkippedSectionDefers; import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; -import net.consensys.linea.zktracer.module.hub.section.copy.*; +import net.consensys.linea.zktracer.module.hub.section.copy.CallDataCopySection; +import net.consensys.linea.zktracer.module.hub.section.copy.CodeCopySection; +import net.consensys.linea.zktracer.module.hub.section.copy.ExtCodeCopySection; +import net.consensys.linea.zktracer.module.hub.section.copy.ReturnDataCopySection; import net.consensys.linea.zktracer.module.hub.section.create.CreateSection; +import net.consensys.linea.zktracer.module.hub.section.halt.ReturnSection; import net.consensys.linea.zktracer.module.hub.section.halt.RevertSection; +import net.consensys.linea.zktracer.module.hub.section.halt.SelfdestructSection; import net.consensys.linea.zktracer.module.hub.section.halt.StopSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; @@ -98,14 +122,18 @@ import net.consensys.linea.zktracer.module.trm.Trm; import net.consensys.linea.zktracer.module.txndata.TxnData; import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.opcode.*; +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.opcode.OpCodeData; import net.consensys.linea.zktracer.opcode.gas.projector.GasProjector; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.callstack.CallFrameType; import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.runtime.stack.StackContext; import net.consensys.linea.zktracer.runtime.stack.StackLine; -import net.consensys.linea.zktracer.types.*; +import net.consensys.linea.zktracer.types.Bytecode; +import net.consensys.linea.zktracer.types.MemorySpan; +import net.consensys.linea.zktracer.types.Precompile; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; @@ -647,7 +675,7 @@ public void traceContextExit(MessageFrame frame) { this.currentTraceSection().setContextExceptions(contextExceptions); if (contextExceptions.any()) { - this.callStack.revert(this.state.stamps().hub()); + this.callStack.revert(this.state.stamps().hub()); // TODO: Duplicate s? this.defers.resolvePostRollback(this, frame, this.currentFrame()); } @@ -701,7 +729,6 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope final boolean unexceptional = Exceptions.none(exceptions); final boolean exceptional = Exceptions.any(exceptions); - /* TODO: Might be dangerous : in some cases, we add fragments at the end of the transaction, we need an other mechanism ... */ // NOTE: whenever there is an exception, a context row // is added at the end of the section; its purpose is // to update the caller / creator context with empty @@ -710,6 +737,8 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope if (exceptional) { this.currentTraceSection() .addFragmentsWithoutStack(ContextFragment.executionProvidesEmptyReturnData(this)); + this.squashCurrentFrameOutputData(); + this.squashParentFrameReturnData(); } // Setting gas cost IN MOST CASES @@ -755,9 +784,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope case ACCOUNT -> {} case COPY -> {} case TRANSACTION -> {} - case BATCH -> { - this.blockhash.tracePostOpcode(frame); - } + case BATCH -> this.blockhash.tracePostOpcode(frame); case STACK_RAM -> {} case STORAGE -> {} case JUMP -> {} @@ -766,9 +793,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope case DUP -> {} case SWAP -> {} case LOG -> {} - case CREATE -> { - this.romLex.tracePostOpcode(frame); - } + case CREATE -> this.romLex.tracePostOpcode(frame); case CALL -> {} case HALT -> {} case INVALID -> {} @@ -954,6 +979,10 @@ void processStateExec(MessageFrame frame) { } this.traceOperation(frame); } else { + + this.squashCurrentFrameOutputData(); + this.squashParentFrameReturnData(); + this.addTraceSection(new StackOnlySection(this)); } } @@ -1004,43 +1033,29 @@ void traceOperation(MessageFrame frame) { } case HALT -> { final CallFrame parentFrame = this.callStack.parent(); - // this.addTraceSection(new StackOnlySection(this)); + parentFrame.returnDataContextNumber(this.currentFrame().contextNumber()); + final Bytes outputData = this.transients.op().outputData(); + this.currentFrame().outputDataSpan(transients.op().outputDataSpan()); + this.currentFrame().outputData(outputData); + + // The output data always becomes return data of the caller when REVERT'ing + // and in all other cases becomes return data of the caller iff the present + // context is a message call context + final boolean outputDataBecomesParentReturnData = + (this.opCode() == OpCode.REVERT || this.currentFrame().isMessageCall()); + + if (outputDataBecomesParentReturnData) { + parentFrame.returnData(outputData); + parentFrame.returnDataSpan(transients.op().outputDataSpan()); + } else { + this.squashParentFrameReturnData(); + } switch (this.opCode()) { - case RETURN -> { - Bytes returnData = Bytes.EMPTY; - // Trying to read memory with absurd arguments will throw an exception - if (Exceptions.none(pch.exceptions())) { - returnData = this.transients.op().returnData(); - } - this.currentFrame().returnDataSource(transients.op().returnDataSegment()); - this.currentFrame().returnData(returnData); - if (!Exceptions.any(this.pch.exceptions()) && !this.currentFrame().isDeployment()) { - parentFrame.latestReturnData(returnData); - } else { - parentFrame.latestReturnData(Bytes.EMPTY); - } - // TODO add returnSection - } - case REVERT -> { - new RevertSection(this); - final Bytes returnData = this.transients.op().returnData(); - this.currentFrame().returnDataSource(transients.op().returnDataSegment()); - this.currentFrame().returnData(returnData); - if (Exceptions.none(this.pch.exceptions())) { - parentFrame.latestReturnData(returnData); - } else { - parentFrame.latestReturnData(Bytes.EMPTY); - } - } - case STOP -> { - new StopSection(this); - parentFrame.latestReturnData(Bytes.EMPTY); - } - case SELFDESTRUCT -> { - // TODO - parentFrame.latestReturnData(Bytes.EMPTY); - } + case RETURN -> new ReturnSection(this); + case REVERT -> new RevertSection(this); + case STOP -> new StopSection(this); + case SELFDESTRUCT -> new SelfdestructSection(this); } } @@ -1211,4 +1226,15 @@ void traceOperation(MessageFrame frame) { public TraceSection getCurrentSection() { return this.state.currentTxTrace().currentSection(); } + + public void squashCurrentFrameOutputData() { + this.currentFrame().outputDataSpan(MemorySpan.empty()); + this.currentFrame().outputData(Bytes.EMPTY); + } + + public void squashParentFrameReturnData() { + final CallFrame parentFrame = this.callStack.parent(); + parentFrame.returnData(Bytes.EMPTY); + parentFrame.returnDataSpan(MemorySpan.empty()); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 2caa950bd6..bb5f52386a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -99,7 +99,7 @@ public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame */ public void resolveWithNextContext(Hub hub, MessageFrame frame) { for (Pair defer : this.contextReentry) { - if (hub.currentFrame().parentFrame() == defer.getLeft()) { + if (hub.currentFrame().parentFrameId() == defer.getLeft()) { defer.getRight().resolveWithNextContext(hub, frame); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index c1ffb3d3cd..bcda6d1f78 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -45,7 +45,7 @@ public static ContextFragment readContextDataByContextNumber( callStack, Either.right(contextNumber), callStack.getByContextNumber(contextNumber).returnDataContextNumber(), - callStack.current().latestReturnDataSource().snapshot(), + callStack.current().returnDataSpan().snapshot(), false); } @@ -56,7 +56,7 @@ public static ContextFragment readContextDataById(final Hub hub, final int conte callStack, Either.left(contextId), callStack.getById(contextId).returnDataContextNumber(), - callStack.current().latestReturnDataSource().snapshot(), + callStack.current().returnDataSpan().snapshot(), false); } @@ -88,7 +88,7 @@ public static ContextFragment executionProvidesEmptyReturnData(final Hub hub) { public static ContextFragment executionProvidesEmptyReturnData(final Hub hub, int contextNumber) { CallStack callStack = hub.callStack(); - int parentId = callStack.getByContextNumber(contextNumber).parentFrame(); + int parentId = callStack.getByContextNumber(contextNumber).parentFrameId(); return new ContextFragment( hub, callStack, Either.left(parentId), contextNumber, MemorySpan.empty(), true); } @@ -111,7 +111,7 @@ public static ContextFragment executionReturnData(final Hub hub) { callStack, Either.left(callStack.parent().id()), hub.currentFrame().contextNumber(), - callStack.current().returnDataSource(), + callStack.current().outputDataSpan(), true); } @@ -129,7 +129,7 @@ public static ContextFragment providesReturnData( callStack, Either.right(receiverContextNumber), providerContextNumber, - callStack.current().latestReturnDataSource().snapshot(), + callStack.current().returnDataSpan().snapshot(), true); // TODO: is this what we want ? // also: will the latestReturnData have been updated ? @@ -165,8 +165,8 @@ public Trace trace(Trace trace) { .pContextCallDataContextNumber(parent.contextNumber()) .pContextCallDataOffset(callFrame.callDataInfo().memorySpan().offset()) .pContextCallDataSize(callFrame.callDataInfo().memorySpan().length()) - .pContextReturnAtOffset(callFrame.requestedReturnDataTarget().offset()) - .pContextReturnAtCapacity(callFrame.requestedReturnDataTarget().length()) + .pContextReturnAtOffset(callFrame.parentReturnDataTarget().offset()) + .pContextReturnAtCapacity(callFrame.parentReturnDataTarget().length()) .pContextUpdate(updateReturnData) .pContextReturnDataContextNumber(returnDataContextNumber) // callFrame.id() == 0 diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java index b8444e6602..ed24e5d033 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java @@ -85,7 +85,7 @@ public Trace trace(Trace trace) { .contextNumber(isExec ? frame.contextNumber() : 0) .contextNumberNew(commonFragmentValues.contextNumberNew) .callerContextNumber( - commonFragmentValues.callStack.getById(frame.parentFrame()).contextNumber()) + commonFragmentValues.callStack.getById(frame.parentFrameId()).contextNumber()) .contextWillRevert(frame.willRevert() && isExec) .contextGetsReverted(frame.getsReverted() && isExec) .contextSelfReverts(frame.selfReverts() && isExec) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index b19e2e7e9e..7d2d45b780 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -238,7 +238,7 @@ public static MmuCall extCodeCopy(final Hub hub) { } public static MmuCall returnDataCopy(final Hub hub) { - final MemorySpan returnDataSegment = hub.currentFrame().latestReturnDataSource(); + final MemorySpan returnDataSegment = hub.currentFrame().returnDataSpan(); final CallFrame returnerFrame = hub.callStack().getByContextNumber(hub.currentFrame().returnDataContextNumber()); return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) @@ -290,11 +290,11 @@ public static MmuCall invalidCodePrefix(final Hub hub) { public static MmuCall revert(final Hub hub) { return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(hub.currentFrame().contextNumber()) - .targetId(hub.callStack().getById(hub.currentFrame().parentFrame()).contextNumber()) + .targetId(hub.callStack().getById(hub.currentFrame().parentFrameId()).contextNumber()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(1))) - .referenceOffset(hub.currentFrame().requestedReturnDataTarget().offset()) - .referenceSize(hub.currentFrame().requestedReturnDataTarget().length()); + .referenceOffset(hub.currentFrame().parentReturnDataTarget().offset()) + .referenceSize(hub.currentFrame().parentReturnDataTarget().length()); } public static MmuCall txInit(final Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 1cdde1adbc..3ffa4625f2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -54,7 +54,7 @@ public class ScenarioFragment implements TraceFragment, PostTransactionDefer { private boolean callerReverts = false; MemorySpan callDataSegment; - MemorySpan requestedReturnDataSegment; + MemorySpan parentReturnDataTarget; /** * Is set if: - this is a CALL and the callee reverts - this is a CREATE and the creation failed - @@ -92,7 +92,7 @@ public static ScenarioFragment forSmartContractCallSection( false, false); r.callDataSegment = hub.transients().op().callDataSegment(); - r.requestedReturnDataSegment = hub.transients().op().returnDataRequestedSegment(); + r.parentReturnDataTarget = hub.transients().op().returnDataRequestedSegment(); return r; } @@ -125,7 +125,7 @@ public static ScenarioFragment forNoCodeCallSection( false); } r.callDataSegment = hub.transients().op().callDataSegment(); - r.requestedReturnDataSegment = hub.transients().op().returnDataRequestedSegment(); + r.parentReturnDataTarget = hub.transients().op().returnDataRequestedSegment(); r.fillPostCallInformation(hub); return r; @@ -146,7 +146,7 @@ public static ScenarioFragment forPrecompileEpilogue( false); // This one is already created from a post-tx hook r.callDataSegment = precompile.callDataSource(); - r.requestedReturnDataSegment = precompile.requestedReturnDataTarget(); + r.parentReturnDataTarget = precompile.requestedReturnDataTarget(); r.fillPostCallInformation(hub); return r; } @@ -176,7 +176,7 @@ private boolean targetIsPrecompile() { */ private void fillPreCallInformation(final Hub hub) { this.callDataSegment = hub.callStack().getById(calleeId).callDataInfo().memorySpan(); - this.requestedReturnDataSegment = hub.callStack().getById(calleeId).requestedReturnDataTarget(); + this.parentReturnDataTarget = hub.callStack().getById(calleeId).parentReturnDataTarget(); } /** @@ -313,8 +313,8 @@ && targetIsPrecompile() .orElse(0L)) .pScenarioPrcCdo(type.isPrecompile() ? callDataSegment.offset() : 0) .pScenarioPrcCds(type.isPrecompile() ? callDataSegment.length() : 0) - .pScenarioPrcRao(type.isPrecompile() ? requestedReturnDataSegment.offset() : 0) - .pScenarioPrcRac(type.isPrecompile() ? requestedReturnDataSegment.length() : 0) + .pScenarioPrcRao(type.isPrecompile() ? parentReturnDataTarget.offset() : 0) + .pScenarioPrcRac(type.isPrecompile() ? parentReturnDataTarget.length() : 0) // .pScenarioCodedeposit(type.isDeposit()) // .pScenarioCodedepositInvalidCodePrefix(type.isDeposit() && raisedInvalidCodePrefix) // .pScenarioCodedepositValidCodePrefix(false) // TODO: @Olivier diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 6eebf7e2f3..f54205d3d1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -137,7 +137,7 @@ public ReturnSection(Hub hub) { final boolean messageCallReturnTouchesRam = !hub.currentFrame().isRoot() && nontrivialMmOperation // [size ≠ 0] ∧ ¬MXPX - && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); // [r@c ≠ 0] + && !hub.currentFrame().parentReturnDataTarget().isEmpty(); // [r@c ≠ 0] returnScenarioFragment.setScenario( messageCallReturnTouchesRam @@ -154,7 +154,7 @@ public ReturnSection(Hub hub) { final ContextFragment updateCallerReturnData = ContextFragment.providesReturnData( hub, - hub.callStack().getById(hub.currentFrame().parentFrame()).contextNumber(), + hub.callStack().getById(hub.currentFrame().parentFrameId()).contextNumber(), hub.currentFrame().contextNumber()); this.addFragment(updateCallerReturnData); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index aa552a2d31..ac91436667 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -54,7 +54,7 @@ public RevertSection(Hub hub) { (Exceptions.none(exceptions)) && !hub.currentFrame().isRoot() && mxpCall.isMayTriggerNonTrivialMmuOperation() // i.e. size ≠ 0 ∧ ¬MXPX - && !hub.currentFrame().requestedReturnDataTarget().isEmpty(); + && !hub.currentFrame().parentReturnDataTarget().isEmpty(); if (triggerMmu) { mmuCall = MmuCall.revert(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index b9d3f65759..22ebb7a105 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -178,17 +178,30 @@ public MemorySpan returnDataRequestedSegment() { * @param frame the execution context * @return the return data segment */ - public static MemorySpan returnDataSegment(final MessageFrame frame) { - switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { + public static MemorySpan outputDataSpan(final MessageFrame frame) { + + if (frame.getExceptionalHaltReason().isPresent()) { + return MemorySpan.empty(); + } + + final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); + + if (opCode == OpCode.RETURN && frame.getType() == MessageFrame.Type.CONTRACT_CREATION) { + return MemorySpan.empty(); + } + + switch (opCode) { case RETURN, REVERT -> { - // TODO: make sure this isn't triggered when RETURNing from a CREATE(2) - // or when RETURNing from the root context of a deployment transaction. - // Recall that this case leads to the deployment of bytecode and produces - // empty return data in the caller context. long offset = Words.clampedToLong(frame.getStackItem(0)); long length = Words.clampedToLong(frame.getStackItem(1)); return MemorySpan.fromStartLength(offset, length); } + case STOP, SELFDESTRUCT -> { + return MemorySpan.empty(); + } + + // TODO: what the case below provides isn't output data, but the return data ... + // We cannot use this method for that purpose. case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { Address target = Words.toAddress(frame.getStackItem(1)); if (isPrecompile(target)) { @@ -210,8 +223,8 @@ public static MemorySpan returnDataSegment(final MessageFrame frame) { * * @return the return data target */ - public MemorySpan returnDataSegment() { - return returnDataSegment(hub.messageFrame()); + public MemorySpan outputDataSpan() { + return outputDataSpan(hub.messageFrame()); } /** @@ -219,22 +232,22 @@ public MemorySpan returnDataSegment() { * * @return the return data content */ - public Bytes returnData() { - final MemorySpan returnDataSegment = returnDataSegment(); + public Bytes outputData() { + final MemorySpan outputDataSpan = outputDataSpan(); // Accesses to huge offset with 0-length are valid - if (returnDataSegment.isEmpty()) { + if (outputDataSpan.isEmpty()) { return Bytes.EMPTY; } // Besu is limited to i32 for memory offset/length - if (returnDataSegment.besuOverflow()) { - log.warn("Overflowing memory access: {}", returnDataSegment); + if (outputDataSpan.besuOverflow()) { + log.warn("Overflowing memory access: {}", outputDataSpan); return Bytes.EMPTY; } // TODO: this WON'T work for precompiles, they don't have memory. - return maybeShadowReadMemory(returnDataSegment, hub.messageFrame()); + return maybeShadowReadMemory(outputDataSpan, hub.messageFrame()); } /** @@ -244,8 +257,8 @@ public Bytes returnData() { * @param frame the execution context * @return the returndata content */ - public static Bytes returnData(final MessageFrame frame) { - final MemorySpan returnDataSegment = returnDataSegment(frame); + public static Bytes outputData(final MessageFrame frame) { + final MemorySpan returnDataSegment = outputDataSpan(frame); return maybeShadowReadMemory(returnDataSegment, frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java index 9d3e0a61a5..89af3a0eb0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java @@ -39,7 +39,7 @@ public Bytes valueFromMemory(final long contextNumber, final boolean ramIsSource if (callFrame.type() == CallFrameType.PRECOMPILE_RETURN_DATA) { if (ramIsSource) { - return callFrame.returnData(); + return callFrame.outputData(); } else { return Bytes.EMPTY; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index e276bda75f..02730eace0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -169,7 +169,11 @@ public void triggerRomLex(final MessageFrame frame) { } } case RETURN -> { - final Bytes code = hub.transients().op().returnData(); + Preconditions.checkArgument(frame.getType() != MessageFrame.Type.CONTRACT_CREATION); + Preconditions.checkArgument( + hub.transients().conflation().deploymentInfo().isDeploying(frame.getContractAddress())); + + final Bytes code = hub.transients().op().outputData(); if (code.isEmpty()) { return; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index d9e71a691b..54778dce03 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -55,13 +55,7 @@ public class CallFrame { /** the depth of this CallFrame within its call hierarchy. */ @Getter private int depth; - /** */ - @Getter private int accountDeploymentNumber; - - /** */ - @Getter private int codeDeploymentNumber; - - /** */ + /** true iff the current context was spawned by a deployment transaction or a CREATE(2) opcode */ @Getter private boolean isDeployment; public boolean isMessageCall() { @@ -71,7 +65,7 @@ public boolean isMessageCall() { @Getter @Setter private TraceSection sectionToUnlatch = null; /** the ID of this {@link CallFrame} parent in the {@link CallStack}. */ - @Getter private int parentFrame; + @Getter private int parentFrameId; /** all the {@link CallFrame} that have been called by this frame. */ @Getter private final List childFrames = new ArrayList<>(); @@ -79,19 +73,15 @@ public boolean isMessageCall() { /** the {@link Address} of the account executing this {@link CallFrame}. */ @Getter private final Address accountAddress; + @Getter private int accountDeploymentNumber; + /** A memoized {@link EWord} conversion of `address` */ private EWord eAddress = null; /** the {@link Address} of the code executed in this {@link CallFrame}. */ @Getter private Address byteCodeAddress = Address.ZERO; - @Getter private Address callerAddress = Address.ZERO; - - /** A memoized {@link EWord} conversion of `codeAddress` */ - private EWord eCodeAddress = null; - - /** the {@link CallFrameType} of this frame. */ - @Getter private final CallFrameType type; + @Getter private int codeDeploymentNumber; /** the {@link Bytecode} executing within this frame. */ @Getter private Bytecode code = Bytecode.EMPTY; @@ -99,6 +89,14 @@ public boolean isMessageCall() { /** the CFI of this frame bytecode if applicable */ @Getter private int codeFragmentIndex = -1; + /** A memoized {@link EWord} conversion of `codeAddress` */ + private EWord eCodeAddress = null; + + @Getter private Address callerAddress = Address.ZERO; + + /** the {@link CallFrameType} of this frame. */ + @Getter private final CallFrameType type; + public int getCodeFragmentIndex(Hub hub) { return this == CallFrame.EMPTY || this.type() == CallFrameType.MANTLE ? 0 @@ -122,32 +120,29 @@ public int getCodeFragmentIndex(Hub hub) { /** the call data given to this frame. */ @Getter CallDataInfo callDataInfo; + /** the latest child context to have been called from this frame */ + @Getter @Setter private int returnDataContextNumber = 0; + /** the data returned by the latest callee. */ - @Getter @Setter private Bytes latestReturnData = Bytes.EMPTY; + @Getter @Setter private Bytes returnData = Bytes.EMPTY; /** returnData position within the latest callee memory space. */ - @Getter @Setter private MemorySpan latestReturnDataSource = new MemorySpan(0, 0); + @Getter @Setter private MemorySpan returnDataSpan = new MemorySpan(0, 0); /** the return data provided by this frame */ - @Getter @Setter private Bytes returnData = Bytes.EMPTY; + @Getter @Setter private Bytes outputData = Bytes.EMPTY; /** where this frame store its return data in its own RAM */ - @Getter @Setter private MemorySpan returnDataSource; + @Getter @Setter private MemorySpan outputDataSpan; - /** where this frame is expected to write its returnData within its parent's memory space. */ - @Getter private MemorySpan requestedReturnDataTarget = MemorySpan.empty(); - - /** the latest child context to have been called from this frame */ - @Getter @Setter private int returnDataContextNumber = 0; + /** where this frame is expected to write its outputData within its parent's memory space. */ + @Getter private MemorySpan parentReturnDataTarget = MemorySpan.empty(); @Getter @Setter private boolean selfReverts = false; @Getter @Setter private boolean getsReverted = false; - @Getter @Setter - private int revertStamp = - 0; // the hub stamp at which this frame reverts (0 means it does not revert) - - // TODO: create an enum with WILL_REVERT, WONT_REVERT + // the hub stamp at which this frame reverts (0 means it does not revert) + @Getter @Setter private int revertStamp = 0; /** this frame {@link Stack}. */ @Getter private final Stack stack = new Stack(); @@ -160,11 +155,11 @@ public static void provideParentContextWithEmptyReturnData(Hub hub) { } public static void updateParentContextReturnData( - Hub hub, Bytes returnData, MemorySpan returnDataSource) { + Hub hub, Bytes outputData, MemorySpan returnDataSource) { CallFrame parent = hub.callStack().parent(); parent.returnDataContextNumber = hub.currentFrame().contextNumber; - parent.latestReturnData = returnData; - parent.returnDataSource(returnDataSource); + parent.returnData = outputData; + parent.outputDataSpan(returnDataSource); } /** Create a MANTLE call frame. */ @@ -186,8 +181,8 @@ public static void updateParentContextReturnData( "ReturnDataOffset is 0 for all precompile except Modexp"); this.type = CallFrameType.PRECOMPILE_RETURN_DATA; this.contextNumber = contextNumber; - this.returnData = precompileResult; - this.returnDataSource = new MemorySpan(returnDataOffset, precompileResult.size()); + this.outputData = precompileResult; + this.outputDataSpan = new MemorySpan(returnDataOffset, precompileResult.size()); this.accountAddress = precompileAddress; } @@ -196,7 +191,7 @@ public static void updateParentContextReturnData( this.type = CallFrameType.EMPTY; this.contextNumber = 0; this.accountAddress = Address.ZERO; - this.parentFrame = -1; + this.parentFrameId = -1; this.callDataInfo = new CallDataInfo(Bytes.EMPTY, 0, 0, 0); } @@ -244,15 +239,15 @@ public static void updateParentContextReturnData( this.callerAddress = callerAddress; this.code = code; this.type = type; - this.parentFrame = caller; + this.parentFrameId = caller; this.value = value; this.gasEndowment = gas; this.callDataInfo = new CallDataInfo(callData, callDataOffset, callDataSize, callDataContextNumber); this.depth = depth; - this.returnDataSource = MemorySpan.empty(); - this.latestReturnDataSource = MemorySpan.empty(); - this.requestedReturnDataTarget = MemorySpan.empty(); // TODO: fix me Franklin + this.outputDataSpan = MemorySpan.empty(); + this.returnDataSpan = MemorySpan.empty(); + this.parentReturnDataTarget = MemorySpan.empty(); // TODO: fix me Franklin } public boolean isRoot() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 8d50c3eca2..30e65b6462 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -186,8 +186,8 @@ public int futureId() { * @return the parent {@link CallFrame} of the current frame */ public CallFrame parent() { - if (this.current().parentFrame() != -1) { - return this.frames.get(this.current().parentFrame()); + if (this.current().parentFrameId() != -1) { + return this.frames.get(this.current().parentFrameId()); } else { return CallFrame.EMPTY; } @@ -260,7 +260,7 @@ public void enter( this.frames.add(newFrame); this.current = newTop; if (caller != -1) { - this.frames.get(caller).latestReturnData(Bytes.EMPTY); + this.frames.get(caller).returnData(Bytes.EMPTY); this.frames.get(caller).childFrames().add(newTop); } } @@ -272,7 +272,7 @@ public void enter( public void exit() { this.depth -= 1; Preconditions.checkState(this.depth >= 0); - this.current = this.current().parentFrame(); + this.current = this.current().parentFrameId(); } /** @@ -302,7 +302,7 @@ public boolean isStatic() { * @return the caller of the current frame */ public CallFrame caller() { - return this.frames.get(this.current().parentFrame()); + return this.frames.get(this.current().parentFrameId()); } /** @@ -348,7 +348,7 @@ public CallFrame getParentCallFrameById(int id) { return CallFrame.EMPTY; } - return this.getById(this.frames.get(id).parentFrame()); + return this.getById(this.frames.get(id).parentFrameId()); } /** From d6047e09b6ec6c1d08e77173802a4a9cc4b8c519 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 23 Jul 2024 21:43:14 +0200 Subject: [PATCH 275/461] getting rid as much as possible of one of the DomSubStampsFragment.standardDomSubStamps(...) methods --- .../linea/zktracer/module/hub/Hub.java | 8 ++++---- .../module/hub/HubProcessingPhase.java | 6 +++--- .../hub/fragment/DomSubStampsSubFragment.java | 6 +----- .../hub/fragment/common/CommonFragment.java | 2 +- .../fragment/common/CommonFragmentValues.java | 2 -- .../module/hub/section/AccountSection.java | 2 +- .../module/hub/section/JumpSection.java | 2 +- .../module/hub/section/SloadSection.java | 2 +- .../module/hub/section/SstoreSection.java | 2 +- .../module/hub/section/TraceSection.java | 6 ++---- .../hub/section/TxFinalizationSection.java | 20 +++++++++---------- .../hub/section/TxInitializationSection.java | 4 ++-- .../hub/section/TxPreWarmingMacroSection.java | 2 +- .../hub/section/TxSkippedSectionDefers.java | 6 +++--- .../hub/section/calls/NoCodeCallSection.java | 4 ++-- .../calls/SmartContractCallSection.java | 4 ++-- .../hub/section/copy/CodeCopySection.java | 2 +- .../hub/section/copy/ExtCodeCopySection.java | 2 +- .../hub/section/create/AbortCreate.java | 2 +- .../hub/section/halt/ReturnSection.java | 4 ++-- .../hub/section/halt/SelfdestructSection.java | 4 ++-- .../module/hub/section/halt/StopSection.java | 2 +- zkevm-constraints | 2 +- 23 files changed, 44 insertions(+), 52 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c5c3e6be93..6c47010111 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -700,7 +700,7 @@ public void traceContextExit(MessageFrame frame) { minerIsWarm, this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); if (this.state.getProcessingPhase() != TX_SKIP) { - this.state.setProcessingPhase(TX_FINAL); + this.state.setProcessingPhase(TX_FINL); new TxFinalizationSection(this, frame.getWorldUpdater()); } } @@ -1149,7 +1149,7 @@ void traceOperation(MessageFrame frame) { calledAccountSnapshot, calledAccountSnapshot, rawCalledAddress, - DomSubStampsSubFragment.standardDomSubStamps(this, 0)))); + DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)))); } } else if (this.pch.abortingConditions().any()) { // @@ -1166,14 +1166,14 @@ void traceOperation(MessageFrame frame) { .make( myAccountSnapshot, myAccountSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this, 0)), + DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)), this.factories .accountFragment() .makeWithTrm( calledAccountSnapshot, calledAccountSnapshot, rawCalledAddress, - DomSubStampsSubFragment.standardDomSubStamps(this, 1)), + DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 1)), ContextFragment.nonExecutionEmptyReturnData(this)); this.addTraceSection(abortedSection); } else { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java index 1e8f5aa832..26ac0c8eeb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/HubProcessingPhase.java @@ -16,9 +16,9 @@ package net.consensys.linea.zktracer.module.hub; public enum HubProcessingPhase { + TX_EXEC, + TX_FINL, + TX_INIT, TX_SKIP, TX_WARM, - TX_INIT, - TX_EXEC, - TX_FINAL } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java index ab4b914854..d8e1a4c53d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/DomSubStampsSubFragment.java @@ -39,16 +39,12 @@ public enum DomSubType { final int childRevertStamp; final int transactionEndStamp; - // TODO: to be use with care, as stamps might have changed - public static DomSubStampsSubFragment standardDomSubStamps(final Hub hub, final int domOffset) { - return new DomSubStampsSubFragment(DomSubType.STANDARD, hub.stamp(), domOffset, 0, 0, 0, 0); - } - public static DomSubStampsSubFragment standardDomSubStamps(final int h, final int domOffset) { return new DomSubStampsSubFragment(DomSubType.STANDARD, h, domOffset, 0, 0, 0, 0); } // TODO: to be use with care, as stamps might have changed + // TODO: remove altogether public static DomSubStampsSubFragment revertWithCurrentDomSubStamps( final Hub hub, final int subOffset) { return new DomSubStampsSubFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java index ed24e5d033..199bf5833e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragment.java @@ -73,7 +73,7 @@ public Trace trace(Trace trace) { .txWarm(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_WARM) .txInit(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_INIT) .txExec(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_EXEC) - .txFinl(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_FINAL) + .txFinl(commonFragmentValues.hubProcessingPhase == HubProcessingPhase.TX_FINL) .hubStamp(commonFragmentValues.hubStamp) .hubStampTransactionEnd(tx.getHubStampTransactionEnd()) .contextMayChange(commonFragmentValues.contextMayChange) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java index fb2dd3adab..4937ef67e1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/common/CommonFragmentValues.java @@ -45,7 +45,6 @@ public class CommonFragmentValues { @Getter final CallFrame callFrame; public final boolean exceptionAhoy; @Setter public int contextNumberNew; - public final int cnRevertStamp; public final int pc; public final int pcNew; final short height; @@ -74,7 +73,6 @@ public CommonFragmentValues(Hub hub) { this.callFrame = hub.currentFrame(); this.exceptionAhoy = Exceptions.any(hub.pch().exceptions()); // this.contextNumberNew = hub.contextNumberNew(callFrame); - this.cnRevertStamp = 0; // TODO this.pc = hubProcessingPhase == TX_EXEC ? hub.currentFrame().pc() : 0; this.pcNew = computePcNew(hub, pc, noStackException, hub.state.getProcessingPhase() == TX_EXEC); this.height = (short) callFrame.stack().getHeight(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index db66a65daf..9e3d9bf135 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -49,7 +49,7 @@ public void appendToTrace(Hub hub) { } final DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); AccountFragment doingAccountFragment = hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index 207aacc5f5..ddc1b1becb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -69,7 +69,7 @@ public void populateSection(Hub hub) { AccountFragment accountRowCodeAccount = hub.factories() .accountFragment() - .make(codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + .make(codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); // MISCELLANEOUS fragment ///////////////////////// diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 96a2efdc5b..732a2c604d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -86,7 +86,7 @@ private StorageFragment doingSload(Hub hub) { this.valueCurrent, this.incomingWarmth, true, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0), + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index a648c5a3fd..1fabc724a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -113,7 +113,7 @@ private StorageFragment doingSstore(Hub hub) { this.valueNext, this.incomingWarmth, true, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0), + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size()); } 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 018249f2dc..f0d7ec34b1 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 @@ -16,7 +16,7 @@ package net.consensys.linea.zktracer.module.hub.section; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINL; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; @@ -124,7 +124,6 @@ public void seal() { (int) this.fragments.stream().filter(l -> !(l instanceof StackFragment)).count()); commonValues.TLI( (int) this.fragments.stream().filter(l -> (l instanceof StackFragment)).count() == 2); - commonValues.codeFragmentIndex( currentPhase == TX_EXEC ? this.hub.getCfiByMetaData( @@ -132,7 +131,6 @@ public void seal() { this.commonValues.callFrame().codeDeploymentNumber(), this.commonValues.callFrame().isDeployment()) : 0); - commonValues.contextNumberNew(computeContextNumberNew()); commonValues.gasRefund( @@ -149,7 +147,7 @@ public void seal() { private int computeContextNumberNew() { final HubProcessingPhase currentPhase = this.commonValues.hubProcessingPhase; - if (currentPhase == TX_WARM || currentPhase == TX_FINAL || currentPhase == TX_SKIP) { + if (currentPhase == TX_WARM || currentPhase == TX_FINL || currentPhase == TX_SKIP) { return 0; } return this.nextSection.commonValues.hubProcessingPhase == TX_EXEC diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 570c135b89..182dff526b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -113,13 +113,13 @@ private void successfulFinalization(Hub hub) { .make( this.fromAccountBeforeTxFinalization, this.fromAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), hub.factories() .accountFragment() .make( this.minerAccountBeforeTxFinalization, this.minerAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), TransactionFragment.prepare(hub.txStack().current()))); } else { // TODO: verify it works @@ -132,13 +132,13 @@ private void successfulFinalization(Hub hub) { this.fromAccountBeforeTxFinalization, this.fromAccountBeforeTxFinalization.incrementBalance( txMetadata.getGasRefundInWei()), - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), hub.factories() .accountFragment() .make( this.fromAccountBeforeTxFinalization, this.minerAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), TransactionFragment.prepare(hub.txStack().current()))); } } @@ -153,19 +153,19 @@ private void unsuccessfulFinalization(Hub hub) { .make( this.fromAccountBeforeTxFinalization, this.fromAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), hub.factories() .accountFragment() .make( this.toAccountBeforeTxFinalization, this.toAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), hub.factories() .accountFragment() .make( this.minerAccountBeforeTxFinalization, this.minerAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2)), TransactionFragment.prepare(hub.txStack().current()))); } else { // TODO: test this @@ -179,7 +179,7 @@ private void unsuccessfulFinalization(Hub hub) { this.fromAccountBeforeTxFinalization .incrementBalance((Wei) txMetadata.getBesuTransaction().getValue()) .incrementBalance(txMetadata.getGasRefundInWei()), - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), hub.factories() .accountFragment() .make( @@ -191,7 +191,7 @@ private void unsuccessfulFinalization(Hub hub) { (Wei) txMetadata.getBesuTransaction().getValue()) : this.toAccountBeforeTxFinalization.decrementBalance( (Wei) txMetadata.getBesuTransaction().getValue()), - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), hub.factories() .accountFragment() .make( @@ -199,7 +199,7 @@ private void unsuccessfulFinalization(Hub hub) { txMetadata.getMinerReward()), this.minerAccountAfterTxFinalization.incrementBalance( txMetadata.getMinerReward()), - DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2)), TransactionFragment.prepare(hub.txStack().current()))); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index d186d9b0d4..877ed2a07e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -54,7 +54,7 @@ public TxInitializationSection(Hub hub, WorldView world) { deploymentInfo.number(senderAddress), deploymentInfo.isDeploying(senderAddress)); final DomSubStampsSubFragment senderDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0); final Wei transactionGasPrice = Wei.of(tx.getEffectiveGasPrice()); final Wei value = (Wei) tx.getBesuTransaction().getValue(); @@ -88,7 +88,7 @@ public TxInitializationSection(Hub hub, WorldView world) { value, initBytecode, deploymentInfo.getDeploymentNumber(toAddress)) : recipientBeforeValueTransfer.credit(value).turnOnWarmth(); final DomSubStampsSubFragment recipientDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 1); + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1); final TransactionFragment txFragment = TransactionFragment.prepare(tx); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index fb5a2c0501..3012b14fa7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -119,7 +119,7 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { value, seenKeys.computeIfAbsent(address, x -> new HashSet<>()).contains(key), true, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size()); hub.addTraceSection(new TxPrewarmingSection(hub, storageFragment)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java index 5524dff3b6..277d0fe332 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java @@ -115,21 +115,21 @@ public void resolvePostTransaction( .make( oldFromAccount, newFromAccount, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), // To hub.factories() .accountFragment() .make( oldToAccount, newToAccount, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), // Miner hub.factories() .accountFragment() .make( oldMinerAccount, newMinerAccount, - DomSubStampsSubFragment.standardDomSubStamps(hub, 2)), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2)), // 1 line -- transaction data TransactionFragment.prepare(hub.txStack().current()))); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index 13d8d3956a..c91fbff9d2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -127,12 +127,12 @@ public void resolvePostTransaction( accountFragmentFactory.make( this.preCallCallerAccountSnapshot, this.postCallCallerAccountSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)), + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)), accountFragmentFactory.makeWithTrm( this.preCallCalledAccountSnapshot, this.postCallCalledAccountSnapshot, this.rawCalledAddress, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1))); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1))); if (precompileInvocation.isPresent()) { if (this.callSuccessful && callerCallFrame.hasReverted()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index 4de0f0d78c..3e918734c9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -128,10 +128,10 @@ public void resolvePostTransaction( this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); DomSubStampsSubFragment firstCallerDoingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); DomSubStampsSubFragment firstCalleeDoingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 1); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1); this.addFragmentsWithoutStack( this.scenarioFragment, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 0585bb46a9..e8a708a107 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -93,7 +93,7 @@ public CodeCopySection(Hub hub) { hub.transients().conflation().deploymentInfo().isDeploying(codeAddress)); final DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); // Specifics for CODECOPY + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); // Specifics for CODECOPY final AccountFragment accountReadingFragment = hub.factories() diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 9e2f6d7a82..876898fdd0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -98,7 +98,7 @@ public ExtCodeCopySection(Hub hub) { foreignAccount, incomingWarmth, incomingDeploymentNumber, incomingDeploymentStatus); final DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(hub, 0); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); // The OOGX case //////////////// diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java index 3785047783..a8703f3afd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java @@ -43,7 +43,7 @@ public AbortCreate( accountFragmentFactory.make( oldCreatorSnapshot, oldCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); final ContextFragment contextFragment = ContextFragment.nonExecutionEmptyReturnData(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index f54205d3d1..cf3a0c7f8e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -188,7 +188,7 @@ public ReturnSection(Hub hub) { .make( accountBeforeDeployment, accountAfterEmptyDeployment, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); this.addFragment(emptyDeploymentAccountFragment); // Note: @@ -222,7 +222,7 @@ public ReturnSection(Hub hub) { .make( accountBeforeDeployment, accountBeforeDeployment.deployByteCode(deploymentCode), - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); nonemptyDeploymentAccountFragment.requiresRomlex(true); hub.romLex().triggerRomLex(hub.messageFrame()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 258361279f..4511a4769d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -119,7 +119,7 @@ public SelfdestructSection(Hub hub) { .make( this.accountBefore, this.accountBefore, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); this.addFragment(selfDestroyerFirstAccountFragment); @@ -130,7 +130,7 @@ public SelfdestructSection(Hub hub) { this.recipientAccountBefore, this.recipientAccountBefore, this.recipientRawAddress, - DomSubStampsSubFragment.standardDomSubStamps(hub, 1)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); this.addFragment(recipientFirstAccountFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index eb88659c24..9ad0fec1cd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -86,7 +86,7 @@ public void deploymentStopSection(Hub hub) { .make( priorEmptyDeployment, afterEmptyDeployment, - DomSubStampsSubFragment.standardDomSubStamps(hub, 0)); + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); this.addFragmentsAndStack(hub, readCurrentContextData(hub), doingAccountFragment); } diff --git a/zkevm-constraints b/zkevm-constraints index 66cf5cf54f..29b10da4cd 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 66cf5cf54f2e7d3a11dd740e44cf1eb9771e0e17 +Subproject commit 29b10da4cd96cfbe8bf12d84020fb4df177021db From b377a8536d307b70c04e6ad203cc585023eaa176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 24 Jul 2024 22:55:00 +0200 Subject: [PATCH 276/461] fix(defers): ChildContextEntryDefers + other - CREATE2 writes to ROM conditionnally to not failure condition - single "context (fragment) initialization" method - lots of renaming --- .../linea/zktracer/module/hub/Hub.java | 19 +- ...Defer.java => ChildContextEntryDefer.java} | 4 +- .../module/hub/defer/DeferRegistry.java | 94 ++++----- .../module/hub/defer/ReEnterContextDefer.java | 4 +- .../module/hub/fragment/ContextFragment.java | 20 +- .../module/hub/fragment/StackFragment.java | 5 +- .../module/hub/fragment/imc/call/MxpCall.java | 3 + .../hub/fragment/imc/call/mmu/MmuCall.java | 4 +- .../fragment/imc/call/mmu/opcode/Create2.java | 9 +- .../precompiles/PrecompileLinesGenerator.java | 26 +-- .../module/hub/section/JumpSection.java | 5 +- .../hub/section/TxInitializationSection.java | 2 +- .../hub/section/calls/NoCodeCallSection.java | 8 +- .../calls/SmartContractCallSection.java | 13 +- .../hub/section/create/AbortCreate.java | 12 +- .../hub/section/create/CreateSection.java | 181 ++++++++++-------- .../create/FailureOrEmptyInitCreate.java | 4 +- .../hub/section/create/FillCreateSection.java | 1 + .../hub/section/halt/ReturnSection.java | 2 +- .../hub/signals/PlatformController.java | 1 + .../hub/transients/OperationAncillaries.java | 14 +- 21 files changed, 225 insertions(+), 206 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/{NextContextDefer.java => ChildContextEntryDefer.java} (87%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6c47010111..3e97535f42 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -16,7 +16,7 @@ package net.consensys.linea.zktracer.module.hub; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINAL; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINL; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; @@ -576,7 +576,6 @@ public void traceContextEnter(MessageFrame frame) { ? 0 : this.transients.conflation().deploymentInfo().number(toAddress), this.transients.conflation().deploymentInfo().isDeploying(toAddress)); - this.defers.enterFrame(this.callStack.current()); } else { this.callStack.newBedrock( this.state.stamps().hub(), @@ -597,7 +596,6 @@ public void traceContextEnter(MessageFrame frame) { ? 0 : this.transients.conflation().deploymentInfo().number(toAddress), this.transients.conflation().deploymentInfo().isDeploying(toAddress)); - this.defers.enterFrame(this.callStack.current()); } } else { // ...or CALL @@ -645,8 +643,7 @@ public void traceContextEnter(MessageFrame frame) { codeDeploymentNumber, isDeployment); - this.defers.enterFrame(this.callStack.current()); - this.defers.resolveWithNextContext(this, frame); + this.defers.resolveUponEnteringChildContext(this, frame); for (Module m : this.modules) { m.traceContextEnter(frame); @@ -655,7 +652,7 @@ public void traceContextEnter(MessageFrame frame) { } public void traceContextReEnter(MessageFrame frame) { - this.defers.resolveAtReEntry(this, frame); + this.defers.resolveAtContextReEntry(this, this.currentFrame()); if (this.currentFrame().sectionToUnlatch() != null) { this.unlatchStack(frame, this.currentFrame().sectionToUnlatch()); this.currentFrame().sectionToUnlatch(null); @@ -988,9 +985,9 @@ void processStateExec(MessageFrame frame) { } // TODO: how do these implementations of remainingGas() - // and expectedGas() behave with respect to resuming - // execution after a CALL / CREATE ? One of them is - // necessarily false ... + // and expectedGas() behave with respect to resuming + // execution after a CALL / CREATE ? One of them is + // necessarily false ... public long remainingGas() { return this.state().getProcessingPhase() == TX_EXEC ? this.currentFrame().frame().getRemainingGas() @@ -1174,7 +1171,7 @@ void traceOperation(MessageFrame frame) { calledAccountSnapshot, rawCalledAddress, DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 1)), - ContextFragment.nonExecutionEmptyReturnData(this)); + ContextFragment.nonExecutionProvidesEmptyReturnData(this)); this.addTraceSection(abortedSection); } else { final ImcFragment imcFragment = /* ImcFragment.forOpcode(this, frame)*/ @@ -1192,7 +1189,7 @@ void traceOperation(MessageFrame frame) { // // TODO: fill the callee & requested return data for the current call frame - // TODO: i.e. ensure that the precompile frame behaves as expected + // i.e. ensure that the precompile frame behaves as expected Optional precompileInvocation = targetPrecompile.map(p -> PrecompileInvocation.of(this, p)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java similarity index 87% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java index 307abfa1bf..2d9237e510 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/NextContextDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java @@ -18,6 +18,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import org.hyperledger.besu.evm.frame.MessageFrame; -public interface NextContextDefer { - void resolveWithNextContext(Hub hub, MessageFrame frame); +public interface ChildContextEntryDefer { + void resolveUponEnteringChildContext(Hub hub, MessageFrame frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index bb5f52386a..e4b38f48b0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -15,15 +15,11 @@ package net.consensys.linea.zktracer.module.hub.defer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.runtime.callstack.CallStack; -import org.apache.commons.lang3.tuple.Pair; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; @@ -35,21 +31,26 @@ */ // TODO: fix naming and implement the missing interfaces public class DeferRegistry - implements PostExecDefer, PostRollbackDefer, PostTransactionDefer, PostConflationDefer { - /** A list of actions deferred until the end of the current conflation execution */ - private final List postConflationDefers = new ArrayList<>(); - - /** A list of actions deferred until the end of the current transaction */ - private final List postTransactionDefers = new ArrayList<>(); + implements PostExecDefer, + PostRollbackDefer, + PostTransactionDefer, + PostConflationDefer, + ChildContextEntryDefer { /** A list of actions deferred until the end of the current opcode execution */ private final List postExecDefers = new ArrayList<>(); /** A list of actions deferred until the end of the current opcode execution */ - private final List reEntryDefers = new ArrayList<>(); + private final List childContextEntryDefers = new ArrayList<>(); /** A list of actions deferred until the end of the current opcode execution */ - private final List> contextReentry = new ArrayList<>(); + private final Map> contextReEntryDefers = new HashMap<>(); + + /** A list of actions deferred until the end of the current transaction */ + private final List postTransactionDefers = new ArrayList<>(); + + /** A list of actions deferred until the end of the current conflation execution */ + private final List postConflationDefers = new ArrayList<>(); /** * A collection of actions whose execution is deferred to a hypothetical future rollback. This @@ -59,8 +60,8 @@ public class DeferRegistry private final Map> rollbackDefers = new HashMap<>(); /** Schedule an action to be executed after the completion of the current opcode. */ - public void scheduleForContextReEntry(NextContextDefer defer, int frameId) { - this.contextReentry.add(Pair.of(frameId, defer)); + public void scheduleForImmediateContextEntry(ChildContextEntryDefer defer) { + this.childContextEntryDefers.add(defer); } /** Schedule an action to be executed after the completion of the current opcode. */ @@ -79,32 +80,18 @@ public void schedulePostConflation(PostConflationDefer defer) { } /** Schedule an action to be executed at the re-entry in the current context. */ - public void reEntry(ReEnterContextDefer defer) { - this.reEntryDefers.add(defer); - } - - public void enterFrame(final CallFrame callFrame) { - this.rollbackDefers.put(callFrame, new ArrayList<>()); + public void scheduleForContextReEntry(ReEnterContextDefer defer, CallFrame callFrame) { + if (!contextReEntryDefers.containsKey(callFrame)) { + contextReEntryDefers.put(callFrame, new ArrayList<>()); + } + contextReEntryDefers.get(callFrame).add(defer); } public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame) { - this.rollbackDefers.get(callFrame).add(defer); - } - - /** - * Trigger the execution of the actions deferred to the next context. - * - * @param hub a {@link Hub} context - * @param frame the new context {@link MessageFrame} - */ - public void resolveWithNextContext(Hub hub, MessageFrame frame) { - for (Pair defer : this.contextReentry) { - if (hub.currentFrame().parentFrameId() == defer.getLeft()) { - defer.getRight().resolveWithNextContext(hub, frame); - } + if (!rollbackDefers.containsKey(callFrame)) { + rollbackDefers.put(callFrame, new ArrayList<>()); } - // TODO: we clear everything ?!? not just the one that was just resolved ? - this.contextReentry.clear(); + rollbackDefers.get(callFrame).add(defer); } /** @@ -162,26 +149,15 @@ public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.Operatio * Trigger the execution of the actions deferred to the re-entry in the current context. * * @param hub the {@link Hub} context - * @param frame the {@link MessageFrame} of the transaction + * @param callFrame the {@link CallFrame} of the transaction */ - // (ReEnterContextDefer?) - public void resolveAtReEntry(Hub hub, MessageFrame frame) { - for (ReEnterContextDefer defer : this.reEntryDefers) { - defer.resolveAtContextReEntry(hub, frame); + public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { + if (this.contextReEntryDefers.containsKey(callFrame)) { + for (ReEnterContextDefer defer : this.contextReEntryDefers.get(callFrame)) { + defer.resolveAtContextReEntry(hub, callFrame); + } + this.contextReEntryDefers.remove(callFrame); } - // TODO: make sure this is correct; - // it used to be this.postExecDefers.clear() - // ... obvious mistake ? - this.reEntryDefers.clear(); - // TODO: how would us clearing the reentryDefers not - // fail in case you have e.g. A calls B calls C ? - // When we 're-enter' B after finishing with C wouldn't - // we try to resolve the re-entry business of A ? Which - // is too early ... ? - // Note: this is used for CREATE's, specifically for when - // deployment terminates and we re-enter the creator context ... - // But what if we have nested CREATE's ? - // A creates B, and during deployment B creates C ... ?! } /** @@ -209,4 +185,12 @@ public void resolvePostRollback( .map(callStack::getById) .forEach(childCallFrame -> resolvePostRollback(hub, messageFrame, childCallFrame)); } + + @Override + public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { + for (ChildContextEntryDefer defer : this.childContextEntryDefers) { + defer.resolveUponEnteringChildContext(hub, frame); + } + this.childContextEntryDefers.clear(); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java index b907c655be..d935f307af 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java @@ -16,8 +16,8 @@ package net.consensys.linea.zktracer.module.hub.defer; import net.consensys.linea.zktracer.module.hub.Hub; -import org.hyperledger.besu.evm.frame.MessageFrame; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; public interface ReEnterContextDefer { - void resolveAtContextReEntry(final Hub hub, final MessageFrame frame); + void resolveAtContextReEntry(final Hub hub, final CallFrame frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index bcda6d1f78..eda3732231 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -24,7 +24,6 @@ import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.types.Either; import net.consensys.linea.zktracer.types.MemorySpan; -import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; public record ContextFragment( @@ -64,14 +63,13 @@ public static ContextFragment readCurrentContextData(final Hub hub) { return readContextDataById(hub, hub.callStack().current().id()); } - public static ContextFragment initializeExecutionContext(final Hub hub) { + public static ContextFragment initializeNewExecutionContext(final Hub hub) { return new ContextFragment( hub, hub.callStack(), - Either.right(hub.stamp() + 1), + Either.right(hub.newChildContextNumber()), 0, - MemorySpan.fromStartEnd( - 0, hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)), + MemorySpan.empty(), false); } @@ -93,7 +91,7 @@ public static ContextFragment executionProvidesEmptyReturnData(final Hub hub, in hub, callStack, Either.left(parentId), contextNumber, MemorySpan.empty(), true); } - public static ContextFragment nonExecutionEmptyReturnData(final Hub hub) { + public static ContextFragment nonExecutionProvidesEmptyReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, @@ -104,7 +102,7 @@ public static ContextFragment nonExecutionEmptyReturnData(final Hub hub) { true); } - public static ContextFragment executionReturnData(final Hub hub) { + public static ContextFragment executionProvidesReturnData(final Hub hub) { CallStack callStack = hub.callStack(); return new ContextFragment( hub, @@ -115,13 +113,7 @@ public static ContextFragment executionReturnData(final Hub hub) { true); } - public static ContextFragment enterContext(final Hub hub, final CallFrame calledCallFrame) { - CallStack callStack = hub.callStack(); - return new ContextFragment( - hub, callStack, Either.left(calledCallFrame.id()), 0, MemorySpan.empty(), false); - } - - public static ContextFragment providesReturnData( + public static ContextFragment executionProvidesReturnData( final Hub hub, int receiverContextNumber, int providerContextNumber) { CallStack callStack = hub.callStack(); return new ContextFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 6c3296980a..96efa59c3d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -80,10 +80,7 @@ private StackFragment( switch (this.opCode) { case SHA3 -> Exceptions.none(exceptions) && gp.messageSize() > 0; case RETURN -> Exceptions.none(exceptions) && gp.messageSize() > 0 && isDeploying; - case CREATE2 -> Exceptions.none(exceptions) - && contextExceptions.none() - && aborts.none() - && gp.messageSize() > 0; + case CREATE2 -> Exceptions.none(exceptions) && aborts.none() && gp.messageSize() > 0; default -> false; }; if (this.hashInfoFlag) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index 9b30e9a9d0..973217e4a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -40,7 +40,10 @@ public class MxpCall implements TraceSubFragment { @Getter @Setter public EWord offset2 = EWord.ZERO; @Getter @Setter public EWord size2 = EWord.ZERO; @Getter @Setter public boolean mayTriggerNonTrivialMmuOperation; + + /** mxpx is short of Memory eXPansion eXception */ @Getter @Setter public boolean mxpx; + @Getter @Setter public long memorySizeInWords; @Getter @Setter public long gasMxp; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 7d2d45b780..7acd8aaf8c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -271,8 +271,8 @@ public static MmuCall returnFromMessageCall(final Hub hub) { return MmuCall.revert(hub); } - public static MmuCall create2(final Hub hub) { - return new Create2(hub); + public static MmuCall create2(final Hub hub, boolean failureCondition) { + return new Create2(hub, failureCondition); } public static MmuCall invalidCodePrefix(final Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java index 029e6fd36d..a0fa7bdec8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java @@ -34,7 +34,7 @@ public class Create2 extends MmuCall implements RomLexDefer { private final Hub hub; private ContractMetadata contract; - public Create2(final Hub hub) { + public Create2(final Hub hub, boolean failureCondition) { super(MMU_INST_RAM_TO_EXO_WITH_PADDING); this.hub = hub; this.hub.romLex().createDefers().register(this); @@ -49,8 +49,11 @@ public Create2(final Hub hub) { .sourceOffset(EWord.of(hub.messageFrame().getStackItem(1))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(2))) .referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(2))) - .setKec() - .setRom(); + .setKec(); + + if (!failureCondition) { + this.setRom(); + } } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index 5dbeb03d8c..79f30bd181 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -152,7 +152,7 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add(line5); r.add(ImcFragment.empty(hub).callOob(new ModexpPricingOobCall(p))); if (p.ramFailure()) { - r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); + r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) @@ -174,20 +174,20 @@ public static List generateFor(final Hub hub, final PrecompileInv } r.add( - ContextFragment.providesReturnData( + ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_ADD -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); + r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcAdd(hub, p, 0))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); + r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) @@ -204,20 +204,20 @@ public static List generateFor(final Hub hub, final PrecompileInv ? MmuCall.nop() : MmuCall.forEcAdd(hub, p, 2))); r.add( - ContextFragment.providesReturnData( + ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_MUL -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); + r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcMul(hub, p, 0))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); + r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) @@ -234,20 +234,20 @@ public static List generateFor(final Hub hub, final PrecompileInv ? MmuCall.nop() : MmuCall.forEcMul(hub, p, 2))); r.add( - ContextFragment.providesReturnData( + ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case EC_PAIRING -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); + r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcPairing(hub, p, 0))); - r.add(ContextFragment.nonExecutionEmptyReturnData(hub)); + r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( ImcFragment.empty(hub) @@ -261,7 +261,7 @@ public static List generateFor(final Hub hub, final PrecompileInv ? MmuCall.nop() : MmuCall.forEcPairing(hub, p, 2))); r.add( - ContextFragment.providesReturnData( + ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } @@ -291,9 +291,9 @@ public static List generateFor(final Hub hub, final PrecompileInv r.add( p.success() - ? ContextFragment.providesReturnData( + ? ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber()) - : ContextFragment.nonExecutionEmptyReturnData(hub)); + : ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); return r; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index ddc1b1becb..e1419c43db 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -69,7 +69,10 @@ public void populateSection(Hub hub) { AccountFragment accountRowCodeAccount = hub.factories() .accountFragment() - .make(codeAccount, codeAccount, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + .make( + codeAccount, + codeAccount, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); // MISCELLANEOUS fragment ///////////////////////// diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 877ed2a07e..401699f6ae 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -110,7 +110,7 @@ public TxInitializationSection(Hub hub, WorldView world) { recipientDomSubStamps) .requiresRomlex(true), ImcFragment.forTxInit(hub), - ContextFragment.initializeExecutionContext(hub), + ContextFragment.initializeNewExecutionContext(hub), txFragment)); hub.state.setProcessingPhase(TX_EXEC); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java index c91fbff9d2..8e1ba6e14b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java @@ -80,7 +80,7 @@ public NoCodeCallSection( hub.defers().schedulePostExecution(this); hub.defers().schedulePostTransaction(this); - hub.defers().reEntry(this); + hub.defers().scheduleForContextReEntry(this); } @Override @@ -166,7 +166,11 @@ public void resolvePostTransaction( this.preCallCalledAccountSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); } - this.addFragmentsWithoutStack(ContextFragment.nonExecutionEmptyReturnData(hub)); + this.addFragmentsWithoutStack(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } } + + // TODO + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index 3e918734c9..9f04cbe28a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -17,7 +17,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.NextContextDefer; +import net.consensys.linea.zktracer.module.hub.defer.ChildContextEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; @@ -36,7 +36,7 @@ import org.hyperledger.besu.evm.worldstate.WorldView; public class SmartContractCallSection extends TraceSection - implements PostTransactionDefer, PostExecDefer, NextContextDefer { + implements PostTransactionDefer, PostExecDefer, ChildContextEntryDefer { private final Bytes rawCalledAddress; private final CallFrame callerCallFrame; private final int calledCallFrameId; @@ -72,8 +72,11 @@ public SmartContractCallSection( this.addStack(hub); hub.defers().schedulePostExecution(this); - hub.defers().scheduleForContextReEntry(this, hub.currentFrame().id()); + hub.defers().scheduleForImmediateContextEntry(this); hub.defers().schedulePostTransaction(this); + + // TODO: remove (but: ContextFragment calleeContextInitializationFragment = ContextFragment.initializeNewExecutionContext(hub); + // should be added to the section } @Override @@ -99,7 +102,7 @@ public void resolvePostExecution( } @Override - public void resolveWithNextContext(Hub hub, MessageFrame frame) { + public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { final Address callerAddress = preCallCallerAccountSnapshot.address(); final Account callerAccount = frame.getWorldUpdater().get(callerAddress); final Address calledAddress = preCallCalleeAccountSnapshot.address(); @@ -198,6 +201,6 @@ public void resolvePostTransaction( } } - this.addFragmentsWithoutStack(ContextFragment.enterContext(hub, calledCallFrame)); + // this.addFragmentsWithoutStack(ContextFragment.enterContext(hub, calledCallFrame)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java index a8703f3afd..c47ea20507 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java @@ -29,7 +29,7 @@ class AbortCreate extends TraceSection { public AbortCreate( final Hub hub, - final ContextFragment commonContext, + final ContextFragment currentContextFragment, final ImcFragment imcFragment, final AccountSnapshot oldCreatorSnapshot) { super(hub, (short) 7); @@ -45,9 +45,15 @@ public AbortCreate( oldCreatorSnapshot, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - final ContextFragment contextFragment = ContextFragment.nonExecutionEmptyReturnData(hub); + final ContextFragment updatedCurrentContextFragment = + ContextFragment.nonExecutionProvidesEmptyReturnData(hub); this.addFragmentsAndStack( - hub, scenarioFragment, commonContext, imcFragment, creatorAccountFragment, contextFragment); + hub, + scenarioFragment, + currentContextFragment, + imcFragment, + creatorAccountFragment, + updatedCurrentContextFragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 55856ea35e..35f662ed2a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -17,12 +17,14 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_EMPTY_INIT_CODE_WONT_REVERT; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT; -import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; +import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; import java.util.Optional; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.ChildContextEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; @@ -32,7 +34,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; @@ -47,26 +48,27 @@ import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldView; -public class CreateSection implements PostExecDefer, ReEnterContextDefer, PostTransactionDefer { +public class CreateSection + implements PostExecDefer, ReEnterContextDefer, PostTransactionDefer, ChildContextEntryDefer { private FillCreateSection createSection; private int creatorContextId; // Just before create - private AccountSnapshot oldCreatorSnapshot; - private AccountSnapshot oldCreatedSnapshot; + private AccountSnapshot preOpcodeCreatorSnapshot; + private AccountSnapshot preOpcodeCreateeSnapshot; // Just after create but before entering child frame private AccountSnapshot midCreatorSnapshot; - private AccountSnapshot midCreatedSnapshot; + private AccountSnapshot midCreateeSnapshot; // After return from child-context private AccountSnapshot newCreatorSnapshot; - private AccountSnapshot newCreatedSnapshot; + private AccountSnapshot newCreateeSnapshot; private RlpAddrSubFragment rlpAddrSubFragment; - /* true if the CREATE was successful **/ + /** true if the CREATE was successful */ private boolean createSuccessful = false; // row i+2 @@ -74,110 +76,120 @@ public class CreateSection implements PostExecDefer, ReEnterContextDefer, PostTr private MmuCall mmuCall; // row i+? - private ContextFragment lastContextFragment; + private ContextFragment finalContextFragment; public CreateSection(Hub hub) { - final short exception = hub.pch().exceptions(); + final short exceptions = hub.pch().exceptions(); // row i + 1 - final ContextFragment commonContext = ContextFragment.readCurrentContextData(hub); + final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); - imcFragment = ImcFragment.empty(hub); + // row: i + 2 + // Note: in the static case this imc fragment remains empty - if (Exceptions.staticFault(exception)) { - new ExceptionalCreate(hub, commonContext, imcFragment); + // STATICX case + imcFragment = ImcFragment.empty(hub); + if (Exceptions.staticFault(exceptions)) { + new ExceptionalCreate(hub, currentContextFragment, imcFragment); return; } final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); - if (Exceptions.memoryExpansionException(exception)) { - new ExceptionalCreate(hub, commonContext, imcFragment); + // MXPX case + if (Exceptions.memoryExpansionException(exceptions)) { + new ExceptionalCreate(hub, currentContextFragment, imcFragment); return; } final StpCall stpCall = new StpCall(hub, mxpCall.getGasMxp()); stpCall.stpCallForCreates(hub); imcFragment.callStp(stpCall); + Preconditions.checkArgument( + stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions)); - if (Exceptions.outOfGasException(exception)) { - new ExceptionalCreate(hub, commonContext, imcFragment); + // OOGX case + if (Exceptions.outOfGasException(exceptions)) { + new ExceptionalCreate(hub, currentContextFragment, imcFragment); return; } - final OobCall oobCall = new CreateOobCall(); + Preconditions.checkArgument(Exceptions.none(exceptions)); + + final CreateOobCall oobCall = new CreateOobCall(); imcFragment.callOob(oobCall); - // We are now with unexceptional create + // The CREATE(2) is now unexceptional final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); + Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts.any()); final CallFrame callFrame = hub.currentFrame(); final MessageFrame frame = callFrame.frame(); final Address creatorAddress = callFrame.accountAddress(); - final Account creatorAccount = frame.getWorldUpdater().get(creatorAddress); - oldCreatorSnapshot = - AccountSnapshot.fromAccount( - creatorAccount, - frame.isAddressWarm(creatorAddress), - hub.transients().conflation().deploymentInfo().number(creatorAddress), - hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); + preOpcodeCreatorSnapshot = AccountSnapshot.canonical(hub, creatorAddress); if (aborts.any()) { - new AbortCreate(hub, commonContext, imcFragment, oldCreatorSnapshot); + new AbortCreate(hub, currentContextFragment, imcFragment, preOpcodeCreatorSnapshot); return; } - // We are now with unexceptional, non-aborting create + // The CREATE(2) is now unexceptional and unaborted hub.defers().schedulePostExecution(this); - hub.defers().reEntry(this); + hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); hub.defers().schedulePostTransaction(this); + // Note: all future account rows will be added during the resolvePostTransaction + this.creatorContextId = hub.currentFrame().id(); - final Address createdAddress = getCreateAddress(frame); - final Account createdAccount = frame.getWorldUpdater().get(createdAddress); - oldCreatedSnapshot = - AccountSnapshot.fromAccount( - createdAccount, - frame.isAddressWarm(createdAddress), - hub.transients().conflation().deploymentInfo().number(createdAddress), - hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + final Address createeAddress = getDeploymentAddress(frame); + preOpcodeCreateeSnapshot = AccountSnapshot.canonical(hub, createeAddress); - rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createdAddress); + rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createeAddress); final Optional deploymentAccount = - Optional.ofNullable(frame.getWorldUpdater().get(createdAddress)); + Optional.ofNullable(frame.getWorldUpdater().get(createeAddress)); final boolean createdAddressHasNonZeroNonce = deploymentAccount.map(a -> a.getNonce() != 0).orElse(false); final boolean createdAddressHasNonEmptyCode = deploymentAccount.map(AccountState::hasCode).orElse(false); - final boolean failure = createdAddressHasNonZeroNonce || createdAddressHasNonEmptyCode; - final boolean emptyInitCode = hub.transients().op().callDataSegment().isEmpty(); + final boolean failureCondition = createdAddressHasNonZeroNonce || createdAddressHasNonEmptyCode; + final boolean emptyInitCode = hub.transients().op().initCodeSegment().isEmpty(); - if (failure || emptyInitCode) { + if (failureCondition || emptyInitCode) { final ScenarioEnum scenario = - failure ? CREATE_FAILURE_CONDITION_WONT_REVERT : CREATE_EMPTY_INIT_CODE_WONT_REVERT; - this.createSection = new FailureOrEmptyInitCreate(hub, scenario, commonContext, imcFragment); - this.lastContextFragment = ContextFragment.nonExecutionEmptyReturnData(hub); + failureCondition + ? CREATE_FAILURE_CONDITION_WONT_REVERT + : CREATE_EMPTY_INIT_CODE_WONT_REVERT; + this.createSection = + new FailureOrEmptyInitCreate(hub, scenario, currentContextFragment, imcFragment); + this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + if (hub.opCode() == OpCode.CREATE2 && !emptyInitCode) { - this.mmuCall = MmuCall.create2(hub); + this.mmuCall = MmuCall.create2(hub, failureCondition); } return; } // Finally, non-exceptional, non-aborting, non-failing, non-emptyInitCode create - this.createSection = new NonEmptyInitCodeCreate(hub, commonContext, imcFragment); - this.mmuCall = hub.opCode() == OpCode.CREATE2 ? MmuCall.create2(hub) : MmuCall.create(hub); - this.lastContextFragment = ContextFragment.initializeExecutionContext(hub); + hub.defers().scheduleForImmediateContextEntry(this); + this.createSection = new NonEmptyInitCodeCreate(hub, currentContextFragment, imcFragment); + this.mmuCall = + hub.opCode() == OpCode.CREATE2 + ? MmuCall.create2(hub, failureCondition) + : MmuCall.create(hub); + + this.finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); } @Override public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - final Address creatorAddress = oldCreatorSnapshot.address(); + final Address creatorAddress = preOpcodeCreatorSnapshot.address(); this.midCreatorSnapshot = AccountSnapshot.fromAccount( frame.getWorldUpdater().get(creatorAddress), @@ -185,8 +197,8 @@ public void resolvePostExecution( hub.transients().conflation().deploymentInfo().number(creatorAddress), hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); - final Address createdAddress = oldCreatedSnapshot.address(); - this.midCreatedSnapshot = + final Address createdAddress = preOpcodeCreateeSnapshot.address(); + this.midCreateeSnapshot = AccountSnapshot.fromAccount( frame.getWorldUpdater().get(createdAddress), true, @@ -196,30 +208,10 @@ public void resolvePostExecution( // Pre-emptively set new* snapshots in case we never enter the child frame. // Will be overwritten if we enter the child frame and runNextContext is explicitly called by // the defer registry. - this.resolveAtContextReEntry(hub, frame); - } - - @Override - public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { - this.createSuccessful = !frame.getStackItem(0).isZero(); // TODO: are we sure it's working ?? - - final Address creatorAddress = oldCreatorSnapshot.address(); - this.newCreatorSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(creatorAddress), - true, - hub.transients().conflation().deploymentInfo().number(creatorAddress), - hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); - - final Address createdAddress = oldCreatedSnapshot.address(); - this.newCreatedSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(createdAddress), - true, - hub.transients().conflation().deploymentInfo().number(createdAddress), - hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); + // this.resolveAtContextReEntry(hub, frame); } + // TODO: @François: there was something around triggering the ROM_LEX module at the right time @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { @@ -240,12 +232,12 @@ public void resolvePostTransaction( createSuccessful, childRevertStamp, rlpAddrSubFragment, - oldCreatorSnapshot, + preOpcodeCreatorSnapshot, midCreatorSnapshot, newCreatorSnapshot, - oldCreatedSnapshot, - midCreatedSnapshot, - newCreatedSnapshot); + preOpcodeCreateeSnapshot, + midCreateeSnapshot, + newCreateeSnapshot); if (createCallFrame.hasReverted()) { final int currentRevertStamp = createCallFrame.revertStamp(); @@ -253,14 +245,35 @@ public void resolvePostTransaction( hub, createSuccessful, currentRevertStamp, - oldCreatorSnapshot, + preOpcodeCreatorSnapshot, midCreatorSnapshot, newCreatorSnapshot, - oldCreatedSnapshot, - midCreatedSnapshot, - newCreatedSnapshot); + preOpcodeCreateeSnapshot, + midCreateeSnapshot, + newCreateeSnapshot); } - this.createSection.fillContextFragment(this.lastContextFragment); + this.createSection.fillContextFragment(this.finalContextFragment); + } + + // TODO: ensure with @Daniel.Lehrner that at contextEntry the accounts + // of both creator and createe were updated (and potentially created) + // otherwise do it later + @Override + public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { + + final MessageFrame frame = callFrame.frame(); + + this.createSuccessful = !frame.getStackItem(0).isZero(); // TODO: are we sure it's working ?? + + final Address creatorAddress = preOpcodeCreatorSnapshot.address(); + this.newCreatorSnapshot = AccountSnapshot.canonical(hub, creatorAddress); + + final Address createeAddress = preOpcodeCreateeSnapshot.address(); + this.newCreateeSnapshot = AccountSnapshot.canonical(hub, createeAddress); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java index dc5fb559b9..93a978a86e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -36,14 +36,14 @@ public class FailureOrEmptyInitCreate extends TraceSection implements FillCreate public FailureOrEmptyInitCreate( final Hub hub, final ScenarioEnum scenario, - final ContextFragment commonContext, + final ContextFragment currentContextFragment, final ImcFragment imcFragment) { super(hub, (short) 10); hub.addTraceSection(this); this.scenarioFragment = new CreateScenarioFragment(scenario); - this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); + this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, imcFragment); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java index b09d6ba33f..57a2ee604f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java @@ -21,6 +21,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; public interface FillCreateSection { + void fillAccountFragment( final Hub hub, final boolean createSuccess, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index cf3a0c7f8e..f8c6b25481 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -152,7 +152,7 @@ public ReturnSection(Hub hub) { // no need for the else case (and a nop) as per @François final ContextFragment updateCallerReturnData = - ContextFragment.providesReturnData( + ContextFragment.executionProvidesReturnData( hub, hub.callStack().getById(hub.currentFrame().parentFrameId()).contextNumber(), hub.currentFrame().contextNumber()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java index 7c06aa8a9c..9f6d81317e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/PlatformController.java @@ -28,6 +28,7 @@ public class PlatformController { private final Hub hub; + // TODO: clean up extraneous signals (OOB, MXP, EXP, ...) /** What other modules should be triggered for the current operation */ @Getter private final Signals signals; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index 22ebb7a105..e0087a3493 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -97,12 +97,20 @@ public static MemorySpan callDataSegment(final MessageFrame frame) { long length = Words.clampedToLong(frame.getStackItem(3)); return MemorySpan.fromStartLength(offset, length); } + default -> throw new IllegalArgumentException( + "callDataSegment called outside of a CALL-type instruction"); + } + } + + public static MemorySpan initCodeSegment(final MessageFrame frame) { + switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { case CREATE, CREATE2 -> { long offset = Words.clampedToLong(frame.getStackItem(1)); long length = Words.clampedToLong(frame.getStackItem(2)); return MemorySpan.fromStartLength(offset, length); } - default -> throw new IllegalArgumentException("callDataSegment called outside of a *CALL"); + default -> throw new IllegalArgumentException( + "callDataSegment called outside of a CREATE(2)"); } } @@ -116,6 +124,10 @@ public MemorySpan callDataSegment() { return callDataSegment(hub.messageFrame()); } + public MemorySpan initCodeSegment() { + return initCodeSegment(hub.messageFrame()); + } + /** * Return the bytes of the calldata if the current operation is a call, throws otherwise. * From b9dac47fce2e838805c8a9e2764b5ce742917632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 25 Jul 2024 09:27:34 +0200 Subject: [PATCH 277/461] fix(constraints): new hub constraints and columns + CALL scenarios --- .../linea/zktracer/module/hub/Trace.java | 1295 +++++++++-------- .../scenario/CallScenarioFragment.java | 72 + .../hub/fragment/scenario/ScenarioEnum.java | 1 + .../calls/SmartContractCallSection.java | 3 +- .../hub/section/create/CreateSection.java | 3 +- zkevm-constraints | 2 +- 6 files changed, 727 insertions(+), 649 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 9563c7b142..daff5410cf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -79,13 +79,14 @@ public class Trace { private final MappedByteBuffer contextWillRevert; private final MappedByteBuffer counterNsr; private final MappedByteBuffer counterTli; - private final MappedByteBuffer createFailureConditionWillRevertXorHashInfoFlag; - private final MappedByteBuffer createFailureConditionWontRevertXorIcpx; - private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorInvalidFlag; - private final MappedByteBuffer createNonemptyInitCodeFailureWontRevertXorJumpx; + private final MappedByteBuffer createExceptionXorHashInfoFlag; + private final MappedByteBuffer createFailureConditionWillRevertXorIcpx; + private final MappedByteBuffer createFailureConditionWontRevertXorInvalidFlag; + private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorJumpx; private final MappedByteBuffer - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired; - private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorJumpFlag; + createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpFlag; + private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorKecFlag; private final MappedByteBuffer delta; private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi; @@ -94,17 +95,17 @@ public class Trace { private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize; private final MappedByteBuffer - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment; + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment; private final MappedByteBuffer - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2; + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2; private final MappedByteBuffer - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd; + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; private final MappedByteBuffer - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode; + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode; private final MappedByteBuffer - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution; + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; @@ -112,9 +113,8 @@ public class Trace { private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; private final MappedByteBuffer - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig; - private final MappedByteBuffer - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr; + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig; + private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr; private final MappedByteBuffer hashInfoStamp; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; @@ -122,12 +122,12 @@ public class Trace { private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; private final MappedByteBuffer - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero; + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero; private final MappedByteBuffer logInfoStamp; private final MappedByteBuffer - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth; + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth; private final MappedByteBuffer - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero; + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -158,19 +158,19 @@ public class Trace { private final MappedByteBuffer peekAtStack; private final MappedByteBuffer peekAtStorage; private final MappedByteBuffer peekAtTransaction; - private final MappedByteBuffer prcBlake2FXorKecFlag; - private final MappedByteBuffer prcEcaddXorLogFlag; - private final MappedByteBuffer prcEcmulXorLogInfoFlag; - private final MappedByteBuffer prcEcpairingXorMachineStateFlag; - private final MappedByteBuffer prcEcrecoverXorMaxcsx; - private final MappedByteBuffer prcFailureKnownToHubXorModFlag; - private final MappedByteBuffer prcFailureKnownToRamXorMulFlag; - private final MappedByteBuffer prcIdentityXorMxpx; - private final MappedByteBuffer prcModexpXorMxpFlag; - private final MappedByteBuffer prcRipemd160XorOogx; - private final MappedByteBuffer prcSha2256XorOpcx; - private final MappedByteBuffer prcSuccessCallerWillRevertXorPushpopFlag; - private final MappedByteBuffer prcSuccessCallerWontRevertXorRdcx; + private final MappedByteBuffer prcBlake2FXorLogFlag; + private final MappedByteBuffer prcEcaddXorLogInfoFlag; + private final MappedByteBuffer prcEcmulXorMachineStateFlag; + private final MappedByteBuffer prcEcpairingXorMaxcsx; + private final MappedByteBuffer prcEcrecoverXorModFlag; + private final MappedByteBuffer prcFailureKnownToHubXorMulFlag; + private final MappedByteBuffer prcFailureKnownToRamXorMxpx; + private final MappedByteBuffer prcIdentityXorMxpFlag; + private final MappedByteBuffer prcModexpXorOogx; + private final MappedByteBuffer prcRipemd160XorOpcx; + private final MappedByteBuffer prcSha2256XorPushpopFlag; + private final MappedByteBuffer prcSuccessCallerWillRevertXorRdcx; + private final MappedByteBuffer prcSuccessCallerWontRevertXorShfFlag; private final MappedByteBuffer priorityFeePerGas; private final MappedByteBuffer programCounter; private final MappedByteBuffer programCounterNew; @@ -183,27 +183,27 @@ public class Trace { private final MappedByteBuffer returnDataContextNumberXorStpGasStipend; private final MappedByteBuffer returnDataOffsetXorStpInstruction; private final MappedByteBuffer returnDataSize; - private final MappedByteBuffer returnExceptionXorShfFlag; - private final MappedByteBuffer returnFromDeploymentEmptyCodeWillRevertXorSox; - private final MappedByteBuffer returnFromDeploymentEmptyCodeWontRevertXorSstorex; - private final MappedByteBuffer returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag; - private final MappedByteBuffer returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1; - private final MappedByteBuffer returnFromMessageCallWillTouchRamXorStackItemPop2; - private final MappedByteBuffer returnFromMessageCallWontTouchRamXorStackItemPop3; + private final MappedByteBuffer returnExceptionXorSox; + private final MappedByteBuffer returnFromDeploymentEmptyCodeWillRevertXorSstorex; + private final MappedByteBuffer returnFromDeploymentEmptyCodeWontRevertXorStackramFlag; + private final MappedByteBuffer returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1; + private final MappedByteBuffer returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2; + private final MappedByteBuffer returnFromMessageCallWillTouchRamXorStackItemPop3; + private final MappedByteBuffer returnFromMessageCallWontTouchRamXorStackItemPop4; private final MappedByteBuffer rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize; private final MappedByteBuffer rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi; private final MappedByteBuffer - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew; + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew; private final MappedByteBuffer rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo; private final MappedByteBuffer rlpaddrKecLoXorMmuTgtOffsetLo; private final MappedByteBuffer rlpaddrRecipe; private final MappedByteBuffer rlpaddrSaltHiXorMxpGasMxp; private final MappedByteBuffer rlpaddrSaltLoXorMxpOffset1Hi; - private final MappedByteBuffer romlexFlagXorStpOogxXorCreateAbortXorDecFlag4; - private final MappedByteBuffer selfdestructExceptionXorStackItemPop4; - private final MappedByteBuffer selfdestructWillRevertXorStaticx; - private final MappedByteBuffer selfdestructWontRevertAlreadyMarkedXorStaticFlag; - private final MappedByteBuffer selfdestructWontRevertNotYetMarkedXorStoFlag; + private final MappedByteBuffer romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4; + private final MappedByteBuffer selfdestructExceptionXorStaticx; + private final MappedByteBuffer selfdestructWillRevertXorStaticFlag; + private final MappedByteBuffer selfdestructWontRevertAlreadyMarkedXorStoFlag; + private final MappedByteBuffer selfdestructWontRevertNotYetMarkedXorSux; private final MappedByteBuffer stackItemHeight1; private final MappedByteBuffer stackItemHeight2; private final MappedByteBuffer stackItemHeight3; @@ -228,9 +228,8 @@ public class Trace { private final MappedByteBuffer stpValueHi; private final MappedByteBuffer stpValueLo; private final MappedByteBuffer subStamp; - private final MappedByteBuffer sux; private final MappedByteBuffer swapFlag; - private final MappedByteBuffer trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag; + private final MappedByteBuffer trmFlagXorStpWarmthXorCreateAbortXorDupFlag; private final MappedByteBuffer trmRawAddressHiXorMxpOffset1Lo; private final MappedByteBuffer twoLineInstruction; private final MappedByteBuffer txExec; @@ -239,8 +238,8 @@ public class Trace { private final MappedByteBuffer txSkip; private final MappedByteBuffer txWarm; private final MappedByteBuffer txnFlag; - private final MappedByteBuffer warmthNewXorCreateExceptionXorHaltFlag; - private final MappedByteBuffer warmthXorCreateEmptyInitCodeWontRevertXorExtFlag; + private final MappedByteBuffer warmthNewXorCreateEmptyInitCodeWontRevertXorHaltFlag; + private final MappedByteBuffer warmthXorCreateEmptyInitCodeWillRevertXorExtFlag; private final MappedByteBuffer wcpFlag; static List headers(int length) { @@ -303,17 +302,18 @@ static List headers(int length) { new ColumnHeader("hub.CONTEXT_WILL_REVERT", 1, length), new ColumnHeader("hub.COUNTER_NSR", 1, length), new ColumnHeader("hub.COUNTER_TLI", 1, length), - new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG", 1, length), - new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX", 1, length), - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG", 1, length), - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX", 1, length), + new ColumnHeader("hub.CREATE_EXCEPTION_xor_HASH_INFO_FLAG", 1, length), + new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX", 1, length), + new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG", 1, length), + new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX", 1, length), new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", 1, length), new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG", 1, length), + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG", 1, length), + new ColumnHeader( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG", 1, length), new ColumnHeader("hub.DELTA", 1, length), new ColumnHeader( "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO_xor_TO_ADDRESS_HI", @@ -328,25 +328,25 @@ static List headers(int length) { 4, length), new ColumnHeader( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT", + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT", 1, length), new ColumnHeader( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2", + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2", 1, length), new ColumnHeader( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD", + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD", 1, length), new ColumnHeader("hub.DOM_STAMP", 4, length), new ColumnHeader("hub.EXCEPTION_AHOY", 1, length), new ColumnHeader( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE", + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE", 1, length), new ColumnHeader( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION", + "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), @@ -356,11 +356,11 @@ static List headers(int length) { new ColumnHeader("hub.GAS_NEXT", 4, length), new ColumnHeader("hub.GAS_PRICE", 8, length), new ColumnHeader( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG", + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG", 1, length), new ColumnHeader( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR", + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR", 1, length), new ColumnHeader("hub.HASH_INFO_STAMP", 4, length), @@ -370,16 +370,16 @@ static List headers(int length) { new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 4, length), new ColumnHeader("hub.INSTRUCTION", 32, length), new ColumnHeader( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO", + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO", 1, length), new ColumnHeader("hub.LOG_INFO_STAMP", 4, length), new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH", + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_WARMTH", 1, length), new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO", + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO", 1, length), new ColumnHeader("hub.MMU_STAMP", 4, length), @@ -413,19 +413,19 @@ static List headers(int length) { new ColumnHeader("hub.PEEK_AT_STACK", 1, length), new ColumnHeader("hub.PEEK_AT_STORAGE", 1, length), new ColumnHeader("hub.PEEK_AT_TRANSACTION", 1, length), - new ColumnHeader("hub.PRC_BLAKE2f_xor_KEC_FLAG", 1, length), - new ColumnHeader("hub.PRC_ECADD_xor_LOG_FLAG", 1, length), - new ColumnHeader("hub.PRC_ECMUL_xor_LOG_INFO_FLAG", 1, length), - new ColumnHeader("hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG", 1, length), - new ColumnHeader("hub.PRC_ECRECOVER_xor_MAXCSX", 1, length), - new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG", 1, length), - new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG", 1, length), - new ColumnHeader("hub.PRC_IDENTITY_xor_MXPX", 1, length), - new ColumnHeader("hub.PRC_MODEXP_xor_MXP_FLAG", 1, length), - new ColumnHeader("hub.PRC_RIPEMD-160_xor_OOGX", 1, length), - new ColumnHeader("hub.PRC_SHA2-256_xor_OPCX", 1, length), - new ColumnHeader("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG", 1, length), - new ColumnHeader("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX", 1, length), + new ColumnHeader("hub.PRC_BLAKE2f_xor_LOG_FLAG", 1, length), + new ColumnHeader("hub.PRC_ECADD_xor_LOG_INFO_FLAG", 1, length), + new ColumnHeader("hub.PRC_ECMUL_xor_MACHINE_STATE_FLAG", 1, length), + new ColumnHeader("hub.PRC_ECPAIRING_xor_MAXCSX", 1, length), + new ColumnHeader("hub.PRC_ECRECOVER_xor_MOD_FLAG", 1, length), + new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MUL_FLAG", 1, length), + new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MXPX", 1, length), + new ColumnHeader("hub.PRC_IDENTITY_xor_MXP_FLAG", 1, length), + new ColumnHeader("hub.PRC_MODEXP_xor_OOGX", 1, length), + new ColumnHeader("hub.PRC_RIPEMD-160_xor_OPCX", 1, length), + new ColumnHeader("hub.PRC_SHA2-256_xor_PUSHPOP_FLAG", 1, length), + new ColumnHeader("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_RDCX", 1, length), + new ColumnHeader("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_SHF_FLAG", 1, length), new ColumnHeader("hub.PRIORITY_FEE_PER_GAS", 8, length), new ColumnHeader("hub.PROGRAM_COUNTER", 4, length), new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 4, length), @@ -438,24 +438,25 @@ static List headers(int length) { new ColumnHeader("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND", 4, length), new ColumnHeader("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION", 4, length), new ColumnHeader("hub.RETURN_DATA_SIZE", 4, length), - new ColumnHeader("hub.RETURN_EXCEPTION_xor_SHF_FLAG", 1, length), - new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX", 1, length), + new ColumnHeader("hub.RETURN_EXCEPTION_xor_SOX", 1, length), new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX", 1, length), + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SSTOREX", 1, length), new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG", 1, length), + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_STACKRAM_FLAG", 1, length), new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1", 1, length), + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACK_ITEM_POP_1", 1, length), new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2", 1, length), + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_2", 1, length), new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length), + new ColumnHeader( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_4", 1, length), new ColumnHeader( "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 4, length), new ColumnHeader( "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_VALUE_ORIG_HI", 16, length), new ColumnHeader( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW", + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW", 1, length), new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_VALUE_ORIG_LO", 16, length), @@ -463,11 +464,14 @@ static List headers(int length) { new ColumnHeader("hub.RLPADDR_RECIPE", 1, length), new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP", 16, length), new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI", 16, length), - new ColumnHeader("hub.ROMLEX_FLAG_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4", 1, length), - new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4", 1, length), - new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX", 1, length), - new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG", 1, length), - new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG", 1, length), + new ColumnHeader( + "hub.ROMLEX_FLAG_xor_STP_OOGX_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4", + 1, + length), + new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STATICX", 1, length), + new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATIC_FLAG", 1, length), + new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STO_FLAG", 1, length), + new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_SUX", 1, length), new ColumnHeader("hub.STACK_ITEM_HEIGHT_1", 32, length), new ColumnHeader("hub.STACK_ITEM_HEIGHT_2", 32, length), new ColumnHeader("hub.STACK_ITEM_HEIGHT_3", 32, length), @@ -492,12 +496,8 @@ static List headers(int length) { new ColumnHeader("hub.STP_VALUE_HI", 16, length), new ColumnHeader("hub.STP_VALUE_LO", 16, length), new ColumnHeader("hub.SUB_STAMP", 4, length), - new ColumnHeader("hub.SUX", 1, length), new ColumnHeader("hub.SWAP_FLAG", 1, length), - new ColumnHeader( - "hub.TRM_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG", - 1, - length), + new ColumnHeader("hub.TRM_FLAG_xor_STP_WARMTH_xor_CREATE_ABORT_xor_DUP_FLAG", 1, length), new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 16, length), new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length), new ColumnHeader("hub.TX_EXEC", 1, length), @@ -506,9 +506,10 @@ static List headers(int length) { new ColumnHeader("hub.TX_SKIP", 1, length), new ColumnHeader("hub.TX_WARM", 1, length), new ColumnHeader("hub.TXN_FLAG", 1, length), - new ColumnHeader("hub.WARMTH_NEW_xor_CREATE_EXCEPTION_xor_HALT_FLAG", 1, length), new ColumnHeader( - "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG", 1, length), + "hub.WARMTH_NEW_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG", 1, length), + new ColumnHeader( + "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG", 1, length), new ColumnHeader("hub.WCP_FLAG", 1, length)); } @@ -558,160 +559,160 @@ public Trace(List buffers) { this.contextWillRevert = buffers.get(30); this.counterNsr = buffers.get(31); this.counterTli = buffers.get(32); - this.createFailureConditionWillRevertXorHashInfoFlag = buffers.get(33); - this.createFailureConditionWontRevertXorIcpx = buffers.get(34); - this.createNonemptyInitCodeFailureWillRevertXorInvalidFlag = buffers.get(35); - this.createNonemptyInitCodeFailureWontRevertXorJumpx = buffers.get(36); - this.createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired = buffers.get(37); - this.createNonemptyInitCodeSuccessWontRevertXorJumpFlag = buffers.get(38); - this.delta = buffers.get(39); + this.createExceptionXorHashInfoFlag = buffers.get(33); + this.createFailureConditionWillRevertXorIcpx = buffers.get(34); + this.createFailureConditionWontRevertXorInvalidFlag = buffers.get(35); + this.createNonemptyInitCodeFailureWillRevertXorJumpx = buffers.get(36); + this.createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired = buffers.get(37); + this.createNonemptyInitCodeSuccessWillRevertXorJumpFlag = buffers.get(38); + this.createNonemptyInitCodeSuccessWontRevertXorKecFlag = buffers.get(39); + this.delta = buffers.get(40); this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRaoXorToAddressHi = - buffers.get(40); - this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(41); + buffers.get(41); + this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(42); this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorInitCodeSize = - buffers.get(42); - this - .deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment = buffers.get(43); this - .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 = + .deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment = buffers.get(44); this - .deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd = + .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 = buffers.get(45); - this.domStamp = buffers.get(46); - this.exceptionAhoy = buffers.get(47); - this.existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode = - buffers.get(48); - this.existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = + this + .deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd = + buffers.get(46); + this.domStamp = buffers.get(47); + this.exceptionAhoy = buffers.get(48); + this.existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode = buffers.get(49); - this.gasActual = buffers.get(50); - this.gasCost = buffers.get(51); - this.gasExpected = buffers.get(52); - this.gasLimit = buffers.get(53); - this.gasNext = buffers.get(54); - this.gasPrice = buffers.get(55); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig = - buffers.get(56); - this.hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr = - buffers.get(57); - this.hashInfoStamp = buffers.get(58); - this.height = buffers.get(59); - this.heightNew = buffers.get(60); - this.hubStamp = buffers.get(61); - this.hubStampTransactionEnd = buffers.get(62); - this.instruction = buffers.get(63); - this.isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero = - buffers.get(64); - this.logInfoStamp = buffers.get(65); - this.markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth = - buffers.get(66); this - .markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero = + .existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = + buffers.get(50); + this.gasActual = buffers.get(51); + this.gasCost = buffers.get(52); + this.gasExpected = buffers.get(53); + this.gasLimit = buffers.get(54); + this.gasNext = buffers.get(55); + this.gasPrice = buffers.get(56); + this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig = + buffers.get(57); + this.hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr = buffers.get(58); + this.hashInfoStamp = buffers.get(59); + this.height = buffers.get(60); + this.heightNew = buffers.get(61); + this.hubStamp = buffers.get(62); + this.hubStampTransactionEnd = buffers.get(63); + this.instruction = buffers.get(64); + this.isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero = + buffers.get(65); + this.logInfoStamp = buffers.get(66); + this.markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth = buffers.get(67); - this.mmuStamp = buffers.get(68); - this.mxpOffset2Hi = buffers.get(69); - this.mxpOffset2Lo = buffers.get(70); - this.mxpSize1Hi = buffers.get(71); - this.mxpSize1Lo = buffers.get(72); - this.mxpSize2Hi = buffers.get(73); - this.mxpSize2Lo = buffers.get(74); - this.mxpStamp = buffers.get(75); - this.mxpWords = buffers.get(76); - this.nbAdded = buffers.get(77); - this.nbRemoved = buffers.get(78); - this.nonStackRows = buffers.get(79); - this.nonce = buffers.get(80); - this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(81); - this.nonceXorStpGasMxpXorBasefee = buffers.get(82); - this.oobData1 = buffers.get(83); - this.oobData2 = buffers.get(84); - this.oobData3 = buffers.get(85); - this.oobData4 = buffers.get(86); - this.oobData5 = buffers.get(87); - this.oobData6 = buffers.get(88); - this.oobData7 = buffers.get(89); - this.oobData8 = buffers.get(90); - this.peekAtAccount = buffers.get(91); - this.peekAtContext = buffers.get(92); - this.peekAtMiscellaneous = buffers.get(93); - this.peekAtScenario = buffers.get(94); - this.peekAtStack = buffers.get(95); - this.peekAtStorage = buffers.get(96); - this.peekAtTransaction = buffers.get(97); - this.prcBlake2FXorKecFlag = buffers.get(98); - this.prcEcaddXorLogFlag = buffers.get(99); - this.prcEcmulXorLogInfoFlag = buffers.get(100); - this.prcEcpairingXorMachineStateFlag = buffers.get(101); - this.prcEcrecoverXorMaxcsx = buffers.get(102); - this.prcFailureKnownToHubXorModFlag = buffers.get(103); - this.prcFailureKnownToRamXorMulFlag = buffers.get(104); - this.prcIdentityXorMxpx = buffers.get(105); - this.prcModexpXorMxpFlag = buffers.get(106); - this.prcRipemd160XorOogx = buffers.get(107); - this.prcSha2256XorOpcx = buffers.get(108); - this.prcSuccessCallerWillRevertXorPushpopFlag = buffers.get(109); - this.prcSuccessCallerWontRevertXorRdcx = buffers.get(110); - this.priorityFeePerGas = buffers.get(111); - this.programCounter = buffers.get(112); - this.programCounterNew = buffers.get(113); - this.refundCounter = buffers.get(114); - this.refundCounterInfinity = buffers.get(115); - this.refundCounterNew = buffers.get(116); - this.refundEffective = buffers.get(117); - this.returnAtCapacityXorMxpInst = buffers.get(118); - this.returnAtOffsetXorOobInst = buffers.get(119); - this.returnDataContextNumberXorStpGasStipend = buffers.get(120); - this.returnDataOffsetXorStpInstruction = buffers.get(121); - this.returnDataSize = buffers.get(122); - this.returnExceptionXorShfFlag = buffers.get(123); - this.returnFromDeploymentEmptyCodeWillRevertXorSox = buffers.get(124); - this.returnFromDeploymentEmptyCodeWontRevertXorSstorex = buffers.get(125); - this.returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag = buffers.get(126); - this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1 = buffers.get(127); - this.returnFromMessageCallWillTouchRamXorStackItemPop2 = buffers.get(128); - this.returnFromMessageCallWontTouchRamXorStackItemPop3 = buffers.get(129); - this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(130); - this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi = buffers.get(131); - this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew = - buffers.get(132); - this.rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo = buffers.get(133); - this.rlpaddrKecLoXorMmuTgtOffsetLo = buffers.get(134); - this.rlpaddrRecipe = buffers.get(135); - this.rlpaddrSaltHiXorMxpGasMxp = buffers.get(136); - this.rlpaddrSaltLoXorMxpOffset1Hi = buffers.get(137); - this.romlexFlagXorStpOogxXorCreateAbortXorDecFlag4 = buffers.get(138); - this.selfdestructExceptionXorStackItemPop4 = buffers.get(139); - this.selfdestructWillRevertXorStaticx = buffers.get(140); - this.selfdestructWontRevertAlreadyMarkedXorStaticFlag = buffers.get(141); - this.selfdestructWontRevertNotYetMarkedXorStoFlag = buffers.get(142); - this.stackItemHeight1 = buffers.get(143); - this.stackItemHeight2 = buffers.get(144); - this.stackItemHeight3 = buffers.get(145); - this.stackItemHeight4 = buffers.get(146); - this.stackItemStamp1 = buffers.get(147); - this.stackItemStamp2 = buffers.get(148); - this.stackItemStamp3 = buffers.get(149); - this.stackItemStamp4 = buffers.get(150); - this.stackItemValueHi1 = buffers.get(151); - this.stackItemValueHi2 = buffers.get(152); - this.stackItemValueHi3 = buffers.get(153); - this.stackItemValueHi4 = buffers.get(154); - this.stackItemValueLo1 = buffers.get(155); - this.stackItemValueLo2 = buffers.get(156); - this.stackItemValueLo3 = buffers.get(157); - this.stackItemValueLo4 = buffers.get(158); - this.stoFinal = buffers.get(159); - this.stoFirst = buffers.get(160); - this.stpGasHi = buffers.get(161); - this.stpGasLo = buffers.get(162); - this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(163); - this.stpValueHi = buffers.get(164); - this.stpValueLo = buffers.get(165); - this.subStamp = buffers.get(166); - this.sux = buffers.get(167); + this + .markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero = + buffers.get(68); + this.mmuStamp = buffers.get(69); + this.mxpOffset2Hi = buffers.get(70); + this.mxpOffset2Lo = buffers.get(71); + this.mxpSize1Hi = buffers.get(72); + this.mxpSize1Lo = buffers.get(73); + this.mxpSize2Hi = buffers.get(74); + this.mxpSize2Lo = buffers.get(75); + this.mxpStamp = buffers.get(76); + this.mxpWords = buffers.get(77); + this.nbAdded = buffers.get(78); + this.nbRemoved = buffers.get(79); + this.nonStackRows = buffers.get(80); + this.nonce = buffers.get(81); + this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(82); + this.nonceXorStpGasMxpXorBasefee = buffers.get(83); + this.oobData1 = buffers.get(84); + this.oobData2 = buffers.get(85); + this.oobData3 = buffers.get(86); + this.oobData4 = buffers.get(87); + this.oobData5 = buffers.get(88); + this.oobData6 = buffers.get(89); + this.oobData7 = buffers.get(90); + this.oobData8 = buffers.get(91); + this.peekAtAccount = buffers.get(92); + this.peekAtContext = buffers.get(93); + this.peekAtMiscellaneous = buffers.get(94); + this.peekAtScenario = buffers.get(95); + this.peekAtStack = buffers.get(96); + this.peekAtStorage = buffers.get(97); + this.peekAtTransaction = buffers.get(98); + this.prcBlake2FXorLogFlag = buffers.get(99); + this.prcEcaddXorLogInfoFlag = buffers.get(100); + this.prcEcmulXorMachineStateFlag = buffers.get(101); + this.prcEcpairingXorMaxcsx = buffers.get(102); + this.prcEcrecoverXorModFlag = buffers.get(103); + this.prcFailureKnownToHubXorMulFlag = buffers.get(104); + this.prcFailureKnownToRamXorMxpx = buffers.get(105); + this.prcIdentityXorMxpFlag = buffers.get(106); + this.prcModexpXorOogx = buffers.get(107); + this.prcRipemd160XorOpcx = buffers.get(108); + this.prcSha2256XorPushpopFlag = buffers.get(109); + this.prcSuccessCallerWillRevertXorRdcx = buffers.get(110); + this.prcSuccessCallerWontRevertXorShfFlag = buffers.get(111); + this.priorityFeePerGas = buffers.get(112); + this.programCounter = buffers.get(113); + this.programCounterNew = buffers.get(114); + this.refundCounter = buffers.get(115); + this.refundCounterInfinity = buffers.get(116); + this.refundCounterNew = buffers.get(117); + this.refundEffective = buffers.get(118); + this.returnAtCapacityXorMxpInst = buffers.get(119); + this.returnAtOffsetXorOobInst = buffers.get(120); + this.returnDataContextNumberXorStpGasStipend = buffers.get(121); + this.returnDataOffsetXorStpInstruction = buffers.get(122); + this.returnDataSize = buffers.get(123); + this.returnExceptionXorSox = buffers.get(124); + this.returnFromDeploymentEmptyCodeWillRevertXorSstorex = buffers.get(125); + this.returnFromDeploymentEmptyCodeWontRevertXorStackramFlag = buffers.get(126); + this.returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1 = buffers.get(127); + this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2 = buffers.get(128); + this.returnFromMessageCallWillTouchRamXorStackItemPop3 = buffers.get(129); + this.returnFromMessageCallWontTouchRamXorStackItemPop4 = buffers.get(130); + this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(131); + this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorValueOrigHi = buffers.get(132); + this.rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew = + buffers.get(133); + this.rlpaddrKecHiXorMmuSrcOffsetLoXorValueOrigLo = buffers.get(134); + this.rlpaddrKecLoXorMmuTgtOffsetLo = buffers.get(135); + this.rlpaddrRecipe = buffers.get(136); + this.rlpaddrSaltHiXorMxpGasMxp = buffers.get(137); + this.rlpaddrSaltLoXorMxpOffset1Hi = buffers.get(138); + this.romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4 = buffers.get(139); + this.selfdestructExceptionXorStaticx = buffers.get(140); + this.selfdestructWillRevertXorStaticFlag = buffers.get(141); + this.selfdestructWontRevertAlreadyMarkedXorStoFlag = buffers.get(142); + this.selfdestructWontRevertNotYetMarkedXorSux = buffers.get(143); + this.stackItemHeight1 = buffers.get(144); + this.stackItemHeight2 = buffers.get(145); + this.stackItemHeight3 = buffers.get(146); + this.stackItemHeight4 = buffers.get(147); + this.stackItemStamp1 = buffers.get(148); + this.stackItemStamp2 = buffers.get(149); + this.stackItemStamp3 = buffers.get(150); + this.stackItemStamp4 = buffers.get(151); + this.stackItemValueHi1 = buffers.get(152); + this.stackItemValueHi2 = buffers.get(153); + this.stackItemValueHi3 = buffers.get(154); + this.stackItemValueHi4 = buffers.get(155); + this.stackItemValueLo1 = buffers.get(156); + this.stackItemValueLo2 = buffers.get(157); + this.stackItemValueLo3 = buffers.get(158); + this.stackItemValueLo4 = buffers.get(159); + this.stoFinal = buffers.get(160); + this.stoFirst = buffers.get(161); + this.stpGasHi = buffers.get(162); + this.stpGasLo = buffers.get(163); + this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(164); + this.stpValueHi = buffers.get(165); + this.stpValueLo = buffers.get(166); + this.subStamp = buffers.get(167); this.swapFlag = buffers.get(168); - this.trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag = buffers.get(169); + this.trmFlagXorStpWarmthXorCreateAbortXorDupFlag = buffers.get(169); this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(170); this.twoLineInstruction = buffers.get(171); this.txExec = buffers.get(172); @@ -720,8 +721,8 @@ public Trace(List buffers) { this.txSkip = buffers.get(175); this.txWarm = buffers.get(176); this.txnFlag = buffers.get(177); - this.warmthNewXorCreateExceptionXorHaltFlag = buffers.get(178); - this.warmthXorCreateEmptyInitCodeWontRevertXorExtFlag = buffers.get(179); + this.warmthNewXorCreateEmptyInitCodeWontRevertXorHaltFlag = buffers.get(178); + this.warmthXorCreateEmptyInitCodeWillRevertXorExtFlag = buffers.get(179); this.wcpFlag = buffers.get(180); } @@ -1616,8 +1617,8 @@ public Trace pAccountDeploymentStatus(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .put((byte) (b ? 1 : 0)); return this; } @@ -1629,7 +1630,7 @@ public Trace pAccountDeploymentStatusInfty(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .put((byte) (b ? 1 : 0)); return this; @@ -1642,7 +1643,7 @@ public Trace pAccountDeploymentStatusNew(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -1655,8 +1656,8 @@ public Trace pAccountExists(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .put((byte) (b ? 1 : 0)); return this; } @@ -1668,7 +1669,7 @@ public Trace pAccountExistsNew(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -1681,8 +1682,7 @@ public Trace pAccountHasCode(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -1694,7 +1694,7 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( (byte) (b ? 1 : 0)); return this; @@ -1707,7 +1707,7 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( (byte) (b ? 1 : 0)); return this; @@ -1720,7 +1720,7 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero .put((byte) (b ? 1 : 0)); return this; @@ -1733,7 +1733,7 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -1847,7 +1847,7 @@ public Trace pAccountRlpaddrFlag(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; @@ -1981,7 +1981,7 @@ public Trace pAccountRomlexFlag(final Boolean b) { filled.set(63); } - romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } @@ -1993,7 +1993,7 @@ public Trace pAccountTrmFlag(final Boolean b) { filled.set(64); } - trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorStpWarmthXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -2031,7 +2031,7 @@ public Trace pAccountWarmth(final Boolean b) { filled.set(65); } - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateEmptyInitCodeWillRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } @@ -2043,7 +2043,7 @@ public Trace pAccountWarmthNew(final Boolean b) { filled.set(66); } - warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateEmptyInitCodeWontRevertXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } @@ -2431,8 +2431,8 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .put((byte) (b ? 1 : 0)); return this; } @@ -2444,7 +2444,7 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .put((byte) (b ? 1 : 0)); return this; @@ -2550,7 +2550,7 @@ public Trace pContextUpdate(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -2588,8 +2588,8 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .put((byte) (b ? 1 : 0)); return this; } @@ -2747,7 +2747,7 @@ public Trace pMiscExpFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .put((byte) (b ? 1 : 0)); return this; @@ -2834,7 +2834,7 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -3080,8 +3080,8 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .put((byte) (b ? 1 : 0)); return this; } @@ -3137,7 +3137,7 @@ public Trace pMiscMxpDeploys(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -3150,8 +3150,7 @@ public Trace pMiscMxpFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -3208,7 +3207,7 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( (byte) (b ? 1 : 0)); return this; @@ -3221,7 +3220,7 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( (byte) (b ? 1 : 0)); return this; @@ -3667,7 +3666,7 @@ public Trace pMiscOobFlag(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero .put((byte) (b ? 1 : 0)); return this; @@ -3698,7 +3697,7 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -3711,7 +3710,7 @@ public Trace pMiscStpFlag(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; @@ -3892,7 +3891,7 @@ public Trace pMiscStpOogx(final Boolean b) { filled.set(63); } - romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } @@ -3956,299 +3955,310 @@ public Trace pMiscStpWarmth(final Boolean b) { filled.set(64); } - trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorStpWarmthXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallAbort(final Boolean b) { + public Trace pScenarioCallAbortWillRevert(final Boolean b) { if (filled.get(52)) { - throw new IllegalStateException("hub.scenario/CALL_ABORT already set"); + throw new IllegalStateException("hub.scenario/CALL_ABORT_WILL_REVERT already set"); } else { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { + public Trace pScenarioCallAbortWontRevert(final Boolean b) { if (filled.get(53)) { - throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_ABORT_WONT_REVERT already set"); } else { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { + public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { if (filled.get(54)) { throw new IllegalStateException( - "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallException(final Boolean b) { + public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { if (filled.get(55)) { - throw new IllegalStateException("hub.scenario/CALL_EXCEPTION already set"); + throw new IllegalStateException( + "hub.scenario/CALL_EOA_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallPrcFailure(final Boolean b) { + public Trace pScenarioCallException(final Boolean b) { if (filled.get(56)) { - throw new IllegalStateException("hub.scenario/CALL_PRC_FAILURE already set"); + throw new IllegalStateException("hub.scenario/CALL_EXCEPTION already set"); } else { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( (byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { + public Trace pScenarioCallPrcFailure(final Boolean b) { if (filled.get(57)) { - throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/CALL_PRC_FAILURE already set"); } else { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { + public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { if (filled.get(58)) { throw new IllegalStateException( - "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( (byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { + public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { if (filled.get(59)) { throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); + "hub.scenario/CALL_PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( (byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { + public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { if (filled.get(60)) { throw new IllegalStateException( - "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); + "hub.scenario/CALL_SMC_FAILURE_CALLER_WILL_REVERT already set"); } else { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero .put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { + public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { if (filled.get(61)) { throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); + "hub.scenario/CALL_SMC_FAILURE_CALLER_WONT_REVERT already set"); } else { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth.put( (byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { + public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { if (filled.get(62)) { throw new IllegalStateException( - "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WILL_REVERT already set"); } else { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCreateAbort(final Boolean b) { + public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { if (filled.get(63)) { - throw new IllegalStateException("hub.scenario/CREATE_ABORT already set"); + throw new IllegalStateException( + "hub.scenario/CALL_SMC_SUCCESS_CALLER_WONT_REVERT already set"); } else { filled.set(63); } - romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } - public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { + public Trace pScenarioCreateAbort(final Boolean b) { if (filled.get(64)) { + throw new IllegalStateException("hub.scenario/CREATE_ABORT already set"); + } else { + filled.set(64); + } + + trmFlagXorStpWarmthXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { + if (filled.get(65)) { throw new IllegalStateException( "hub.scenario/CREATE_EMPTY_INIT_CODE_WILL_REVERT already set"); } else { - filled.set(64); + filled.set(65); } - trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateEmptyInitCodeWillRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { - if (filled.get(65)) { + if (filled.get(66)) { throw new IllegalStateException( "hub.scenario/CREATE_EMPTY_INIT_CODE_WONT_REVERT already set"); } else { - filled.set(65); + filled.set(66); } - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateEmptyInitCodeWontRevertXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateException(final Boolean b) { - if (filled.get(66)) { + if (filled.get(67)) { throw new IllegalStateException("hub.scenario/CREATE_EXCEPTION already set"); } else { - filled.set(66); + filled.set(67); } - warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + createExceptionXorHashInfoFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { - if (filled.get(67)) { + if (filled.get(68)) { throw new IllegalStateException( "hub.scenario/CREATE_FAILURE_CONDITION_WILL_REVERT already set"); } else { - filled.set(67); + filled.set(68); } - createFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); + createFailureConditionWillRevertXorIcpx.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { - if (filled.get(68)) { + if (filled.get(69)) { throw new IllegalStateException( "hub.scenario/CREATE_FAILURE_CONDITION_WONT_REVERT already set"); } else { - filled.set(68); + filled.set(69); } - createFailureConditionWontRevertXorIcpx.put((byte) (b ? 1 : 0)); + createFailureConditionWontRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { - if (filled.get(69)) { + if (filled.get(70)) { throw new IllegalStateException( "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT already set"); } else { - filled.set(69); + filled.set(70); } - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeFailureWillRevertXorJumpx.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { - if (filled.get(70)) { + if (filled.get(71)) { throw new IllegalStateException( "hub.scenario/CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT already set"); } else { - filled.set(70); + filled.set(71); } - createNonemptyInitCodeFailureWontRevertXorJumpx.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.put( + (byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { - if (filled.get(71)) { + if (filled.get(72)) { throw new IllegalStateException( "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT already set"); } else { - filled.set(71); + filled.set(72); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { - if (filled.get(72)) { + if (filled.get(73)) { throw new IllegalStateException( "hub.scenario/CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT already set"); } else { - filled.set(72); + filled.set(73); } - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWontRevertXorKecFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcBlake2F(final Boolean b) { - if (filled.get(73)) { + if (filled.get(74)) { throw new IllegalStateException("hub.scenario/PRC_BLAKE2f already set"); } else { - filled.set(73); + filled.set(74); } - prcBlake2FXorKecFlag.put((byte) (b ? 1 : 0)); + prcBlake2FXorLogFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4353,97 +4363,97 @@ public Trace pScenarioPrcCds(final long b) { } public Trace pScenarioPrcEcadd(final Boolean b) { - if (filled.get(74)) { + if (filled.get(75)) { throw new IllegalStateException("hub.scenario/PRC_ECADD already set"); } else { - filled.set(74); + filled.set(75); } - prcEcaddXorLogFlag.put((byte) (b ? 1 : 0)); + prcEcaddXorLogInfoFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcEcmul(final Boolean b) { - if (filled.get(75)) { + if (filled.get(76)) { throw new IllegalStateException("hub.scenario/PRC_ECMUL already set"); } else { - filled.set(75); + filled.set(76); } - prcEcmulXorLogInfoFlag.put((byte) (b ? 1 : 0)); + prcEcmulXorMachineStateFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcEcpairing(final Boolean b) { - if (filled.get(76)) { + if (filled.get(77)) { throw new IllegalStateException("hub.scenario/PRC_ECPAIRING already set"); } else { - filled.set(76); + filled.set(77); } - prcEcpairingXorMachineStateFlag.put((byte) (b ? 1 : 0)); + prcEcpairingXorMaxcsx.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcEcrecover(final Boolean b) { - if (filled.get(77)) { + if (filled.get(78)) { throw new IllegalStateException("hub.scenario/PRC_ECRECOVER already set"); } else { - filled.set(77); + filled.set(78); } - prcEcrecoverXorMaxcsx.put((byte) (b ? 1 : 0)); + prcEcrecoverXorModFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcFailureKnownToHub(final Boolean b) { - if (filled.get(78)) { + if (filled.get(79)) { throw new IllegalStateException("hub.scenario/PRC_FAILURE_KNOWN_TO_HUB already set"); } else { - filled.set(78); + filled.set(79); } - prcFailureKnownToHubXorModFlag.put((byte) (b ? 1 : 0)); + prcFailureKnownToHubXorMulFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcFailureKnownToRam(final Boolean b) { - if (filled.get(79)) { + if (filled.get(80)) { throw new IllegalStateException("hub.scenario/PRC_FAILURE_KNOWN_TO_RAM already set"); } else { - filled.set(79); + filled.set(80); } - prcFailureKnownToRamXorMulFlag.put((byte) (b ? 1 : 0)); + prcFailureKnownToRamXorMxpx.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcIdentity(final Boolean b) { - if (filled.get(80)) { + if (filled.get(81)) { throw new IllegalStateException("hub.scenario/PRC_IDENTITY already set"); } else { - filled.set(80); + filled.set(81); } - prcIdentityXorMxpx.put((byte) (b ? 1 : 0)); + prcIdentityXorMxpFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcModexp(final Boolean b) { - if (filled.get(81)) { + if (filled.get(82)) { throw new IllegalStateException("hub.scenario/PRC_MODEXP already set"); } else { - filled.set(81); + filled.set(82); } - prcModexpXorMxpFlag.put((byte) (b ? 1 : 0)); + prcModexpXorOogx.put((byte) (b ? 1 : 0)); return this; } @@ -4519,189 +4529,189 @@ public Trace pScenarioPrcReturnGas(final long b) { } public Trace pScenarioPrcRipemd160(final Boolean b) { - if (filled.get(82)) { + if (filled.get(83)) { throw new IllegalStateException("hub.scenario/PRC_RIPEMD-160 already set"); } else { - filled.set(82); + filled.set(83); } - prcRipemd160XorOogx.put((byte) (b ? 1 : 0)); + prcRipemd160XorOpcx.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcSha2256(final Boolean b) { - if (filled.get(83)) { + if (filled.get(84)) { throw new IllegalStateException("hub.scenario/PRC_SHA2-256 already set"); } else { - filled.set(83); + filled.set(84); } - prcSha2256XorOpcx.put((byte) (b ? 1 : 0)); + prcSha2256XorPushpopFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcSuccessCallerWillRevert(final Boolean b) { - if (filled.get(84)) { + if (filled.get(85)) { throw new IllegalStateException("hub.scenario/PRC_SUCCESS_CALLER_WILL_REVERT already set"); } else { - filled.set(84); + filled.set(85); } - prcSuccessCallerWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); + prcSuccessCallerWillRevertXorRdcx.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcSuccessCallerWontRevert(final Boolean b) { - if (filled.get(85)) { + if (filled.get(86)) { throw new IllegalStateException("hub.scenario/PRC_SUCCESS_CALLER_WONT_REVERT already set"); } else { - filled.set(85); + filled.set(86); } - prcSuccessCallerWontRevertXorRdcx.put((byte) (b ? 1 : 0)); + prcSuccessCallerWontRevertXorShfFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioReturnException(final Boolean b) { - if (filled.get(86)) { + if (filled.get(87)) { throw new IllegalStateException("hub.scenario/RETURN_EXCEPTION already set"); } else { - filled.set(86); + filled.set(87); } - returnExceptionXorShfFlag.put((byte) (b ? 1 : 0)); + returnExceptionXorSox.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { - if (filled.get(87)) { + if (filled.get(88)) { throw new IllegalStateException( "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { - filled.set(87); + filled.set(88); } - returnFromDeploymentEmptyCodeWillRevertXorSox.put((byte) (b ? 1 : 0)); + returnFromDeploymentEmptyCodeWillRevertXorSstorex.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { - if (filled.get(88)) { + if (filled.get(89)) { throw new IllegalStateException( "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { - filled.set(88); + filled.set(89); } - returnFromDeploymentEmptyCodeWontRevertXorSstorex.put((byte) (b ? 1 : 0)); + returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { - if (filled.get(89)) { + if (filled.get(90)) { throw new IllegalStateException( "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { - filled.set(89); + filled.set(90); } - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.put((byte) (b ? 1 : 0)); + returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { - if (filled.get(90)) { + if (filled.get(91)) { throw new IllegalStateException( "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { - filled.set(90); + filled.set(91); } - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.put((byte) (b ? 1 : 0)); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { - if (filled.get(91)) { + if (filled.get(92)) { throw new IllegalStateException( "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { - filled.set(91); + filled.set(92); } - returnFromMessageCallWillTouchRamXorStackItemPop2.put((byte) (b ? 1 : 0)); + returnFromMessageCallWillTouchRamXorStackItemPop3.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { - if (filled.get(92)) { + if (filled.get(93)) { throw new IllegalStateException( "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { - filled.set(92); + filled.set(93); } - returnFromMessageCallWontTouchRamXorStackItemPop3.put((byte) (b ? 1 : 0)); + returnFromMessageCallWontTouchRamXorStackItemPop4.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioSelfdestructException(final Boolean b) { - if (filled.get(93)) { + if (filled.get(94)) { throw new IllegalStateException("hub.scenario/SELFDESTRUCT_EXCEPTION already set"); } else { - filled.set(93); + filled.set(94); } - selfdestructExceptionXorStackItemPop4.put((byte) (b ? 1 : 0)); + selfdestructExceptionXorStaticx.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioSelfdestructWillRevert(final Boolean b) { - if (filled.get(94)) { + if (filled.get(95)) { throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WILL_REVERT already set"); } else { - filled.set(94); + filled.set(95); } - selfdestructWillRevertXorStaticx.put((byte) (b ? 1 : 0)); + selfdestructWillRevertXorStaticFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { - if (filled.get(95)) { + if (filled.get(96)) { throw new IllegalStateException( "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { - filled.set(95); + filled.set(96); } - selfdestructWontRevertAlreadyMarkedXorStaticFlag.put((byte) (b ? 1 : 0)); + selfdestructWontRevertAlreadyMarkedXorStoFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { - if (filled.get(96)) { + if (filled.get(97)) { throw new IllegalStateException( "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { - filled.set(96); + filled.set(97); } - selfdestructWontRevertNotYetMarkedXorStoFlag.put((byte) (b ? 1 : 0)); + selfdestructWontRevertNotYetMarkedXorSux.put((byte) (b ? 1 : 0)); return this; } @@ -4713,8 +4723,8 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .put((byte) (b ? 1 : 0)); return this; } @@ -4726,7 +4736,7 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .put((byte) (b ? 1 : 0)); return this; @@ -4751,7 +4761,7 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -4764,8 +4774,8 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .put((byte) (b ? 1 : 0)); return this; } @@ -4777,7 +4787,7 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -4790,8 +4800,7 @@ public Trace pStackConFlag(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -4803,7 +4812,7 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( (byte) (b ? 1 : 0)); return this; @@ -4816,7 +4825,7 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( (byte) (b ? 1 : 0)); return this; @@ -4829,7 +4838,7 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero .put((byte) (b ? 1 : 0)); return this; @@ -4842,7 +4851,7 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -4855,7 +4864,7 @@ public Trace pStackDecFlag3(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; @@ -4868,7 +4877,7 @@ public Trace pStackDecFlag4(final Boolean b) { filled.set(63); } - romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); return this; } @@ -4892,7 +4901,7 @@ public Trace pStackDupFlag(final Boolean b) { filled.set(64); } - trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorStpWarmthXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4904,7 +4913,7 @@ public Trace pStackExtFlag(final Boolean b) { filled.set(65); } - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.put((byte) (b ? 1 : 0)); + warmthXorCreateEmptyInitCodeWillRevertXorExtFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4916,7 +4925,7 @@ public Trace pStackHaltFlag(final Boolean b) { filled.set(66); } - warmthNewXorCreateExceptionXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthNewXorCreateEmptyInitCodeWontRevertXorHaltFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4928,7 +4937,7 @@ public Trace pStackHashInfoFlag(final Boolean b) { filled.set(67); } - createFailureConditionWillRevertXorHashInfoFlag.put((byte) (b ? 1 : 0)); + createExceptionXorHashInfoFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5000,7 +5009,7 @@ public Trace pStackIcpx(final Boolean b) { filled.set(68); } - createFailureConditionWontRevertXorIcpx.put((byte) (b ? 1 : 0)); + createFailureConditionWillRevertXorIcpx.put((byte) (b ? 1 : 0)); return this; } @@ -5038,7 +5047,7 @@ public Trace pStackInvalidFlag(final Boolean b) { filled.set(69); } - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); + createFailureConditionWontRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5050,7 +5059,7 @@ public Trace pStackJumpDestinationVettingRequired(final Boolean b) { filled.set(71); } - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.put( + createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.put( (byte) (b ? 1 : 0)); return this; @@ -5063,7 +5072,7 @@ public Trace pStackJumpFlag(final Boolean b) { filled.set(72); } - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWillRevertXorJumpFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5075,7 +5084,7 @@ public Trace pStackJumpx(final Boolean b) { filled.set(70); } - createNonemptyInitCodeFailureWontRevertXorJumpx.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeFailureWillRevertXorJumpx.put((byte) (b ? 1 : 0)); return this; } @@ -5087,7 +5096,7 @@ public Trace pStackKecFlag(final Boolean b) { filled.set(73); } - prcBlake2FXorKecFlag.put((byte) (b ? 1 : 0)); + createNonemptyInitCodeSuccessWontRevertXorKecFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5099,7 +5108,7 @@ public Trace pStackLogFlag(final Boolean b) { filled.set(74); } - prcEcaddXorLogFlag.put((byte) (b ? 1 : 0)); + prcBlake2FXorLogFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5111,7 +5120,7 @@ public Trace pStackLogInfoFlag(final Boolean b) { filled.set(75); } - prcEcmulXorLogInfoFlag.put((byte) (b ? 1 : 0)); + prcEcaddXorLogInfoFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5123,7 +5132,7 @@ public Trace pStackMachineStateFlag(final Boolean b) { filled.set(76); } - prcEcpairingXorMachineStateFlag.put((byte) (b ? 1 : 0)); + prcEcmulXorMachineStateFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5135,7 +5144,7 @@ public Trace pStackMaxcsx(final Boolean b) { filled.set(77); } - prcEcrecoverXorMaxcsx.put((byte) (b ? 1 : 0)); + prcEcpairingXorMaxcsx.put((byte) (b ? 1 : 0)); return this; } @@ -5147,7 +5156,7 @@ public Trace pStackModFlag(final Boolean b) { filled.set(78); } - prcFailureKnownToHubXorModFlag.put((byte) (b ? 1 : 0)); + prcEcrecoverXorModFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5159,7 +5168,7 @@ public Trace pStackMulFlag(final Boolean b) { filled.set(79); } - prcFailureKnownToRamXorMulFlag.put((byte) (b ? 1 : 0)); + prcFailureKnownToHubXorMulFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5171,7 +5180,7 @@ public Trace pStackMxpFlag(final Boolean b) { filled.set(81); } - prcModexpXorMxpFlag.put((byte) (b ? 1 : 0)); + prcIdentityXorMxpFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5183,7 +5192,7 @@ public Trace pStackMxpx(final Boolean b) { filled.set(80); } - prcIdentityXorMxpx.put((byte) (b ? 1 : 0)); + prcFailureKnownToRamXorMxpx.put((byte) (b ? 1 : 0)); return this; } @@ -5219,7 +5228,7 @@ public Trace pStackOogx(final Boolean b) { filled.set(82); } - prcRipemd160XorOogx.put((byte) (b ? 1 : 0)); + prcModexpXorOogx.put((byte) (b ? 1 : 0)); return this; } @@ -5231,7 +5240,7 @@ public Trace pStackOpcx(final Boolean b) { filled.set(83); } - prcSha2256XorOpcx.put((byte) (b ? 1 : 0)); + prcRipemd160XorOpcx.put((byte) (b ? 1 : 0)); return this; } @@ -5301,7 +5310,7 @@ public Trace pStackPushpopFlag(final Boolean b) { filled.set(84); } - prcSuccessCallerWillRevertXorPushpopFlag.put((byte) (b ? 1 : 0)); + prcSha2256XorPushpopFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5313,7 +5322,7 @@ public Trace pStackRdcx(final Boolean b) { filled.set(85); } - prcSuccessCallerWontRevertXorRdcx.put((byte) (b ? 1 : 0)); + prcSuccessCallerWillRevertXorRdcx.put((byte) (b ? 1 : 0)); return this; } @@ -5325,7 +5334,7 @@ public Trace pStackShfFlag(final Boolean b) { filled.set(86); } - returnExceptionXorShfFlag.put((byte) (b ? 1 : 0)); + prcSuccessCallerWontRevertXorShfFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5337,7 +5346,7 @@ public Trace pStackSox(final Boolean b) { filled.set(87); } - returnFromDeploymentEmptyCodeWillRevertXorSox.put((byte) (b ? 1 : 0)); + returnExceptionXorSox.put((byte) (b ? 1 : 0)); return this; } @@ -5349,7 +5358,7 @@ public Trace pStackSstorex(final Boolean b) { filled.set(88); } - returnFromDeploymentEmptyCodeWontRevertXorSstorex.put((byte) (b ? 1 : 0)); + returnFromDeploymentEmptyCodeWillRevertXorSstorex.put((byte) (b ? 1 : 0)); return this; } @@ -5465,7 +5474,7 @@ public Trace pStackStackItemPop1(final Boolean b) { filled.set(90); } - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.put((byte) (b ? 1 : 0)); + returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.put((byte) (b ? 1 : 0)); return this; } @@ -5477,7 +5486,7 @@ public Trace pStackStackItemPop2(final Boolean b) { filled.set(91); } - returnFromMessageCallWillTouchRamXorStackItemPop2.put((byte) (b ? 1 : 0)); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.put((byte) (b ? 1 : 0)); return this; } @@ -5489,7 +5498,7 @@ public Trace pStackStackItemPop3(final Boolean b) { filled.set(92); } - returnFromMessageCallWontTouchRamXorStackItemPop3.put((byte) (b ? 1 : 0)); + returnFromMessageCallWillTouchRamXorStackItemPop3.put((byte) (b ? 1 : 0)); return this; } @@ -5501,7 +5510,7 @@ public Trace pStackStackItemPop4(final Boolean b) { filled.set(93); } - selfdestructExceptionXorStackItemPop4.put((byte) (b ? 1 : 0)); + returnFromMessageCallWontTouchRamXorStackItemPop4.put((byte) (b ? 1 : 0)); return this; } @@ -5825,7 +5834,7 @@ public Trace pStackStackramFlag(final Boolean b) { filled.set(89); } - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.put((byte) (b ? 1 : 0)); + returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5837,7 +5846,7 @@ public Trace pStackStaticFlag(final Boolean b) { filled.set(95); } - selfdestructWontRevertAlreadyMarkedXorStaticFlag.put((byte) (b ? 1 : 0)); + selfdestructWillRevertXorStaticFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5874,7 +5883,7 @@ public Trace pStackStaticx(final Boolean b) { filled.set(94); } - selfdestructWillRevertXorStaticx.put((byte) (b ? 1 : 0)); + selfdestructExceptionXorStaticx.put((byte) (b ? 1 : 0)); return this; } @@ -5886,7 +5895,7 @@ public Trace pStackStoFlag(final Boolean b) { filled.set(96); } - selfdestructWontRevertNotYetMarkedXorStoFlag.put((byte) (b ? 1 : 0)); + selfdestructWontRevertAlreadyMarkedXorStoFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5898,7 +5907,7 @@ public Trace pStackSux(final Boolean b) { filled.set(97); } - sux.put((byte) (b ? 1 : 0)); + selfdestructWontRevertNotYetMarkedXorSux.put((byte) (b ? 1 : 0)); return this; } @@ -6111,8 +6120,8 @@ public Trace pStorageUnconstrainedFinal(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .put((byte) (b ? 1 : 0)); return this; } @@ -6124,7 +6133,7 @@ public Trace pStorageUnconstrainedFirst(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .put((byte) (b ? 1 : 0)); return this; @@ -6137,7 +6146,7 @@ public Trace pStorageValueCurrChanges(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -6178,8 +6187,8 @@ public Trace pStorageValueCurrIsOrig(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .put((byte) (b ? 1 : 0)); return this; } @@ -6191,7 +6200,7 @@ public Trace pStorageValueCurrIsZero(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -6258,8 +6267,7 @@ public Trace pStorageValueNextIsCurr(final Boolean b) { filled.set(57); } - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.put( - (byte) (b ? 1 : 0)); + hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -6271,7 +6279,7 @@ public Trace pStorageValueNextIsOrig(final Boolean b) { filled.set(58); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.put( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( (byte) (b ? 1 : 0)); return this; @@ -6284,7 +6292,7 @@ public Trace pStorageValueNextIsZero(final Boolean b) { filled.set(59); } - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero.put( + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( (byte) (b ? 1 : 0)); return this; @@ -6351,7 +6359,7 @@ public Trace pStorageValueOrigIsZero(final Boolean b) { filled.set(60); } - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero .put((byte) (b ? 1 : 0)); return this; @@ -6392,7 +6400,7 @@ public Trace pStorageWarmth(final Boolean b) { filled.set(61); } - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth.put( + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth.put( (byte) (b ? 1 : 0)); return this; @@ -6405,7 +6413,7 @@ public Trace pStorageWarmthNew(final Boolean b) { filled.set(62); } - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.put( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( (byte) (b ? 1 : 0)); return this; @@ -6549,8 +6557,8 @@ public Trace pTransactionCopyTxcd(final Boolean b) { filled.set(52); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + .put((byte) (b ? 1 : 0)); return this; } @@ -6774,7 +6782,7 @@ public Trace pTransactionIsDeployment(final Boolean b) { filled.set(53); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .put((byte) (b ? 1 : 0)); return this; @@ -6787,7 +6795,7 @@ public Trace pTransactionIsType2(final Boolean b) { filled.set(54); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -6903,8 +6911,8 @@ public Trace pTransactionRequiresEvmExecution(final Boolean b) { filled.set(55); } - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution.put( - (byte) (b ? 1 : 0)); + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + .put((byte) (b ? 1 : 0)); return this; } @@ -6916,7 +6924,7 @@ public Trace pTransactionStatusCode(final Boolean b) { filled.set(56); } - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -7419,32 +7427,37 @@ public Trace validateRow() { if (!filled.get(67)) { throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_HASH_INFO_FLAG has not been filled"); + "hub.CREATE_EXCEPTION_xor_HASH_INFO_FLAG has not been filled"); } if (!filled.get(68)) { throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_ICPX has not been filled"); + "hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX has not been filled"); } if (!filled.get(69)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_INVALID_FLAG has not been filled"); + "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG has not been filled"); } if (!filled.get(70)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMPX has not been filled"); + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX has not been filled"); } if (!filled.get(71)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); } if (!filled.get(72)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_JUMP_FLAG has not been filled"); + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG has not been filled"); + } + + if (!filled.get(73)) { + throw new IllegalStateException( + "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG has not been filled"); } if (!filled.get(102)) { @@ -7468,17 +7481,17 @@ public Trace validateRow() { if (!filled.get(53)) { throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT has not been filled"); + "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(54)) { throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2 has not been filled"); + "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2 has not been filled"); } if (!filled.get(52)) { throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD has not been filled"); + "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD has not been filled"); } if (!filled.get(13)) { @@ -7491,12 +7504,12 @@ public Trace validateRow() { if (!filled.get(56)) { throw new IllegalStateException( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_PRC_FAILURE_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE has not been filled"); + "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE has not been filled"); } if (!filled.get(55)) { throw new IllegalStateException( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EXCEPTION_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION has not been filled"); + "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 has not been filled"); } if (!filled.get(15)) { @@ -7525,12 +7538,12 @@ public Trace validateRow() { if (!filled.get(58)) { throw new IllegalStateException( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); + "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); } if (!filled.get(57)) { throw new IllegalStateException( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); + "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); } if (!filled.get(19)) { @@ -7559,7 +7572,7 @@ public Trace validateRow() { if (!filled.get(59)) { throw new IllegalStateException( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(24)) { @@ -7568,12 +7581,12 @@ public Trace validateRow() { if (!filled.get(61)) { throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_2_xor_WARMTH has not been filled"); + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_STP_EXISTS_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_WARMTH has not been filled"); } if (!filled.get(60)) { throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO has not been filled"); + "hub.MARKED_FOR_SELFDESTRUCT_xor_OOB_FLAG_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(25)) { @@ -7697,61 +7710,59 @@ public Trace validateRow() { throw new IllegalStateException("hub.PEEK_AT_TRANSACTION has not been filled"); } - if (!filled.get(73)) { - throw new IllegalStateException("hub.PRC_BLAKE2f_xor_KEC_FLAG has not been filled"); - } - if (!filled.get(74)) { - throw new IllegalStateException("hub.PRC_ECADD_xor_LOG_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_BLAKE2f_xor_LOG_FLAG has not been filled"); } if (!filled.get(75)) { - throw new IllegalStateException("hub.PRC_ECMUL_xor_LOG_INFO_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_ECADD_xor_LOG_INFO_FLAG has not been filled"); } if (!filled.get(76)) { - throw new IllegalStateException( - "hub.PRC_ECPAIRING_xor_MACHINE_STATE_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_ECMUL_xor_MACHINE_STATE_FLAG has not been filled"); } if (!filled.get(77)) { - throw new IllegalStateException("hub.PRC_ECRECOVER_xor_MAXCSX has not been filled"); + throw new IllegalStateException("hub.PRC_ECPAIRING_xor_MAXCSX has not been filled"); } if (!filled.get(78)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MOD_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_ECRECOVER_xor_MOD_FLAG has not been filled"); } if (!filled.get(79)) { throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MUL_FLAG has not been filled"); + "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MUL_FLAG has not been filled"); } if (!filled.get(80)) { - throw new IllegalStateException("hub.PRC_IDENTITY_xor_MXPX has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MXPX has not been filled"); } if (!filled.get(81)) { - throw new IllegalStateException("hub.PRC_MODEXP_xor_MXP_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_IDENTITY_xor_MXP_FLAG has not been filled"); } if (!filled.get(82)) { - throw new IllegalStateException("hub.PRC_RIPEMD-160_xor_OOGX has not been filled"); + throw new IllegalStateException("hub.PRC_MODEXP_xor_OOGX has not been filled"); } if (!filled.get(83)) { - throw new IllegalStateException("hub.PRC_SHA2-256_xor_OPCX has not been filled"); + throw new IllegalStateException("hub.PRC_RIPEMD-160_xor_OPCX has not been filled"); } if (!filled.get(84)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_PUSHPOP_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_SHA2-256_xor_PUSHPOP_FLAG has not been filled"); } if (!filled.get(85)) { throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_RDCX has not been filled"); + "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_RDCX has not been filled"); + } + + if (!filled.get(86)) { + throw new IllegalStateException( + "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_SHF_FLAG has not been filled"); } if (!filled.get(129)) { @@ -7804,38 +7815,38 @@ public Trace validateRow() { throw new IllegalStateException("hub.RETURN_DATA_SIZE has not been filled"); } - if (!filled.get(86)) { - throw new IllegalStateException("hub.RETURN_EXCEPTION_xor_SHF_FLAG has not been filled"); - } - if (!filled.get(87)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SOX has not been filled"); + throw new IllegalStateException("hub.RETURN_EXCEPTION_xor_SOX has not been filled"); } if (!filled.get(88)) { throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_SSTOREX has not been filled"); + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(89)) { throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACKRAM_FLAG has not been filled"); + "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(90)) { throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(91)) { throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_2 has not been filled"); + "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(92)) { throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + } + + if (!filled.get(93)) { + throw new IllegalStateException( + "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_4 has not been filled"); } if (!filled.get(114)) { @@ -7850,7 +7861,7 @@ public Trace validateRow() { if (!filled.get(62)) { throw new IllegalStateException( - "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW has not been filled"); + "hub.RLPADDR_FLAG_xor_STP_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW has not been filled"); } if (!filled.get(140)) { @@ -7878,27 +7889,26 @@ public Trace validateRow() { if (!filled.get(63)) { throw new IllegalStateException( - "hub.ROMLEX_FLAG_xor_STP_OOGX_xor_CREATE_ABORT_xor_DEC_FLAG_4 has not been filled"); - } - - if (!filled.get(93)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_EXCEPTION_xor_STACK_ITEM_POP_4 has not been filled"); + "hub.ROMLEX_FLAG_xor_STP_OOGX_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4 has not been filled"); } if (!filled.get(94)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WILL_REVERT_xor_STATICX has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_EXCEPTION_xor_STATICX has not been filled"); } if (!filled.get(95)) { throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STATIC_FLAG has not been filled"); + "hub.SELFDESTRUCT_WILL_REVERT_xor_STATIC_FLAG has not been filled"); } if (!filled.get(96)) { throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_STO_FLAG has not been filled"); + "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STO_FLAG has not been filled"); + } + + if (!filled.get(97)) { + throw new IllegalStateException( + "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_SUX has not been filled"); } if (!filled.get(165)) { @@ -7998,17 +8008,13 @@ public Trace validateRow() { throw new IllegalStateException("hub.SUB_STAMP has not been filled"); } - if (!filled.get(97)) { - throw new IllegalStateException("hub.SUX has not been filled"); - } - if (!filled.get(98)) { throw new IllegalStateException("hub.SWAP_FLAG has not been filled"); } if (!filled.get(64)) { throw new IllegalStateException( - "hub.TRM_FLAG_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_DUP_FLAG has not been filled"); + "hub.TRM_FLAG_xor_STP_WARMTH_xor_CREATE_ABORT_xor_DUP_FLAG has not been filled"); } if (!filled.get(144)) { @@ -8046,12 +8052,12 @@ public Trace validateRow() { if (!filled.get(66)) { throw new IllegalStateException( - "hub.WARMTH_NEW_xor_CREATE_EXCEPTION_xor_HALT_FLAG has not been filled"); + "hub.WARMTH_NEW_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG has not been filled"); } if (!filled.get(65)) { throw new IllegalStateException( - "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_EXT_FLAG has not been filled"); + "hub.WARMTH_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG has not been filled"); } if (!filled.get(100)) { @@ -8229,33 +8235,37 @@ public Trace fillAndValidateRow() { } if (!filled.get(67)) { - createFailureConditionWillRevertXorHashInfoFlag.position( - createFailureConditionWillRevertXorHashInfoFlag.position() + 1); + createExceptionXorHashInfoFlag.position(createExceptionXorHashInfoFlag.position() + 1); } if (!filled.get(68)) { - createFailureConditionWontRevertXorIcpx.position( - createFailureConditionWontRevertXorIcpx.position() + 1); + createFailureConditionWillRevertXorIcpx.position( + createFailureConditionWillRevertXorIcpx.position() + 1); } if (!filled.get(69)) { - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position( - createNonemptyInitCodeFailureWillRevertXorInvalidFlag.position() + 1); + createFailureConditionWontRevertXorInvalidFlag.position( + createFailureConditionWontRevertXorInvalidFlag.position() + 1); } if (!filled.get(70)) { - createNonemptyInitCodeFailureWontRevertXorJumpx.position( - createNonemptyInitCodeFailureWontRevertXorJumpx.position() + 1); + createNonemptyInitCodeFailureWillRevertXorJumpx.position( + createNonemptyInitCodeFailureWillRevertXorJumpx.position() + 1); } if (!filled.get(71)) { - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position( - createNonemptyInitCodeSuccessWillRevertXorJumpDestinationVettingRequired.position() + 1); + createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.position( + createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.position() + 1); } if (!filled.get(72)) { - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position( - createNonemptyInitCodeSuccessWontRevertXorJumpFlag.position() + 1); + createNonemptyInitCodeSuccessWillRevertXorJumpFlag.position( + createNonemptyInitCodeSuccessWillRevertXorJumpFlag.position() + 1); + } + + if (!filled.get(73)) { + createNonemptyInitCodeSuccessWontRevertXorKecFlag.position( + createNonemptyInitCodeSuccessWontRevertXorKecFlag.position() + 1); } if (!filled.get(102)) { @@ -8281,25 +8291,25 @@ public Trace fillAndValidateRow() { } if (!filled.get(53)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .position( - deploymentStatusInftyXorIsStaticXorExpFlagXorCallEoaSuccessCallerWillRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment .position() + 1); } if (!filled.get(54)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .position( - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWontRevertXorBinFlagXorValueCurrChangesXorIsType2 + deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 .position() + 1); } if (!filled.get(52)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd .position( - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortXorAccFlagXorUnconstrainedFinalXorCopyTxcd + deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd .position() + 1); } @@ -8313,16 +8323,16 @@ public Trace fillAndValidateRow() { } if (!filled.get(56)) { - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode.position( - existsNewXorMxpDeploysXorCallPrcFailureXorCallFlagXorValueCurrIsZeroXorStatusCode + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.position( + existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode .position() + 1); } if (!filled.get(55)) { - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution .position( - existsXorMmuSuccessBitXorCallExceptionXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution .position() + 1); } @@ -8352,16 +8362,15 @@ public Trace fillAndValidateRow() { } if (!filled.get(58)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig.position( - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWontRevertXorCopyFlagXorValueNextIsOrig + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.position( + hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig .position() + 1); } if (!filled.get(57)) { - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position( - hasCodeXorMxpFlagXorCallPrcSuccessCallerWillRevertXorConFlagXorValueNextIsCurr.position() - + 1); + hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.position( + hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.position() + 1); } if (!filled.get(19)) { @@ -8389,9 +8398,9 @@ public Trace fillAndValidateRow() { } if (!filled.get(59)) { - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero .position( - isPrecompileXorMxpMxpxXorCallSmcFailureCallerWillRevertXorCreateFlagXorValueNextIsZero + isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero .position() + 1); } @@ -8401,17 +8410,17 @@ public Trace fillAndValidateRow() { } if (!filled.get(61)) { - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth .position( - markedForSelfdestructNewXorStpExistsXorCallSmcSuccessCallerWillRevertXorDecFlag2XorWarmth + markedForSelfdestructNewXorStpExistsXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth .position() + 1); } if (!filled.get(60)) { - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero .position( - markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWontRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorOobFlagXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero .position() + 1); } @@ -8537,57 +8546,57 @@ public Trace fillAndValidateRow() { peekAtTransaction.position(peekAtTransaction.position() + 1); } - if (!filled.get(73)) { - prcBlake2FXorKecFlag.position(prcBlake2FXorKecFlag.position() + 1); - } - if (!filled.get(74)) { - prcEcaddXorLogFlag.position(prcEcaddXorLogFlag.position() + 1); + prcBlake2FXorLogFlag.position(prcBlake2FXorLogFlag.position() + 1); } if (!filled.get(75)) { - prcEcmulXorLogInfoFlag.position(prcEcmulXorLogInfoFlag.position() + 1); + prcEcaddXorLogInfoFlag.position(prcEcaddXorLogInfoFlag.position() + 1); } if (!filled.get(76)) { - prcEcpairingXorMachineStateFlag.position(prcEcpairingXorMachineStateFlag.position() + 1); + prcEcmulXorMachineStateFlag.position(prcEcmulXorMachineStateFlag.position() + 1); } if (!filled.get(77)) { - prcEcrecoverXorMaxcsx.position(prcEcrecoverXorMaxcsx.position() + 1); + prcEcpairingXorMaxcsx.position(prcEcpairingXorMaxcsx.position() + 1); } if (!filled.get(78)) { - prcFailureKnownToHubXorModFlag.position(prcFailureKnownToHubXorModFlag.position() + 1); + prcEcrecoverXorModFlag.position(prcEcrecoverXorModFlag.position() + 1); } if (!filled.get(79)) { - prcFailureKnownToRamXorMulFlag.position(prcFailureKnownToRamXorMulFlag.position() + 1); + prcFailureKnownToHubXorMulFlag.position(prcFailureKnownToHubXorMulFlag.position() + 1); } if (!filled.get(80)) { - prcIdentityXorMxpx.position(prcIdentityXorMxpx.position() + 1); + prcFailureKnownToRamXorMxpx.position(prcFailureKnownToRamXorMxpx.position() + 1); } if (!filled.get(81)) { - prcModexpXorMxpFlag.position(prcModexpXorMxpFlag.position() + 1); + prcIdentityXorMxpFlag.position(prcIdentityXorMxpFlag.position() + 1); } if (!filled.get(82)) { - prcRipemd160XorOogx.position(prcRipemd160XorOogx.position() + 1); + prcModexpXorOogx.position(prcModexpXorOogx.position() + 1); } if (!filled.get(83)) { - prcSha2256XorOpcx.position(prcSha2256XorOpcx.position() + 1); + prcRipemd160XorOpcx.position(prcRipemd160XorOpcx.position() + 1); } if (!filled.get(84)) { - prcSuccessCallerWillRevertXorPushpopFlag.position( - prcSuccessCallerWillRevertXorPushpopFlag.position() + 1); + prcSha2256XorPushpopFlag.position(prcSha2256XorPushpopFlag.position() + 1); } if (!filled.get(85)) { - prcSuccessCallerWontRevertXorRdcx.position(prcSuccessCallerWontRevertXorRdcx.position() + 1); + prcSuccessCallerWillRevertXorRdcx.position(prcSuccessCallerWillRevertXorRdcx.position() + 1); + } + + if (!filled.get(86)) { + prcSuccessCallerWontRevertXorShfFlag.position( + prcSuccessCallerWontRevertXorShfFlag.position() + 1); } if (!filled.get(129)) { @@ -8639,38 +8648,38 @@ public Trace fillAndValidateRow() { returnDataSize.position(returnDataSize.position() + 4); } - if (!filled.get(86)) { - returnExceptionXorShfFlag.position(returnExceptionXorShfFlag.position() + 1); - } - if (!filled.get(87)) { - returnFromDeploymentEmptyCodeWillRevertXorSox.position( - returnFromDeploymentEmptyCodeWillRevertXorSox.position() + 1); + returnExceptionXorSox.position(returnExceptionXorSox.position() + 1); } if (!filled.get(88)) { - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position( - returnFromDeploymentEmptyCodeWontRevertXorSstorex.position() + 1); + returnFromDeploymentEmptyCodeWillRevertXorSstorex.position( + returnFromDeploymentEmptyCodeWillRevertXorSstorex.position() + 1); } if (!filled.get(89)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position( - returnFromDeploymentNonemptyCodeWillRevertXorStackramFlag.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.position( + returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.position() + 1); } if (!filled.get(90)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position( - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop1.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.position( + returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.position() + 1); } if (!filled.get(91)) { - returnFromMessageCallWillTouchRamXorStackItemPop2.position( - returnFromMessageCallWillTouchRamXorStackItemPop2.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.position( + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.position() + 1); } if (!filled.get(92)) { - returnFromMessageCallWontTouchRamXorStackItemPop3.position( - returnFromMessageCallWontTouchRamXorStackItemPop3.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop3.position( + returnFromMessageCallWillTouchRamXorStackItemPop3.position() + 1); + } + + if (!filled.get(93)) { + returnFromMessageCallWontTouchRamXorStackItemPop4.position( + returnFromMessageCallWontTouchRamXorStackItemPop4.position() + 1); } if (!filled.get(114)) { @@ -8684,8 +8693,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(62)) { - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position( - rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWontRevertXorDecFlag3XorWarmthNew.position() + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.position( + rlpaddrFlagXorStpFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.position() + 1); } @@ -8711,27 +8720,27 @@ public Trace fillAndValidateRow() { } if (!filled.get(63)) { - romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.position( - romlexFlagXorStpOogxXorCreateAbortXorDecFlag4.position() + 1); - } - - if (!filled.get(93)) { - selfdestructExceptionXorStackItemPop4.position( - selfdestructExceptionXorStackItemPop4.position() + 1); + romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4.position( + romlexFlagXorStpOogxXorCallSmcSuccessCallerWontRevertXorDecFlag4.position() + 1); } if (!filled.get(94)) { - selfdestructWillRevertXorStaticx.position(selfdestructWillRevertXorStaticx.position() + 1); + selfdestructExceptionXorStaticx.position(selfdestructExceptionXorStaticx.position() + 1); } if (!filled.get(95)) { - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position( - selfdestructWontRevertAlreadyMarkedXorStaticFlag.position() + 1); + selfdestructWillRevertXorStaticFlag.position( + selfdestructWillRevertXorStaticFlag.position() + 1); } if (!filled.get(96)) { - selfdestructWontRevertNotYetMarkedXorStoFlag.position( - selfdestructWontRevertNotYetMarkedXorStoFlag.position() + 1); + selfdestructWontRevertAlreadyMarkedXorStoFlag.position( + selfdestructWontRevertAlreadyMarkedXorStoFlag.position() + 1); + } + + if (!filled.get(97)) { + selfdestructWontRevertNotYetMarkedXorSux.position( + selfdestructWontRevertNotYetMarkedXorSux.position() + 1); } if (!filled.get(165)) { @@ -8831,17 +8840,13 @@ public Trace fillAndValidateRow() { subStamp.position(subStamp.position() + 4); } - if (!filled.get(97)) { - sux.position(sux.position() + 1); - } - if (!filled.get(98)) { swapFlag.position(swapFlag.position() + 1); } if (!filled.get(64)) { - trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position( - trmFlagXorStpWarmthXorCreateEmptyInitCodeWillRevertXorDupFlag.position() + 1); + trmFlagXorStpWarmthXorCreateAbortXorDupFlag.position( + trmFlagXorStpWarmthXorCreateAbortXorDupFlag.position() + 1); } if (!filled.get(144)) { @@ -8877,13 +8882,13 @@ public Trace fillAndValidateRow() { } if (!filled.get(66)) { - warmthNewXorCreateExceptionXorHaltFlag.position( - warmthNewXorCreateExceptionXorHaltFlag.position() + 1); + warmthNewXorCreateEmptyInitCodeWontRevertXorHaltFlag.position( + warmthNewXorCreateEmptyInitCodeWontRevertXorHaltFlag.position() + 1); } if (!filled.get(65)) { - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.position( - warmthXorCreateEmptyInitCodeWontRevertXorExtFlag.position() + 1); + warmthXorCreateEmptyInitCodeWillRevertXorExtFlag.position( + warmthXorCreateEmptyInitCodeWillRevertXorExtFlag.position() + 1); } if (!filled.get(100)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java new file mode 100644 index 0000000000..f576e5f768 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -0,0 +1,72 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment.scenario; + +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; + +public class CallScenarioFragment implements TraceFragment { + + CallScenario scenario; + + public CallScenarioFragment() { + this.scenario = CallScenario.UNDEFINED; + } + + public enum CallScenario { + UNDEFINED, + CALL_EXCEPTION, + CALL_ABORT_WILL_REVERT, + CALL_ABORT_WONT_REVERT, + CALL_EOA_SUCCESS_WILL_REVERT, + CALL_EOA_SUCCESS_WONT_REVERT, + CALL_SMC_FAILURE_WILL_REVERT, + CALL_SMC_FAILURE_WONT_REVERT, + CALL_SMC_SUCCESS_WILL_REVERT, + CALL_SMC_SUCCESS_WONT_REVERT, + CALL_PRC_FAILURE, + CALL_PRC_SUCCESS_WILL_REVERT, + CALL_PRC_SUCCESS_WONT_REVERT + } + + public Trace trace(Trace trace) { + Preconditions.checkArgument(!this.scenario.equals(CallScenario.UNDEFINED)); + return trace + .peekAtScenario(true) + // // CALL scenarios + //////////////////// + .pScenarioCallException(this.scenario.equals(CallScenario.CALL_EXCEPTION)) + .pScenarioCallAbortWillRevert(this.scenario.equals(CallScenario.CALL_ABORT_WILL_REVERT)) + .pScenarioCallAbortWontRevert(this.scenario.equals(CallScenario.CALL_ABORT_WONT_REVERT)) + .pScenarioCallPrcFailure(this.scenario.equals(CallScenario.CALL_PRC_FAILURE)) + .pScenarioCallPrcSuccessCallerWillRevert( + this.scenario.equals(CallScenario.CALL_PRC_SUCCESS_WILL_REVERT)) + .pScenarioCallPrcSuccessCallerWontRevert( + this.scenario.equals(CallScenario.CALL_PRC_SUCCESS_WONT_REVERT)) + .pScenarioCallSmcFailureCallerWillRevert( + this.scenario.equals(CallScenario.CALL_SMC_FAILURE_WILL_REVERT)) + .pScenarioCallSmcFailureCallerWontRevert( + this.scenario.equals(CallScenario.CALL_SMC_FAILURE_WONT_REVERT)) + .pScenarioCallSmcSuccessCallerWontRevert( + this.scenario.equals(CallScenario.CALL_SMC_SUCCESS_WILL_REVERT)) + .pScenarioCallSmcSuccessCallerWillRevert( + this.scenario.equals(CallScenario.CALL_SMC_SUCCESS_WONT_REVERT)) + .pScenarioCallEoaSuccessCallerWontRevert( + this.scenario.equals(CallScenario.CALL_EOA_SUCCESS_WILL_REVERT)) + .pScenarioCallEoaSuccessCallerWillRevert( + this.scenario.equals(CallScenario.CALL_EOA_SUCCESS_WONT_REVERT)); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java index 248844fd29..344a1b5b86 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java @@ -22,6 +22,7 @@ public enum ScenarioEnum { /** scenarios related to CREATE(2) instructions */ CREATE_EXCEPTION, CREATE_ABORT, + CREATE_FAILURE_CONDITION_WILL_REVERT, CREATE_FAILURE_CONDITION_WONT_REVERT, CREATE_EMPTY_INIT_CODE_WILL_REVERT, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java index 9f04cbe28a..70ff0857a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java @@ -75,7 +75,8 @@ public SmartContractCallSection( hub.defers().scheduleForImmediateContextEntry(this); hub.defers().schedulePostTransaction(this); - // TODO: remove (but: ContextFragment calleeContextInitializationFragment = ContextFragment.initializeNewExecutionContext(hub); + // TODO: remove (but: ContextFragment calleeContextInitializationFragment = + // ContextFragment.initializeNewExecutionContext(hub); // should be added to the section } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 35f662ed2a..753a43ee22 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -260,8 +260,7 @@ public void resolvePostTransaction( // of both creator and createe were updated (and potentially created) // otherwise do it later @Override - public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { - } + public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) {} @Override public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { diff --git a/zkevm-constraints b/zkevm-constraints index 29b10da4cd..980397eee7 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 29b10da4cd96cfbe8bf12d84020fb4df177021db +Subproject commit 980397eee7544124a2603679cf1be8bec320b975 From e0b07f0abe85cdb4771ff1fcf0f7767ff2f0109b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 09:28:46 +0200 Subject: [PATCH 278/461] feat(CALL): wip --- .../linea/zktracer/module/hub/Hub.java | 262 +++++++++--------- .../module/hub/section/call/AbortCall.java | 36 +++ .../module/hub/section/call/CallSection.java | 90 ++++++ .../module/hub/section/call/NoCodeCall.java | 25 ++ .../module/hub/section/call/OogXCall.java | 74 +++++ .../hub/section/call/StaticMxpXCall.java | 39 +++ .../FailedCallSection.java | 2 +- .../NoCodeCallSection.java | 2 +- .../SmartContractCallSection.java | 5 +- .../hub/section/copy/ExtCodeCopySection.java | 2 +- .../hub/section/create/CreateSection.java | 5 +- .../create/NonEmptyInitCodeCreate.java | 2 +- .../hub/section/halt/ReturnSection.java | 2 +- .../linea/zktracer/module/romlex/RomLex.java | 2 +- .../linea/zktracer/module/trm/Trm.java | 6 + zkevm-constraints | 2 +- 16 files changed, 410 insertions(+), 146 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{calls => callsOld}/FailedCallSection.java (93%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{calls => callsOld}/NoCodeCallSection.java (99%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{calls => callsOld}/SmartContractCallSection.java (98%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 3e97535f42..1e9a4d8000 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -47,12 +47,8 @@ import net.consensys.linea.zktracer.module.gas.Gas; import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.section.AccountSection; import net.consensys.linea.zktracer.module.hub.section.CallDataLoadSection; import net.consensys.linea.zktracer.module.hub.section.ContextSection; @@ -70,9 +66,7 @@ import net.consensys.linea.zktracer.module.hub.section.TxInitializationSection; import net.consensys.linea.zktracer.module.hub.section.TxPreWarmingMacroSection; import net.consensys.linea.zktracer.module.hub.section.TxSkippedSectionDefers; -import net.consensys.linea.zktracer.module.hub.section.calls.FailedCallSection; -import net.consensys.linea.zktracer.module.hub.section.calls.NoCodeCallSection; -import net.consensys.linea.zktracer.module.hub.section.calls.SmartContractCallSection; +import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.module.hub.section.copy.CallDataCopySection; import net.consensys.linea.zktracer.module.hub.section.copy.CodeCopySection; import net.consensys.linea.zktracer.module.hub.section.copy.ExtCodeCopySection; @@ -132,13 +126,11 @@ import net.consensys.linea.zktracer.runtime.stack.StackLine; import net.consensys.linea.zktracer.types.Bytecode; import net.consensys.linea.zktracer.types.MemorySpan; -import net.consensys.linea.zktracer.types.Precompile; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountState; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @@ -215,7 +207,7 @@ public int lineCount() { private final Mul mul = new Mul(this); private final Mod mod = new Mod(); private final Shf shf = new Shf(); - private final Trm trm = new Trm(); + @Getter private final Trm trm = new Trm(); // other private final Blockdata blockdata; @@ -1091,130 +1083,132 @@ void traceOperation(MessageFrame frame) { case CREATE -> new CreateSection(this); - case CALL -> { - final Address myAddress = this.currentFrame().accountAddress(); - final Account myAccount = frame.getWorldUpdater().get(myAddress); - final AccountSnapshot myAccountSnapshot = - AccountSnapshot.fromAccount( - myAccount, - frame.isAddressWarm(myAddress), - this.transients.conflation().deploymentInfo().number(myAddress), - this.transients.conflation().deploymentInfo().isDeploying(myAddress)); - - final Bytes rawCalledAddress = frame.getStackItem(1); - final Address calledAddress = Words.toAddress(rawCalledAddress); - final Optional calledAccount = - Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)); - final boolean hasCode = calledAccount.map(AccountState::hasCode).orElse(false); - - final AccountSnapshot calledAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(myAddress), - this.transients.conflation().deploymentInfo().number(myAddress), - this.transients.conflation().deploymentInfo().isDeploying(myAddress)); - - Optional targetPrecompile = Precompile.maybeOf(calledAddress); - - if (Exceptions.any(this.pch().exceptions())) { - // - // THERE IS AN EXCEPTION - // - if (Exceptions.staticFault(this.pch().exceptions())) { - this.addTraceSection( - new FailedCallSection( - this, - ScenarioFragment.forCall(this, hasCode), - ImcFragment.forCall(this, myAccount, calledAccount), - ContextFragment.readContextDataByContextNumber( - this, this.currentFrame().contextNumber()))); // TODO - } else if (Exceptions.memoryExpansionException(this.pch().exceptions())) { - this.addTraceSection( - new FailedCallSection( - this, - ScenarioFragment.forCall(this, hasCode), - ImcFragment.forCall(this, myAccount, calledAccount))); - } else if (Exceptions.outOfGasException(this.pch().exceptions())) { - this.addTraceSection( - new FailedCallSection( - this, - ScenarioFragment.forCall(this, hasCode), - ImcFragment.forCall(this, myAccount, calledAccount), - this.factories - .accountFragment() - .makeWithTrm( - calledAccountSnapshot, - calledAccountSnapshot, - rawCalledAddress, - DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)))); - } - } else if (this.pch.abortingConditions().any()) { - // - // THERE IS AN ABORT - // - TraceSection abortedSection = - new FailedCallSection( - this, - ScenarioFragment.forCall(this, hasCode), - ImcFragment.forCall(this, myAccount, calledAccount), - ContextFragment.readCurrentContextData(this), - this.factories - .accountFragment() - .make( - myAccountSnapshot, - myAccountSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)), - this.factories - .accountFragment() - .makeWithTrm( - calledAccountSnapshot, - calledAccountSnapshot, - rawCalledAddress, - DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 1)), - ContextFragment.nonExecutionProvidesEmptyReturnData(this)); - this.addTraceSection(abortedSection); - } else { - final ImcFragment imcFragment = /* ImcFragment.forOpcode(this, frame)*/ - ImcFragment.empty(this); - - if (hasCode) { - final SmartContractCallSection section = - new SmartContractCallSection( - this, myAccountSnapshot, calledAccountSnapshot, rawCalledAddress, imcFragment); - this.addTraceSection(section); - this.currentFrame().sectionToUnlatch(section); - } else { - // - // CALL EXECUTED - // - - // TODO: fill the callee & requested return data for the current call frame - // i.e. ensure that the precompile frame behaves as expected - - Optional precompileInvocation = - targetPrecompile.map(p -> PrecompileInvocation.of(this, p)); - - // TODO: this is ugly, and surely not at the right place. It should provide the - // precompile result (from the precompile module) - // TODO useless (and potentially dangerous) if the precompile is a failure - if (targetPrecompile.isPresent()) { - this.callStack.newPrecompileResult( - this.stamp(), Bytes.EMPTY, 0, targetPrecompile.get().address); - } - - final NoCodeCallSection section = - new NoCodeCallSection( - this, - precompileInvocation, - myAccountSnapshot, - calledAccountSnapshot, - rawCalledAddress, - imcFragment); - this.addTraceSection(section); - this.currentFrame().sectionToUnlatch(section); - } - } - } + case CALL -> new CallSection(this); + // { + // final Address myAddress = this.currentFrame().accountAddress(); + // final Account myAccount = frame.getWorldUpdater().get(myAddress); + // final AccountSnapshot myAccountSnapshot = + // AccountSnapshot.fromAccount( + // myAccount, + // frame.isAddressWarm(myAddress), + // this.transients.conflation().deploymentInfo().number(myAddress), + // this.transients.conflation().deploymentInfo().isDeploying(myAddress)); + // + // final Bytes rawCalledAddress = frame.getStackItem(1); + // final Address calledAddress = Words.toAddress(rawCalledAddress); + // final Optional calledAccount = + // Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)); + // final boolean hasCode = calledAccount.map(AccountState::hasCode).orElse(false); + // + // final AccountSnapshot calledAccountSnapshot = + // AccountSnapshot.fromAccount( + // calledAccount, + // frame.isAddressWarm(myAddress), + // this.transients.conflation().deploymentInfo().number(myAddress), + // this.transients.conflation().deploymentInfo().isDeploying(myAddress)); + // + // Optional targetPrecompile = Precompile.maybeOf(calledAddress); + // + // if (Exceptions.any(this.pch().exceptions())) { + // // + // // THERE IS AN EXCEPTION + // // + // if (Exceptions.staticFault(this.pch().exceptions())) { + // this.addTraceSection( + // new FailedCallSection( + // this, + // ScenarioFragment.forCall(this, hasCode), + // ImcFragment.forCall(this, myAccount, calledAccount), + // ContextFragment.readContextDataByContextNumber( + // this, this.currentFrame().contextNumber()))); // TODO + // } else if (Exceptions.memoryExpansionException(this.pch().exceptions())) { + // this.addTraceSection( + // new FailedCallSection( + // this, + // ScenarioFragment.forCall(this, hasCode), + // ImcFragment.forCall(this, myAccount, calledAccount))); + // } else if (Exceptions.outOfGasException(this.pch().exceptions())) { + // this.addTraceSection( + // new FailedCallSection( + // this, + // ScenarioFragment.forCall(this, hasCode), + // ImcFragment.forCall(this, myAccount, calledAccount), + // this.factories + // .accountFragment() + // .makeWithTrm( + // calledAccountSnapshot, + // calledAccountSnapshot, + // rawCalledAddress, + // DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)))); + // } + // } else if (this.pch.abortingConditions().any()) { + // // + // // THERE IS AN ABORT + // // + // TraceSection abortedSection = + // new FailedCallSection( + // this, + // ScenarioFragment.forCall(this, hasCode), + // ImcFragment.forCall(this, myAccount, calledAccount), + // ContextFragment.readCurrentContextData(this), + // this.factories + // .accountFragment() + // .make( + // myAccountSnapshot, + // myAccountSnapshot, + // DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)), + // this.factories + // .accountFragment() + // .makeWithTrm( + // calledAccountSnapshot, + // calledAccountSnapshot, + // rawCalledAddress, + // DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 1)), + // ContextFragment.nonExecutionProvidesEmptyReturnData(this)); + // this.addTraceSection(abortedSection); + // } else { + // final ImcFragment imcFragment = /* ImcFragment.forOpcode(this, frame)*/ + // ImcFragment.empty(this); + // + // if (hasCode) { + // final SmartContractCallSection section = + // new SmartContractCallSection( + // this, myAccountSnapshot, calledAccountSnapshot, rawCalledAddress, + // imcFragment); + // this.addTraceSection(section); + // this.currentFrame().sectionToUnlatch(section); + // } else { + // // + // // CALL EXECUTED + // // + // + // // TODO: fill the callee & requested return data for the current call frame + // // i.e. ensure that the precompile frame behaves as expected + // + // Optional precompileInvocation = + // targetPrecompile.map(p -> PrecompileInvocation.of(this, p)); + // + // // TODO: this is ugly, and surely not at the right place. It should provide the + // // precompile result (from the precompile module) + // // TODO useless (and potentially dangerous) if the precompile is a failure + // if (targetPrecompile.isPresent()) { + // this.callStack.newPrecompileResult( + // this.stamp(), Bytes.EMPTY, 0, targetPrecompile.get().address); + // } + // + // final NoCodeCallSection section = + // new NoCodeCallSection( + // this, + // precompileInvocation, + // myAccountSnapshot, + // calledAccountSnapshot, + // rawCalledAddress, + // imcFragment); + // this.addTraceSection(section); + // this.currentFrame().sectionToUnlatch(section); + // } + // } + // } case JUMP -> new JumpSection(this); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java new file mode 100644 index 0000000000..b9e16ccdd0 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java @@ -0,0 +1,36 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import org.apache.tuweni.bytes.Bytes; + +public class AbortCall extends TraceSection { + + public AbortCall( + Hub hub, + final ContextFragment currentContextFragment, + final ImcFragment firstImcFragment, + final AccountSnapshot preOpcodeCallerAccount, + final AccountSnapshot preOpcodeCalleeAccount, + final Bytes eCalleeAddress) { + super(hub, (short) 9); + hub.addTraceSection(this); +}} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java new file mode 100644 index 0000000000..c123cdf580 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -0,0 +1,90 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call; + +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; + +public class CallSection { + private TraceSection createSection; + + // row i+2 + private final ImcFragment firstImcFragment; + + // Just before call + private AccountSnapshot preOpcodeCallerSnapshot; + private AccountSnapshot preOpcodeCalleeSnapshot; + + public CallSection(Hub hub) { + final short exceptions = hub.pch().exceptions(); + + // row i+1 + final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); + + // row i+2 + this.firstImcFragment = ImcFragment.empty(hub); + + // STATICX and MXPX cases + if (Exceptions.staticFault(exceptions) || Exceptions.memoryExpansionException(exceptions)) { + new StaticMxpXCall(hub, currentContextFragment, firstImcFragment); + return; + } + + final Address callerAddress = hub.currentFrame().callerAddress(); + this.preOpcodeCallerSnapshot = AccountSnapshot.canonical(hub, callerAddress); + + final Bytes eCalleeAddress = hub.currentFrame().frame().getStackItem(0); + final Address calleeAddress = hub.trm().callTrimming(eCalleeAddress); + this.preOpcodeCalleeSnapshot = AccountSnapshot.canonical(hub, calleeAddress); + + // OOGX case + if (Exceptions.outOfGasException(exceptions)) { + new OogXCall( + hub, + currentContextFragment, + firstImcFragment, + preOpcodeCallerSnapshot, + preOpcodeCalleeSnapshot, + eCalleeAddress); + return; + } + + // The CALL is now unexceptional + Preconditions.checkArgument(Exceptions.none(exceptions)); + + final CallOobCall oobCall = new CallOobCall(); + firstImcFragment.callOob(oobCall); + + final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); + Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts.any()); + + if (aborts.any()){ + new AbortCall(); + return; + } + + // The CALL is now unexceptional and unaborted + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java new file mode 100644 index 0000000000..0047ae8a56 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java @@ -0,0 +1,25 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class NoCodeCall extends TraceSection { + public NoCodeCall(Hub hub) { + super(hub, (short) 10); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java new file mode 100644 index 0000000000..103d31af09 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java @@ -0,0 +1,74 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call; + +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Factories; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import org.apache.tuweni.bytes.Bytes; + +public class OogXCall extends TraceSection { + public OogXCall( + Hub hub, + final ContextFragment currentContextFragment, + final ImcFragment firstImcFragment, + final AccountSnapshot preOpcodeCallerAccount, + final AccountSnapshot preOpcodeCalleeAccount, + final Bytes eCalleeAddress) { + super(hub, (short) 6); + hub.addTraceSection(this); + + final ScenarioFragment scenarioFragment = new ScenarioFragment(); // TODO + + final OobCall oobCall = new XCallOobCall(); + firstImcFragment.callOob(oobCall); + + final Factories factories = hub.factories(); + + final AccountFragment callerAccountFragment = + factories + .accountFragment() + .make( + preOpcodeCallerAccount, + preOpcodeCallerAccount, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + + final AccountFragment calleeAccountFragment = + factories + .accountFragment() + .makeWithTrm( + preOpcodeCalleeAccount, + preOpcodeCalleeAccount, + eCalleeAddress, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + + this.addFragmentsAndStack( + hub, + scenarioFragment, + currentContextFragment, + firstImcFragment, + callerAccountFragment, + calleeAccountFragment); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java new file mode 100644 index 0000000000..5456fb170f --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java @@ -0,0 +1,39 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; + +public class StaticMxpXCall extends TraceSection { + public StaticMxpXCall( + Hub hub, final ContextFragment currentContextFragment, final ImcFragment firstImcFragment) { + super(hub, (short) 6); + hub.addTraceSection(this); + + final ScenarioFragment scenarioFragment = new ScenarioFragment(); // TODO + + final OobCall oobCall = new XCallOobCall(); + firstImcFragment.callOob(oobCall); + + this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, firstImcFragment); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/FailedCallSection.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/FailedCallSection.java index 020ebb7099..5076297462 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/FailedCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/FailedCallSection.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section.calls; +package net.consensys.linea.zktracer.module.hub.section.callsOld; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java similarity index 99% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java index 8e1ba6e14b..46bcce6b1d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section.calls; +package net.consensys.linea.zktracer.module.hub.section.callsOld; import java.util.List; import java.util.Optional; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java index 9f04cbe28a..62c9f68a06 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/calls/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section.calls; +package net.consensys.linea.zktracer.module.hub.section.callsOld; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -75,7 +75,8 @@ public SmartContractCallSection( hub.defers().scheduleForImmediateContextEntry(this); hub.defers().schedulePostTransaction(this); - // TODO: remove (but: ContextFragment calleeContextInitializationFragment = ContextFragment.initializeNewExecutionContext(hub); + // TODO: remove (but: ContextFragment calleeContextInitializationFragment = + // ContextFragment.initializeNewExecutionContext(hub); // should be added to the section } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 876898fdd0..a961e09b19 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -135,7 +135,7 @@ public ExtCodeCopySection(Hub hub) { .makeWithTrm(accountBefore, accountAfter, rawAddress, doingDomSubStamps); accountDoingFragment.requiresRomlex(triggerCfi); this.addFragment(accountDoingFragment); - hub.romLex().triggerRomLex(hub.messageFrame()); + hub.romLex().callRomLex(hub.messageFrame()); // an EXTCODECOPY section is only scheduled // for rollback if it is unexceptional diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 35f662ed2a..ff144dff9d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -116,12 +116,12 @@ public CreateSection(Hub hub) { return; } + // The CREATE(2) is now unexceptional Preconditions.checkArgument(Exceptions.none(exceptions)); final CreateOobCall oobCall = new CreateOobCall(); imcFragment.callOob(oobCall); - // The CREATE(2) is now unexceptional final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts.any()); @@ -260,8 +260,7 @@ public void resolvePostTransaction( // of both creator and createe were updated (and potentially created) // otherwise do it later @Override - public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { - } + public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) {} @Override public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index 354b119a8b..4c9ff7c099 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -42,7 +42,7 @@ public NonEmptyInitCodeCreate( this.scenarioFragment = new CreateScenarioFragment(); this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); - hub.romLex().triggerRomLex(hub.messageFrame()); + hub.romLex().callRomLex(hub.messageFrame()); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index f8c6b25481..b8dd2650a5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -224,7 +224,7 @@ public ReturnSection(Hub hub) { accountBeforeDeployment.deployByteCode(deploymentCode), DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); nonemptyDeploymentAccountFragment.requiresRomlex(true); - hub.romLex().triggerRomLex(hub.messageFrame()); + hub.romLex().callRomLex(hub.messageFrame()); this.addFragment(nonemptyDeploymentAccountFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 02730eace0..efa5f95cdf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -152,7 +152,7 @@ public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMe }); } - public void triggerRomLex(final MessageFrame frame) { + public void callRomLex(final MessageFrame frame) { switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { case CREATE -> { hub.defers().schedulePostExecution(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java index a4ffca4139..1d91e4dfc0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java @@ -26,6 +26,7 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.AccessListEntry; import org.hyperledger.besu.datatypes.Address; @@ -73,6 +74,11 @@ public Address callTrimming(Bytes32 rawHash) { return Address.extract(rawHash); } + public Address callTrimming(Bytes addressToTrim) { + Bytes32 addressPadded = Bytes32.leftPad(addressToTrim); + return callTrimming(addressPadded); + } + @Override public void traceStartTx(WorldView world, TransactionProcessingMetadata txMetaData) { // Add effective receiver Address diff --git a/zkevm-constraints b/zkevm-constraints index 29b10da4cd..66cf5cf54f 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 29b10da4cd96cfbe8bf12d84020fb4df177021db +Subproject commit 66cf5cf54f2e7d3a11dd740e44cf1eb9771e0e17 From b1fabb8547448c2a076b02e579d3104f7f6308ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 25 Jul 2024 11:48:23 +0200 Subject: [PATCH 279/461] feat(aborted calls): DONE !!!!!1! --- .../module/hub/section/call/AbortCall.java | 37 ---------- .../module/hub/section/call/NoCodeCall.java | 25 ------- .../module/hub/section/call/OogXCall.java | 71 ------------------- .../hub/section/call/StaticMxpXCall.java | 36 ---------- 4 files changed, 169 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java deleted file mode 100644 index d20e93cea0..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/AbortCall.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.call; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import org.apache.tuweni.bytes.Bytes; - -public class AbortCall extends TraceSection { - - public AbortCall( - Hub hub, - final ContextFragment currentContextFragment, - final ImcFragment firstImcFragment, - final AccountSnapshot preOpcodeCallerAccount, - final AccountSnapshot preOpcodeCalleeAccount, - final Bytes eCalleeAddress) { - super(hub, (short) 9); - hub.addTraceSection(this); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java deleted file mode 100644 index 0047ae8a56..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/NoCodeCall.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.call; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class NoCodeCall extends TraceSection { - public NoCodeCall(Hub hub) { - super(hub, (short) 10); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java deleted file mode 100644 index 1c88e7a1df..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/OogXCall.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.call; - -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.CALL_EXCEPTION; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Factories; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import org.apache.tuweni.bytes.Bytes; - -public class OogXCall extends TraceSection { - public OogXCall( - Hub hub, - final ContextFragment currentContextFragment, - final ImcFragment firstImcFragment, - final AccountSnapshot preOpcodeCallerAccount, - final AccountSnapshot preOpcodeCalleeAccount, - final Bytes rawCalleeAddress) { - super(hub, (short) 6); - hub.addTraceSection(this); - - final CallScenarioFragment scenarioFragment = new CallScenarioFragment(CALL_EXCEPTION); - - final Factories factories = hub.factories(); - - final AccountFragment callerAccountFragment = - factories - .accountFragment() - .make( - preOpcodeCallerAccount, - preOpcodeCallerAccount, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - - final AccountFragment calleeAccountFragment = - factories - .accountFragment() - .makeWithTrm( - preOpcodeCalleeAccount, - preOpcodeCalleeAccount, - rawCalleeAddress, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); - - this.addFragmentsAndStack( - hub, - scenarioFragment, - currentContextFragment, - firstImcFragment, - callerAccountFragment, - calleeAccountFragment); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java deleted file mode 100644 index ad43bd6585..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/StaticMxpXCall.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.call; - -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.CALL_EXCEPTION; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class StaticMxpXCall extends TraceSection { - public StaticMxpXCall( - Hub hub, final ContextFragment currentContextFragment, final ImcFragment firstImcFragment) { - super(hub, (short) 6); - hub.addTraceSection(this); - - final CallScenarioFragment scenarioFragment = new CallScenarioFragment(CALL_EXCEPTION); - - this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, firstImcFragment); - } -} From ad68df222ab6fa49c66617df5b450af7484bdd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 25 Jul 2024 11:49:16 +0200 Subject: [PATCH 280/461] fix: added missing files ... --- .../scenario/CallScenarioFragment.java | 4 +- .../module/hub/section/call/CallSection.java | 148 +++++++++++++++--- .../hub/signals/AbortingConditions.java | 12 +- 3 files changed, 136 insertions(+), 28 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java index 9967e40a85..9528ceafc7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -15,12 +15,14 @@ package net.consensys.linea.zktracer.module.hub.fragment.scenario; import com.google.common.base.Preconditions; +import lombok.Getter; +import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; public class CallScenarioFragment implements TraceFragment { - CallScenario scenario; + @Setter @Getter CallScenario scenario; public CallScenarioFragment() { this.scenario = CallScenario.UNDEFINED; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 8f05968b74..4e5028e33d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -15,81 +15,99 @@ package net.consensys.linea.zktracer.module.hub.section.call; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.*; + import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.operation.Operation; +import org.hyperledger.besu.evm.worldstate.WorldView; -public class CallSection implements PostRollbackDefer { +public class CallSection extends TraceSection + implements PostExecDefer, PostRollbackDefer, PostTransactionDefer { private TraceSection callSection; // row i+2 + private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); private final ImcFragment firstImcFragment; // Just before call private AccountSnapshot preOpcodeCallerSnapshot; private AccountSnapshot preOpcodeCalleeSnapshot; + private AccountSnapshot postOpcodeCallerSnapshot; + private AccountSnapshot postOpcodeCalleeSnapshot; + private ContextFragment finalContextFragment; + private Bytes rawCalleeAddress; public CallSection(Hub hub) { + // TODO: create a refined line count method + super(hub); + hub.addTraceSection(this); final short exceptions = hub.pch().exceptions(); - // row i+1 + // row i, i + 1 and i + 2 final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); - - // row i+2 this.firstImcFragment = ImcFragment.empty(hub); + this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, firstImcFragment); + if (Exceptions.any(exceptions)) { + scenarioFragment.setScenario(CALL_EXCEPTION); final XCallOobCall oobCall = new XCallOobCall(); firstImcFragment.callOob(oobCall); } // STATICX cases if (Exceptions.staticFault(exceptions)) { - new StaticMxpXCall(hub, currentContextFragment, firstImcFragment); return; } final MxpCall mxpCall = new MxpCall(hub); firstImcFragment.callMxp(mxpCall); - Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); // MXPX case if (Exceptions.memoryExpansionException(exceptions)) { - new StaticMxpXCall(hub, currentContextFragment, firstImcFragment); return; } + final StpCall stpCall = new StpCall(hub, mxpCall.gasMxp); + stpCall.stpCallForCalls(hub); + firstImcFragment.callStp(stpCall); + Preconditions.checkArgument( + stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions)); + final Address callerAddress = hub.currentFrame().callerAddress(); this.preOpcodeCallerSnapshot = AccountSnapshot.canonical(hub, callerAddress); - final Bytes rawCalleeAddress = hub.currentFrame().frame().getStackItem(1); + this.rawCalleeAddress = hub.currentFrame().frame().getStackItem(1); final Address calleeAddress = Address.extract(EWord.of(rawCalleeAddress)); // TODO check this this.preOpcodeCalleeSnapshot = AccountSnapshot.canonical(hub, calleeAddress); // OOGX case if (Exceptions.outOfGasException(exceptions)) { - new OogXCall( - hub, - currentContextFragment, - firstImcFragment, - preOpcodeCallerSnapshot, - preOpcodeCalleeSnapshot, - rawCalleeAddress); + this.oogXCall(hub); return; } @@ -99,19 +117,107 @@ public CallSection(Hub hub) { final CallOobCall oobCall = new CallOobCall(); firstImcFragment.callOob(oobCall); - final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); - Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts.any()); + final boolean aborts = hub.pch().abortingConditions().any(); + Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts); + hub.defers().schedulePostExecution(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + hub.defers().schedulePostTransaction(this); - if (aborts.any()) { - new AbortCall(); + if (aborts) { + this.abortingCall(hub); return; } // The CALL is now unexceptional and unaborted } + private void oogXCall(Hub hub) { + + final Factories factories = hub.factories(); + + final AccountFragment callerAccountFragment = + factories + .accountFragment() + .make( + preOpcodeCallerSnapshot, + preOpcodeCallerSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + + final AccountFragment calleeAccountFragment = + factories + .accountFragment() + .makeWithTrm( + preOpcodeCalleeSnapshot, + preOpcodeCalleeSnapshot, + rawCalleeAddress, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + + this.addFragmentsWithoutStack(callerAccountFragment, calleeAccountFragment); + } + + private void abortingCall(Hub hub) { + this.scenarioFragment.setScenario(CALL_ABORT_WONT_REVERT); + this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + } + + @Override + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + this.postOpcodeCallerSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); + this.postOpcodeCalleeSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); + + final Factories factories = hub.factories(); + final AccountFragment callerAccountFragment = + factories + .accountFragment() + .make( + preOpcodeCallerSnapshot, + postOpcodeCallerSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + + final AccountFragment calleeAccountFragment = + factories + .accountFragment() + .makeWithTrm( + preOpcodeCalleeSnapshot, + postOpcodeCalleeSnapshot, + rawCalleeAddress, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + + this.addFragmentsWithoutStack(callerAccountFragment, calleeAccountFragment); + } + @Override - public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) {} + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + switch (this.scenarioFragment.getScenario()) { + case CALL_ABORT_WONT_REVERT -> { + this.scenarioFragment.setScenario(CALL_ABORT_WILL_REVERT); + final AccountSnapshot postRollbackCalleeSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); + final Factories factories = hub.factories(); + final AccountFragment undoingCalleeAccountFragment = + factories + .accountFragment() + .make( + postOpcodeCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.commonValues.hubStamp, + this.commonValues.callFrame().revertStamp(), + 0)); + this.addFragment(undoingCalleeAccountFragment); + } + default -> throw new IllegalArgumentException("What were you thinking ?"); + } + } + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + + this.callSection.addFragment(finalContextFragment); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java index 4de014b11e..6a70dc561a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/AbortingConditions.java @@ -29,7 +29,7 @@ @Accessors(fluent = true) public final class AbortingConditions { private boolean callStackOverflow; - private boolean balanceTooLow; + private boolean insufficientBalance; /** * @param callStackOverflow too many nested contexts @@ -37,7 +37,7 @@ public final class AbortingConditions { */ public AbortingConditions(boolean callStackOverflow, boolean insufficientBalance) { this.callStackOverflow = callStackOverflow; - this.balanceTooLow = insufficientBalance; + this.insufficientBalance = insufficientBalance; } public static AbortingConditions of(Hub hub) { @@ -48,7 +48,7 @@ public static AbortingConditions of(Hub hub) { public void reset() { this.callStackOverflow = false; - this.balanceTooLow = false; + this.insufficientBalance = false; } public void prepare(Hub hub) { @@ -57,7 +57,7 @@ public void prepare(Hub hub) { return; } - this.balanceTooLow = + this.insufficientBalance = switch (hub.currentFrame().opCode()) { case CALL, CALLCODE -> { if (Exceptions.none(hub.pch().exceptions())) { @@ -88,7 +88,7 @@ public void prepare(Hub hub) { } public AbortingConditions snapshot() { - return new AbortingConditions(this.callStackOverflow, this.balanceTooLow); + return new AbortingConditions(this.callStackOverflow, this.insufficientBalance); } public boolean none() { @@ -96,6 +96,6 @@ public boolean none() { } public boolean any() { - return this.callStackOverflow || this.balanceTooLow; + return this.callStackOverflow || this.insufficientBalance; } } From aba8cda37b8f16c60c9bb0daf59f104714d81abf Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 14:59:51 +0200 Subject: [PATCH 281/461] feat(EOA CALL): DONE ! --- .../scenario/CallScenarioFragment.java | 11 ++- .../module/hub/section/TraceSection.java | 2 +- .../module/hub/section/call/CallSection.java | 79 ++++++++++++++++--- 3 files changed, 80 insertions(+), 12 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java index 9528ceafc7..a12a018896 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -14,6 +14,8 @@ */ package net.consensys.linea.zktracer.module.hub.fragment.scenario; +import java.util.List; + import com.google.common.base.Preconditions; import lombok.Getter; import lombok.Setter; @@ -39,17 +41,24 @@ public enum CallScenario { CALL_ABORT_WONT_REVERT, CALL_EOA_SUCCESS_WILL_REVERT, CALL_EOA_SUCCESS_WONT_REVERT, + CALL_SMC_UNDEFINED, CALL_SMC_FAILURE_WILL_REVERT, CALL_SMC_FAILURE_WONT_REVERT, CALL_SMC_SUCCESS_WILL_REVERT, CALL_SMC_SUCCESS_WONT_REVERT, + CALL_PRC_UNDEFINED, CALL_PRC_FAILURE, CALL_PRC_SUCCESS_WILL_REVERT, CALL_PRC_SUCCESS_WONT_REVERT } + private static final List illegalTracingScenario = + List.of( + CallScenario.UNDEFINED, CallScenario.CALL_SMC_UNDEFINED, CallScenario.CALL_PRC_UNDEFINED); + public Trace trace(Trace trace) { - Preconditions.checkArgument(!this.scenario.equals(CallScenario.UNDEFINED)); + Preconditions.checkArgument( + !illegalTracingScenario.contains(this.scenario), "Final Scenario hasn't been set"); return trace .peekAtScenario(true) // // CALL scenarios 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 f0d7ec34b1..ce92e798cc 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 @@ -62,7 +62,7 @@ public TraceSection(Hub hub) { this.commonValues = new CommonFragmentValues(hub); this.fragments = new ArrayList<>( - 22); // 22 is the maximum number of lines in a section (Successfull reverted Modexp) + 22); // 22 is the maximum number of lines in a section (Successful reverted Modexp) } /** Default creator specifying the max number of rows the section can contain. */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 4e5028e33d..78e6d5f68c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.module.hub.section.call; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.*; +import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; @@ -42,26 +43,34 @@ import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; +import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection implements PostExecDefer, PostRollbackDefer, PostTransactionDefer { - private TraceSection callSection; - // row i+2 + // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); + + // row i+2 private final ImcFragment firstImcFragment; // Just before call private AccountSnapshot preOpcodeCallerSnapshot; private AccountSnapshot preOpcodeCalleeSnapshot; - private AccountSnapshot postOpcodeCallerSnapshot; - private AccountSnapshot postOpcodeCalleeSnapshot; private ContextFragment finalContextFragment; private Bytes rawCalleeAddress; + // Just After the CALL Opcode + private AccountSnapshot postOpcodeCallerSnapshot; + private AccountSnapshot postOpcodeCalleeSnapshot; + + // Just at re-entry + private AccountSnapshot postReEntryCallerSnapshot; + private AccountSnapshot postReEntryCalleeSnapshot; + public CallSection(Hub hub) { - // TODO: create a refined line count method + // TODO: create a refined line count method ? super(hub); hub.addTraceSection(this); final short exceptions = hub.pch().exceptions(); @@ -130,12 +139,31 @@ public CallSection(Hub hub) { } // The CALL is now unexceptional and unaborted + final WorldUpdater world = hub.messageFrame().getWorldUpdater(); + + if (isPrecompile(calleeAddress)) { + this.scenarioFragment.setScenario(CALL_PRC_UNDEFINED); + } else { + this.scenarioFragment.setScenario( + world.get(calleeAddress).hasCode() + ? CALL_SMC_UNDEFINED + : CALL_EOA_SUCCESS_WONT_REVERT); // TODO is world == worldUpdater & what happen if get + // doesn't + // work ? + } + + // TODO: lastContextFragment for PRC + if (this.scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { + this.finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); + } + if (this.scenarioFragment.getScenario() == CALL_EOA_SUCCESS_WONT_REVERT) { + this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + } } private void oogXCall(Hub hub) { final Factories factories = hub.factories(); - final AccountFragment callerAccountFragment = factories .accountFragment() @@ -161,6 +189,10 @@ private void abortingCall(Hub hub) { this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); } + private short maxNumberOfLines(final Hub hub) { + if (Exceptions.any(hub.pch().exceptions())) {} + } + @Override public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { @@ -192,12 +224,13 @@ public void resolvePostExecution( @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + final Factories factories = hub.factories(); + final AccountSnapshot postRollbackCalleeSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); + switch (this.scenarioFragment.getScenario()) { case CALL_ABORT_WONT_REVERT -> { this.scenarioFragment.setScenario(CALL_ABORT_WILL_REVERT); - final AccountSnapshot postRollbackCalleeSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); - final Factories factories = hub.factories(); final AccountFragment undoingCalleeAccountFragment = factories .accountFragment() @@ -210,6 +243,32 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca 0)); this.addFragment(undoingCalleeAccountFragment); } + + case CALL_EOA_SUCCESS_WONT_REVERT -> { + this.scenarioFragment.setScenario(CALL_EOA_SUCCESS_WILL_REVERT); + final AccountSnapshot postRollbackCallerSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); + + final AccountFragment undoingCallerAccountFragment = + factories + .accountFragment() + .make( + postOpcodeCallerSnapshot, + postRollbackCallerSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.commonValues.callFrame().revertStamp(), 2)); + + final AccountFragment undoingCalleeAccountFragment = + factories + .accountFragment() + .make( + postOpcodeCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.commonValues.callFrame().revertStamp(), 3)); + + this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); + } default -> throw new IllegalArgumentException("What were you thinking ?"); } } @@ -218,6 +277,6 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - this.callSection.addFragment(finalContextFragment); + this.addFragment(finalContextFragment); } } From 555fbac0f4be432fb7cdf60eb15a22b509586310 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 15:17:10 +0200 Subject: [PATCH 282/461] perf(CALL): specify max nb of fragment --- .../module/hub/section/call/CallSection.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 78e6d5f68c..0c9919ddcb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -70,8 +70,7 @@ public class CallSection extends TraceSection private AccountSnapshot postReEntryCalleeSnapshot; public CallSection(Hub hub) { - // TODO: create a refined line count method ? - super(hub); + super(hub, maxNumberOfLines(hub)); hub.addTraceSection(this); final short exceptions = hub.pch().exceptions(); @@ -161,6 +160,16 @@ public CallSection(Hub hub) { } } + private static short maxNumberOfLines(final Hub hub) { + if (Exceptions.any(hub.pch().exceptions())) { + return 8; + } + if (hub.pch().abortingConditions().any()) { + return 9; + } + return 12; // 12 = 2 (stack) + 5 (CALL prequel) + 5 (successful PRC, except BLAKE and MODEXP) + } + private void oogXCall(Hub hub) { final Factories factories = hub.factories(); @@ -189,10 +198,6 @@ private void abortingCall(Hub hub) { this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); } - private short maxNumberOfLines(final Hub hub) { - if (Exceptions.any(hub.pch().exceptions())) {} - } - @Override public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { From 04a09d691d50aeabba77ed55402b66fa1c352435 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 16:49:04 +0200 Subject: [PATCH 283/461] add conversions + fix Trace.java issue --- .../module/ecdata/EcDataOperation.java | 2 +- .../linea/zktracer/module/ecdata/Trace.java | 18 +++++++++--------- .../fragment/scenario/ScenarioFragment.java | 6 +++++- .../section/callsOld/NoCodeCallSection.java | 3 +-- .../linea/zktracer/types/Conversions.java | 8 ++++++++ 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index f21390951b..db6e1aa719 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -697,7 +697,7 @@ void trace(Trace trace, final int stamp, final long previousId) { && overallTrivialPairing.get( i)) // && conditions necessary because default value is true .g2MembershipTestRequired(g2MembershipTestRequired) - .acceptablePairOfPointForPairingCircuit(acceptablePairOfPointsForPairingCircuit) + .acceptablePairOfPointsForPairingCircuit(acceptablePairOfPointsForPairingCircuit) .circuitSelectorEcrecover(circuitSelectorEcrecover) .circuitSelectorEcadd(circuitSelectorEcadd) .circuitSelectorEcmul(circuitSelectorEcmul) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java index 057cfa1a9f..afbdf3cfa9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java @@ -67,7 +67,7 @@ public class Trace { private int currentLine = 0; private final MappedByteBuffer accPairings; - private final MappedByteBuffer acceptablePairOfPointForPairingCircuit; + private final MappedByteBuffer acceptablePairOfPointsForPairingCircuit; private final MappedByteBuffer byteDelta; private final MappedByteBuffer circuitSelectorEcadd; private final MappedByteBuffer circuitSelectorEcmul; @@ -124,7 +124,7 @@ public class Trace { static List headers(int length) { return List.of( new ColumnHeader("ecdata.ACC_PAIRINGS", 32, length), - new ColumnHeader("ecdata.ACCEPTABLE_PAIR_OF_POINT_FOR_PAIRING_CIRCUIT", 1, 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), new ColumnHeader("ecdata.CIRCUIT_SELECTOR_ECMUL", 1, length), @@ -181,7 +181,7 @@ static List headers(int length) { public Trace(List buffers) { this.accPairings = buffers.get(0); - this.acceptablePairOfPointForPairingCircuit = buffers.get(1); + this.acceptablePairOfPointsForPairingCircuit = buffers.get(1); this.byteDelta = buffers.get(2); this.circuitSelectorEcadd = buffers.get(3); this.circuitSelectorEcmul = buffers.get(4); @@ -270,15 +270,15 @@ public Trace accPairings(final Bytes b) { return this; } - public Trace acceptablePairOfPointForPairingCircuit(final Boolean b) { + public Trace acceptablePairOfPointsForPairingCircuit(final Boolean b) { if (filled.get(0)) { throw new IllegalStateException( - "ecdata.ACCEPTABLE_PAIR_OF_POINT_FOR_PAIRING_CIRCUIT already set"); + "ecdata.ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT already set"); } else { filled.set(0); } - acceptablePairOfPointForPairingCircuit.put((byte) (b ? 1 : 0)); + acceptablePairOfPointsForPairingCircuit.put((byte) (b ? 1 : 0)); return this; } @@ -1156,7 +1156,7 @@ public Trace validateRow() { if (!filled.get(0)) { throw new IllegalStateException( - "ecdata.ACCEPTABLE_PAIR_OF_POINT_FOR_PAIRING_CIRCUIT has not been filled"); + "ecdata.ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT has not been filled"); } if (!filled.get(2)) { @@ -1379,8 +1379,8 @@ public Trace fillAndValidateRow() { } if (!filled.get(0)) { - acceptablePairOfPointForPairingCircuit.position( - acceptablePairOfPointForPairingCircuit.position() + 1); + acceptablePairOfPointsForPairingCircuit.position( + acceptablePairOfPointsForPairingCircuit.position() + 1); } if (!filled.get(2)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index 3ffa4625f2..d497df5474 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -201,12 +201,16 @@ public void resolvePostTransaction( this.fillPostCallInformation(hub); } + // TODO: should disappear @Override public Trace trace(Trace trace) { return trace .peekAtScenario(true) .pScenarioCallException(type.isCall() && raisedException) - .pScenarioCallAbort(type.isCall() && hasAborted) + .pScenarioCallAbortWontRevert( + type.isCall() && hasAborted) // TODO: this is false but will disappear + .pScenarioCallAbortWillRevert( + type.isCall() && hasAborted) // TODO: this is false but will disappear .pScenarioCallPrcFailure( type.isCall() && !hasAborted diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java index 46bcce6b1d..9e6c65cdb0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java @@ -80,10 +80,9 @@ public NoCodeCallSection( hub.defers().schedulePostExecution(this); hub.defers().schedulePostTransaction(this); - hub.defers().scheduleForContextReEntry(this); + hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); } - @Override public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { // The precompile lines will read the return data, so they need to be added after re-entry. this.maybePrecompileLines = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java index c233f0c3f0..54daa28b6b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Conversions.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.List; +import com.google.common.base.Preconditions; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; @@ -168,4 +169,11 @@ public static BigInteger lowPart(final BigInteger input) { final Bytes lowBytes = inputBytes.slice(inputBytes.size() - LLARGE, LLARGE); return lowBytes.toUnsignedBigInteger(); } + + public static boolean bytesToBoolean(final Bytes input) { + final int bitLength = input.bitLength(); + Preconditions.checkArgument( + bitLength == 0 || bitLength == 1, String.format("Can't convert %s to boolean", input)); + return bitLength == 1; + } } From ed90dd2f8a9265645f0cce14d760a13f0fb9ffb2 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 25 Jul 2024 16:50:37 +0200 Subject: [PATCH 284/461] feat(call): were they both decemented? --- .../module/hub/section/call/CallSection.java | 132 +++++++++++++++--- 1 file changed, 114 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 0c9919ddcb..01057d5fe2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -25,6 +25,7 @@ import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; @@ -37,17 +38,19 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.types.Conversions; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection - implements PostExecDefer, PostRollbackDefer, PostTransactionDefer { + implements PostExecDefer, PostRollbackDefer, PostTransactionDefer, ReEnterContextDefer { // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); @@ -56,19 +59,31 @@ public class CallSection extends TraceSection private final ImcFragment firstImcFragment; // Just before call - private AccountSnapshot preOpcodeCallerSnapshot; - private AccountSnapshot preOpcodeCalleeSnapshot; + private ContextFragment finalContextFragment; private Bytes rawCalleeAddress; - // Just After the CALL Opcode + // Just before the CALL Opcode + private AccountSnapshot preOpcodeCallerSnapshot; + private AccountSnapshot preOpcodeCalleeSnapshot; + + // Just after the CALL Opcode private AccountSnapshot postOpcodeCallerSnapshot; private AccountSnapshot postOpcodeCalleeSnapshot; - // Just at re-entry + // Just before re-entry + private AccountSnapshot preReEntryCallerSnapshot; + private AccountSnapshot preReEntryCalleeSnapshot; + + // Just after re-entry private AccountSnapshot postReEntryCallerSnapshot; private AccountSnapshot postReEntryCalleeSnapshot; + private boolean isSelfCall; + private boolean callCanTransferValue; + + private Wei value; + public CallSection(Hub hub) { super(hub, maxNumberOfLines(hub)); hub.addTraceSection(this); @@ -138,29 +153,36 @@ public CallSection(Hub hub) { } // The CALL is now unexceptional and unaborted + hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); if (isPrecompile(calleeAddress)) { this.scenarioFragment.setScenario(CALL_PRC_UNDEFINED); } else { this.scenarioFragment.setScenario( - world.get(calleeAddress).hasCode() - ? CALL_SMC_UNDEFINED - : CALL_EOA_SUCCESS_WONT_REVERT); // TODO is world == worldUpdater & what happen if get - // doesn't - // work ? + world.get(calleeAddress).hasCode() ? CALL_SMC_UNDEFINED : CALL_EOA_SUCCESS_WONT_REVERT); + + // TODO is world == worldUpdater & what happen if get + // doesn't work ? + // TODO: write a test where the recipient of the call does not exist in the state } - // TODO: lastContextFragment for PRC + this.callCanTransferValue = hub.currentFrame().opCode().callCanTransferValue(); + + // TODO: lastContextFragment for PRC + if (this.scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { this.finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); + this.isSelfCall = callerAddress.equals(calleeAddress); } + if (this.scenarioFragment.getScenario() == CALL_EOA_SUCCESS_WONT_REVERT) { this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); } } private static short maxNumberOfLines(final Hub hub) { + // 99 % of the time this number of rows will be sufficient if (Exceptions.any(hub.pch().exceptions())) { return 8; } @@ -201,13 +223,30 @@ private void abortingCall(Hub hub) { @Override public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - this.postOpcodeCallerSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); - this.postOpcodeCalleeSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); + switch (this.scenarioFragment.getScenario()) { + case CALL_EOA_SUCCESS_WONT_REVERT, CALL_SMC_UNDEFINED -> { + this.postOpcodeCallerSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); + this.postOpcodeCalleeSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); + + if (isSelfCall && callCanTransferValue) { + // In case of a self-call that transfers value, the balance of the caller + // is decremented by the value transferred. This becomes the initial state + // of the callee, which is then credited by that value. This can happen + // only for the SMC case. + value = Wei.of(frame.getStackItem(2).toUnsignedBigInteger()); + postOpcodeCallerSnapshot.decrementBalance(value); + preOpcodeCalleeSnapshot.decrementBalance(value); + } + } + case CALL_PRC_UNDEFINED -> { + // TODO: implement + } + } final Factories factories = hub.factories(); - final AccountFragment callerAccountFragment = + final AccountFragment firstCallerAccountFragment = factories .accountFragment() .make( @@ -215,7 +254,7 @@ public void resolvePostExecution( postOpcodeCallerSnapshot, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - final AccountFragment calleeAccountFragment = + final AccountFragment firstCalleeAccountFragment = factories .accountFragment() .makeWithTrm( @@ -224,7 +263,7 @@ public void resolvePostExecution( rawCalleeAddress, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); - this.addFragmentsWithoutStack(callerAccountFragment, calleeAccountFragment); + this.addFragmentsWithoutStack(firstCallerAccountFragment, firstCalleeAccountFragment); } @Override @@ -284,4 +323,61 @@ public void resolvePostTransaction( this.addFragment(finalContextFragment); } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) { + switch (this.scenarioFragment.getScenario()) { + case CALL_SMC_UNDEFINED -> { + // TODO: what follows assumes that the caller's stack has been updated + // to contain the success bit of the call at traceContextReEntry. + // See issue #872. + boolean successBit = Conversions.bytesToBoolean(hub.messageFrame().getStackItem(0)); + if (successBit) { + return; + } + + scenarioFragment.setScenario(CALL_SMC_FAILURE_WONT_REVERT); + + preReEntryCallerSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); + preReEntryCalleeSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + + postReEntryCallerSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); + postReEntryCalleeSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + + if (isSelfCall && callCanTransferValue) { + postReEntryCallerSnapshot.decrementBalance(value); + postReEntryCalleeSnapshot.decrementBalance(value); + } else { + preReEntryCallerSnapshot.decrementBalance(value); + preReEntryCalleeSnapshot.incrementBalance(value); + } + + AccountFragment postReEntryCallerAccountFragment = + hub.factories() + .accountFragment() + .make( + postOpcodeCallerSnapshot, + postReEntryCallerSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), frame.revertStamp(), 2)); + + AccountFragment postReEntryCalleeAccountFragment = + hub.factories() + .accountFragment() + .make( + postOpcodeCalleeSnapshot, + postReEntryCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), frame.revertStamp(), 3)); + + this.addFragmentsWithoutStack( + postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); + } + default -> {} + } + } } From b75ee2a9b1ded43c470ae7d6355753a39f40b20a Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 17:36:17 +0200 Subject: [PATCH 285/461] feat: add ContextExitDefers registers --- .../module/hub/defer/ContextExitDefer.java | 23 +++++++++++++++++++ .../module/hub/defer/DeferRegistry.java | 17 +++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java new file mode 100644 index 0000000000..2dc4d9808d --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java @@ -0,0 +1,23 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.defer; + +import net.consensys.linea.zktracer.module.hub.Hub; +import org.hyperledger.besu.evm.frame.MessageFrame; + +public interface ContextExitDefer { + void resolveUponExitingContext(Hub hub, MessageFrame frame); +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index e4b38f48b0..b8a4232ee4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -35,7 +35,8 @@ public class DeferRegistry PostRollbackDefer, PostTransactionDefer, PostConflationDefer, - ChildContextEntryDefer { + ChildContextEntryDefer, + ContextExitDefer { /** A list of actions deferred until the end of the current opcode execution */ private final List postExecDefers = new ArrayList<>(); @@ -43,6 +44,9 @@ public class DeferRegistry /** A list of actions deferred until the end of the current opcode execution */ private final List childContextEntryDefers = new ArrayList<>(); + /** A list of actions deferred until the exit of a given context */ + private final Map> contextExitDefers = new HashMap<>(); + /** A list of actions deferred until the end of the current opcode execution */ private final Map> contextReEntryDefers = new HashMap<>(); @@ -69,6 +73,14 @@ public void schedulePostExecution(PostExecDefer defer) { this.postExecDefers.add(defer); } + /** Schedule an action to be executed at the exit of a given context. */ + public void scheduleContextExit(ContextExitDefer defer, Integer callFrameId) { + if (!contextExitDefers.containsKey(callFrameId)) { + contextExitDefers.put(callFrameId, new ArrayList<>()); + } + contextExitDefers.get(callFrameId).add(defer); + } + /** Schedule an action to be executed at the end of the current transaction. */ public void schedulePostTransaction(PostTransactionDefer defer) { this.postTransactionDefers.add(defer); @@ -193,4 +205,7 @@ public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { } this.childContextEntryDefers.clear(); } + + @Override + public void resolveUponExitingContext(Hub hub, MessageFrame frame) {} } From 9d27051377f1df2935071ec296f1f080d61872b1 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 17:37:59 +0200 Subject: [PATCH 286/461] CallFrame is better --- .../linea/zktracer/module/hub/defer/ContextExitDefer.java | 3 ++- .../linea/zktracer/module/hub/defer/DeferRegistry.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java index 2dc4d9808d..c62d33ab78 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java @@ -16,8 +16,9 @@ package net.consensys.linea.zktracer.module.hub.defer; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.hyperledger.besu.evm.frame.MessageFrame; public interface ContextExitDefer { - void resolveUponExitingContext(Hub hub, MessageFrame frame); + void resolveUponExitingContext(Hub hub, CallFrame frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index b8a4232ee4..399bea6901 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -207,5 +207,5 @@ public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { } @Override - public void resolveUponExitingContext(Hub hub, MessageFrame frame) {} + public void resolveUponExitingContext(Hub hub, CallFrame frame) {} } From 335e978e86410056ff89092a49dfedeb59d73ffe Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 25 Jul 2024 17:41:29 +0200 Subject: [PATCH 287/461] feat(call): added ContextExitDefer interface --- .../module/hub/section/call/CallSection.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 01057d5fe2..5fef30d8f5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -17,11 +17,13 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.*; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; +import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; @@ -38,7 +40,6 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.Conversions; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; @@ -50,7 +51,11 @@ import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection - implements PostExecDefer, PostRollbackDefer, PostTransactionDefer, ReEnterContextDefer { + implements PostExecDefer, + PostRollbackDefer, + PostTransactionDefer, + ReEnterContextDefer, + ContextExitDefer { // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); @@ -152,7 +157,8 @@ public CallSection(Hub hub) { return; } - // The CALL is now unexceptional and unaborted + // The CALL is now unexceptional and un-aborted + hub.defers().scheduleContextExit(this, hub.currentFrame().id()); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); @@ -331,7 +337,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { // TODO: what follows assumes that the caller's stack has been updated // to contain the success bit of the call at traceContextReEntry. // See issue #872. - boolean successBit = Conversions.bytesToBoolean(hub.messageFrame().getStackItem(0)); + boolean successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); if (successBit) { return; } @@ -380,4 +386,9 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { default -> {} } } + + @Override + public void resolveUponExitingContext(Hub hub, CallFrame frame) { + + } } From d2285a614972b686723919f20554e43f4b59ae0d Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 17:48:35 +0200 Subject: [PATCH 288/461] refactoring name of schedule defers --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/defer/ContextExitDefer.java | 1 - .../module/hub/defer/DeferRegistry.java | 20 +++++++++++++------ .../hub/fragment/account/AccountFragment.java | 4 ++-- .../fragment/scenario/ScenarioFragment.java | 2 +- .../hub/section/CallDataLoadSection.java | 2 +- .../module/hub/section/KeccakSection.java | 4 ++-- .../module/hub/section/LogSection.java | 2 +- .../module/hub/section/StackRamSection.java | 2 +- .../hub/section/TxFinalizationSection.java | 2 +- .../module/hub/section/call/CallSection.java | 10 ++++------ .../section/callsOld/NoCodeCallSection.java | 4 ++-- .../callsOld/SmartContractCallSection.java | 4 ++-- .../hub/section/copy/CallDataCopySection.java | 2 +- .../hub/section/copy/CodeCopySection.java | 2 +- .../hub/section/copy/ExtCodeCopySection.java | 2 +- .../section/copy/ReturnDataCopySection.java | 2 +- .../hub/section/create/CreateSection.java | 4 ++-- .../hub/section/halt/ReturnSection.java | 6 +++--- .../hub/section/halt/RevertSection.java | 2 +- .../hub/section/halt/SelfdestructSection.java | 2 +- .../module/hub/section/halt/StopSection.java | 2 +- .../linea/zktracer/module/romlex/RomLex.java | 4 ++-- 23 files changed, 46 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 1e9a4d8000..6705e2eaf2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -481,7 +481,7 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { if (!this.txStack.current().requiresEvmExecution()) { this.state.setProcessingPhase(TX_SKIP); this.state.stamps().incrementHubStamp(); - this.defers.schedulePostTransaction( + this.defers.scheduleForPostTransaction( new TxSkippedSectionDefers(world, this.txStack.current(), this.transients)); } else { if (this.txStack.current().requiresPrewarming()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java index c62d33ab78..02ff9e514a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextExitDefer.java @@ -17,7 +17,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import org.hyperledger.besu.evm.frame.MessageFrame; public interface ContextExitDefer { void resolveUponExitingContext(Hub hub, CallFrame frame); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 399bea6901..cf6507f852 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -69,12 +69,12 @@ public void scheduleForImmediateContextEntry(ChildContextEntryDefer defer) { } /** Schedule an action to be executed after the completion of the current opcode. */ - public void schedulePostExecution(PostExecDefer defer) { + public void scheduleForPostExecution(PostExecDefer defer) { this.postExecDefers.add(defer); } /** Schedule an action to be executed at the exit of a given context. */ - public void scheduleContextExit(ContextExitDefer defer, Integer callFrameId) { + public void scheduleForContextExit(ContextExitDefer defer, Integer callFrameId) { if (!contextExitDefers.containsKey(callFrameId)) { contextExitDefers.put(callFrameId, new ArrayList<>()); } @@ -82,12 +82,12 @@ public void scheduleContextExit(ContextExitDefer defer, Integer callFrameId) { } /** Schedule an action to be executed at the end of the current transaction. */ - public void schedulePostTransaction(PostTransactionDefer defer) { + public void scheduleForPostTransaction(PostTransactionDefer defer) { this.postTransactionDefers.add(defer); } /** Schedule an action to be executed at the end of the current transaction. */ - public void schedulePostConflation(PostConflationDefer defer) { + public void scheduleForPostConflation(PostConflationDefer defer) { this.postConflationDefers.add(defer); } @@ -192,7 +192,7 @@ public void resolvePostRollback( hub.defers().rollbackDefers.get(currentCallFrame).clear(); // recursively roll back child call frames - CallStack callStack = hub.callStack(); + final CallStack callStack = hub.callStack(); currentCallFrame.childFrames().stream() .map(callStack::getById) .forEach(childCallFrame -> resolvePostRollback(hub, messageFrame, childCallFrame)); @@ -207,5 +207,13 @@ public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { } @Override - public void resolveUponExitingContext(Hub hub, CallFrame frame) {} + public void resolveUponExitingContext(Hub hub, CallFrame callFrame) { + final Integer frameId = callFrame.id(); + if (contextExitDefers.containsKey(frameId)) { + for (ContextExitDefer defers : contextExitDefers.get(frameId)) { + defers.resolveUponExitingContext(hub, callFrame); + } + contextExitDefers.remove(frameId); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 7e34621cc4..1c7e84bae3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -114,11 +114,11 @@ public AccountFragment( this.domSubStampsSubFragment = domSubStampsSubFragment; // This allows us to properly fill EXISTS_INFTY, DEPLOYMENT_NUMBER_INFTY and CODE_FRAGMENT_INDEX - hub.defers().schedulePostConflation(this); + hub.defers().scheduleForPostConflation(this); // This allows us to properly fill MARKED_FOR_SELFDESTRUCT and MARKED_FOR_SELFDESTRUCT_NEW, // among other things - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java index d497df5474..a0916ab1fe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java @@ -74,7 +74,7 @@ public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { hub.pch().abortingConditions().any(), false, Exceptions.invalidCodePrefix(hub.pch().exceptions())); - hub.defers().schedulePostTransaction(r); + hub.defers().scheduleForPostTransaction(r); return r; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index df9470bd29..fd69cea245 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -71,7 +71,7 @@ public CallDataLoadSection(Hub hub) { final ContextFragment context = readCurrentContextData(hub); this.addFragment(context); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 15427c5b75..18277b2bd6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -49,8 +49,8 @@ public KeccakSection(Hub hub) { triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); if (triggerMmu) { - hub.defers().schedulePostExecution(this); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostExecution(this); + hub.defers().scheduleForPostTransaction(this); mmuCall = MmuCall.sha3(hub); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index d47ff0a864..affc32a7fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -61,7 +61,7 @@ public LogSection(Hub hub) { miscFragment = ImcFragment.empty(hub).callMxp(mxpCall); this.sectionPrequel.addFragment(miscFragment); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index d964a34c66..30a3fa95cf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -67,7 +67,7 @@ public StackRamSection(Hub hub) { this.addFragment(imcFragment); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 182dff526b..2bbcd3cd94 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -67,7 +67,7 @@ public TxFinalizationSection(Hub hub, WorldView world) { depInfo.number(minerAddress), depInfo.isDeploying(minerAddress)); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 5fef30d8f5..7416f0300c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -148,9 +148,9 @@ public CallSection(Hub hub) { final boolean aborts = hub.pch().abortingConditions().any(); Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts); - hub.defers().schedulePostExecution(this); + hub.defers().scheduleForPostExecution(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); if (aborts) { this.abortingCall(hub); @@ -158,7 +158,7 @@ public CallSection(Hub hub) { } // The CALL is now unexceptional and un-aborted - hub.defers().scheduleContextExit(this, hub.currentFrame().id()); + hub.defers().scheduleForContextExit(this, hub.currentFrame().id()); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); @@ -388,7 +388,5 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { } @Override - public void resolveUponExitingContext(Hub hub, CallFrame frame) { - - } + public void resolveUponExitingContext(Hub hub, CallFrame frame) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java index 9e6c65cdb0..c5ebea22d1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java @@ -78,8 +78,8 @@ public NoCodeCallSection( hub, precompileInvocation, this.callerCallFrame.id(), this.calledCallFrameId); this.addStack(hub); - hub.defers().schedulePostExecution(this); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostExecution(this); + hub.defers().scheduleForPostTransaction(this); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java index 62c9f68a06..a0b8b692e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java @@ -71,9 +71,9 @@ public SmartContractCallSection( this.addStack(hub); - hub.defers().schedulePostExecution(this); + hub.defers().scheduleForPostExecution(this); hub.defers().scheduleForImmediateContextEntry(this); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); // TODO: remove (but: ContextFragment calleeContextInitializationFragment = // ContextFragment.initializeNewExecutionContext(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index f7bac61629..22d2c9013f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -82,7 +82,7 @@ public CallDataCopySection(Hub hub) { } mmuCall = MmuCall.callDataCopy(hub); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index e8a708a107..ed3b34d261 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -107,7 +107,7 @@ public CodeCopySection(Hub hub) { triggerMmu = mxpCall.isMayTriggerNonTrivialMmuOperation(); if (triggerMmu) { mmuCall = MmuCall.codeCopy(hub); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index a961e09b19..788966a202 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -118,7 +118,7 @@ public ExtCodeCopySection(Hub hub) { triggerMmu = none(exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { mmuCall = MmuCall.extCodeCopy(hub); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } // TODO: make sure that hasCode returns false during deployments diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 5e985a9cf2..ffd0f6c34d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -76,7 +76,7 @@ public ReturnDataCopySection(Hub hub) { triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; if (triggerMmu) { mmuCall = MmuCall.returnDataCopy(hub); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index ff144dff9d..abd527c709 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -137,9 +137,9 @@ public CreateSection(Hub hub) { } // The CREATE(2) is now unexceptional and unaborted - hub.defers().schedulePostExecution(this); + hub.defers().scheduleForPostExecution(this); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); // Note: all future account rows will be added during the resolvePostTransaction diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index b8dd2650a5..4444aeff31 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -117,7 +117,7 @@ public ReturnSection(Hub hub) { if (triggerMmuForInvalidCodePrefix) { Preconditions.checkArgument(hub.currentFrame().isDeployment()); firstMmuCall = MmuCall.invalidCodePrefix(hub); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); return; } @@ -147,7 +147,7 @@ public ReturnSection(Hub hub) { if (messageCallReturnTouchesRam) { firstMmuCall = MmuCall.returnFromMessageCall(hub); Preconditions.checkArgument(!firstMmuCall.successBit()); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } // no need for the else case (and a nop) as per @François @@ -200,7 +200,7 @@ public ReturnSection(Hub hub) { // Nonempty deployments /////////////////////// - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); firstMmuCall = MmuCall.invalidCodePrefix(hub); Preconditions.checkArgument(firstMmuCall.successBit()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index ac91436667..876b52b068 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -58,7 +58,7 @@ public RevertSection(Hub hub) { if (triggerMmu) { mmuCall = MmuCall.revert(hub); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); } // The XAHOY case diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 4511a4769d..c71a99f924 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -158,7 +158,7 @@ public SelfdestructSection(Hub hub) { } hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - hub.defers().schedulePostTransaction(this); + hub.defers().scheduleForPostTransaction(this); // Modify the current account and the recipient account // - The current account has its balance reduced to 0 (i+2) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index 9ad0fec1cd..70dbfa1874 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -48,7 +48,7 @@ public StopSection(Hub hub) { // 5 = 1 + max_NON_STACK_ROWS in deployment case super(hub, hub.callStack().current().isMessageCall() ? (short) 3 : (short) 5); hub.addTraceSection(this); - hub.defers().schedulePostTransaction(this); // always + hub.defers().scheduleForPostTransaction(this); // always hubStamp = hub.stamp(); address = hub.currentFrame().accountAddress(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index efa5f95cdf..4ae08d996e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -155,14 +155,14 @@ public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMe public void callRomLex(final MessageFrame frame) { switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { case CREATE -> { - hub.defers().schedulePostExecution(this); + hub.defers().scheduleForPostExecution(this); this.byteCode = this.hub.transients().op().callData(); if (!this.byteCode.isEmpty()) { this.address = getCreateAddress(frame); } } case CREATE2 -> { - hub.defers().schedulePostExecution(this); + hub.defers().scheduleForPostExecution(this); this.byteCode = this.hub.transients().op().callData(); if (!this.byteCode.isEmpty()) { this.address = getCreate2Address(frame); From da44c91a51c3e259263428b925cee9bafc355807 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 25 Jul 2024 17:59:47 +0200 Subject: [PATCH 289/461] feat: trigger resolving ContextExitDefers --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6705e2eaf2..9c144414f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -693,6 +693,8 @@ public void traceContextExit(MessageFrame frame) { new TxFinalizationSection(this, frame.getWorldUpdater()); } } + + this.defers.resolveUponExitingContext(this, this.currentFrame()); } public void tracePreExecution(final MessageFrame frame) { From 9af8698fb8ec270473d278eaf52f85282f35426d Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 25 Jul 2024 18:12:43 +0200 Subject: [PATCH 290/461] feat(call): implement ContextExitDefer --- .../module/hub/section/call/CallSection.java | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 7416f0300c..6618ddf57e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -77,18 +77,22 @@ public class CallSection extends TraceSection private AccountSnapshot postOpcodeCalleeSnapshot; // Just before re-entry - private AccountSnapshot preReEntryCallerSnapshot; - private AccountSnapshot preReEntryCalleeSnapshot; + private AccountSnapshot childContextExitCallerSnapshot; + private AccountSnapshot childContextExitCalleeSnapshot; // Just after re-entry - private AccountSnapshot postReEntryCallerSnapshot; - private AccountSnapshot postReEntryCalleeSnapshot; + private AccountSnapshot reEntryCallerSnapshot; + private AccountSnapshot reEntryCalleeSnapshot; private boolean isSelfCall; private boolean callCanTransferValue; private Wei value; + // The successBit will only be set + // if the call is acted upon i.e. if the call is un-exceptional and un-aborted + private boolean successBit; + public CallSection(Hub hub) { super(hub, maxNumberOfLines(hub)); hub.addTraceSection(this); @@ -158,7 +162,7 @@ public CallSection(Hub hub) { } // The CALL is now unexceptional and un-aborted - hub.defers().scheduleForContextExit(this, hub.currentFrame().id()); + hub.defers().scheduleForContextExit(this, hub.callStack().futureId()); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); @@ -332,34 +336,32 @@ public void resolvePostTransaction( @Override public void resolveAtContextReEntry(Hub hub, CallFrame frame) { + // TODO: what follows assumes that the caller's stack has been updated + // to contain the success bit of the call at traceContextReEntry. + // See issue #872. + successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); switch (this.scenarioFragment.getScenario()) { + case CALL_PRC_UNDEFINED -> { + if (successBit) { + scenarioFragment.setScenario(CALL_PRC_SUCCESS_WONT_REVERT); + } else { + scenarioFragment.setScenario(CALL_PRC_FAILURE); + } + } case CALL_SMC_UNDEFINED -> { - // TODO: what follows assumes that the caller's stack has been updated - // to contain the success bit of the call at traceContextReEntry. - // See issue #872. - boolean successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); if (successBit) { + scenarioFragment.setScenario(CALL_SMC_SUCCESS_WONT_REVERT); return; } scenarioFragment.setScenario(CALL_SMC_FAILURE_WONT_REVERT); - preReEntryCallerSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); - preReEntryCalleeSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); - - postReEntryCallerSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); - postReEntryCalleeSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + reEntryCallerSnapshot = AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); + reEntryCalleeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); if (isSelfCall && callCanTransferValue) { - postReEntryCallerSnapshot.decrementBalance(value); - postReEntryCalleeSnapshot.decrementBalance(value); - } else { - preReEntryCallerSnapshot.decrementBalance(value); - preReEntryCalleeSnapshot.incrementBalance(value); + childContextExitCallerSnapshot.decrementBalance(value); + reEntryCalleeSnapshot.decrementBalance(value); } AccountFragment postReEntryCallerAccountFragment = @@ -367,7 +369,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { .accountFragment() .make( postOpcodeCallerSnapshot, - postReEntryCallerSnapshot, + reEntryCallerSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), frame.revertStamp(), 2)); @@ -376,7 +378,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { .accountFragment() .make( postOpcodeCalleeSnapshot, - postReEntryCalleeSnapshot, + reEntryCalleeSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), frame.revertStamp(), 3)); @@ -388,5 +390,13 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { } @Override - public void resolveUponExitingContext(Hub hub, CallFrame frame) {} + public void resolveUponExitingContext(Hub hub, CallFrame frame) { + if (!scenarioFragment.getScenario().equals(CALL_SMC_UNDEFINED)) { + return; + } + childContextExitCallerSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); + childContextExitCalleeSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + } } From 0790dd8ba0f0bb66b40100d801b6ed6e949a3b2f Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 25 Jul 2024 19:08:12 +0200 Subject: [PATCH 291/461] ras --- .../linea/zktracer/module/hub/Hub.java | 4 ++- .../module/hub/section/call/CallSection.java | 33 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 9c144414f0..eb8126f7b7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -511,6 +511,7 @@ public void traceEndTransaction( boolean isSuccessful, List logs, Set

selfDestructs) { + // TODO: this.defers.resolvePostRollback(this, ... this.txStack .current() .completeLineaTransaction( @@ -644,6 +645,8 @@ public void traceContextEnter(MessageFrame frame) { } public void traceContextReEnter(MessageFrame frame) { + final int latestChildId = this.currentFrame().childFrames().getLast(); + this.defers.resolvePostRollback(this, frame, this.callStack.getById(latestChildId)); this.defers.resolveAtContextReEntry(this, this.currentFrame()); if (this.currentFrame().sectionToUnlatch() != null) { this.unlatchStack(frame, this.currentFrame().sectionToUnlatch()); @@ -665,7 +668,6 @@ public void traceContextExit(MessageFrame frame) { if (contextExceptions.any()) { this.callStack.revert(this.state.stamps().hub()); // TODO: Duplicate s? - this.defers.resolvePostRollback(this, frame, this.currentFrame()); } this.callStack.exit(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 6618ddf57e..64615a781f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -41,6 +41,7 @@ import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; @@ -84,11 +85,15 @@ public class CallSection extends TraceSection private AccountSnapshot reEntryCallerSnapshot; private AccountSnapshot reEntryCalleeSnapshot; + private boolean initialCalleeWarmth; private boolean isSelfCall; private boolean callCanTransferValue; private Wei value; + private MemorySpan returnDataMemorySpan; + private int returnDataContextNumber; + // The successBit will only be set // if the call is acted upon i.e. if the call is un-exceptional and un-aborted private boolean successBit; @@ -323,7 +328,22 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); } - default -> throw new IllegalArgumentException("What were you thinking ?"); + case CALL_SMC_FAILURE_WONT_REVERT -> { + scenarioFragment.setScenario(CALL_SMC_FAILURE_WILL_REVERT); + + AccountFragment warmthUndoingAccountFragment; + + if (isSelfCall && callCanTransferValue) { + // warmthUndoingAccountFragment = + } + } + case CALL_SMC_SUCCESS_WONT_REVERT -> { + scenarioFragment.setScenario(CALL_SMC_SUCCESS_WILL_REVERT); + } + case CALL_PRC_SUCCESS_WONT_REVERT -> { + scenarioFragment.setScenario(CALL_PRC_SUCCESS_WILL_REVERT); + } + default -> throw new IllegalArgumentException("Illegal CALL scenario"); } } @@ -364,7 +384,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { reEntryCalleeSnapshot.decrementBalance(value); } - AccountFragment postReEntryCallerAccountFragment = + final AccountFragment postReEntryCallerAccountFragment = hub.factories() .accountFragment() .make( @@ -373,7 +393,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), frame.revertStamp(), 2)); - AccountFragment postReEntryCalleeAccountFragment = + final AccountFragment postReEntryCalleeAccountFragment = hub.factories() .accountFragment() .make( @@ -398,5 +418,12 @@ public void resolveUponExitingContext(Hub hub, CallFrame frame) { AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); childContextExitCalleeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + + // TODO: what follows assumes that the caller's stack has been updated + // to contain the success bit of the call at traceContextReEntry. + // See issue #872. + returnDataContextNumber = hub.currentFrame().contextNumber(); + // TODO: when does the callFrame update its output data? + returnDataMemorySpan = hub.currentFrame().outputDataSpan(); } } From 3af609aee34b53329ea10fb39cf43bb3ceab1ca9 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 25 Jul 2024 19:23:46 +0200 Subject: [PATCH 292/461] docs(hub): added comment for traceEndTransaction --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index eb8126f7b7..d456c1a334 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -511,7 +511,11 @@ public void traceEndTransaction( boolean isSuccessful, List logs, Set
selfDestructs) { - // TODO: this.defers.resolvePostRollback(this, ... + // TODO: see issue #875. It is currently unclear which, if any, + // rollbacks already took place at traceEndTransaction. + + // TODO: add the following resolution this.defers.resolvePostRollback(this, ... + this.txStack .current() .completeLineaTransaction( From 8aecf61a88c0a60a2c869ba8173408d8ccb4a913 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 26 Jul 2024 11:13:53 +0200 Subject: [PATCH 293/461] add reverStamp shortcut --- .../linea/zktracer/module/hub/section/call/CallSection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 64615a781f..cbba911742 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -391,7 +391,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { postOpcodeCallerSnapshot, reEntryCallerSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), frame.revertStamp(), 2)); + this.hubStamp(), revertStamp(), 2)); final AccountFragment postReEntryCalleeAccountFragment = hub.factories() @@ -400,7 +400,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { postOpcodeCalleeSnapshot, reEntryCalleeSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), frame.revertStamp(), 3)); + this.hubStamp(), revertStamp(), 3)); this.addFragmentsWithoutStack( postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); From 831d20936e354e50f46991720706b01f65efc2e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 26 Jul 2024 11:20:05 +0200 Subject: [PATCH 294/461] fix(call): wip for SMC --- .../scenario/CallScenarioFragment.java | 3 + .../module/hub/section/call/CallSection.java | 222 ++++++++++-------- 2 files changed, 130 insertions(+), 95 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java index a12a018896..21fdde00b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -39,13 +39,16 @@ public enum CallScenario { CALL_EXCEPTION, CALL_ABORT_WILL_REVERT, CALL_ABORT_WONT_REVERT, + // Externally owned account call scenarios CALL_EOA_SUCCESS_WILL_REVERT, CALL_EOA_SUCCESS_WONT_REVERT, + // Smart contract call scenarios: CALL_SMC_UNDEFINED, CALL_SMC_FAILURE_WILL_REVERT, CALL_SMC_FAILURE_WONT_REVERT, CALL_SMC_SUCCESS_WILL_REVERT, CALL_SMC_SUCCESS_WONT_REVERT, + // Precompile call scenarios: CALL_PRC_UNDEFINED, CALL_PRC_FAILURE, CALL_PRC_SUCCESS_WILL_REVERT, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index cbba911742..fbb819370f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -52,11 +52,13 @@ import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection - implements PostExecDefer, - PostRollbackDefer, - PostTransactionDefer, + implements + PostExecDefer, + ContextExitDefer, ReEnterContextDefer, - ContextExitDefer { + PostRollbackDefer, + PostTransactionDefer +{ // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); @@ -85,9 +87,7 @@ public class CallSection extends TraceSection private AccountSnapshot reEntryCallerSnapshot; private AccountSnapshot reEntryCalleeSnapshot; - private boolean initialCalleeWarmth; - private boolean isSelfCall; - private boolean callCanTransferValue; + private boolean selfCallWithNonzeroValueTransfer; private Wei value; @@ -182,13 +182,15 @@ public CallSection(Hub hub) { // TODO: write a test where the recipient of the call does not exist in the state } - this.callCanTransferValue = hub.currentFrame().opCode().callCanTransferValue(); // TODO: lastContextFragment for PRC if (this.scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { - this.finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); - this.isSelfCall = callerAddress.equals(calleeAddress); + finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); + final boolean callCanTransferValue = hub.currentFrame().opCode().callCanTransferValue(); + final boolean isSelfCall = callerAddress.equals(calleeAddress); + value = Wei.of(hub.messageFrame().getStackItem(2).toUnsignedBigInteger()); + selfCallWithNonzeroValueTransfer = isSelfCall && callCanTransferValue && !value.isZero(); } if (this.scenarioFragment.getScenario() == CALL_EOA_SUCCESS_WONT_REVERT) { @@ -245,12 +247,11 @@ public void resolvePostExecution( this.postOpcodeCalleeSnapshot = AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); - if (isSelfCall && callCanTransferValue) { + if (selfCallWithNonzeroValueTransfer) { // In case of a self-call that transfers value, the balance of the caller // is decremented by the value transferred. This becomes the initial state // of the callee, which is then credited by that value. This can happen // only for the SMC case. - value = Wei.of(frame.getStackItem(2).toUnsignedBigInteger()); postOpcodeCallerSnapshot.decrementBalance(value); preOpcodeCalleeSnapshot.decrementBalance(value); } @@ -281,13 +282,91 @@ public void resolvePostExecution( this.addFragmentsWithoutStack(firstCallerAccountFragment, firstCalleeAccountFragment); } + @Override + public void resolveUponExitingContext(Hub hub, CallFrame frame) { + if (!(scenarioFragment.getScenario() == CALL_SMC_UNDEFINED)) { + return; + } + childContextExitCallerSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); + childContextExitCalleeSnapshot = + AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + + // TODO: what follows assumes that the caller's stack has been updated + // to contain the success bit of the call at traceContextReEntry. + // See issue #872. + returnDataContextNumber = hub.currentFrame().contextNumber(); + // TODO: when does the callFrame update its output data? + returnDataMemorySpan = hub.currentFrame().outputDataSpan(); + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) { + // TODO: what follows assumes that the caller's stack has been updated + // to contain the success bit of the call at traceContextReEntry. + // See issue #872. + successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); + switch (this.scenarioFragment.getScenario()) { + case CALL_PRC_UNDEFINED -> { + if (successBit) { + scenarioFragment.setScenario(CALL_PRC_SUCCESS_WONT_REVERT); + } else { + scenarioFragment.setScenario(CALL_PRC_FAILURE); + } + } + + case CALL_SMC_UNDEFINED -> { + + reEntryCallerSnapshot = AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); + reEntryCalleeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + + if (successBit) { + scenarioFragment.setScenario(CALL_SMC_SUCCESS_WONT_REVERT); + return; + } + + scenarioFragment.setScenario(CALL_SMC_FAILURE_WONT_REVERT); + + if (selfCallWithNonzeroValueTransfer) { + childContextExitCallerSnapshot.decrementBalance(value); + reEntryCalleeSnapshot.decrementBalance(value); + } + + final AccountFragment postReEntryCallerAccountFragment = + hub.factories() + .accountFragment() + .make( + postOpcodeCallerSnapshot, + reEntryCallerSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), frame.revertStamp(), 2)); + + final AccountFragment postReEntryCalleeAccountFragment = + hub.factories() + .accountFragment() + .make( + postOpcodeCalleeSnapshot, + reEntryCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), frame.revertStamp(), 3)); + + this.addFragmentsWithoutStack( + postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); + } + default -> {} + } + } + @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { final Factories factories = hub.factories(); final AccountSnapshot postRollbackCalleeSnapshot = AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); + final AccountSnapshot postRollbackCallerSnapshot = + AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); - switch (this.scenarioFragment.getScenario()) { + CallScenarioFragment.CallScenario callScenario = this.scenarioFragment.getScenario(); + switch (callScenario) { case CALL_ABORT_WONT_REVERT -> { this.scenarioFragment.setScenario(CALL_ABORT_WILL_REVERT); final AccountFragment undoingCalleeAccountFragment = @@ -305,8 +384,6 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca case CALL_EOA_SUCCESS_WONT_REVERT -> { this.scenarioFragment.setScenario(CALL_EOA_SUCCESS_WILL_REVERT); - final AccountSnapshot postRollbackCallerSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); final AccountFragment undoingCallerAccountFragment = factories @@ -331,99 +408,54 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca case CALL_SMC_FAILURE_WONT_REVERT -> { scenarioFragment.setScenario(CALL_SMC_FAILURE_WILL_REVERT); - AccountFragment warmthUndoingAccountFragment; + // this (should) work for both self calls and foreign address calls + final AccountFragment undoingCalleeWarmthAccountFragment = + factories + .accountFragment() + .make( + reEntryCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), callFrame.revertStamp(), 4)); - if (isSelfCall && callCanTransferValue) { - // warmthUndoingAccountFragment = - } - } - case CALL_SMC_SUCCESS_WONT_REVERT -> { - scenarioFragment.setScenario(CALL_SMC_SUCCESS_WILL_REVERT); - } - case CALL_PRC_SUCCESS_WONT_REVERT -> { - scenarioFragment.setScenario(CALL_PRC_SUCCESS_WILL_REVERT); + this.addFragment(undoingCalleeWarmthAccountFragment); } - default -> throw new IllegalArgumentException("Illegal CALL scenario"); - } - } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - - this.addFragment(finalContextFragment); - } + case CALL_SMC_SUCCESS_WONT_REVERT, CALL_PRC_SUCCESS_WONT_REVERT-> { - @Override - public void resolveAtContextReEntry(Hub hub, CallFrame frame) { - // TODO: what follows assumes that the caller's stack has been updated - // to contain the success bit of the call at traceContextReEntry. - // See issue #872. - successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); - switch (this.scenarioFragment.getScenario()) { - case CALL_PRC_UNDEFINED -> { - if (successBit) { - scenarioFragment.setScenario(CALL_PRC_SUCCESS_WONT_REVERT); + if (callScenario == CALL_SMC_SUCCESS_WONT_REVERT) { + scenarioFragment.setScenario(CALL_SMC_SUCCESS_WILL_REVERT); } else { - scenarioFragment.setScenario(CALL_PRC_FAILURE); - } - } - case CALL_SMC_UNDEFINED -> { - if (successBit) { - scenarioFragment.setScenario(CALL_SMC_SUCCESS_WONT_REVERT); - return; + scenarioFragment.setScenario(CALL_PRC_SUCCESS_WILL_REVERT); } - scenarioFragment.setScenario(CALL_SMC_FAILURE_WONT_REVERT); - - reEntryCallerSnapshot = AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); - reEntryCalleeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + if (selfCallWithNonzeroValueTransfer) { - if (isSelfCall && callCanTransferValue) { - childContextExitCallerSnapshot.decrementBalance(value); - reEntryCalleeSnapshot.decrementBalance(value); + } else { + final AccountFragment undoingCallerAccountFragment = + factories + .accountFragment() + .make( + reEntryCallerSnapshot, + postRollbackCallerSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), callFrame.revertStamp(), 2)); + final AccountFragment undoingCalleeAccountFragment = + factories + .accountFragment() + .make( + reEntryCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), callFrame.revertStamp(), 3)); + + this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); } - - final AccountFragment postReEntryCallerAccountFragment = - hub.factories() - .accountFragment() - .make( - postOpcodeCallerSnapshot, - reEntryCallerSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), revertStamp(), 2)); - - final AccountFragment postReEntryCalleeAccountFragment = - hub.factories() - .accountFragment() - .make( - postOpcodeCalleeSnapshot, - reEntryCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), revertStamp(), 3)); - - this.addFragmentsWithoutStack( - postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); } - default -> {} + default -> throw new IllegalArgumentException("Illegal CALL scenario"); } } @Override - public void resolveUponExitingContext(Hub hub, CallFrame frame) { - if (!scenarioFragment.getScenario().equals(CALL_SMC_UNDEFINED)) { - return; - } - childContextExitCallerSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); - childContextExitCalleeSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - // TODO: what follows assumes that the caller's stack has been updated - // to contain the success bit of the call at traceContextReEntry. - // See issue #872. - returnDataContextNumber = hub.currentFrame().contextNumber(); - // TODO: when does the callFrame update its output data? - returnDataMemorySpan = hub.currentFrame().outputDataSpan(); + this.addFragment(finalContextFragment); } } From 6b7d531491232ea0c89486c0595dba2382ad3640 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 26 Jul 2024 11:29:10 +0200 Subject: [PATCH 295/461] refactor ras --- .../module/hub/section/TraceSection.java | 2 + .../module/hub/section/call/CallSection.java | 44 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) 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 ce92e798cc..7aa9b4c5f2 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 @@ -247,4 +247,6 @@ public void trace(Trace hubTrace) { public int hubStamp() { return commonValues.hubStamp; } + + public int revertStamp() {return commonValues.callFrame().revertStamp();} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index fbb819370f..ce15cb9819 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -105,7 +105,7 @@ public CallSection(Hub hub) { // row i, i + 1 and i + 2 final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); - this.firstImcFragment = ImcFragment.empty(hub); + firstImcFragment = ImcFragment.empty(hub); this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, firstImcFragment); @@ -136,11 +136,11 @@ public CallSection(Hub hub) { stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions)); final Address callerAddress = hub.currentFrame().callerAddress(); - this.preOpcodeCallerSnapshot = AccountSnapshot.canonical(hub, callerAddress); + preOpcodeCallerSnapshot = AccountSnapshot.canonical(hub, callerAddress); - this.rawCalleeAddress = hub.currentFrame().frame().getStackItem(1); + rawCalleeAddress = hub.currentFrame().frame().getStackItem(1); final Address calleeAddress = Address.extract(EWord.of(rawCalleeAddress)); // TODO check this - this.preOpcodeCalleeSnapshot = AccountSnapshot.canonical(hub, calleeAddress); + preOpcodeCalleeSnapshot = AccountSnapshot.canonical(hub, calleeAddress); // OOGX case if (Exceptions.outOfGasException(exceptions)) { @@ -172,9 +172,9 @@ public CallSection(Hub hub) { final WorldUpdater world = hub.messageFrame().getWorldUpdater(); if (isPrecompile(calleeAddress)) { - this.scenarioFragment.setScenario(CALL_PRC_UNDEFINED); + scenarioFragment.setScenario(CALL_PRC_UNDEFINED); } else { - this.scenarioFragment.setScenario( + scenarioFragment.setScenario( world.get(calleeAddress).hasCode() ? CALL_SMC_UNDEFINED : CALL_EOA_SUCCESS_WONT_REVERT); // TODO is world == worldUpdater & what happen if get @@ -185,7 +185,7 @@ public CallSection(Hub hub) { // TODO: lastContextFragment for PRC - if (this.scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { + if (scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); final boolean callCanTransferValue = hub.currentFrame().opCode().callCanTransferValue(); final boolean isSelfCall = callerAddress.equals(calleeAddress); @@ -193,8 +193,8 @@ public CallSection(Hub hub) { selfCallWithNonzeroValueTransfer = isSelfCall && callCanTransferValue && !value.isZero(); } - if (this.scenarioFragment.getScenario() == CALL_EOA_SUCCESS_WONT_REVERT) { - this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + if (scenarioFragment.getScenario() == CALL_EOA_SUCCESS_WONT_REVERT) { + finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); } } @@ -233,14 +233,14 @@ private void oogXCall(Hub hub) { } private void abortingCall(Hub hub) { - this.scenarioFragment.setScenario(CALL_ABORT_WONT_REVERT); - this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + scenarioFragment.setScenario(CALL_ABORT_WONT_REVERT); + finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); } @Override public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - switch (this.scenarioFragment.getScenario()) { + switch (scenarioFragment.getScenario()) { case CALL_EOA_SUCCESS_WONT_REVERT, CALL_SMC_UNDEFINED -> { this.postOpcodeCallerSnapshot = AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); @@ -306,7 +306,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { // to contain the success bit of the call at traceContextReEntry. // See issue #872. successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); - switch (this.scenarioFragment.getScenario()) { + switch (scenarioFragment.getScenario()) { case CALL_PRC_UNDEFINED -> { if (successBit) { scenarioFragment.setScenario(CALL_PRC_SUCCESS_WONT_REVERT); @@ -339,7 +339,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { postOpcodeCallerSnapshot, reEntryCallerSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), frame.revertStamp(), 2)); + this.hubStamp(), this.revertStamp(), 2)); final AccountFragment postReEntryCalleeAccountFragment = hub.factories() @@ -348,7 +348,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { postOpcodeCalleeSnapshot, reEntryCalleeSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), frame.revertStamp(), 3)); + this.hubStamp(), this.revertStamp(), 3)); this.addFragmentsWithoutStack( postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); @@ -376,8 +376,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca postOpcodeCalleeSnapshot, postRollbackCalleeSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.commonValues.hubStamp, - this.commonValues.callFrame().revertStamp(), + this.hubStamp(), + this.revertStamp(), 0)); this.addFragment(undoingCalleeAccountFragment); } @@ -392,7 +392,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca postOpcodeCallerSnapshot, postRollbackCallerSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), this.commonValues.callFrame().revertStamp(), 2)); + this.hubStamp(), this.revertStamp(), 2)); final AccountFragment undoingCalleeAccountFragment = factories @@ -401,7 +401,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca postOpcodeCalleeSnapshot, postRollbackCalleeSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), this.commonValues.callFrame().revertStamp(), 3)); + this.hubStamp(), this.revertStamp(), 3)); this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); } @@ -415,7 +415,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca .make( reEntryCalleeSnapshot, postRollbackCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), callFrame.revertStamp(), 4)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), this.revertStamp(), 4)); this.addFragment(undoingCalleeWarmthAccountFragment); } @@ -436,14 +436,14 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca .make( reEntryCallerSnapshot, postRollbackCallerSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), callFrame.revertStamp(), 2)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), this.revertStamp(), 2)); final AccountFragment undoingCalleeAccountFragment = factories .accountFragment() .make( reEntryCalleeSnapshot, postRollbackCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), callFrame.revertStamp(), 3)); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), this.revertStamp(), 3)); this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); } From 771d70eab06766ec5d22e322001575db8e9a9502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 26 Jul 2024 15:58:58 +0200 Subject: [PATCH 296/461] ras --- .../linea/zktracer/module/hub/section/create/CreateSection.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index abd527c709..504996f51c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -78,6 +78,8 @@ public class CreateSection // row i+? private ContextFragment finalContextFragment; + // TODO: according to our preliminary conclusion in issue #866 + // CREATE's that raise a failure condition _do spawn a child context_. public CreateSection(Hub hub) { final short exceptions = hub.pch().exceptions(); From dc6f19b184d927ce195c61431f960d0e5c1600b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 26 Jul 2024 17:35:50 +0200 Subject: [PATCH 297/461] fix(call): various --- .../module/hub/fragment/ContextFragment.java | 25 +- .../module/hub/section/TraceSection.java | 4 +- .../module/hub/section/call/CallSection.java | 266 +++++++++--------- zkevm-constraints | 2 +- 4 files changed, 156 insertions(+), 141 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index eda3732231..3d2a3270ce 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -18,6 +18,10 @@ import static net.consensys.linea.zktracer.types.AddressUtils.highPart; import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -26,15 +30,18 @@ import net.consensys.linea.zktracer.types.MemorySpan; import org.hyperledger.besu.datatypes.Address; -public record ContextFragment( - Hub hub, - CallStack callStack, - // Left: callFrameId, Right: contextNumber - Either callFrameReference, - int returnDataContextNumber, - MemorySpan returnDataSegment, - boolean updateReturnData) - implements TraceFragment { +@Getter +@Setter +@Accessors(fluent = true) +@AllArgsConstructor +public class ContextFragment implements TraceFragment { + private final Hub hub; + private final CallStack callStack; + // Left: callFrameId, Right: contextNumber + private Either callFrameReference; + private int returnDataContextNumber; + private MemorySpan returnDataSegment; + private boolean updateReturnData; public static ContextFragment readContextDataByContextNumber( final Hub hub, final int contextNumber) { 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 7aa9b4c5f2..14b845992d 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 @@ -248,5 +248,7 @@ public int hubStamp() { return commonValues.hubStamp; } - public int revertStamp() {return commonValues.callFrame().revertStamp();} + public int revertStamp() { + return commonValues.callFrame().revertStamp(); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index ce15cb9819..8dda50bdc9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section.call; +import static net.consensys.linea.zktracer.module.hub.AccountSnapshot.canonical; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.*; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; @@ -41,7 +42,6 @@ import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; @@ -52,20 +52,15 @@ import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection - implements - PostExecDefer, + implements PostExecDefer, ContextExitDefer, ReEnterContextDefer, PostRollbackDefer, - PostTransactionDefer -{ + PostTransactionDefer { // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); - // row i+2 - private final ImcFragment firstImcFragment; - // Just before call private ContextFragment finalContextFragment; @@ -87,16 +82,15 @@ public class CallSection extends TraceSection private AccountSnapshot reEntryCallerSnapshot; private AccountSnapshot reEntryCalleeSnapshot; - private boolean selfCallWithNonzeroValueTransfer; + private boolean selfCallWithNonzeroValueTransfer; private Wei value; - private MemorySpan returnDataMemorySpan; - private int returnDataContextNumber; - // The successBit will only be set // if the call is acted upon i.e. if the call is un-exceptional and un-aborted private boolean successBit; + private AccountSnapshot postRollbackCalleeSnapshot; + private AccountSnapshot postRollbackCallerSnapshot; public CallSection(Hub hub) { super(hub, maxNumberOfLines(hub)); @@ -105,7 +99,8 @@ public CallSection(Hub hub) { // row i, i + 1 and i + 2 final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); - firstImcFragment = ImcFragment.empty(hub); + // row i+2 + final ImcFragment firstImcFragment = ImcFragment.empty(hub); this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, firstImcFragment); @@ -136,11 +131,11 @@ public CallSection(Hub hub) { stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions)); final Address callerAddress = hub.currentFrame().callerAddress(); - preOpcodeCallerSnapshot = AccountSnapshot.canonical(hub, callerAddress); + preOpcodeCallerSnapshot = canonical(hub, callerAddress); rawCalleeAddress = hub.currentFrame().frame().getStackItem(1); final Address calleeAddress = Address.extract(EWord.of(rawCalleeAddress)); // TODO check this - preOpcodeCalleeSnapshot = AccountSnapshot.canonical(hub, calleeAddress); + preOpcodeCalleeSnapshot = canonical(hub, calleeAddress); // OOGX case if (Exceptions.outOfGasException(exceptions)) { @@ -182,7 +177,6 @@ public CallSection(Hub hub) { // TODO: write a test where the recipient of the call does not exist in the state } - // TODO: lastContextFragment for PRC if (scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { @@ -191,6 +185,7 @@ public CallSection(Hub hub) { final boolean isSelfCall = callerAddress.equals(calleeAddress); value = Wei.of(hub.messageFrame().getStackItem(2).toUnsignedBigInteger()); selfCallWithNonzeroValueTransfer = isSelfCall && callCanTransferValue && !value.isZero(); + hub.romLex().callRomLex(hub.currentFrame().frame()); } if (scenarioFragment.getScenario() == CALL_EOA_SUCCESS_WONT_REVERT) { @@ -242,10 +237,8 @@ public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { switch (scenarioFragment.getScenario()) { case CALL_EOA_SUCCESS_WONT_REVERT, CALL_SMC_UNDEFINED -> { - this.postOpcodeCallerSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); - this.postOpcodeCalleeSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); + postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); + postOpcodeCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); if (selfCallWithNonzeroValueTransfer) { // In case of a self-call that transfers value, the balance of the caller @@ -279,25 +272,29 @@ public void resolvePostExecution( rawCalleeAddress, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + if (scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { + firstCalleeAccountFragment.requiresRomlex(true); + } + this.addFragmentsWithoutStack(firstCallerAccountFragment, firstCalleeAccountFragment); } + /** Resolution happens as the child context is about to terminate. */ @Override public void resolveUponExitingContext(Hub hub, CallFrame frame) { if (!(scenarioFragment.getScenario() == CALL_SMC_UNDEFINED)) { return; } - childContextExitCallerSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); - childContextExitCalleeSnapshot = - AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + childContextExitCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); + childContextExitCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); // TODO: what follows assumes that the caller's stack has been updated // to contain the success bit of the call at traceContextReEntry. // See issue #872. - returnDataContextNumber = hub.currentFrame().contextNumber(); // TODO: when does the callFrame update its output data? - returnDataMemorySpan = hub.currentFrame().outputDataSpan(); + // TODO: when does the callFrame update to the parent callFrame ? + finalContextFragment.returnDataContextNumber(hub.currentFrame().contextNumber()); + finalContextFragment.returnDataSegment(hub.currentFrame().outputDataSpan()); } @Override @@ -316,9 +313,8 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { } case CALL_SMC_UNDEFINED -> { - - reEntryCallerSnapshot = AccountSnapshot.canonical(hub, preOpcodeCallerSnapshot.address()); - reEntryCalleeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCalleeSnapshot.address()); + reEntryCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); + reEntryCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); if (successBit) { scenarioFragment.setScenario(CALL_SMC_SUCCESS_WONT_REVERT); @@ -333,25 +329,25 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { } final AccountFragment postReEntryCallerAccountFragment = - hub.factories() - .accountFragment() - .make( - postOpcodeCallerSnapshot, - reEntryCallerSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), this.revertStamp(), 2)); + hub.factories() + .accountFragment() + .make( + childContextExitCallerSnapshot, + reEntryCallerSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 2)); final AccountFragment postReEntryCalleeAccountFragment = - hub.factories() - .accountFragment() - .make( - postOpcodeCalleeSnapshot, - reEntryCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), this.revertStamp(), 3)); + hub.factories() + .accountFragment() + .make( + childContextExitCalleeSnapshot, + reEntryCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 3)); this.addFragmentsWithoutStack( - postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); + postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); } default -> {} } @@ -359,103 +355,113 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - final Factories factories = hub.factories(); - final AccountSnapshot postRollbackCalleeSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCalleeSnapshot.address()); - final AccountSnapshot postRollbackCallerSnapshot = - AccountSnapshot.canonical(hub, this.preOpcodeCallerSnapshot.address()); + final Factories factory = hub.factories(); + postRollbackCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); + postRollbackCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); - CallScenarioFragment.CallScenario callScenario = this.scenarioFragment.getScenario(); + CallScenarioFragment.CallScenario callScenario = scenarioFragment.getScenario(); switch (callScenario) { - case CALL_ABORT_WONT_REVERT -> { - this.scenarioFragment.setScenario(CALL_ABORT_WILL_REVERT); - final AccountFragment undoingCalleeAccountFragment = - factories - .accountFragment() - .make( - postOpcodeCalleeSnapshot, - postRollbackCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), - this.revertStamp(), - 0)); - this.addFragment(undoingCalleeAccountFragment); - } + case CALL_ABORT_WONT_REVERT -> completeAbortWillRevert(factory); + case CALL_EOA_SUCCESS_WONT_REVERT -> completeEoaSuccessWillRevert(factory); + case CALL_SMC_FAILURE_WONT_REVERT -> completeSmcFailureWillRevert(factory); + case CALL_SMC_SUCCESS_WONT_REVERT, + CALL_PRC_SUCCESS_WONT_REVERT -> completeSmcSuccessWillRevertOrPrcSuccessWillRevert( + factory); + default -> throw new IllegalArgumentException("Illegal CALL scenario"); + } + } - case CALL_EOA_SUCCESS_WONT_REVERT -> { - this.scenarioFragment.setScenario(CALL_EOA_SUCCESS_WILL_REVERT); + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - final AccountFragment undoingCallerAccountFragment = - factories - .accountFragment() - .make( - postOpcodeCallerSnapshot, - postRollbackCallerSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), this.revertStamp(), 2)); + this.addFragment(finalContextFragment); + } - final AccountFragment undoingCalleeAccountFragment = - factories - .accountFragment() - .make( - postOpcodeCalleeSnapshot, - postRollbackCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), this.revertStamp(), 3)); + private void completeAbortWillRevert(Factories factory) { + scenarioFragment.setScenario(CALL_ABORT_WILL_REVERT); + final AccountFragment undoingCalleeAccountFragment = + factory + .accountFragment() + .make( + postOpcodeCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 0)); + this.addFragment(undoingCalleeAccountFragment); + } - this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); - } - case CALL_SMC_FAILURE_WONT_REVERT -> { - scenarioFragment.setScenario(CALL_SMC_FAILURE_WILL_REVERT); - - // this (should) work for both self calls and foreign address calls - final AccountFragment undoingCalleeWarmthAccountFragment = - factories - .accountFragment() - .make( - reEntryCalleeSnapshot, - postRollbackCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), this.revertStamp(), 4)); - - this.addFragment(undoingCalleeWarmthAccountFragment); - } - case CALL_SMC_SUCCESS_WONT_REVERT, CALL_PRC_SUCCESS_WONT_REVERT-> { + private void completeEoaSuccessWillRevert(Factories factory) { + scenarioFragment.setScenario(CALL_EOA_SUCCESS_WILL_REVERT); - if (callScenario == CALL_SMC_SUCCESS_WONT_REVERT) { - scenarioFragment.setScenario(CALL_SMC_SUCCESS_WILL_REVERT); - } else { - scenarioFragment.setScenario(CALL_PRC_SUCCESS_WILL_REVERT); - } + final AccountFragment undoingCallerAccountFragment = + factory + .accountFragment() + .make( + postOpcodeCallerSnapshot, + postRollbackCallerSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 2)); - if (selfCallWithNonzeroValueTransfer) { + final AccountFragment undoingCalleeAccountFragment = + factory + .accountFragment() + .make( + postOpcodeCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 3)); - } else { - final AccountFragment undoingCallerAccountFragment = - factories - .accountFragment() - .make( - reEntryCallerSnapshot, - postRollbackCallerSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), this.revertStamp(), 2)); - final AccountFragment undoingCalleeAccountFragment = - factories - .accountFragment() - .make( - reEntryCalleeSnapshot, - postRollbackCalleeSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(this.hubStamp(), this.revertStamp(), 3)); - - this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); - } - } - default -> throw new IllegalArgumentException("Illegal CALL scenario"); - } + this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); } - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + private void completeSmcFailureWillRevert(Factories factory) { + scenarioFragment.setScenario(CALL_SMC_FAILURE_WILL_REVERT); - this.addFragment(finalContextFragment); + // this (should) work for both self calls and foreign address calls + final AccountFragment undoingCalleeWarmthAccountFragment = + factory + .accountFragment() + .make( + reEntryCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 4)); + + this.addFragment(undoingCalleeWarmthAccountFragment); + } + + private void completeSmcSuccessWillRevertOrPrcSuccessWillRevert(Factories factory) { + + final CallScenarioFragment.CallScenario callScenario = scenarioFragment.getScenario(); + if (callScenario == CALL_SMC_SUCCESS_WONT_REVERT) { + scenarioFragment.setScenario(CALL_SMC_SUCCESS_WILL_REVERT); + } else { + scenarioFragment.setScenario(CALL_PRC_SUCCESS_WILL_REVERT); + } + + if (selfCallWithNonzeroValueTransfer) { + reEntryCallerSnapshot.decrementBalance(value); + postRollbackCalleeSnapshot.decrementBalance(value); + } + + final AccountFragment undoingCallerAccountFragment = + factory + .accountFragment() + .make( + reEntryCallerSnapshot, + postRollbackCallerSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 2)); + final AccountFragment undoingCalleeAccountFragment = + factory + .accountFragment() + .make( + reEntryCalleeSnapshot, + postRollbackCalleeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), this.revertStamp(), 3)); + + this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); } } diff --git a/zkevm-constraints b/zkevm-constraints index 980397eee7..7c44e4b9c5 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 980397eee7544124a2603679cf1be8bec320b975 +Subproject commit 7c44e4b9c5e8488d4e3694618b1f2159c01bdd6b From a818d703e52087474cb9592274804e38aea73d7a Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 26 Jul 2024 17:37:11 +0200 Subject: [PATCH 298/461] clean-up --- .../module/hub/fragment/account/AccountFragment.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 1c7e84bae3..c289aa8ad2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -63,11 +63,6 @@ public final class AccountFragment final int hubStamp; final TransactionProcessingMetadata transactionProcessingMetadata; - // TODO: will be needed to properly compute MARKED_FOR_SELFDESTRUCT - // and to have the correct value of the hub stamp for the subordinate - // stamp of any reverting scenario. @Olivier @Francois @Lorenzo - // final int hubStamp; - /** * {@link AccountFragment} creation requires access to a {@link DeferRegistry} for post-conflation * data gathering, which is provided by this factory. @@ -176,9 +171,9 @@ public Trace trace(Trace trace) { @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - Map effectiveSelfDestructMap = - this.transactionProcessingMetadata.getEffectiveSelfDestructMap(); - TransactionProcessingMetadata.EphemeralAccount ephemeralAccount = + final Map effectiveSelfDestructMap = + transactionProcessingMetadata.getEffectiveSelfDestructMap(); + final TransactionProcessingMetadata.EphemeralAccount ephemeralAccount = new TransactionProcessingMetadata.EphemeralAccount( this.oldState.address(), this.oldState.deploymentNumber()); if (effectiveSelfDestructMap.containsKey(ephemeralAccount)) { From 27438f218ba90b304a1026685b2891ac6b8a90f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 26 Jul 2024 17:39:34 +0200 Subject: [PATCH 299/461] feat(precompiles): first commit --- .../PrecompileScenarios.java | 17 +++++++++ .../PrecompileSubsection.java | 38 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenarios.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenarios.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenarios.java new file mode 100644 index 0000000000..4f6ab4f1d4 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenarios.java @@ -0,0 +1,17 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; + +public enum PrecompileScenarios {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java new file mode 100644 index 0000000000..f56b00e098 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -0,0 +1,38 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.call.CallSection; + +@AllArgsConstructor +@Accessors(fluent = true) +public abstract class PrecompileSubsection { + @Getter List fragments; + + /** + * Default creator specifying the max number of rows the precompile processing subsection can + * contain. + */ + public PrecompileSubsection(final CallSection callSection, final short maxNumberOfLines) { + this.fragments = new ArrayList<>(maxNumberOfLines); + } +} From d78ab16447f4050389079651a4db493f9a0282f6 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 26 Jul 2024 19:02:45 +0200 Subject: [PATCH 300/461] bye bye old call ;( --- .../scenario/PrecompileScenarioFragment.java} | 14 +- .../precompileSubsection/PrecompileFlag.java | 28 +++ ...Scenarios.java => PrecompileScenario.java} | 7 +- .../section/callsOld/NoCodeCallSection.java | 175 --------------- .../callsOld/SmartContractCallSection.java | 207 ------------------ 5 files changed, 37 insertions(+), 394 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/{section/callsOld/FailedCallSection.java => fragment/scenario/PrecompileScenarioFragment.java} (55%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/{PrecompileScenarios.java => PrecompileScenario.java} (83%) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/FailedCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java similarity index 55% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/FailedCallSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 5076297462..27854112b7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/FailedCallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -1,5 +1,5 @@ /* - * Copyright Consensys Software Inc. + * Copyright ConsenSys Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -13,15 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.section.callsOld; +package net.consensys.linea.zktracer.module.hub.fragment.scenario; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class FailedCallSection extends TraceSection { - public FailedCallSection(Hub hub, TraceFragment... fragments) { - super(hub); - this.addFragmentsAndStack(hub, fragments); - } +public class PrecompileScenarioFragment { } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java new file mode 100644 index 0000000000..06a56290a0 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java @@ -0,0 +1,28 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; + +public enum PrecompileFlags { + PRC_ECRECOVER, + PRC_SHA2_256, + PRC_RIPEMD_160, + PRC_IDENTITY, + PRC_MODEXP, + PRC_ECADD, + PRC_ECMUL, + PRC_ECPAIRING, + PRC_BLAKE2F +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenarios.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java similarity index 83% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenarios.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java index 4f6ab4f1d4..44e68892e7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenarios.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java @@ -14,4 +14,9 @@ */ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; -public enum PrecompileScenarios {} +public enum PrecompileScenarios { + PRC_FAILURE_KNOWN_TO_HUB, + PRC_FAILURE_KNOWN_TO_RAM, + PRC_SUCCESS_WILL_REVERT, + PRC_SUCCESS_WONT_REVERT +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java deleted file mode 100644 index c5ebea22d1..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/NoCodeCallSection.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.callsOld; - -import java.util.List; -import java.util.Optional; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileLinesGenerator; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class NoCodeCallSection extends TraceSection - implements PostTransactionDefer, PostExecDefer, ReEnterContextDefer { - private final Bytes rawCalledAddress; - private final Optional precompileInvocation; - private final CallFrame callerCallFrame; - private final int calledCallFrameId; - private boolean callSuccessful = false; - private final AccountSnapshot preCallCallerAccountSnapshot; - private final AccountSnapshot preCallCalledAccountSnapshot; - - private AccountSnapshot postCallCallerAccountSnapshot; - private AccountSnapshot postCallCalledAccountSnapshot; - private final ImcFragment imcFragment; - private final ScenarioFragment scenarioFragment; - - private Optional> maybePrecompileLines = Optional.empty(); - - public NoCodeCallSection( - Hub hub, - Optional targetPrecompile, - AccountSnapshot preCallCallerAccountSnapshot, - AccountSnapshot preCallCalledAccountSnapshot, - Bytes rawCalledAddress, - ImcFragment imcFragment) { - super(hub); - this.rawCalledAddress = rawCalledAddress; - this.precompileInvocation = targetPrecompile; - this.preCallCallerAccountSnapshot = preCallCallerAccountSnapshot; - this.preCallCalledAccountSnapshot = preCallCalledAccountSnapshot; - this.callerCallFrame = hub.currentFrame(); - this.calledCallFrameId = hub.callStack().futureId(); - this.imcFragment = imcFragment; - this.scenarioFragment = - ScenarioFragment.forNoCodeCallSection( - hub, precompileInvocation, this.callerCallFrame.id(), this.calledCallFrameId); - this.addStack(hub); - - hub.defers().scheduleForPostExecution(this); - hub.defers().scheduleForPostTransaction(this); - hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); - } - - public void resolveAtContextReEntry(Hub hub, MessageFrame frame) { - // The precompile lines will read the return data, so they need to be added after re-entry. - this.maybePrecompileLines = - this.precompileInvocation.map(p -> PrecompileLinesGenerator.generateFor(hub, p)); - } - - @Override - public void resolvePostExecution( - Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - this.callSuccessful = !frame.getStackItem(0).isZero(); - final Address callerAddress = preCallCallerAccountSnapshot.address(); - final Account callerAccount = frame.getWorldUpdater().get(callerAddress); - final Address calledAddress = preCallCalledAccountSnapshot.address(); - final Account calledAccount = frame.getWorldUpdater().get(calledAddress); - - this.postCallCallerAccountSnapshot = - AccountSnapshot.fromAccount( - callerAccount, - frame.isAddressWarm(callerAddress), - hub.transients().conflation().deploymentInfo().number(callerAddress), - hub.transients().conflation().deploymentInfo().isDeploying(callerAddress)); - this.postCallCalledAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(calledAddress), - hub.transients().conflation().deploymentInfo().number(calledAddress), - hub.transients().conflation().deploymentInfo().isDeploying(calledAddress)); - } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); - - this.addFragmentsWithoutStack( - this.scenarioFragment, - this.imcFragment, - ContextFragment.readCurrentContextData(hub), - accountFragmentFactory.make( - this.preCallCallerAccountSnapshot, - this.postCallCallerAccountSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)), - accountFragmentFactory.makeWithTrm( - this.preCallCalledAccountSnapshot, - this.postCallCalledAccountSnapshot, - this.rawCalledAddress, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1))); - - if (precompileInvocation.isPresent()) { - if (this.callSuccessful && callerCallFrame.hasReverted()) { - this.addFragmentsWithoutStack( - accountFragmentFactory.make( - this.postCallCallerAccountSnapshot, - this.preCallCallerAccountSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), - accountFragmentFactory.make( - this.postCallCalledAccountSnapshot, - this.preCallCalledAccountSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); - } - this.addFragmentsWithoutStack( - ScenarioFragment.forPrecompileEpilogue( - hub, precompileInvocation.get(), callerCallFrame.id(), calledCallFrameId)); - for (TraceFragment f : - this.maybePrecompileLines.orElseThrow( - () -> new IllegalStateException("missing precompile lines"))) { - this.addFragment(f); - } - } else { - if (callerCallFrame.hasReverted()) { - this.addFragmentsWithoutStack( - accountFragmentFactory.make( - this.postCallCallerAccountSnapshot, - this.preCallCallerAccountSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), - accountFragmentFactory.make( - this.postCallCalledAccountSnapshot, - this.preCallCalledAccountSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); - } - this.addFragmentsWithoutStack(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } - } - - // TODO - @Override - public void resolveAtContextReEntry(Hub hub, CallFrame frame) {} -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java deleted file mode 100644 index a0b8b692e4..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/callsOld/SmartContractCallSection.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.callsOld; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.ChildContextEntryDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class SmartContractCallSection extends TraceSection - implements PostTransactionDefer, PostExecDefer, ChildContextEntryDefer { - private final Bytes rawCalledAddress; - private final CallFrame callerCallFrame; - private final int calledCallFrameId; - private final AccountSnapshot preCallCallerAccountSnapshot; - private final AccountSnapshot preCallCalleeAccountSnapshot; - - private AccountSnapshot inCallCallerAccountSnapshot; - private AccountSnapshot inCallCalleeAccountSnapshot; - - private AccountSnapshot postCallCallerAccountSnapshot; - private AccountSnapshot postCallCalleeAccountSnapshot; - - private final ScenarioFragment scenarioFragment; - private final ImcFragment imcFragment; - - public SmartContractCallSection( - Hub hub, - AccountSnapshot preCallCallerAccountSnapshot, - AccountSnapshot preCallCalleeAccountSnapshot, - Bytes rawCalledAddress, - ImcFragment imcFragment) { - super(hub); - this.rawCalledAddress = rawCalledAddress; - this.callerCallFrame = hub.currentFrame(); - this.calledCallFrameId = hub.callStack().futureId(); - this.preCallCallerAccountSnapshot = preCallCallerAccountSnapshot; - this.preCallCalleeAccountSnapshot = preCallCalleeAccountSnapshot; - this.imcFragment = imcFragment; - this.scenarioFragment = - ScenarioFragment.forSmartContractCallSection( - hub, calledCallFrameId, this.callerCallFrame.id()); - - this.addStack(hub); - - hub.defers().scheduleForPostExecution(this); - hub.defers().scheduleForImmediateContextEntry(this); - hub.defers().scheduleForPostTransaction(this); - - // TODO: remove (but: ContextFragment calleeContextInitializationFragment = - // ContextFragment.initializeNewExecutionContext(hub); - // should be added to the section - } - - @Override - public void resolvePostExecution( - Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - final Address callerAddress = preCallCallerAccountSnapshot.address(); - final Account callerAccount = frame.getWorldUpdater().get(callerAddress); - final Address calledAddress = preCallCalleeAccountSnapshot.address(); - final Account calledAccount = frame.getWorldUpdater().get(calledAddress); - - this.postCallCallerAccountSnapshot = - AccountSnapshot.fromAccount( - callerAccount, - frame.isAddressWarm(callerAddress), - hub.transients().conflation().deploymentInfo().number(callerAddress), - hub.transients().conflation().deploymentInfo().isDeploying(callerAddress)); - this.postCallCalleeAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(calledAddress), - hub.transients().conflation().deploymentInfo().number(calledAddress), - hub.transients().conflation().deploymentInfo().isDeploying(calledAddress)); - } - - @Override - public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { - final Address callerAddress = preCallCallerAccountSnapshot.address(); - final Account callerAccount = frame.getWorldUpdater().get(callerAddress); - final Address calledAddress = preCallCalleeAccountSnapshot.address(); - final Account calledAccount = frame.getWorldUpdater().get(calledAddress); - - this.inCallCallerAccountSnapshot = - AccountSnapshot.fromAccount( - callerAccount, - frame.isAddressWarm(callerAddress), - hub.transients().conflation().deploymentInfo().number(callerAddress), - hub.transients().conflation().deploymentInfo().isDeploying(callerAddress)); - this.inCallCalleeAccountSnapshot = - AccountSnapshot.fromAccount( - calledAccount, - frame.isAddressWarm(calledAddress), - hub.transients().conflation().deploymentInfo().number(calledAddress), - hub.transients().conflation().deploymentInfo().isDeploying(calledAddress)); - } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - final CallFrame calledCallFrame = hub.callStack().getById(this.calledCallFrameId); - this.scenarioFragment.resolvePostTransaction(hub, state, tx, isSuccessful); - - DomSubStampsSubFragment firstCallerDoingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); - - DomSubStampsSubFragment firstCalleeDoingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1); - - this.addFragmentsWithoutStack( - this.scenarioFragment, - ContextFragment.readCurrentContextData(hub), - this.imcFragment, - accountFragmentFactory.make( - this.preCallCallerAccountSnapshot, - this.inCallCallerAccountSnapshot, - firstCallerDoingDomSubStamps), - accountFragmentFactory.makeWithTrm( - this.preCallCalleeAccountSnapshot, - this.inCallCalleeAccountSnapshot, - this.rawCalledAddress, - firstCalleeDoingDomSubStamps)); - - // caller: WILL_REVERT - // child: FAILURE - // TODO: get the right account snapshots - if (callerCallFrame.willRevert() && calledCallFrame.selfReverts()) { - this.addFragmentsWithoutStack( - accountFragmentFactory.make( - this.inCallCallerAccountSnapshot, - this.preCallCallerAccountSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 2)), - accountFragmentFactory.make( - this.inCallCalleeAccountSnapshot, - this.postCallCalleeAccountSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 3)), - accountFragmentFactory.make( - this.postCallCalleeAccountSnapshot, - this.preCallCalleeAccountSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 4))); - } - - // caller: WILL_REVERT - // child: SUCCESS - // TODO: get the right account snapshots - if (callerCallFrame.willRevert() && !calledCallFrame.selfReverts()) { - this.addFragmentsWithoutStack( - accountFragmentFactory.make( - this.inCallCallerAccountSnapshot, - this.preCallCallerAccountSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 2)), - accountFragmentFactory.make( - this.inCallCalleeAccountSnapshot, - this.preCallCalleeAccountSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hub, 3))); - } - - // caller: WONT_REVERT - // child: FAILURE - // TODO: get the right account snapshots - if (!callerCallFrame.willRevert() && calledCallFrame.selfReverts()) { - if (calledCallFrame.selfReverts()) { - this.addFragmentsWithoutStack( - accountFragmentFactory.make( - this.inCallCallerAccountSnapshot, - this.postCallCallerAccountSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 2)), - accountFragmentFactory.make( - this.inCallCalleeAccountSnapshot, - this.postCallCalleeAccountSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps(hub, calledCallFrame, 3))); - } - } - - // this.addFragmentsWithoutStack(ContextFragment.enterContext(hub, calledCallFrame)); - } -} From b4a45e977ac4c1bd3ba70790d3547fd9aee7ecfa Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 26 Jul 2024 23:22:35 +0200 Subject: [PATCH 301/461] feat(precompiles): precompile subsection work + the ADDRESS_TO_PRECOMPILE map --- .../linea/zktracer/module/hub/Hub.java | 127 +----------------- .../hub/defer/ChildContextEntryDefer.java | 3 +- .../module/hub/defer/DeferRegistry.java | 7 +- .../scenario/PrecompileScenarioFragment.java | 25 +++- .../module/hub/section/TraceSection.java | 2 +- .../module/hub/section/call/CallSection.java | 34 +++-- .../precompileSubsection/PrecompileFlag.java | 2 +- .../PrecompileScenario.java | 2 +- .../PrecompileSubsection.java | 38 +++++- .../precompileSubsection/Sha2SubSection.java | 40 ++++++ .../hub/section/create/CreateSection.java | 2 +- 11 files changed, 134 insertions(+), 148 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index d456c1a334..7df96ff66c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -640,7 +640,7 @@ public void traceContextEnter(MessageFrame frame) { codeDeploymentNumber, isDeployment); - this.defers.resolveUponEnteringChildContext(this, frame); + this.defers.resolveUponEnteringChildContext(this); for (Module m : this.modules) { m.traceContextEnter(frame); @@ -1092,131 +1092,6 @@ void traceOperation(MessageFrame frame) { case CREATE -> new CreateSection(this); case CALL -> new CallSection(this); - // { - // final Address myAddress = this.currentFrame().accountAddress(); - // final Account myAccount = frame.getWorldUpdater().get(myAddress); - // final AccountSnapshot myAccountSnapshot = - // AccountSnapshot.fromAccount( - // myAccount, - // frame.isAddressWarm(myAddress), - // this.transients.conflation().deploymentInfo().number(myAddress), - // this.transients.conflation().deploymentInfo().isDeploying(myAddress)); - // - // final Bytes rawCalledAddress = frame.getStackItem(1); - // final Address calledAddress = Words.toAddress(rawCalledAddress); - // final Optional calledAccount = - // Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)); - // final boolean hasCode = calledAccount.map(AccountState::hasCode).orElse(false); - // - // final AccountSnapshot calledAccountSnapshot = - // AccountSnapshot.fromAccount( - // calledAccount, - // frame.isAddressWarm(myAddress), - // this.transients.conflation().deploymentInfo().number(myAddress), - // this.transients.conflation().deploymentInfo().isDeploying(myAddress)); - // - // Optional targetPrecompile = Precompile.maybeOf(calledAddress); - // - // if (Exceptions.any(this.pch().exceptions())) { - // // - // // THERE IS AN EXCEPTION - // // - // if (Exceptions.staticFault(this.pch().exceptions())) { - // this.addTraceSection( - // new FailedCallSection( - // this, - // ScenarioFragment.forCall(this, hasCode), - // ImcFragment.forCall(this, myAccount, calledAccount), - // ContextFragment.readContextDataByContextNumber( - // this, this.currentFrame().contextNumber()))); // TODO - // } else if (Exceptions.memoryExpansionException(this.pch().exceptions())) { - // this.addTraceSection( - // new FailedCallSection( - // this, - // ScenarioFragment.forCall(this, hasCode), - // ImcFragment.forCall(this, myAccount, calledAccount))); - // } else if (Exceptions.outOfGasException(this.pch().exceptions())) { - // this.addTraceSection( - // new FailedCallSection( - // this, - // ScenarioFragment.forCall(this, hasCode), - // ImcFragment.forCall(this, myAccount, calledAccount), - // this.factories - // .accountFragment() - // .makeWithTrm( - // calledAccountSnapshot, - // calledAccountSnapshot, - // rawCalledAddress, - // DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)))); - // } - // } else if (this.pch.abortingConditions().any()) { - // // - // // THERE IS AN ABORT - // // - // TraceSection abortedSection = - // new FailedCallSection( - // this, - // ScenarioFragment.forCall(this, hasCode), - // ImcFragment.forCall(this, myAccount, calledAccount), - // ContextFragment.readCurrentContextData(this), - // this.factories - // .accountFragment() - // .make( - // myAccountSnapshot, - // myAccountSnapshot, - // DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 0)), - // this.factories - // .accountFragment() - // .makeWithTrm( - // calledAccountSnapshot, - // calledAccountSnapshot, - // rawCalledAddress, - // DomSubStampsSubFragment.standardDomSubStamps(this.stamp(), 1)), - // ContextFragment.nonExecutionProvidesEmptyReturnData(this)); - // this.addTraceSection(abortedSection); - // } else { - // final ImcFragment imcFragment = /* ImcFragment.forOpcode(this, frame)*/ - // ImcFragment.empty(this); - // - // if (hasCode) { - // final SmartContractCallSection section = - // new SmartContractCallSection( - // this, myAccountSnapshot, calledAccountSnapshot, rawCalledAddress, - // imcFragment); - // this.addTraceSection(section); - // this.currentFrame().sectionToUnlatch(section); - // } else { - // // - // // CALL EXECUTED - // // - // - // // TODO: fill the callee & requested return data for the current call frame - // // i.e. ensure that the precompile frame behaves as expected - // - // Optional precompileInvocation = - // targetPrecompile.map(p -> PrecompileInvocation.of(this, p)); - // - // // TODO: this is ugly, and surely not at the right place. It should provide the - // // precompile result (from the precompile module) - // // TODO useless (and potentially dangerous) if the precompile is a failure - // if (targetPrecompile.isPresent()) { - // this.callStack.newPrecompileResult( - // this.stamp(), Bytes.EMPTY, 0, targetPrecompile.get().address); - // } - // - // final NoCodeCallSection section = - // new NoCodeCallSection( - // this, - // precompileInvocation, - // myAccountSnapshot, - // calledAccountSnapshot, - // rawCalledAddress, - // imcFragment); - // this.addTraceSection(section); - // this.currentFrame().sectionToUnlatch(section); - // } - // } - // } case JUMP -> new JumpSection(this); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java index 2d9237e510..7b16b12bbe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java @@ -16,8 +16,7 @@ package net.consensys.linea.zktracer.module.hub.defer; import net.consensys.linea.zktracer.module.hub.Hub; -import org.hyperledger.besu.evm.frame.MessageFrame; public interface ChildContextEntryDefer { - void resolveUponEnteringChildContext(Hub hub, MessageFrame frame); + void resolveUponEnteringChildContext(Hub hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index cf6507f852..04dc06c5c1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -114,6 +114,9 @@ public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame * @param tx the current {@link Transaction} */ // TODO: should use the TransactionProcessingMetadata + + // TODO add docs to understand why we do two rounds of resolving (due to AccountFragment created + // at endTx which are too deferEndTx) @Override public void resolvePostTransaction( Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { @@ -199,9 +202,9 @@ public void resolvePostRollback( } @Override - public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) { + public void resolveUponEnteringChildContext(Hub hub) { for (ChildContextEntryDefer defer : this.childContextEntryDefers) { - defer.resolveUponEnteringChildContext(hub, frame); + defer.resolveUponEnteringChildContext(hub); } this.childContextEntryDefers.clear(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 27854112b7..c0c0cd2044 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -15,5 +15,28 @@ package net.consensys.linea.zktracer.module.hub.fragment.scenario; -public class PrecompileScenarioFragment { +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileFlag; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileScenario; + +@Getter +@AllArgsConstructor +public class PrecompileScenarioFragment implements TraceFragment { + + @Setter PrecompileScenario scenario; + final PrecompileFlag flag; + + public PrecompileScenarioFragment(final PrecompileFlag flag, final PrecompileScenario scenario) { + this.flag = flag; + this.scenario = scenario; + } + + @Override + public Trace trace(Trace trace) { + return null; + } } 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 14b845992d..a267c1a8c1 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 @@ -44,7 +44,7 @@ @Accessors(fluent = true) /* A TraceSection gather the trace lines linked to a single operation */ -public abstract class TraceSection { +public class TraceSection { private final Hub hub; public final CommonFragmentValues commonValues; @Getter List fragments; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 8dda50bdc9..4623e9ed2f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -19,13 +19,17 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.*; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; +import static org.hyperledger.besu.datatypes.Address.SHA256; + +import java.util.Map; +import java.util.function.BiFunction; import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.ChildContextEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; @@ -39,6 +43,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.Sha2SubSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; @@ -47,17 +53,20 @@ import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection - implements PostExecDefer, + implements ChildContextEntryDefer, ContextExitDefer, ReEnterContextDefer, PostRollbackDefer, PostTransactionDefer { + // TODO: finish this map + private static final Map> + ADDRESS_TO_PRECOMPILE = Map.of(SHA256, Sha2SubSection::new); + // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); @@ -92,6 +101,9 @@ public class CallSection extends TraceSection private AccountSnapshot postRollbackCalleeSnapshot; private AccountSnapshot postRollbackCallerSnapshot; + // + private PrecompileSubsection precompileSubsection; + public CallSection(Hub hub) { super(hub, maxNumberOfLines(hub)); hub.addTraceSection(this); @@ -152,7 +164,7 @@ public CallSection(Hub hub) { final boolean aborts = hub.pch().abortingConditions().any(); Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts); - hub.defers().scheduleForPostExecution(this); + hub.defers().scheduleForImmediateContextEntry(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); hub.defers().scheduleForPostTransaction(this); @@ -233,8 +245,7 @@ private void abortingCall(Hub hub) { } @Override - public void resolvePostExecution( - Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + public void resolveUponEnteringChildContext(Hub hub) { switch (scenarioFragment.getScenario()) { case CALL_EOA_SUCCESS_WONT_REVERT, CALL_SMC_UNDEFINED -> { postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); @@ -250,7 +261,13 @@ public void resolvePostExecution( } } case CALL_PRC_UNDEFINED -> { - // TODO: implement + // TODO implement + + precompileSubsection = + ADDRESS_TO_PRECOMPILE.get(preOpcodeCalleeSnapshot.address()).apply(hub, this); + + hub.defers().scheduleForContextReEntry(precompileSubsection, hub.callStack().parent()); + hub.defers().scheduleForPostTransaction(precompileSubsection); } } @@ -310,6 +327,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { } else { scenarioFragment.setScenario(CALL_PRC_FAILURE); } + // TODO: we need to fill the first two account rows! } case CALL_SMC_UNDEFINED -> { @@ -359,7 +377,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca postRollbackCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); postRollbackCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); - CallScenarioFragment.CallScenario callScenario = scenarioFragment.getScenario(); + final CallScenarioFragment.CallScenario callScenario = scenarioFragment.getScenario(); switch (callScenario) { case CALL_ABORT_WONT_REVERT -> completeAbortWillRevert(factory); case CALL_EOA_SUCCESS_WONT_REVERT -> completeEoaSuccessWillRevert(factory); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java index 06a56290a0..6e2d550172 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; -public enum PrecompileFlags { +public enum PrecompileFlag { PRC_ECRECOVER, PRC_SHA2_256, PRC_RIPEMD_160, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java index 44e68892e7..20a5b4249f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java @@ -14,7 +14,7 @@ */ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; -public enum PrecompileScenarios { +public enum PrecompileScenario { PRC_FAILURE_KNOWN_TO_HUB, PRC_FAILURE_KNOWN_TO_RAM, PRC_SUCCESS_WILL_REVERT, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index f56b00e098..a674e5df74 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -17,22 +17,50 @@ import java.util.ArrayList; import java.util.List; -import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.types.MemorySpan; -@AllArgsConstructor +@RequiredArgsConstructor @Accessors(fluent = true) -public abstract class PrecompileSubsection { +public abstract class PrecompileSubsection implements ReEnterContextDefer, PostTransactionDefer { @Getter List fragments; + /* The input data for the precompile */ + final MemorySpan callDataMemorySpan; + + /* Where the caller wants the precompile return data to be stored */ + final MemorySpan parentReturnDataTarget; + + /* Leftover gas of the caller */ + final long callerGas; + + /* Available gas of the callee */ + final long calleeGas; + + /* The intrinsic cost of the precompile */ + long precompileCost; /** * Default creator specifying the max number of rows the precompile processing subsection can * contain. */ - public PrecompileSubsection(final CallSection callSection, final short maxNumberOfLines) { - this.fragments = new ArrayList<>(maxNumberOfLines); + public PrecompileSubsection(final Hub hub, final CallSection callSection) { + fragments = new ArrayList<>(maxNumberOfLines()); + callDataMemorySpan = hub.currentFrame().callDataInfo().memorySpan(); + parentReturnDataTarget = hub.currentFrame().parentReturnDataTarget(); + callerGas = hub.callStack().parent().frame().getRemainingGas(); + calleeGas = hub.messageFrame().getRemainingGas(); } + + private long returnGas() { + return calleeGas - precompileCost; + } + + protected abstract short maxNumberOfLines(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java new file mode 100644 index 0000000000..ccf9db404d --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java @@ -0,0 +1,40 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class Sha2SubSection extends PrecompileSubsection { + public Sha2SubSection(Hub hub, CallSection callSection) { + super(hub, callSection); + } + + @Override + protected short maxNumberOfLines() { + return 3; + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) {} + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 504996f51c..6a8b28765b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -262,7 +262,7 @@ public void resolvePostTransaction( // of both creator and createe were updated (and potentially created) // otherwise do it later @Override - public void resolveUponEnteringChildContext(Hub hub, MessageFrame frame) {} + public void resolveUponEnteringChildContext(Hub hub) {} @Override public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { From 804da0177a8f41b2141bf138330183fc6eab33f0 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 27 Jul 2024 08:57:45 +0200 Subject: [PATCH 302/461] tracing of precompile scenario fragment + cleaning scenario package --- .../scenario/CreateScenarioFragment.java | 45 ++- .../scenario/PrecompileScenarioFragment.java | 54 ++- .../scenario/ReturnScenarioFragment.java | 57 +-- .../hub/fragment/scenario/ScenarioEnum.java | 103 ------ .../fragment/scenario/ScenarioFragment.java | 328 ------------------ .../SelfdestructScenarioFragment.java | 61 ---- .../precompileSubsection/PrecompileFlag.java | 28 -- .../PrecompileScenario.java | 22 -- .../PrecompileSubsection.java | 7 +- .../hub/section/create/AbortCreate.java | 2 +- .../hub/section/create/CreateSection.java | 8 +- .../hub/section/create/ExceptionalCreate.java | 2 +- .../create/FailureOrEmptyInitCreate.java | 13 +- .../create/NonEmptyInitCodeCreate.java | 13 +- 14 files changed, 101 insertions(+), 642 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java index d71b359ff2..ed20b22877 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CreateScenarioFragment.java @@ -14,9 +14,6 @@ */ package net.consensys.linea.zktracer.module.hub.fragment.scenario; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; - -import com.google.common.base.Preconditions; import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; @@ -24,39 +21,53 @@ public class CreateScenarioFragment implements TraceFragment { - @Setter @Getter private ScenarioEnum scenario; + public enum CreateScenario { + UNDEFINED, + CREATE_EXCEPTION, + CREATE_ABORT, + CREATE_FAILURE_CONDITION_WILL_REVERT, + CREATE_FAILURE_CONDITION_WONT_REVERT, + CREATE_EMPTY_INIT_CODE_WILL_REVERT, + CREATE_EMPTY_INIT_CODE_WONT_REVERT, + CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT, + CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT, + CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT, + CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT + } + + @Setter @Getter private CreateScenario scenario; public CreateScenarioFragment() { - this.scenario = ScenarioEnum.UNDEFINED; + this.scenario = CreateScenario.UNDEFINED; } - public CreateScenarioFragment(ScenarioEnum scenario) { + public CreateScenarioFragment(CreateScenario scenario) { this.scenario = scenario; } @Override public Trace trace(Trace trace) { - Preconditions.checkArgument(this.scenario.isCreate()); return trace .peekAtScenario(true) // CREATE scenarios - .pScenarioCreateException(scenario == ScenarioEnum.CREATE_EXCEPTION) - .pScenarioCreateAbort(scenario == ScenarioEnum.CREATE_ABORT) + //////////////////// + .pScenarioCreateException(scenario == CreateScenario.CREATE_EXCEPTION) + .pScenarioCreateAbort(scenario == CreateScenario.CREATE_ABORT) .pScenarioCreateFailureConditionWillRevert( - scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT) + scenario == CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT) .pScenarioCreateFailureConditionWontRevert( - scenario == ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT) + scenario == CreateScenario.CREATE_FAILURE_CONDITION_WONT_REVERT) .pScenarioCreateEmptyInitCodeWillRevert( - scenario == ScenarioEnum.CREATE_EMPTY_INIT_CODE_WILL_REVERT) + scenario == CreateScenario.CREATE_EMPTY_INIT_CODE_WILL_REVERT) .pScenarioCreateEmptyInitCodeWontRevert( - scenario == ScenarioEnum.CREATE_EMPTY_INIT_CODE_WONT_REVERT) + scenario == CreateScenario.CREATE_EMPTY_INIT_CODE_WONT_REVERT) .pScenarioCreateNonemptyInitCodeFailureWillRevert( - scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT) + scenario == CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT) .pScenarioCreateNonemptyInitCodeFailureWontRevert( - scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT) + scenario == CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT) .pScenarioCreateNonemptyInitCodeSuccessWillRevert( - scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT) + scenario == CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT) .pScenarioCreateNonemptyInitCodeSuccessWontRevert( - scenario == ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT); + scenario == CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index c0c0cd2044..2081ae7173 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -20,23 +20,69 @@ import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileFlag; -import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileScenario; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; @Getter @AllArgsConstructor public class PrecompileScenarioFragment implements TraceFragment { + public enum PrecompileScenario { + PRC_FAILURE_KNOWN_TO_HUB, + PRC_FAILURE_KNOWN_TO_RAM, + PRC_SUCCESS_WILL_REVERT, + PRC_SUCCESS_WONT_REVERT + } + + public enum PrecompileFlag { + PRC_ECRECOVER, + PRC_SHA2_256, + PRC_RIPEMD_160, + PRC_IDENTITY, + PRC_MODEXP, + PRC_ECADD, + PRC_ECMUL, + PRC_ECPAIRING, + PRC_BLAKE2F + } + + final PrecompileSubsection precompileSubSection; @Setter PrecompileScenario scenario; final PrecompileFlag flag; - public PrecompileScenarioFragment(final PrecompileFlag flag, final PrecompileScenario scenario) { + public PrecompileScenarioFragment( + final PrecompileSubsection precompileSubsection, + final PrecompileFlag flag, + final PrecompileScenario scenario) { + this.precompileSubSection = precompileSubsection; this.flag = flag; this.scenario = scenario; } @Override public Trace trace(Trace trace) { - return null; + return trace + .peekAtScenario(true) + // // Precompile scenarios + //////////////////// + .pScenarioPrcEcrecover(flag == PrecompileFlag.PRC_ECRECOVER) + .pScenarioPrcSha2256(flag == PrecompileFlag.PRC_SHA2_256) + .pScenarioPrcRipemd160(flag == PrecompileFlag.PRC_RIPEMD_160) + .pScenarioPrcIdentity(flag == PrecompileFlag.PRC_IDENTITY) + .pScenarioPrcModexp(flag == PrecompileFlag.PRC_MODEXP) + .pScenarioPrcEcadd(flag == PrecompileFlag.PRC_ECADD) + .pScenarioPrcEcmul(flag == PrecompileFlag.PRC_ECMUL) + .pScenarioPrcEcpairing(flag == PrecompileFlag.PRC_ECPAIRING) + .pScenarioPrcBlake2F(flag == PrecompileFlag.PRC_BLAKE2F) + .pScenarioPrcSuccessCallerWillRevert(scenario == PrecompileScenario.PRC_SUCCESS_WILL_REVERT) + .pScenarioPrcSuccessCallerWontRevert(scenario == PrecompileScenario.PRC_SUCCESS_WONT_REVERT) + .pScenarioPrcFailureKnownToHub(scenario == PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB) + .pScenarioPrcFailureKnownToRam(scenario == PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM) + .pScenarioPrcCallerGas(precompileSubSection.getCallerGas()) + .pScenarioPrcCalleeGas(precompileSubSection.getCalleeGas()) + .pScenarioPrcReturnGas(precompileSubSection.returnGas()) + .pScenarioPrcCdo(precompileSubSection.getCallDataMemorySpan().offset()) + .pScenarioPrcCds(precompileSubSection.getCallDataMemorySpan().length()) + .pScenarioPrcRao(precompileSubSection.getParentReturnDataTarget().offset()) + .pScenarioPrcRac(precompileSubSection.getParentReturnDataTarget().length()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java index 43cbad3b21..a02703f4e1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ReturnScenarioFragment.java @@ -46,54 +46,8 @@ public Trace trace(Trace trace) { Preconditions.checkArgument(!this.scenario.equals(UNDEFINED)); return trace .peekAtScenario(true) - // // CALL scenarios + // // RETURN scenarios //////////////////// - // .pScenarioCallException(false) - // .pScenarioCallAbort(false) - // .pScenarioCallPrcFailure(false) - // .pScenarioCallPrcSuccessCallerWillRevert(false) - // .pScenarioCallPrcSuccessCallerWontRevert(false) - // .pScenarioCallSmcFailureCallerWillRevert(false) - // .pScenarioCallSmcFailureCallerWontRevert(false) - // .pScenarioCallSmcSuccessCallerWontRevert(false) - // .pScenarioCallSmcSuccessCallerWillRevert(false) - // .pScenarioCallEoaSuccessCallerWontRevert(false) - // .pScenarioCallEoaSuccessCallerWillRevert(false) - // // CREATE scenarios - ////////////////////// - // .pScenarioCreateException(false) .pScenarioCreateAbort(false) - // .pScenarioCreateFailureConditionWillRevert(false) - // .pScenarioCreateFailureConditionWontRevert(false) - // .pScenarioCreateEmptyInitCodeWillRevert(false) - // .pScenarioCreateEmptyInitCodeWontRevert(false) - // .pScenarioCreateNonemptyInitCodeFailureWillRevert(false) - // .pScenarioCreateNonemptyInitCodeFailureWontRevert(false) - // .pScenarioCreateNonemptyInitCodeSuccessWillRevert(false) - // .pScenarioCreateNonemptyInitCodeSuccessWontRevert(false) - // // PRECOMPILE CALL scenarios - /////////////////////////////// - // .pScenarioPrcEcrecover(false) - // .pScenarioPrcSha2256(false) - // .pScenarioPrcRipemd160(false) - // .pScenarioPrcIdentity(false) - // .pScenarioPrcModexp(false) - // .pScenarioPrcEcadd(false) - // .pScenarioPrcEcmul(false) - // .pScenarioPrcEcpairing(false) - // .pScenarioPrcBlake2F(false) - // .pScenarioPrcSuccessCallerWillRevert(false) - // .pScenarioPrcSuccessCallerWontRevert(false) - // .pScenarioPrcFailureKnownToHub(false) - // .pScenarioPrcFailureKnownToRam(false) - // .pScenarioPrcCallerGas(0) - // .pScenarioPrcCalleeGas(0) - // .pScenarioPrcReturnGas(0) - // .pScenarioPrcCdo(0) - // .pScenarioPrcCds(0) - // .pScenarioPrcRao(0) - // .pScenarioPrcRac(0) - // RETURN scenarios - /////////////////// .pScenarioReturnException(this.scenario.equals(RETURN_EXCEPTION)) .pScenarioReturnFromMessageCallWillTouchRam( this.scenario.equals(RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM)) @@ -106,13 +60,6 @@ public Trace trace(Trace trace) { .pScenarioReturnFromDeploymentNonemptyCodeWillRevert( this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT)) .pScenarioReturnFromDeploymentNonemptyCodeWontRevert( - this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT)) - // // SELFDESTRUCT scenarios - //////////////////////////// - // .pScenarioSelfdestructException(false) - // .pScenarioSelfdestructWillRevert(false) - // .pScenarioSelfdestructWontRevertAlreadyMarked(false) - // .pScenarioSelfdestructWontRevertNotYetMarked(false) - ; + this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java deleted file mode 100644 index 344a1b5b86..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioEnum.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package net.consensys.linea.zktracer.module.hub.fragment.scenario; - -public enum ScenarioEnum { - /** unset values, to be defined */ - UNDEFINED, - /** scenarios related to CALL-type instructions */ - CALL, - /** scenarios related to CREATE(2) instructions */ - CREATE_EXCEPTION, - CREATE_ABORT, - - CREATE_FAILURE_CONDITION_WILL_REVERT, - CREATE_FAILURE_CONDITION_WONT_REVERT, - CREATE_EMPTY_INIT_CODE_WILL_REVERT, - CREATE_EMPTY_INIT_CODE_WONT_REVERT, - CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT, - CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT, - CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT, - CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT, - /** scenarios related to RETURN */ - RETURN, - RETURN_EXCEPTION, - RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM, - RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM, - RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT, - RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT, - RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT, - RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT, - /** scenarios related to SELFDESTRUCT */ - SELFDESTRUCT, // duplicated logic? - SELFDESTRUCT_EXCEPTION, - SELFDESTRUCT_WILL_REVERT, - SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED, - SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED, - /** describes the second scenario line required by a call to a precompile */ - PRECOMPILE; - - boolean isCall() { - return this == CALL; - } - - boolean isPrecompile() { - return this == PRECOMPILE; - } - - public boolean isCreate() { - return this.isAnyOf( - CREATE_EXCEPTION, - CREATE_ABORT, - CREATE_FAILURE_CONDITION_WILL_REVERT, - CREATE_FAILURE_CONDITION_WONT_REVERT, - CREATE_EMPTY_INIT_CODE_WILL_REVERT, - CREATE_EMPTY_INIT_CODE_WONT_REVERT, - CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT, - CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT, - CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT, - CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT); - } - - boolean isReturn() { - return this.isAnyOf( - RETURN_EXCEPTION, - RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM, - RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM, - RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT, - RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT, - RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT, - RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); - } - - boolean isSelfDestruct() { - return this.isAnyOf( - SELFDESTRUCT, - SELFDESTRUCT_EXCEPTION, - SELFDESTRUCT_WILL_REVERT, - SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED, - SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED); - } - - public boolean isAnyOf(ScenarioEnum... scenarios) { - for (ScenarioEnum scenario : scenarios) { - if (scenario.equals(this)) { - return true; - } - } - - return false; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java deleted file mode 100644 index a0916ab1fe..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/ScenarioFragment.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.fragment.scenario; - -import java.util.Optional; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.types.MemorySpan; -import net.consensys.linea.zktracer.types.Precompile; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** This machine generates lines */ -@RequiredArgsConstructor -public class ScenarioFragment implements TraceFragment, PostTransactionDefer { - - ScenarioEnum scenario; - // TODO: add the duplicate values required for PRC calls - - private final Optional precompileCall; - private final ScenarioEnum type; - - /** - * Is set if: - this is a CALL to an EOA or a precompile - this is a CREATE with an empty initcode - */ - private final boolean targetHasCode; - - private final int callerId; - private final int calleeId; - private final boolean raisedException; - private final boolean hasAborted; - private final boolean hasFailed; - private final boolean raisedInvalidCodePrefix; - - private boolean callerReverts = false; - - MemorySpan callDataSegment; - MemorySpan parentReturnDataTarget; - - /** - * Is set if: - this is a CALL and the callee reverts - this is a CREATE and the creation failed - - * this is a PRECOMPILE and the call is invalid (wrong arguments, lack of gas, ...) - */ - private boolean childContextFails = false; - - public static ScenarioFragment forCall(final Hub hub, boolean targetHasCode) { - ScenarioFragment r = - new ScenarioFragment( - Optional.empty(), - ScenarioEnum.CALL, - targetHasCode, - hub.currentFrame().id(), - hub.callStack().futureId(), - Exceptions.any(hub.pch().exceptions()), - hub.pch().abortingConditions().any(), - false, - Exceptions.invalidCodePrefix(hub.pch().exceptions())); - hub.defers().scheduleForPostTransaction(r); - return r; - } - - public static ScenarioFragment forSmartContractCallSection( - final Hub hub, int calledFrameId, int callerFrameId) { - final ScenarioFragment r = - new ScenarioFragment( - Optional.empty(), - ScenarioEnum.CALL, - true, - callerFrameId, - calledFrameId, - false, - false, - false, - false); - r.callDataSegment = hub.transients().op().callDataSegment(); - r.parentReturnDataTarget = hub.transients().op().returnDataRequestedSegment(); - return r; - } - - public static ScenarioFragment forNoCodeCallSection( - final Hub hub, Optional precompileCall, int callerId, int calleeId) { - ScenarioFragment r; - if (precompileCall.isPresent()) { - r = - new ScenarioFragment( - precompileCall, - ScenarioEnum.CALL, - false, - callerId, - calleeId, - false, - false, - false, - false); - } else { - r = - new ScenarioFragment( - Optional.empty(), - ScenarioEnum.CALL, - false, - callerId, - calleeId, - false, - false, - false, - false); - } - r.callDataSegment = hub.transients().op().callDataSegment(); - r.parentReturnDataTarget = hub.transients().op().returnDataRequestedSegment(); - - r.fillPostCallInformation(hub); - return r; - } - - public static ScenarioFragment forPrecompileEpilogue( - final Hub hub, PrecompileInvocation precompile, int callerId, int calleeId) { - final ScenarioFragment r = - new ScenarioFragment( - Optional.of(precompile), - ScenarioEnum.PRECOMPILE, - false, - callerId, - calleeId, - false, - false, - false, - false); - // This one is already created from a post-tx hook - r.callDataSegment = precompile.callDataSource(); - r.parentReturnDataTarget = precompile.requestedReturnDataTarget(); - r.fillPostCallInformation(hub); - return r; - } - - private boolean calleeSelfReverts() { - return this.childContextFails; - } - - private boolean creationFailed() { - return this.childContextFails; - } - - private boolean successfulPrecompileCall() { - return !this.childContextFails; - } - - private boolean targetIsPrecompile() { - return this.precompileCall.isPresent(); - } - - /** - * Fill the information related to the CALL this fragment stems from. This may be done either - * through a defer if the fragment is created at runtime, or directly if the fragment is already - * created within a post-transaction defer. - * - * @param hub the execution context - */ - private void fillPreCallInformation(final Hub hub) { - this.callDataSegment = hub.callStack().getById(calleeId).callDataInfo().memorySpan(); - this.parentReturnDataTarget = hub.callStack().getById(calleeId).parentReturnDataTarget(); - } - - /** - * Fill the information related to the CALL this fragment stems from. This may be done either - * through a defer if the fragment is created at runtime, or directly if the fragment is already - * created within a post-transaction defer. - * - * @param hub the execution context - */ - private void fillPostCallInformation(final Hub hub) { - // It does not make sense to interrogate a child frame that was never created - if (!this.hasFailed && !this.hasAborted && !this.raisedException && targetHasCode) { - // TODO: can a context without code reverts? @Olivier - this.childContextFails = hub.callStack().getById(calleeId).hasReverted(); - } - this.callerReverts = hub.callStack().getById(callerId).hasReverted(); - } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - this.fillPostCallInformation(hub); - } - - // TODO: should disappear - @Override - public Trace trace(Trace trace) { - return trace - .peekAtScenario(true) - .pScenarioCallException(type.isCall() && raisedException) - .pScenarioCallAbortWontRevert( - type.isCall() && hasAborted) // TODO: this is false but will disappear - .pScenarioCallAbortWillRevert( - type.isCall() && hasAborted) // TODO: this is false but will disappear - .pScenarioCallPrcFailure( - type.isCall() - && !hasAborted - && targetIsPrecompile() - && !callerReverts - && this.calleeSelfReverts()) - .pScenarioCallPrcSuccessCallerWillRevert( - type.isCall() - && !hasAborted - && targetIsPrecompile() - && callerReverts - && !this.calleeSelfReverts()) - .pScenarioCallPrcSuccessCallerWontRevert( - type.isCall() - && !hasAborted - && targetIsPrecompile() - && !callerReverts - && !this.calleeSelfReverts()) - .pScenarioCallSmcFailureCallerWillRevert( - type.isCall() - && !hasAborted - && targetHasCode - && callerReverts - && this.calleeSelfReverts()) - .pScenarioCallSmcFailureCallerWontRevert( - type.isCall() - && !hasAborted - && targetHasCode - && !callerReverts - && this.calleeSelfReverts()) - .pScenarioCallSmcSuccessCallerWontRevert( - type.isCall() - && !hasAborted - && targetHasCode - && !callerReverts - && !this.calleeSelfReverts()) - .pScenarioCallSmcSuccessCallerWillRevert( - type.isCall() - && !hasAborted - && targetHasCode - && callerReverts - && !this.calleeSelfReverts()) - .pScenarioCallEoaSuccessCallerWontRevert( - type.isCall() - && !hasAborted - && !targetIsPrecompile() - && !targetHasCode - && !callerReverts) - .pScenarioCallEoaSuccessCallerWillRevert( - type.isCall() - && !hasAborted - && !targetIsPrecompile() - && !targetHasCode - && callerReverts) - // .pScenarioCreateException(type.isCreate() && raisedException) - // .pScenarioCreateAbort(type.isCreate() && hasAborted) - // .pScenarioCreateFailureConditionWillRevert(type.isCreate() && hasFailed && callerReverts) - // .pScenarioCreateFailureConditionWontRevert(type.isCreate() && hasFailed && - // !callerReverts) - // .pScenarioCreateEmptyInitCodeWillRevert(type.isCreate() && !targetHasCode && - // callerReverts) - // .pScenarioCreateEmptyInitCodeWontRevert(type.isCreate() && !targetHasCode && - // !callerReverts) - // .pScenarioCreateNonemptyInitCodeFailureWillRevert( - // type.isCreate() && targetHasCode && creationFailed() && callerReverts) - // .pScenarioCreateNonemptyInitCodeFailureWontRevert( - // type.isCreate() && targetHasCode && creationFailed() && !callerReverts) - // .pScenarioCreateNonemptyInitCodeSuccessWillRevert( - // type.isCreate() && targetHasCode && !creationFailed() && callerReverts) - // .pScenarioCreateNonemptyInitCodeSuccessWontRevert( - // type.isCreate() && targetHasCode && !creationFailed() && !callerReverts) - .pScenarioPrcEcrecover( - precompileCall.map(x -> x.precompile().equals(Precompile.EC_RECOVER)).orElse(false)) - .pScenarioPrcSha2256( - precompileCall.map(x -> x.precompile().equals(Precompile.SHA2_256)).orElse(false)) - .pScenarioPrcRipemd160( - precompileCall.map(x -> x.precompile().equals(Precompile.RIPEMD_160)).orElse(false)) - .pScenarioPrcIdentity( - precompileCall.map(x -> x.precompile().equals(Precompile.IDENTITY)).orElse(false)) - .pScenarioPrcModexp( - precompileCall.map(x -> x.precompile().equals(Precompile.MODEXP)).orElse(false)) - .pScenarioPrcEcadd( - precompileCall.map(x -> x.precompile().equals(Precompile.EC_ADD)).orElse(false)) - .pScenarioPrcEcmul( - precompileCall.map(x -> x.precompile().equals(Precompile.EC_MUL)).orElse(false)) - .pScenarioPrcEcpairing( - precompileCall.map(x -> x.precompile().equals(Precompile.EC_PAIRING)).orElse(false)) - .pScenarioPrcBlake2F( - precompileCall.map(x -> x.precompile().equals(Precompile.BLAKE2F)).orElse(false)) - .pScenarioPrcSuccessCallerWillRevert( - type.isPrecompile() && successfulPrecompileCall() && callerReverts) - .pScenarioPrcSuccessCallerWontRevert( - type.isPrecompile() && successfulPrecompileCall() && !callerReverts) - .pScenarioPrcFailureKnownToHub( - precompileCall.map(PrecompileInvocation::hubFailure).orElse(false)) - .pScenarioPrcFailureKnownToRam( - precompileCall.map(PrecompileInvocation::ramFailure).orElse(false)) - .pScenarioPrcCallerGas(precompileCall.map(s -> s.gasAtCall() - s.opCodeGas()).orElse(0L)) - .pScenarioPrcCalleeGas(precompileCall.map(PrecompileInvocation::gasAllowance).orElse(0L)) - .pScenarioPrcReturnGas( - precompileCall - .filter(s -> successfulPrecompileCall()) - .map(s -> s.gasAllowance() - s.precompilePrice()) - .orElse(0L)) - .pScenarioPrcCdo(type.isPrecompile() ? callDataSegment.offset() : 0) - .pScenarioPrcCds(type.isPrecompile() ? callDataSegment.length() : 0) - .pScenarioPrcRao(type.isPrecompile() ? parentReturnDataTarget.offset() : 0) - .pScenarioPrcRac(type.isPrecompile() ? parentReturnDataTarget.length() : 0) - // .pScenarioCodedeposit(type.isDeposit()) - // .pScenarioCodedepositInvalidCodePrefix(type.isDeposit() && raisedInvalidCodePrefix) - // .pScenarioCodedepositValidCodePrefix(false) // TODO: @Olivier - // .pScenarioSelfdestruct(false); // TODO: @Olivier - ; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java index 644f29fbea..7d0982d190 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/SelfdestructScenarioFragment.java @@ -43,67 +43,6 @@ public Trace trace(Trace trace) { Preconditions.checkArgument(!this.scenario.equals(UNDEFINED)); return trace .peekAtScenario(true) - // // CALL scenarios - //////////////////// - // .pScenarioCallException(false) - // .pScenarioCallAbort(false) - // .pScenarioCallPrcFailure(false) - // .pScenarioCallPrcSuccessCallerWillRevert(false) - // .pScenarioCallPrcSuccessCallerWontRevert(false) - // .pScenarioCallSmcFailureCallerWillRevert(false) - // .pScenarioCallSmcFailureCallerWontRevert(false) - // .pScenarioCallSmcSuccessCallerWontRevert(false) - // .pScenarioCallSmcSuccessCallerWillRevert(false) - // .pScenarioCallEoaSuccessCallerWontRevert(false) - // .pScenarioCallEoaSuccessCallerWillRevert(false) - // // CREATE scenarios - ////////////////////// - // .pScenarioCreateException(false) .pScenarioCreateAbort(false) - // .pScenarioCreateFailureConditionWillRevert(false) - // .pScenarioCreateFailureConditionWontRevert(false) - // .pScenarioCreateEmptyInitCodeWillRevert(false) - // .pScenarioCreateEmptyInitCodeWontRevert(false) - // .pScenarioCreateNonemptyInitCodeFailureWillRevert(false) - // .pScenarioCreateNonemptyInitCodeFailureWontRevert(false) - // .pScenarioCreateNonemptyInitCodeSuccessWillRevert(false) - // .pScenarioCreateNonemptyInitCodeSuccessWontRevert(false) - // // PRECOMPILE CALL scenarios - /////////////////////////////// - // .pScenarioPrcEcrecover(false) - // .pScenarioPrcSha2256(false) - // .pScenarioPrcRipemd160(false) - // .pScenarioPrcIdentity(false) - // .pScenarioPrcModexp(false) - // .pScenarioPrcEcadd(false) - // .pScenarioPrcEcmul(false) - // .pScenarioPrcEcpairing(false) - // .pScenarioPrcBlake2F(false) - // .pScenarioPrcSuccessCallerWillRevert(false) - // .pScenarioPrcSuccessCallerWontRevert(false) - // .pScenarioPrcFailureKnownToHub(false) - // .pScenarioPrcFailureKnownToRam(false) - // .pScenarioPrcCallerGas(0) - // .pScenarioPrcCalleeGas(0) - // .pScenarioPrcReturnGas(0) - // .pScenarioPrcCdo(0) - // .pScenarioPrcCds(0) - // .pScenarioPrcRao(0) - // .pScenarioPrcRac(0) - // RETURN scenarios - /////////////////// - // .pScenarioReturnException(this.scenario.equals(RETURN_EXCEPTION)) - // .pScenarioReturnFromMessageCallWillTouchRam( - // this.scenario.equals(RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM)) - // .pScenarioReturnFromMessageCallWontTouchRam( - // this.scenario.equals(RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM)) - // .pScenarioReturnFromDeploymentEmptyCodeWillRevert( - // this.scenario.equals(RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT)) - // .pScenarioReturnFromDeploymentEmptyCodeWontRevert( - // this.scenario.equals(RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT)) - // .pScenarioReturnFromDeploymentNonemptyCodeWillRevert( - // this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT)) - // .pScenarioReturnFromDeploymentNonemptyCodeWontRevert( - // this.scenario.equals(RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT)) // // SELFDESTRUCT scenarios //////////////////////////// .pScenarioSelfdestructException( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java deleted file mode 100644 index 6e2d550172..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileFlag.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; - -public enum PrecompileFlag { - PRC_ECRECOVER, - PRC_SHA2_256, - PRC_RIPEMD_160, - PRC_IDENTITY, - PRC_MODEXP, - PRC_ECADD, - PRC_ECMUL, - PRC_ECPAIRING, - PRC_BLAKE2F -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java deleted file mode 100644 index 20a5b4249f..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileScenario.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; - -public enum PrecompileScenario { - PRC_FAILURE_KNOWN_TO_HUB, - PRC_FAILURE_KNOWN_TO_RAM, - PRC_SUCCESS_WILL_REVERT, - PRC_SUCCESS_WONT_REVERT -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index a674e5df74..e41619232f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -19,7 +19,6 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; @@ -28,9 +27,9 @@ import net.consensys.linea.zktracer.types.MemorySpan; @RequiredArgsConstructor -@Accessors(fluent = true) +@Getter public abstract class PrecompileSubsection implements ReEnterContextDefer, PostTransactionDefer { - @Getter List fragments; + List fragments; /* The input data for the precompile */ final MemorySpan callDataMemorySpan; @@ -58,7 +57,7 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { calleeGas = hub.messageFrame().getRemainingGas(); } - private long returnGas() { + public long returnGas() { return calleeGas - precompileCost; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java index c47ea20507..61c3a1c57a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section.create; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_ABORT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_ABORT; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 6a8b28765b..98f8c8eba7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -15,8 +15,8 @@ package net.consensys.linea.zktracer.module.hub.section.create; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_EMPTY_INIT_CODE_WONT_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EMPTY_INIT_CODE_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WONT_REVERT; import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; import java.util.Optional; @@ -35,7 +35,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; @@ -163,7 +163,7 @@ public CreateSection(Hub hub) { final boolean emptyInitCode = hub.transients().op().initCodeSegment().isEmpty(); if (failureCondition || emptyInitCode) { - final ScenarioEnum scenario = + final CreateScenarioFragment.CreateScenario scenario = failureCondition ? CREATE_FAILURE_CONDITION_WONT_REVERT : CREATE_EMPTY_INIT_CODE_WONT_REVERT; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java index 29dfd4ca4c..1c63440d6a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section.create; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_EXCEPTION; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EXCEPTION; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java index 93a978a86e..fc76203aa4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.hub.section.create; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_EMPTY_INIT_CODE_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_FAILURE_CONDITION_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EMPTY_INIT_CODE_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WONT_REVERT; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -27,7 +27,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class FailureOrEmptyInitCreate extends TraceSection implements FillCreateSection { @@ -35,7 +34,7 @@ public class FailureOrEmptyInitCreate extends TraceSection implements FillCreate public FailureOrEmptyInitCreate( final Hub hub, - final ScenarioEnum scenario, + final CreateScenarioFragment.CreateScenario scenario, final ContextFragment currentContextFragment, final ImcFragment imcFragment) { super(hub, (short) 10); @@ -88,8 +87,8 @@ public void fillReverting( AccountSnapshot oldCreatedSnapshot, AccountSnapshot midCreatedSnapshot, AccountSnapshot newCreatedSnapshot) { - final ScenarioEnum newScenario = - this.scenarioFragment.getScenario() == CREATE_FAILURE_CONDITION_WONT_REVERT + final CreateScenarioFragment.CreateScenario newScenario = + scenarioFragment.getScenario() == CREATE_FAILURE_CONDITION_WONT_REVERT ? CREATE_FAILURE_CONDITION_WILL_REVERT : CREATE_EMPTY_INIT_CODE_WILL_REVERT; this.scenarioFragment.setScenario(newScenario); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index 4c9ff7c099..5e0abe894c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -15,10 +15,10 @@ package net.consensys.linea.zktracer.module.hub.section.create; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -28,7 +28,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.ScenarioEnum; import net.consensys.linea.zktracer.module.hub.section.TraceSection; public class NonEmptyInitCodeCreate extends TraceSection implements FillCreateSection { @@ -57,7 +56,7 @@ public void fillAccountFragment( AccountSnapshot oldCreatedSnapshot, AccountSnapshot midCreatedSnapshot, AccountSnapshot newCreatedSnapshot) { - final ScenarioEnum scenario = + final CreateScenarioFragment.CreateScenario scenario = createSuccess ? CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT : CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; @@ -113,7 +112,7 @@ public void fillReverting( AccountSnapshot midCreatedSnapshot, AccountSnapshot newCreatedSnapshot) { - final ScenarioEnum newScenario = + final CreateScenarioFragment.CreateScenario newScenario = createSuccess ? CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT : CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; From 14570a2a67690abf73d0180540885780ff220b76 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 27 Jul 2024 09:18:19 +0200 Subject: [PATCH 303/461] ras --- .../precompileSubsection/PrecompileSubsection.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index e41619232f..6e5f0fb013 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -29,20 +29,22 @@ @RequiredArgsConstructor @Getter public abstract class PrecompileSubsection implements ReEnterContextDefer, PostTransactionDefer { - List fragments; - /* The input data for the precompile */ + /** List of fragments of the precompile specific subsection */ + final List fragments; + + /** The input data for the precompile */ final MemorySpan callDataMemorySpan; - /* Where the caller wants the precompile return data to be stored */ + /** Where the caller wants the precompile return data to be stored */ final MemorySpan parentReturnDataTarget; - /* Leftover gas of the caller */ + /** Leftover gas of the caller */ final long callerGas; - /* Available gas of the callee */ + /** Available gas of the callee */ final long calleeGas; - /* The intrinsic cost of the precompile */ + /** The intrinsic cost of the precompile */ long precompileCost; /** From 17563d30f812d3c0979f6cd980c3a3febb30d7f7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 27 Jul 2024 10:42:47 +0200 Subject: [PATCH 304/461] ras --- .../zktracer/module/hub/section/TraceSection.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 a267c1a8c1..4c078ad7d4 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 @@ -104,6 +104,17 @@ public final void addFragmentsWithoutStack(TraceFragment... fragments) { } } + /** + * Add several fragments within this section for the specified fragments. + * + * @param fragments the fragments to add to the section + */ + public final void addFragmentsWithoutStack(List fragments) { + for (TraceFragment f : fragments) { + this.addFragment(f); + } + } + /** * Insert Stack fragments related to the current state of the stack, then insert the provided * fragments in a single swoop. From 2fb751a5b3b6509e07ade9ac4efe02d9d64cf172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 27 Jul 2024 10:43:50 +0200 Subject: [PATCH 305/461] feat(precompile subsection): generic methods wip --- .../scenario/CallScenarioFragment.java | 13 ++++- .../scenario/PrecompileScenarioFragment.java | 7 ++- .../module/hub/section/call/CallSection.java | 9 ++++ .../PrecompileSubsection.java | 50 ++++++++++++++++--- .../precompileSubsection/Sha2SubSection.java | 20 +++++++- 5 files changed, 89 insertions(+), 10 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java index 21fdde00b9..b45a651511 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -52,7 +52,18 @@ public enum CallScenario { CALL_PRC_UNDEFINED, CALL_PRC_FAILURE, CALL_PRC_SUCCESS_WILL_REVERT, - CALL_PRC_SUCCESS_WONT_REVERT + CALL_PRC_SUCCESS_WONT_REVERT; + + public boolean isPrecompileScenario() { + return this == CALL_PRC_FAILURE || + this == CALL_PRC_SUCCESS_WILL_REVERT || + this == CALL_PRC_SUCCESS_WONT_REVERT; + } + + public boolean noLongerUndefined() { + return this != UNDEFINED && this != CALL_PRC_UNDEFINED && this != CALL_SMC_UNDEFINED; + } + } private static final List illegalTracingScenario = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 2081ae7173..78388f39ac 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.scenario; +import com.google.common.base.Preconditions; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -27,6 +28,7 @@ public class PrecompileScenarioFragment implements TraceFragment { public enum PrecompileScenario { + PRC_UNDEFINED_SCENARIO, PRC_FAILURE_KNOWN_TO_HUB, PRC_FAILURE_KNOWN_TO_RAM, PRC_SUCCESS_WILL_REVERT, @@ -34,6 +36,7 @@ public enum PrecompileScenario { } public enum PrecompileFlag { + PRC_UNDEFINED, PRC_ECRECOVER, PRC_SHA2_256, PRC_RIPEMD_160, @@ -47,7 +50,7 @@ public enum PrecompileFlag { final PrecompileSubsection precompileSubSection; @Setter PrecompileScenario scenario; - final PrecompileFlag flag; + @Setter PrecompileFlag flag; public PrecompileScenarioFragment( final PrecompileSubsection precompileSubsection, @@ -60,6 +63,8 @@ public PrecompileScenarioFragment( @Override public Trace trace(Trace trace) { + Preconditions.checkArgument(this.scenario != PrecompileScenario.PRC_UNDEFINED_SCENARIO); + Preconditions.checkArgument(this.flag != PrecompileFlag.PRC_UNDEFINED); return trace .peekAtScenario(true) // // Precompile scenarios diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 4623e9ed2f..ab019c322f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -35,6 +35,7 @@ import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -393,6 +394,12 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + CallScenarioFragment.CallScenario scenario = scenarioFragment.getScenario(); + + Preconditions.checkArgument(scenario.noLongerUndefined()); + + // iterate over the precompileSubsection + this.addFragment(finalContextFragment); } @@ -482,4 +489,6 @@ private void completeSmcSuccessWillRevertOrPrcSuccessWillRevert(Factories factor this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); } + + } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 6e5f0fb013..45225e8cdd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -20,15 +20,28 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.MemorySpan; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.worldstate.WorldView; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_UNDEFINED; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; +import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; + +/** Note: {@link PrecompileSubsection}'s are created at child context entry by the call section */ @RequiredArgsConstructor @Getter -public abstract class PrecompileSubsection implements ReEnterContextDefer, PostTransactionDefer { +public class PrecompileSubsection implements ContextExitDefer, ReEnterContextDefer, PostRollbackDefer, PostTransactionDefer { /** List of fragments of the precompile specific subsection */ final List fragments; @@ -44,8 +57,12 @@ public abstract class PrecompileSubsection implements ReEnterContextDefer, PostT /** Available gas of the callee */ final long calleeGas; - /** The intrinsic cost of the precompile */ - long precompileCost; + /** The gas to return to the caller context */ + long returnGas; + + boolean successBit; + + final PrecompileScenarioFragment precompileScenarioFragment; /** * Default creator specifying the max number of rows the precompile processing subsection can @@ -57,11 +74,32 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { parentReturnDataTarget = hub.currentFrame().parentReturnDataTarget(); callerGas = hub.callStack().parent().frame().getRemainingGas(); calleeGas = hub.messageFrame().getRemainingGas(); + precompileScenarioFragment = new PrecompileScenarioFragment(this, PRC_UNDEFINED_SCENARIO, PRC_UNDEFINED); + } + + protected short maxNumberOfLines() {return 0;}; + + public void resolveUponExitingContext(Hub hub, CallFrame frame) { + returnGas = frame.frame().getRemainingGas(); } - public long returnGas() { - return calleeGas - precompileCost; + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) { + successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); + if (successBit) { + hub.defers().scheduleForPostRollback(this, frame); + precompileScenarioFragment.setScenario(PRC_SUCCESS_WONT_REVERT); + } } - protected abstract short maxNumberOfLines(); + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + + precompileScenarioFragment.setScenario(PRC_SUCCESS_WILL_REVERT); + } + + @Override + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java index ccf9db404d..df3c7ce3c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java @@ -16,25 +16,41 @@ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_UNDEFINED; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_UNDEFINED_SCENARIO; +import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; + public class Sha2SubSection extends PrecompileSubsection { public Sha2SubSection(Hub hub, CallSection callSection) { super(hub, callSection); + precompileScenarioFragment.setFlag(PRC_SHA2_256); } + // 4 = 1 + 3 (scenario row + up to 3 miscellaneous fragments) @Override protected short maxNumberOfLines() { - return 3; + return (short) (successBit ? 4 : 2); + } + + @Override + public void resolveUponExitingContext(Hub hub, CallFrame frame) { + // TODO } @Override - public void resolveAtContextReEntry(Hub hub, CallFrame frame) {} + public void resolveAtContextReEntry(Hub hub, CallFrame frame) { + super.resolveAtContextReEntry(hub, frame); + } @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + } From 0fbc0c6aeb787d6116b9f80e9e39ef780b994190 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 27 Jul 2024 11:15:12 +0200 Subject: [PATCH 306/461] fix(mmuCall): split the SHA2/RIPEMD mmu calls in 3 --- .../linea/zktracer/module/hub/Hub.java | 4 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 89 ++++++++++--------- .../scenario/CallScenarioFragment.java | 7 +- .../scenario/PrecompileScenarioFragment.java | 2 +- .../precompiles/PrecompileLinesGenerator.java | 1 + .../module/hub/section/ContextSection.java | 2 +- .../module/hub/section/ExpSection.java | 2 +- .../module/hub/section/JumpSection.java | 5 +- .../module/hub/section/KeccakSection.java | 2 +- .../module/hub/section/LogSection.java | 2 +- .../module/hub/section/SloadSection.java | 2 +- .../module/hub/section/SstoreSection.java | 2 +- .../module/hub/section/TraceSection.java | 8 +- .../hub/section/TransactionSection.java | 2 +- .../hub/section/TxFinalizationSection.java | 2 +- .../hub/section/TxInitializationSection.java | 2 +- .../hub/section/TxPreWarmingMacroSection.java | 2 +- .../hub/section/TxSkippedSectionDefers.java | 2 +- .../module/hub/section/call/CallSection.java | 20 ++--- .../PrecompileSubsection.java | 27 +++--- .../precompileSubsection/Sha2SubSection.java | 9 +- .../hub/section/copy/CallDataCopySection.java | 2 +- .../hub/section/copy/CodeCopySection.java | 2 +- .../section/copy/ReturnDataCopySection.java | 2 +- .../hub/section/create/AbortCreate.java | 2 +- .../hub/section/create/ExceptionalCreate.java | 2 +- .../create/FailureOrEmptyInitCreate.java | 6 +- .../create/NonEmptyInitCodeCreate.java | 8 +- .../hub/section/halt/RevertSection.java | 4 +- .../module/hub/section/halt/StopSection.java | 8 +- 30 files changed, 113 insertions(+), 117 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 7df96ff66c..e9f7c5dcc3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -733,7 +733,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope ////////////////////////////////////////////////////// if (exceptional) { this.currentTraceSection() - .addFragmentsWithoutStack(ContextFragment.executionProvidesEmptyReturnData(this)); + .addFragments(ContextFragment.executionProvidesEmptyReturnData(this)); this.squashCurrentFrameOutputData(); this.squashParentFrameReturnData(); } @@ -907,7 +907,7 @@ TraceSection currentTraceSection() { } public void addFragmentsAndStack(TraceFragment... fragments) { - currentTraceSection().addFragmentsAndStack(this, fragments); + currentTraceSection().addStackAndFragments(this, fragments); } public void addTraceSection(TraceSection section) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 7acd8aaf8c..9e5ac83560 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -353,61 +353,62 @@ public static MmuCall forEcRecover( } } - private static MmuCall forRipeMd160Sha( - final Hub hub, PrecompileInvocation p, int i, final boolean isSha) { - Preconditions.checkArgument(i >= 0 && i < 3); + private static MmuCall forShaTwoOrRipemdCallDataExtraction( + final Hub hub, PrecompileInvocation p, final boolean isSha) { final int precompileContextNumber = p.hubStamp() + 1; - if (i == 0) { - if (p.callDataSource().isEmpty()) { - return nop(); - } else { - return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .size(p.callDataSource().length()) - .referenceSize(p.callDataSource().length()) - .phase(isSha ? PHASE_SHA2_DATA : PHASE_RIPEMD_DATA) - .setRipSha(); - } - } else if (i == 1) { - if (p.callDataSource().isEmpty()) { - return new MmuCall(MMU_INST_MSTORE) - .targetId(precompileContextNumber) - .targetOffset(EWord.ZERO) - .limb1(isSha ? bigIntegerToBytes(EMPTY_SHA2_HI) : Bytes.ofUnsignedLong(EMPTY_RIPEMD_HI)) - .limb2(isSha ? bigIntegerToBytes(EMPTY_SHA2_LO) : bigIntegerToBytes(EMPTY_RIPEMD_LO)); - } else { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(precompileContextNumber) - .targetId(precompileContextNumber) - .size(WORD_SIZE) - .phase(isSha ? PHASE_SHA2_RESULT : PHASE_RIPEMD_RESULT) - .setRipSha(); - } + return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + .sourceId(hub.currentFrame().contextNumber()) + .targetId(precompileContextNumber) + .sourceOffset(EWord.of(p.callDataSource().offset())) + .size(p.callDataSource().length()) + .referenceSize(p.callDataSource().length()) + .phase(isSha ? PHASE_SHA2_DATA : PHASE_RIPEMD_DATA) + .setRipSha(); + } + + private static MmuCall forShaTwoOrRipemdFullResultTransfer( + final Hub hub, PrecompileInvocation p, final boolean isSha) { + + final int precompileContextNumber = p.hubStamp() + 1; + + if (p.callDataSource().isEmpty()) { + return new MmuCall(MMU_INST_MSTORE) + .targetId(precompileContextNumber) + .targetOffset(EWord.ZERO) + .limb1(isSha ? bigIntegerToBytes(EMPTY_SHA2_HI) : Bytes.ofUnsignedLong(EMPTY_RIPEMD_HI)) + .limb2(isSha ? bigIntegerToBytes(EMPTY_SHA2_LO) : bigIntegerToBytes(EMPTY_RIPEMD_LO)); } else { - if (p.requestedReturnDataTarget().isEmpty()) { - return nop(); - } else { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.ZERO) - .size(WORD_SIZE) - .referenceOffset(p.requestedReturnDataTarget().offset()) - .referenceSize(p.requestedReturnDataTarget().length()); - } + return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + .sourceId(precompileContextNumber) + .targetId(precompileContextNumber) + .size(WORD_SIZE) + .phase(isSha ? PHASE_SHA2_RESULT : PHASE_RIPEMD_RESULT) + .setRipSha(); } } + private static MmuCall forShaTwoOrRipemdPartialResultCopy( + final Hub hub, PrecompileInvocation p, final boolean isSha) { + + final int precompileContextNumber = p.hubStamp() + 1; + + return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(precompileContextNumber) + .targetId(hub.currentFrame().contextNumber()) + .sourceOffset(EWord.ZERO) + .size(WORD_SIZE) + .referenceOffset(p.requestedReturnDataTarget().offset()) + .referenceSize(p.requestedReturnDataTarget().length()); + } + public static MmuCall forSha2(final Hub hub, PrecompileInvocation p, int i) { - return forRipeMd160Sha(hub, p, i, true); + return forShaTwoOrRipemdFullResultTransfer(hub, p, true); } public static MmuCall forRipeMd160(final Hub hub, PrecompileInvocation p, int i) { - return forRipeMd160Sha(hub, p, i, false); + return forShaTwoOrRipemdFullResultTransfer(hub, p, false); } public static MmuCall forIdentity(final Hub hub, final PrecompileInvocation p, int i) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java index b45a651511..6e1c0c87d7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -55,15 +55,14 @@ public enum CallScenario { CALL_PRC_SUCCESS_WONT_REVERT; public boolean isPrecompileScenario() { - return this == CALL_PRC_FAILURE || - this == CALL_PRC_SUCCESS_WILL_REVERT || - this == CALL_PRC_SUCCESS_WONT_REVERT; + return this == CALL_PRC_FAILURE + || this == CALL_PRC_SUCCESS_WILL_REVERT + || this == CALL_PRC_SUCCESS_WONT_REVERT; } public boolean noLongerUndefined() { return this != UNDEFINED && this != CALL_PRC_UNDEFINED && this != CALL_SMC_UNDEFINED; } - } private static final List illegalTracingScenario = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 78388f39ac..88cb43390a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -84,7 +84,7 @@ public Trace trace(Trace trace) { .pScenarioPrcFailureKnownToRam(scenario == PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM) .pScenarioPrcCallerGas(precompileSubSection.getCallerGas()) .pScenarioPrcCalleeGas(precompileSubSection.getCalleeGas()) - .pScenarioPrcReturnGas(precompileSubSection.returnGas()) + .pScenarioPrcReturnGas(precompileSubSection.getReturnGas()) .pScenarioPrcCdo(precompileSubSection.getCallDataMemorySpan().offset()) .pScenarioPrcCds(precompileSubSection.getCallDataMemorySpan().length()) .pScenarioPrcRao(precompileSubSection.getParentReturnDataTarget().offset()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index 79f30bd181..93bef1c1c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -35,6 +35,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobCall; +// TODO: remove this class ... total annihilation :) @RequiredArgsConstructor public class PrecompileLinesGenerator { public static List generateFor(final Hub hub, final PrecompileInvocation p) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java index cc346bddc2..2821704393 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java @@ -24,6 +24,6 @@ public ContextSection(Hub hub) { hub.addTraceSection(this); ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); - this.addFragmentsAndStack(hub, currentContext); + this.addStackAndFragments(hub, currentContext); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java index 5179042fa2..0baaa4a38f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java @@ -30,6 +30,6 @@ public ExpSection(Hub hub) { final ExpCall expCall = new ExplogExpCall(); final ImcFragment miscFragment = ImcFragment.empty(hub).callExp(expCall); - this.addFragmentsAndStack(hub, miscFragment); + this.addStackAndFragments(hub, miscFragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index e1419c43db..e1369ee839 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -43,7 +43,7 @@ public JumpSection(Hub hub) { public void populateSection(Hub hub) { - this.addFragmentsAndStack(hub); + this.addStackAndFragments(hub); if (Exceptions.outOfGasException(hub.pch().exceptions())) { return; @@ -95,8 +95,7 @@ public void populateSection(Hub hub) { // CONTEXT, ACCOUNT, MISCELLANEOUS ////////////////////////////////// - this.addFragmentsWithoutStack( - contextRowCurrentContext, accountRowCodeAccount, miscellaneousRow); + this.addFragments(contextRowCurrentContext, accountRowCodeAccount, miscellaneousRow); // jump destination vetting /////////////////////////// diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 18277b2bd6..82346f7388 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -40,7 +40,7 @@ public KeccakSection(Hub hub) { hub.addTraceSection(this); miscFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, miscFragment); + this.addStackAndFragments(hub, miscFragment); final MxpCall mxpCall = new MxpCall(hub); miscFragment.callMxp(mxpCall); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index affc32a7fc..a038e2dc56 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -82,7 +82,7 @@ public void resolvePostTransaction( public static class LogCommonSection extends TraceSection { public LogCommonSection(Hub hub, short maxNbOfRows, ContextFragment fragment) { super(hub, maxNbOfRows); - this.addFragmentsAndStack(hub, fragment); + this.addStackAndFragments(hub, fragment); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 732a2c604d..6e55e79a3b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -72,7 +72,7 @@ public SloadSection(Hub hub, WorldView world) { ImcFragment miscFragmentForSload = ImcFragment.empty(hub); StorageFragment doingSload = doingSload(hub); - this.addFragmentsAndStack(hub, readCurrentContext, miscFragmentForSload, doingSload); + this.addStackAndFragments(hub, readCurrentContext, miscFragmentForSload, doingSload); } private StorageFragment doingSload(Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 1fabc724a1..ea10e411cf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -70,7 +70,7 @@ public SstoreSection(Hub hub, WorldView world) { // CONTEXT fragment final ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); - this.addFragmentsAndStack(hub, readCurrentContext); + this.addStackAndFragments(hub, readCurrentContext); if (staticContextException) { return; 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 4c078ad7d4..fd39e89623 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 @@ -98,7 +98,7 @@ public final void addStack(Hub hub) { * * @param fragments the fragments to add to the section */ - public final void addFragmentsWithoutStack(TraceFragment... fragments) { + public final void addFragments(TraceFragment... fragments) { for (TraceFragment f : fragments) { this.addFragment(f); } @@ -109,7 +109,7 @@ public final void addFragmentsWithoutStack(TraceFragment... fragments) { * * @param fragments the fragments to add to the section */ - public final void addFragmentsWithoutStack(List fragments) { + public final void addFragments(List fragments) { for (TraceFragment f : fragments) { this.addFragment(f); } @@ -122,9 +122,9 @@ public final void addFragmentsWithoutStack(List fragments) { * @param hub the execution context * @param fragments the fragments to insert */ - public final void addFragmentsAndStack(Hub hub, TraceFragment... fragments) { + public final void addStackAndFragments(Hub hub, TraceFragment... fragments) { this.addStack(hub); - this.addFragmentsWithoutStack(fragments); + this.addFragments(fragments); } /** This method is called at commit time, to build required information post-hoc. */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java index 34add9e21b..f66d1f4098 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java @@ -27,6 +27,6 @@ public TransactionSection(Hub hub) { super(hub, Exceptions.none(hub.pch().exceptions()) ? (short) 2 : (short) 3); hub.addTraceSection(this); - this.addFragmentsAndStack(hub, TransactionFragment.prepare(hub.txStack().current())); + this.addStackAndFragments(hub, TransactionFragment.prepare(hub.txStack().current())); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 2bbcd3cd94..85e9b4141c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -229,7 +229,7 @@ private boolean noAccountCollision() { public class FinalizationSection extends TraceSection { public FinalizationSection(Hub hub, TraceFragment... fragments) { super(hub, (short) (txMetadata.statusCode() ? 3 : 4)); - this.addFragmentsWithoutStack(fragments); + this.addFragments(fragments); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index 401699f6ae..f584b066c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -119,7 +119,7 @@ public TxInitializationSection(Hub hub, WorldView world) { public static class InitializationSection extends TraceSection { public InitializationSection(Hub hub, TraceFragment... fragments) { super(hub, (short) 5); - this.addFragmentsWithoutStack(fragments); + this.addFragments(fragments); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 3012b14fa7..269ffc9809 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -142,7 +142,7 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { public static class TxPrewarmingSection extends TraceSection { public TxPrewarmingSection(Hub hub, TraceFragment fragment) { super(hub, (short) 1); - this.addFragmentsWithoutStack(fragment); + this.addFragments(fragment); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java index 277d0fe332..a4ba2fa4a9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java @@ -138,7 +138,7 @@ public void resolvePostTransaction( public static class TxSkippedSection extends TraceSection { public TxSkippedSection(Hub hub, TraceFragment... fragments) { super(hub, (short) 4); - this.addFragmentsWithoutStack(fragments); + this.addFragments(fragments); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index ab019c322f..bc84e83748 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -35,7 +35,6 @@ import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -115,7 +114,7 @@ public CallSection(Hub hub) { // row i+2 final ImcFragment firstImcFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, firstImcFragment); + this.addStackAndFragments(hub, scenarioFragment, currentContextFragment, firstImcFragment); if (Exceptions.any(exceptions)) { scenarioFragment.setScenario(CALL_EXCEPTION); @@ -237,7 +236,7 @@ private void oogXCall(Hub hub) { rawCalleeAddress, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); - this.addFragmentsWithoutStack(callerAccountFragment, calleeAccountFragment); + this.addFragments(callerAccountFragment, calleeAccountFragment); } private void abortingCall(Hub hub) { @@ -294,7 +293,7 @@ public void resolveUponEnteringChildContext(Hub hub) { firstCalleeAccountFragment.requiresRomlex(true); } - this.addFragmentsWithoutStack(firstCallerAccountFragment, firstCalleeAccountFragment); + this.addFragments(firstCallerAccountFragment, firstCalleeAccountFragment); } /** Resolution happens as the child context is about to terminate. */ @@ -365,8 +364,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), this.revertStamp(), 3)); - this.addFragmentsWithoutStack( - postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); + this.addFragments(postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); } default -> {} } @@ -398,7 +396,9 @@ public void resolvePostTransaction( Preconditions.checkArgument(scenario.noLongerUndefined()); - // iterate over the precompileSubsection + if (scenario.isPrecompileScenario()) { + this.addFragments(precompileSubsection.getFragments()); + } this.addFragment(finalContextFragment); } @@ -437,7 +437,7 @@ private void completeEoaSuccessWillRevert(Factories factory) { DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), this.revertStamp(), 3)); - this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); + this.addFragments(undoingCallerAccountFragment, undoingCalleeAccountFragment); } private void completeSmcFailureWillRevert(Factories factory) { @@ -487,8 +487,6 @@ private void completeSmcSuccessWillRevertOrPrcSuccessWillRevert(Factories factor DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), this.revertStamp(), 3)); - this.addFragmentsWithoutStack(undoingCallerAccountFragment, undoingCalleeAccountFragment); + this.addFragments(undoingCallerAccountFragment, undoingCalleeAccountFragment); } - - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 45225e8cdd..3f92326462 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -14,6 +14,10 @@ */ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_UNDEFINED; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; +import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; + import java.util.ArrayList; import java.util.List; @@ -33,15 +37,11 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_UNDEFINED; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; -import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; - /** Note: {@link PrecompileSubsection}'s are created at child context entry by the call section */ @RequiredArgsConstructor @Getter -public class PrecompileSubsection implements ContextExitDefer, ReEnterContextDefer, PostRollbackDefer, PostTransactionDefer { +public class PrecompileSubsection + implements ContextExitDefer, ReEnterContextDefer, PostRollbackDefer, PostTransactionDefer { /** List of fragments of the precompile specific subsection */ final List fragments; @@ -74,10 +74,14 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { parentReturnDataTarget = hub.currentFrame().parentReturnDataTarget(); callerGas = hub.callStack().parent().frame().getRemainingGas(); calleeGas = hub.messageFrame().getRemainingGas(); - precompileScenarioFragment = new PrecompileScenarioFragment(this, PRC_UNDEFINED_SCENARIO, PRC_UNDEFINED); + precompileScenarioFragment = + new PrecompileScenarioFragment(this, PRC_UNDEFINED_SCENARIO, PRC_UNDEFINED); } - protected short maxNumberOfLines() {return 0;}; + protected short maxNumberOfLines() { + return 0; + } + ; public void resolveUponExitingContext(Hub hub, CallFrame frame) { returnGas = frame.frame().getRemainingGas(); @@ -85,7 +89,7 @@ public void resolveUponExitingContext(Hub hub, CallFrame frame) { @Override public void resolveAtContextReEntry(Hub hub, CallFrame frame) { - successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); + successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); if (successBit) { hub.defers().scheduleForPostRollback(this, frame); precompileScenarioFragment.setScenario(PRC_SUCCESS_WONT_REVERT); @@ -99,7 +103,6 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - - } + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java index df3c7ce3c7..e692d2e1d8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java @@ -15,18 +15,14 @@ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; + import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_UNDEFINED; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_UNDEFINED_SCENARIO; -import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; - public class Sha2SubSection extends PrecompileSubsection { public Sha2SubSection(Hub hub, CallSection callSection) { super(hub, callSection); @@ -52,5 +48,4 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} - } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index 22d2c9013f..12636f36f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -42,7 +42,7 @@ public CallDataCopySection(Hub hub) { hub.addTraceSection(this); miscFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, miscFragment); + this.addStackAndFragments(hub, miscFragment); // triggerOob = false // triggerMxp = true diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index ed3b34d261..864c09a28a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -47,7 +47,7 @@ public CodeCopySection(Hub hub) { // Miscellaneous row imcFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, imcFragment); + this.addStackAndFragments(hub, imcFragment); // triggerOob = false // triggerMxp = true diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index ffd0f6c34d..14bfc4a5d6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -44,7 +44,7 @@ public ReturnDataCopySection(Hub hub) { hub.addTraceSection(this); final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); - this.addFragmentsAndStack(hub, currentContext); + this.addStackAndFragments(hub, currentContext); miscFragment = ImcFragment.empty(hub); this.addFragment(miscFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java index 61c3a1c57a..04aa1688ca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java @@ -48,7 +48,7 @@ public AbortCreate( final ContextFragment updatedCurrentContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); - this.addFragmentsAndStack( + this.addStackAndFragments( hub, scenarioFragment, currentContextFragment, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java index 1c63440d6a..8b763d3cf6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java @@ -31,6 +31,6 @@ public ExceptionalCreate( final CreateScenarioFragment scenarioFragment = new CreateScenarioFragment(CREATE_EXCEPTION); - this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); + this.addStackAndFragments(hub, scenarioFragment, commonContext, imcFragment); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java index fc76203aa4..ca84bf82eb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java @@ -42,7 +42,7 @@ public FailureOrEmptyInitCreate( this.scenarioFragment = new CreateScenarioFragment(scenario); - this.addFragmentsAndStack(hub, scenarioFragment, currentContextFragment, imcFragment); + this.addStackAndFragments(hub, scenarioFragment, currentContextFragment, imcFragment); } @Override @@ -73,7 +73,7 @@ public void fillAccountFragment( newCreatedSnapshot, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); - this.addFragmentsWithoutStack(creatorAccountFragment, createdAccountFragment); + this.addFragments(creatorAccountFragment, createdAccountFragment); } @Override @@ -109,7 +109,7 @@ public void fillReverting( DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), currentRevertStamp, 3)); - this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); + this.addFragments(undoCreatorAccountFragment, undoCreatedAccountFragment); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java index 5e0abe894c..4bef594462 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java @@ -40,7 +40,7 @@ public NonEmptyInitCodeCreate( this.scenarioFragment = new CreateScenarioFragment(); - this.addFragmentsAndStack(hub, scenarioFragment, commonContext, imcFragment); + this.addStackAndFragments(hub, scenarioFragment, commonContext, imcFragment); hub.romLex().callRomLex(hub.messageFrame()); } @@ -79,7 +79,7 @@ public void fillAccountFragment( DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); oldToMidCreatedAccountFragment.requiresRomlex(true); - this.addFragmentsWithoutStack(oldToMidCreatorAccountFragment, oldToMidCreatedAccountFragment); + this.addFragments(oldToMidCreatorAccountFragment, oldToMidCreatedAccountFragment); if (!createSuccess) { final AccountFragment midToNewCreatorAccountFragment = @@ -96,7 +96,7 @@ public void fillAccountFragment( DomSubStampsSubFragment.revertsWithChildDomSubStamps( this.hubStamp(), childRevertStamp, 3)); - this.addFragmentsWithoutStack(midToNewCreatorAccountFragment, midToNewCreatedAccountFragment); + this.addFragments(midToNewCreatorAccountFragment, midToNewCreatedAccountFragment); } } @@ -134,7 +134,7 @@ public void fillReverting( DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), currentRevertStamp, createSuccess ? 3 : 5)); - this.addFragmentsWithoutStack(undoCreatorAccountFragment, undoCreatedAccountFragment); + this.addFragments(undoCreatorAccountFragment, undoCreatedAccountFragment); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index 876b52b068..68bc486012 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -40,7 +40,7 @@ public RevertSection(Hub hub) { short exceptions = hub.pch().exceptions(); imcFragment = ImcFragment.empty(hub); - this.addFragmentsAndStack(hub, imcFragment); + this.addStackAndFragments(hub, imcFragment); // triggerExp = false // triggerOob = false @@ -69,7 +69,7 @@ public RevertSection(Hub hub) { final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); final ContextFragment parentContext = ContextFragment.executionProvidesEmptyReturnData(hub); - this.addFragmentsWithoutStack(currentContext, parentContext); + this.addFragments(currentContext, parentContext); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index 70dbfa1874..fbcc05b07e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -66,7 +66,7 @@ public StopSection(Hub hub) { // Message call case //////////////////// if (!deploymentStatus) { - this.addFragmentsAndStack(hub, readCurrentContextData(hub)); + this.addStackAndFragments(hub, readCurrentContextData(hub)); return; } @@ -88,7 +88,7 @@ public void deploymentStopSection(Hub hub) { afterEmptyDeployment, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - this.addFragmentsAndStack(hub, readCurrentContextData(hub), doingAccountFragment); + this.addStackAndFragments(hub, readCurrentContextData(hub), doingAccountFragment); } /** @@ -113,7 +113,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca DomSubStampsSubFragment.revertWithCurrentDomSubStamps( hubStamp, hub.callStack().current().revertStamp(), 1); - this.addFragmentsWithoutStack( + this.addFragments( hub.factories() .accountFragment() .make( @@ -134,6 +134,6 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - this.addFragmentsWithoutStack(this.parentContextReturnDataReset); + this.addFragments(this.parentContextReturnDataReset); } } From d745a82b519d5c1077cc3cd852a8fc70b9371df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 27 Jul 2024 15:24:27 +0200 Subject: [PATCH 307/461] feat(test): simple test to track the triggering of Besu's tracer interface for EOA calls --- .../consensys/linea/zktracer/ZkTracer.java | 52 +++++++++++++------ .../module/{Pin55.java => DebugMode.java} | 2 +- .../linea/zktracer/module/hub/Hub.java | 2 +- .../CallTrivialCasesTest.java | 40 ++++++++++++++ 4 files changed, 77 insertions(+), 19 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{Pin55.java => DebugMode.java} (99%) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index f30955accf..0d2239da2e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -37,8 +37,9 @@ import lombok.extern.slf4j.Slf4j; import net.consensys.linea.plugins.config.LineaL1L2BridgeSharedConfiguration; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.Pin55; +import net.consensys.linea.zktracer.module.DebugMode; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.Utils; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; @@ -77,7 +78,7 @@ public class ZkTracer implements ConflationAwareOperationTracer { } @Getter private final Hub hub; - private final Optional pin55; + private final Optional debugMode; private Hash hashOfLastTransactionTraced = Hash.EMPTY; /** Accumulate all the exceptions that happened at tracing time. */ @@ -98,12 +99,12 @@ public ZkTracer(final LineaL1L2BridgeSharedConfiguration bridgeConfiguration) { // >>>> CHANGE ME >>>> // >>>> CHANGE ME >>>> // >>>> CHANGE ME >>>> - final Pin55.PinLevel debugLevel = new Pin55.PinLevel(); + final DebugMode.PinLevel debugLevel = new DebugMode.PinLevel(); // <<<< CHANGE ME <<<< // <<<< CHANGE ME <<<< // <<<< CHANGE ME <<<< - this.pin55 = - debugLevel.none() ? Optional.empty() : Optional.of(new Pin55(debugLevel, this.hub)); + this.debugMode = + debugLevel.none() ? Optional.empty() : Optional.of(new DebugMode(debugLevel, this.hub)); } public Path writeToTmpFile() { @@ -166,7 +167,7 @@ public void writeToFile(final Path filename) { public void traceStartConflation(final long numBlocksInConflation) { try { hub.traceStartConflation(numBlocksInConflation); - this.pin55.ifPresent(x -> x.traceStartConflation(numBlocksInConflation)); + this.debugMode.ifPresent(x -> x.traceStartConflation(numBlocksInConflation)); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -176,7 +177,7 @@ public void traceStartConflation(final long numBlocksInConflation) { public void traceEndConflation(final WorldView state) { try { this.hub.traceEndConflation(state); - this.pin55.ifPresent(Pin55::traceEndConflation); + this.debugMode.ifPresent(DebugMode::traceEndConflation); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -190,7 +191,7 @@ public void traceEndConflation(final WorldView state) { public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) { try { this.hub.traceStartBlock(processableBlockHeader); - this.pin55.ifPresent(Pin55::traceEndConflation); + this.debugMode.ifPresent(DebugMode::traceEndConflation); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -200,7 +201,7 @@ public void traceStartBlock(final ProcessableBlockHeader processableBlockHeader) public void traceStartBlock(final BlockHeader blockHeader, final BlockBody blockBody) { try { this.hub.traceStartBlock(blockHeader); - this.pin55.ifPresent(x -> x.traceStartBlock(blockHeader, blockBody)); + this.debugMode.ifPresent(x -> x.traceStartBlock(blockHeader, blockBody)); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -210,7 +211,7 @@ public void traceStartBlock(final BlockHeader blockHeader, final BlockBody block public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { try { this.hub.traceEndBlock(blockHeader, blockBody); - this.pin55.ifPresent(Pin55::traceEndBlock); + this.debugMode.ifPresent(DebugMode::traceEndBlock); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -220,7 +221,7 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo public void tracePrepareTransaction(WorldView worldView, Transaction transaction) { try { hashOfLastTransactionTraced = transaction.getHash(); - this.pin55.ifPresent(x -> x.tracePrepareTx(worldView, transaction)); + this.debugMode.ifPresent(x -> x.tracePrepareTx(worldView, transaction)); this.hub.traceStartTransaction(worldView, transaction); } catch (final Exception e) { this.tracingExceptions.add(e); @@ -237,31 +238,48 @@ public void traceEndTransaction( Set
selfDestructs, long timeNs) { try { - this.pin55.ifPresent(x -> x.traceEndTx(worldView, tx, status, output, logs, gasUsed)); + this.debugMode.ifPresent(x -> x.traceEndTx(worldView, tx, status, output, logs, gasUsed)); this.hub.traceEndTransaction(worldView, tx, status, logs, selfDestructs); } catch (final Exception e) { this.tracingExceptions.add(e); } } + /** + * Linea's zkEVM does not trace the STOP instruction of either (a) CALL's to accounts with empty + * byte code (b) CREATE's with empty initialization code. + * + *

Note however that the relevant {@link CallFrame}'s are (and SHOULD BE) created regardless. + * + * @param frame + */ @Override public void tracePreExecution(final MessageFrame frame) { if (frame.getCode().getSize() > 0) { try { this.hub.tracePreExecution(frame); - this.pin55.ifPresent(x -> x.tracePreOpcode(frame)); + this.debugMode.ifPresent(x -> x.tracePreOpcode(frame)); } catch (final Exception e) { this.tracingExceptions.add(e); } } } + // TODO: the stack at tracePostExecution (as well as the gas) seems not to have + // changed relative to tracePreExecution. In particular this is not the place to + // get BLOCKHASH or similar fields. + + /** + * Compare with description of {@link #tracePreExecution(MessageFrame)}. + * @param frame + * @param operationResult + */ @Override public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { if (frame.getCode().getSize() > 0) { try { this.hub.tracePostExecution(frame, operationResult); - this.pin55.ifPresent(x -> x.tracePostOpcode(frame, operationResult)); + this.debugMode.ifPresent(x -> x.tracePostOpcode(frame, operationResult)); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -275,7 +293,7 @@ public void traceContextEnter(MessageFrame frame) { if (frame.getState() == MessageFrame.State.NOT_STARTED) { try { this.hub.traceContextEnter(frame); - this.pin55.ifPresent(x -> x.traceContextEnter(frame)); + this.debugMode.ifPresent(x -> x.traceContextEnter(frame)); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -286,7 +304,7 @@ public void traceContextEnter(MessageFrame frame) { public void traceContextReEnter(MessageFrame frame) { try { this.hub.traceContextReEnter(frame); - this.pin55.ifPresent(x -> x.traceContextReEnter(frame)); + this.debugMode.ifPresent(x -> x.traceContextReEnter(frame)); } catch (final Exception e) { this.tracingExceptions.add(e); } @@ -296,7 +314,7 @@ public void traceContextReEnter(MessageFrame frame) { public void traceContextExit(MessageFrame frame) { try { this.hub.traceContextExit(frame); - this.pin55.ifPresent(x -> x.traceContextExit(frame)); + this.debugMode.ifPresent(x -> x.traceContextExit(frame)); } catch (final Exception e) { this.tracingExceptions.add(e); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Pin55.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/DebugMode.java similarity index 99% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/Pin55.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/DebugMode.java index ab57fb19eb..0ca88dcdd1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Pin55.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/DebugMode.java @@ -34,7 +34,7 @@ @Slf4j @RequiredArgsConstructor -public class Pin55 { +public class DebugMode { public static class PinLevel { private static final int CONFLATION = 1; private static final int BLOCK = 1 << 2; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index e9f7c5dcc3..ede92dcebc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -595,7 +595,7 @@ public void traceContextEnter(MessageFrame frame) { this.transients.conflation().deploymentInfo().isDeploying(toAddress)); } } else { - // ...or CALL + // ...or CALL or CREATE final boolean isDeployment = frame.getType() == MessageFrame.Type.CONTRACT_CREATION; final Address codeAddress = frame.getContractAddress(); final CallFrameType frameType = diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java new file mode 100644 index 0000000000..f6b1012765 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java @@ -0,0 +1,40 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; + +public class CallTrivialCasesTest { + @Test + void eoaCallScenarioTest() { + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .push(0) + .push(0) + .push(0) + .push(0x0add7e55) + .push(0xffff) + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); + BytecodeRunner.of(bytecode).run(); + } +} From af9cc192d2dc50af4457655ac8ec989f06732ddb Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 27 Jul 2024 17:18:57 +0200 Subject: [PATCH 308/461] finish all common CALL, finish common Precompile, systematically add the messageFrame to the callFrame --- .../consensys/linea/zktracer/ZkTracer.java | 4 +- .../linea/zktracer/module/hub/Hub.java | 8 +- .../module/hub/fragment/imc/ImcFragment.java | 74 --------------- .../module/hub/section/call/CallSection.java | 93 +++++++++++++------ .../PrecompileSubsection.java | 24 ++++- .../zktracer/module/mmio/CallStackReader.java | 3 +- .../zktracer/runtime/callstack/CallFrame.java | 10 +- .../runtime/callstack/CallFrameType.java | 8 +- .../zktracer/runtime/callstack/CallStack.java | 47 +++++----- 9 files changed, 130 insertions(+), 141 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index 0d2239da2e..f92aaa6d42 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -36,8 +36,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.plugins.config.LineaL1L2BridgeSharedConfiguration; -import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.DebugMode; +import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.Utils; @@ -255,6 +255,7 @@ public void traceEndTransaction( */ @Override public void tracePreExecution(final MessageFrame frame) { + this.hub.currentFrame().frame(frame); if (frame.getCode().getSize() > 0) { try { this.hub.tracePreExecution(frame); @@ -271,6 +272,7 @@ public void tracePreExecution(final MessageFrame frame) { /** * Compare with description of {@link #tracePreExecution(MessageFrame)}. + * * @param frame * @param operationResult */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index ede92dcebc..b1ee821803 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -558,7 +558,7 @@ public void traceContextEnter(MessageFrame frame) { this.state.stamps().hub(), this.transients.tx().getBesuTransaction().getSender(), toAddress, - CallFrameType.MANTLE, + CallFrameType.TRANSACTION_CALL_DATA_HOLDER, new Bytecode( toAddress == null ? this.transients.tx().getBesuTransaction().getData().orElse(Bytes.EMPTY) @@ -578,7 +578,7 @@ public void traceContextEnter(MessageFrame frame) { this.state.stamps().hub(), this.txStack.current().getBesuTransaction().getSender(), toAddress, - CallFrameType.BEDROCK, + CallFrameType.ROOT, new Bytecode( toAddress == null ? this.transients.tx().getBesuTransaction().getData().orElse(Bytes.EMPTY) @@ -694,6 +694,7 @@ public void traceContextExit(MessageFrame frame) { gasRefund, minerIsWarm, this.txStack.getAccumulativeGasUsedInBlockBeforeTxStart()); + if (this.state.getProcessingPhase() != TX_SKIP) { this.state.setProcessingPhase(TX_FINL); new TxFinalizationSection(this, frame.getWorldUpdater()); @@ -950,7 +951,8 @@ void processStateExec(MessageFrame frame) { previousOperationWasCallToEcPrecompile = false; } - this.currentFrame().frame(frame); + // TODO: delete me, we do it in the ZKTracer in every case (ie even if codeSize == 0) + // this.currentFrame().frame(frame); this.state.stamps().incrementHubStamp(); this.pch.setup(frame); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index f75559648c..74f774dbb9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Optional; -import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; @@ -29,15 +28,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.internal.Words; /** * IMCFragments embed data required for Inter-Module Communication, i.e. data that are required to @@ -88,72 +80,6 @@ public static ImcFragment forTxInit(final Hub hub) { return shouldCopyTxCallData ? miscFragment.callMmu(MmuCall.txInit(hub)) : miscFragment; } - /** - * Create an ImcFragment to be used when executing a *CALL. - * - * @param hub the execution context - * @param callerAccount the caller account - * @param calledAccount the (maybe non-existing) called account - * @return the ImcFragment for the *CALL - */ - public static ImcFragment forCall( - Hub hub, Account callerAccount, Optional calledAccount) { - final ImcFragment r = new ImcFragment(hub); - - if (hub.pch().signals().mxp()) { - r.callMxp(MxpCall.build(hub)); - } - - if (hub.pch().signals().oob()) { - switch (hub.opCode()) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - if (hub.opCode().equals(OpCode.CALL) && Exceptions.any(hub.pch().exceptions())) { - r.callOob(new XCallOobCall()); - } else { - r.callOob(new CallOobCall()); - } - } - default -> throw new IllegalArgumentException("unexpected opcode for IMC/CALL"); - } - } - - if (hub.pch().signals().stp()) { - final long gas = Words.clampedToLong(hub.messageFrame().getStackItem(0)); - EWord value = EWord.ZERO; - if (hub.opCode().isAnyOf(OpCode.CALL, OpCode.CALLCODE)) { - value = EWord.of(hub.messageFrame().getStackItem(2)); - } - - final long stipend = value.isZero() ? 0 : GlobalConstants.GAS_CONST_G_CALL_STIPEND; - final long upfrontCost = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()).total(); - - // TODO: @Olivier get memory expansion gas - long memoryExpansionGas = 0xdeadbeefL; - StpCall stpCall = new StpCall(hub, memoryExpansionGas); - - r.callStp(stpCall); - - // EWord.of(gas), - // value, - // calledAccount.isPresent(), - // calledAccount - // .map(a -> hub.messageFrame().isAddressWarm(a.getAddress())) - // .orElse(false), - // hub.pch().exceptions().outOfGasException(), - // upfrontCost, - // Math.max( - // Words.unsignedMin( - // allButOneSixtyFourth(hub.messageFrame().getRemainingGas() - - // upfrontCost), - // gas), - // 0), - // stipend) - // ); - } - - return r; - } - public ImcFragment callOob(OobCall f) { if (oobIsSet) { throw new IllegalStateException("OOB already called"); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index bc84e83748..02c5794214 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -247,7 +247,7 @@ private void abortingCall(Hub hub) { @Override public void resolveUponEnteringChildContext(Hub hub) { switch (scenarioFragment.getScenario()) { - case CALL_EOA_SUCCESS_WONT_REVERT, CALL_SMC_UNDEFINED -> { + case CALL_SMC_UNDEFINED -> { postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); postOpcodeCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); @@ -259,41 +259,48 @@ public void resolveUponEnteringChildContext(Hub hub) { postOpcodeCallerSnapshot.decrementBalance(value); preOpcodeCalleeSnapshot.decrementBalance(value); } + + final Factories factories = hub.factories(); + final AccountFragment firstCallerAccountFragment = + factories + .accountFragment() + .make( + preOpcodeCallerSnapshot, + postOpcodeCallerSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + + final AccountFragment firstCalleeAccountFragment = + factories + .accountFragment() + .makeWithTrm( + preOpcodeCalleeSnapshot, + postOpcodeCalleeSnapshot, + rawCalleeAddress, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + + if (scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { + firstCalleeAccountFragment.requiresRomlex(true); + } + + this.addFragments(firstCallerAccountFragment, firstCalleeAccountFragment); } - case CALL_PRC_UNDEFINED -> { - // TODO implement + case CALL_PRC_UNDEFINED -> { + // Account rows for precompile are traced at contextReEntry precompileSubsection = ADDRESS_TO_PRECOMPILE.get(preOpcodeCalleeSnapshot.address()).apply(hub, this); hub.defers().scheduleForContextReEntry(precompileSubsection, hub.callStack().parent()); hub.defers().scheduleForPostTransaction(precompileSubsection); } - } - - final Factories factories = hub.factories(); - final AccountFragment firstCallerAccountFragment = - factories - .accountFragment() - .make( - preOpcodeCallerSnapshot, - postOpcodeCallerSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - final AccountFragment firstCalleeAccountFragment = - factories - .accountFragment() - .makeWithTrm( - preOpcodeCalleeSnapshot, - postOpcodeCalleeSnapshot, - rawCalleeAddress, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + case CALL_EOA_SUCCESS_WONT_REVERT -> { + // Account rows for EOA calls are traced at contextReEntry + return; + } - if (scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { - firstCalleeAccountFragment.requiresRomlex(true); + default -> throw new IllegalArgumentException("Should be in one of the three scenario above"); } - - this.addFragments(firstCallerAccountFragment, firstCalleeAccountFragment); } /** Resolution happens as the child context is about to terminate. */ @@ -320,20 +327,25 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { // to contain the success bit of the call at traceContextReEntry. // See issue #872. successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); + + reEntryCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); + reEntryCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); + switch (scenarioFragment.getScenario()) { + case CALL_EOA_SUCCESS_WONT_REVERT -> { + emptyCodeFirstCoupleOfAccountFragments(hub); + } + case CALL_PRC_UNDEFINED -> { if (successBit) { scenarioFragment.setScenario(CALL_PRC_SUCCESS_WONT_REVERT); } else { scenarioFragment.setScenario(CALL_PRC_FAILURE); } - // TODO: we need to fill the first two account rows! + emptyCodeFirstCoupleOfAccountFragments(hub); } case CALL_SMC_UNDEFINED -> { - reEntryCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); - reEntryCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); - if (successBit) { scenarioFragment.setScenario(CALL_SMC_SUCCESS_WONT_REVERT); return; @@ -366,6 +378,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { this.addFragments(postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); } + default -> {} } } @@ -489,4 +502,26 @@ private void completeSmcSuccessWillRevertOrPrcSuccessWillRevert(Factories factor this.addFragments(undoingCallerAccountFragment, undoingCalleeAccountFragment); } + + private void emptyCodeFirstCoupleOfAccountFragments(final Hub hub) { + final Factories factories = hub.factories(); + final AccountFragment firstCallerAccountFragment = + factories + .accountFragment() + .make( + preOpcodeCallerSnapshot, + reEntryCallerSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + + final AccountFragment firstCalleeAccountFragment = + factories + .accountFragment() + .makeWithTrm( + preOpcodeCalleeSnapshot, + reEntryCalleeSnapshot, + rawCalleeAddress, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + + this.addFragments(firstCallerAccountFragment, firstCalleeAccountFragment); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 3f92326462..dfbdcf6f89 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -16,6 +16,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_UNDEFINED; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; +import static net.consensys.linea.zktracer.runtime.callstack.CallFrame.extractContiguousLimbsFromMemory; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; import java.util.ArrayList; @@ -23,6 +24,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; @@ -33,6 +35,7 @@ import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.MemorySpan; +import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -43,13 +46,19 @@ public class PrecompileSubsection implements ContextExitDefer, ReEnterContextDefer, PostRollbackDefer, PostTransactionDefer { /** List of fragments of the precompile specific subsection */ - final List fragments; + private final List fragments; + + /** The (potentially empty) call data of the precompile call */ + final Bytes callData; /** The input data for the precompile */ - final MemorySpan callDataMemorySpan; + private final MemorySpan callDataMemorySpan; /** Where the caller wants the precompile return data to be stored */ - final MemorySpan parentReturnDataTarget; + private final MemorySpan parentReturnDataTarget; + + /** The (potentially empty) return data of the precompile call */ + @Setter Bytes returnData; /** Leftover gas of the caller */ final long callerGas; @@ -64,6 +73,9 @@ public class PrecompileSubsection final PrecompileScenarioFragment precompileScenarioFragment; + /** A snapshot of the caller's memory before the execution of the precompile */ + final Bytes callerMemorySnapshot; + /** * Default creator specifying the max number of rows the precompile processing subsection can * contain. @@ -71,11 +83,15 @@ public class PrecompileSubsection public PrecompileSubsection(final Hub hub, final CallSection callSection) { fragments = new ArrayList<>(maxNumberOfLines()); callDataMemorySpan = hub.currentFrame().callDataInfo().memorySpan(); + callData = hub.messageFrame().getInputData(); parentReturnDataTarget = hub.currentFrame().parentReturnDataTarget(); callerGas = hub.callStack().parent().frame().getRemainingGas(); calleeGas = hub.messageFrame().getRemainingGas(); precompileScenarioFragment = new PrecompileScenarioFragment(this, PRC_UNDEFINED_SCENARIO, PRC_UNDEFINED); + + final MessageFrame callerFrame = hub.callStack().parent().frame(); + callerMemorySnapshot = extractContiguousLimbsFromMemory(callerFrame, callDataMemorySpan); } protected short maxNumberOfLines() { @@ -90,6 +106,8 @@ public void resolveUponExitingContext(Hub hub, CallFrame frame) { @Override public void resolveAtContextReEntry(Hub hub, CallFrame frame) { successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); + returnData = frame.frame().getReturnData(); + if (successBit) { hub.defers().scheduleForPostRollback(this, frame); precompileScenarioFragment.setScenario(PRC_SUCCESS_WONT_REVERT); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java index 89af3a0eb0..3cc204750a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java @@ -33,7 +33,8 @@ public class CallStackReader { public Bytes valueFromMemory(final long contextNumber, final boolean ramIsSource) { final CallFrame callFrame = callStack.getByContextNumber(contextNumber); - if (callFrame.type() == CallFrameType.MANTLE || callFrame.type() == CallFrameType.BEDROCK) { + if (callFrame.type() == CallFrameType.TRANSACTION_CALL_DATA_HOLDER + || callFrame.type() == CallFrameType.ROOT) { return callFrame.callDataInfo().data(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 54778dce03..103937b6d7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -98,7 +98,7 @@ public boolean isMessageCall() { @Getter private final CallFrameType type; public int getCodeFragmentIndex(Hub hub) { - return this == CallFrame.EMPTY || this.type() == CallFrameType.MANTLE + return this == CallFrame.EMPTY || this.type() == CallFrameType.TRANSACTION_CALL_DATA_HOLDER ? 0 : hub.getCfiByMetaData( Words.toAddress(this.codeAddressAsEWord()), @@ -164,7 +164,7 @@ public static void updateParentContextReturnData( /** Create a MANTLE call frame. */ CallFrame(final Address origin, final Bytes callData, final int contextNumber) { - this.type = CallFrameType.MANTLE; + this.type = CallFrameType.TRANSACTION_CALL_DATA_HOLDER; this.contextNumber = contextNumber; this.accountAddress = origin; this.callDataInfo = new CallDataInfo(callData, 0, callData.size(), contextNumber); @@ -337,4 +337,10 @@ public void frame(MessageFrame frame) { this.opCodeData = OpCodes.of(this.opCode); this.pc = frame.getPC(); } + + public static Bytes extractContiguousLimbsFromMemory( + final MessageFrame frame, final MemorySpan memorySpan) { + // TODO: optimize me please. Need a review of the MMU operation handling. + return memorySpan.isEmpty() ? Bytes.EMPTY : frame.shadowReadMemory(0, frame.memoryByteSize()); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrameType.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrameType.java index 6f96f0e991..58d457c343 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrameType.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrameType.java @@ -29,10 +29,10 @@ public enum CallFrameType { STATIC, /** Within a call code. */ CALL_CODE, - /** The bedrock context. */ - BEDROCK, - /** A putative phantom frame below the BEDROCK holding the call data */ - MANTLE, + /** The root context. */ + ROOT, + /** A putative phantom frame below the root holding the call data */ + TRANSACTION_CALL_DATA_HOLDER, /** A non-Besu CallFrame where we store the result of a precompile */ PRECOMPILE_RETURN_DATA; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 30e65b6462..99d345f8a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -42,7 +42,7 @@ public final class CallStack { /** a never-pruned-tree of the {@link CallFrame} executed by the {@link Hub} */ @Getter - private final List frames = + private final List callFrames = new ArrayList<>( 50) { // TODO: PERF as the List of TraceSection, we should have an estimate based on // gasLimit on the nb of CallFrame a tx might have @@ -68,7 +68,7 @@ public void newPrecompileResult( -1, -1, false, - this.frames.size(), + this.callFrames.size(), hubStamp, precompileAddress, precompileAddress, @@ -84,7 +84,7 @@ public void newPrecompileResult( -1, this.depth); - this.frames.add(newFrame); + this.callFrames.add(newFrame); } public void newBedrock( @@ -116,7 +116,7 @@ public void newBedrock( accountDeploymentNumber, codeDeploymentNumber, codeDeploymentStatus); - this.current = this.frames.size() - 1; + this.current = this.callFrames.size() - 1; } /** @@ -147,14 +147,14 @@ public void newMantleAndBedrock( int codeDeploymentNumber, boolean codeDeploymentStatus) { this.depth = -1; - this.frames.add(new CallFrame(from, callData, hubStamp)); + this.callFrames.add(new CallFrame(from, callData, hubStamp)); this.enter( hubStamp, to, to, from, toCode == null ? Bytecode.EMPTY : toCode, - CallFrameType.BEDROCK, + CallFrameType.ROOT, value, gas, callData, @@ -164,22 +164,22 @@ public void newMantleAndBedrock( accountDeploymentNumber, codeDeploymentNumber, codeDeploymentStatus); - this.current = this.frames.size() - 1; + this.current = this.callFrames.size() - 1; } /** * @return the currently executing {@link CallFrame} */ public CallFrame current() { - return this.frames.get(this.current); + return this.callFrames.get(this.current); } public boolean isEmpty() { - return this.frames.isEmpty(); + return this.callFrames.isEmpty(); } public int futureId() { - return this.frames.size(); + return this.callFrames.size(); } /** @@ -187,14 +187,14 @@ public int futureId() { */ public CallFrame parent() { if (this.current().parentFrameId() != -1) { - return this.frames.get(this.current().parentFrameId()); + return this.callFrames.get(this.current().parentFrameId()); } else { return CallFrame.EMPTY; } } public Optional maybeCurrent() { - return this.frames.isEmpty() ? Optional.empty() : Optional.of(this.current()); + return this.callFrames.isEmpty() ? Optional.empty() : Optional.of(this.current()); } /** @@ -228,14 +228,13 @@ public void enter( int codeDeploymentNumber, boolean isDeployment) { final int caller = this.depth == -1 ? -1 : this.current; - final int newTop = this.frames.size(); + final int newTop = this.callFrames.size(); this.depth += 1; Bytes callData = Bytes.EMPTY; if (type != CallFrameType.INIT_CODE) { callData = input; } - final CallFrame newFrame = new CallFrame( accountDeploymentNumber, @@ -257,11 +256,11 @@ public void enter( callDataContextNumber, this.depth); - this.frames.add(newFrame); + this.callFrames.add(newFrame); this.current = newTop; if (caller != -1) { - this.frames.get(caller).returnData(Bytes.EMPTY); - this.frames.get(caller).childFrames().add(newTop); + this.callFrames.get(caller).returnData(Bytes.EMPTY); + this.callFrames.get(caller).childFrames().add(newTop); } } @@ -302,7 +301,7 @@ public boolean isStatic() { * @return the caller of the current frame */ public CallFrame caller() { - return this.frames.get(this.current().parentFrameId()); + return this.callFrames.get(this.current().parentFrameId()); } /** @@ -313,10 +312,10 @@ public CallFrame caller() { * @throws IndexOutOfBoundsException if the index is out of range */ public CallFrame getById(int i) { - if (i < 0 || this.frames.isEmpty()) { + if (i < 0 || this.callFrames.isEmpty()) { return CallFrame.EMPTY; } - return this.frames.get(i); + return this.callFrames.get(i); } /** @@ -327,7 +326,7 @@ public CallFrame getById(int i) { * @throws IndexOutOfBoundsException if the index is out of range */ public CallFrame getByContextNumber(final long i) { - for (CallFrame f : this.frames) { + for (CallFrame f : this.callFrames) { if (f.contextNumber() == i) { return f; } @@ -344,11 +343,11 @@ public CallFrame getByContextNumber(final long i) { * @throws IndexOutOfBoundsException if the index is out of range */ public CallFrame getParentCallFrameById(int id) { - if (this.frames.isEmpty()) { + if (this.callFrames.isEmpty()) { return CallFrame.EMPTY; } - return this.getById(this.frames.get(id).parentFrameId()); + return this.getById(this.callFrames.get(id).parentFrameId()); } /** @@ -369,7 +368,7 @@ public void revert(int stamp) { public String pretty() { StringBuilder r = new StringBuilder(2000); - for (CallFrame c : this.frames) { + for (CallFrame c : this.callFrames) { final CallFrame parent = this.getParentCallFrameById(c.id()); r.append(" ".repeat(c.depth())); r.append( From 0cdd2e48ee08b30684deb2c65657d6adbb3fa3f4 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 27 Jul 2024 17:53:58 +0200 Subject: [PATCH 309/461] wip change how we trigger the MMU --- .../module/hub/fragment/imc/ImcFragment.java | 8 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 113 ++++++++++-------- .../imc/call/mmu/opcode/CodeCopy.java | 2 +- .../fragment/imc/call/mmu/opcode/Create.java | 2 +- .../fragment/imc/call/mmu/opcode/Create2.java | 2 +- .../imc/call/mmu/opcode/ExtCodeCopy.java | 2 +- .../call/mmu/opcode/ReturnFromDeployment.java | 2 +- .../hub/section/CallDataLoadSection.java | 62 +++++----- .../module/hub/section/KeccakSection.java | 24 ++-- .../module/hub/section/LogSection.java | 10 +- .../hub/section/copy/CodeCopySection.java | 10 +- 11 files changed, 111 insertions(+), 126 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 74f774dbb9..8d8680c02f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -21,6 +21,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -30,6 +31,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.worldstate.WorldView; /** * IMCFragments embed data required for Inter-Module Communication, i.e. data that are required to @@ -97,10 +100,7 @@ public ImcFragment callMmu(MmuCall f) { } else { mmuIsSet = true; } - if (f.instruction() != -1) { - this.hub.mmu().call(f, this.hub.callStack()); - } - + // Note: the triggering of the MMU is made by the creation of the MmuCAll this.moduleCalls.add(f); return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 9e5ac83560..20bbb0d3a4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -71,6 +71,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.CodeCopy; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.Create; @@ -86,7 +87,9 @@ import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.evm.worldstate.WorldView; /** * This class represents a call to the MMU. However, some MMU calls may have their actual content @@ -97,7 +100,9 @@ @Setter @Getter @Accessors(fluent = true) -public class MmuCall implements TraceSubFragment { +public class MmuCall implements TraceSubFragment, PostTransactionDefer { + protected boolean traceMe = true; + protected int instruction = 0; protected int sourceId = 0; protected int targetId = 0; @@ -159,7 +164,8 @@ final MmuCall setEcData() { } // TODO: make the instruction an enum - public MmuCall(final int instruction) { + public MmuCall(final Hub hub, final int instruction) { + hub.defers().scheduleForPostTransaction(this); this.instruction = instruction; } @@ -168,7 +174,7 @@ public static MmuCall nop() { } public static MmuCall sha3(final Hub hub) { - return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) .sourceRamBytes( Optional.of( @@ -188,7 +194,7 @@ public static MmuCall callDataCopy(final Hub hub) { final int callDataContextNumber = callDataContextNumber(hub); final CallFrame callFrame = hub.callStack().getByContextNumber(callDataContextNumber); - return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) + return new MmuCall(hub, MMU_INST_ANY_TO_RAM_WITH_PADDING) .sourceId(callDataContextNumber) .sourceRamBytes(Optional.of(callFrame.callDataInfo().data())) .targetId(hub.currentFrame().contextNumber()) @@ -213,7 +219,7 @@ public static int callDataContextNumber(final Hub hub) { } public static MmuCall LogX(final Hub hub, final LogInvocation logInvocation) { - return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(logInvocation.callFrame.contextNumber()) .targetId(hub.state.stamps().log()) .sourceOffset(logInvocation.offset) @@ -241,7 +247,7 @@ public static MmuCall returnDataCopy(final Hub hub) { final MemorySpan returnDataSegment = hub.currentFrame().returnDataSpan(); final CallFrame returnerFrame = hub.callStack().getByContextNumber(hub.currentFrame().returnDataContextNumber()); - return new MmuCall(MMU_INST_ANY_TO_RAM_WITH_PADDING) + return new MmuCall(hub, MMU_INST_ANY_TO_RAM_WITH_PADDING) .sourceId(returnerFrame.contextNumber()) .sourceRamBytes( Optional.of( @@ -276,7 +282,7 @@ public static MmuCall create2(final Hub hub, boolean failureCondition) { } public static MmuCall invalidCodePrefix(final Hub hub) { - return new MmuCall(MMU_INST_INVALID_CODE_PREFIX) + return new MmuCall(hub, MMU_INST_INVALID_CODE_PREFIX) .sourceId(hub.currentFrame().contextNumber()) .sourceRamBytes( Optional.of( @@ -288,7 +294,7 @@ public static MmuCall invalidCodePrefix(final Hub hub) { } public static MmuCall revert(final Hub hub) { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(hub.callStack().getById(hub.currentFrame().parentFrameId()).contextNumber()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) @@ -298,7 +304,7 @@ public static MmuCall revert(final Hub hub) { } public static MmuCall txInit(final Hub hub) { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(hub.txStack().current().getAbsoluteTransactionNumber()) .targetId(hub.stamp()) .size(hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)) @@ -316,7 +322,7 @@ public static MmuCall forEcRecover( final long inputSize = p.callDataSource().length(); return inputSize == 0 ? nop() - : new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset())) @@ -327,7 +333,7 @@ public static MmuCall forEcRecover( .setEcData(); } else if (i == 1) { if (recoverySuccessful) { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) .size(WORD_SIZE) @@ -339,7 +345,7 @@ public static MmuCall forEcRecover( } else { if (recoverySuccessful && !p.requestedReturnDataTarget().isEmpty()) { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.ZERO) @@ -358,7 +364,7 @@ private static MmuCall forShaTwoOrRipemdCallDataExtraction( final int precompileContextNumber = p.hubStamp() + 1; - return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset())) @@ -374,13 +380,13 @@ private static MmuCall forShaTwoOrRipemdFullResultTransfer( final int precompileContextNumber = p.hubStamp() + 1; if (p.callDataSource().isEmpty()) { - return new MmuCall(MMU_INST_MSTORE) + return new MmuCall(hub, MMU_INST_MSTORE) .targetId(precompileContextNumber) .targetOffset(EWord.ZERO) .limb1(isSha ? bigIntegerToBytes(EMPTY_SHA2_HI) : Bytes.ofUnsignedLong(EMPTY_RIPEMD_HI)) .limb2(isSha ? bigIntegerToBytes(EMPTY_SHA2_LO) : bigIntegerToBytes(EMPTY_RIPEMD_LO)); } else { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) .size(WORD_SIZE) @@ -394,7 +400,7 @@ private static MmuCall forShaTwoOrRipemdPartialResultCopy( final int precompileContextNumber = p.hubStamp() + 1; - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.ZERO) @@ -421,7 +427,7 @@ public static MmuCall forIdentity(final Hub hub, final PrecompileInvocation p, i final int precompileContextNumber = p.hubStamp() + 1; if (i == 0) { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset())) @@ -432,7 +438,7 @@ public static MmuCall forIdentity(final Hub hub, final PrecompileInvocation p, i if (p.requestedReturnDataTarget().isEmpty()) { return nop(); } else { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.ZERO) @@ -450,7 +456,7 @@ public static MmuCall forEcAdd(final Hub hub, final PrecompileInvocation p, int final long inputSize = p.callDataSource().length(); return inputSize == 0 ? nop() - : new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset())) @@ -460,14 +466,14 @@ public static MmuCall forEcAdd(final Hub hub, final PrecompileInvocation p, int .setEcData() .phase(PHASE_ECADD_DATA); } else if (i == 1) { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) .size(64) .setEcData() .phase(PHASE_ECADD_RESULT); } else { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .targetOffset(EWord.of(p.requestedReturnDataTarget().offset())) @@ -483,7 +489,7 @@ public static MmuCall forEcMul(final Hub hub, final PrecompileInvocation p, int final long inputSize = p.callDataSource().length(); return inputSize == 0 ? nop() - : new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset())) @@ -493,14 +499,14 @@ public static MmuCall forEcMul(final Hub hub, final PrecompileInvocation p, int .setEcData() .phase(PHASE_ECMUL_DATA); } else if (i == 1) { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) .size(64) .setEcData() .phase(PHASE_ECMUL_RESULT); } else { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .targetOffset(EWord.of(p.requestedReturnDataTarget().offset())) @@ -516,7 +522,7 @@ public static MmuCall forEcPairing(final Hub hub, final PrecompileInvocation p, final long inputSize = p.callDataSource().length(); return inputSize == 0 ? nop() - : new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset())) @@ -527,9 +533,9 @@ public static MmuCall forEcPairing(final Hub hub, final PrecompileInvocation p, .phase(PHASE_ECPAIRING_DATA); } else if (i == 1) { if (p.callDataSource().isEmpty()) { - return new MmuCall(MMU_INST_MSTORE).targetId(precompileContextNumber).limb2(Bytes.of(1)); + return new MmuCall(hub, MMU_INST_MSTORE).targetId(precompileContextNumber).limb2(Bytes.of(1)); } else { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) .size(WORD_SIZE) @@ -537,7 +543,7 @@ public static MmuCall forEcPairing(final Hub hub, final PrecompileInvocation p, .phase(PHASE_ECPAIRING_RESULT); } } else { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .targetOffset(EWord.of(p.requestedReturnDataTarget().offset())) @@ -550,7 +556,7 @@ public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, in Preconditions.checkArgument(i >= 0 && i < 4); final int precompileContextNumber = p.hubStamp() + 1; if (i == 0) { - return new MmuCall(MMU_INST_BLAKE) + return new MmuCall(hub, MMU_INST_BLAKE) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset())) @@ -560,7 +566,7 @@ public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, in .setBlakeModexp() .phase(PHASE_BLAKE_PARAMS); } else if (i == 1) { - return new MmuCall(MMU_INST_RAM_TO_EXO_WITH_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(p.callDataSource().offset() + 4)) @@ -569,7 +575,7 @@ public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, in .setBlakeModexp() .phase(PHASE_BLAKE_DATA); } else if (i == 2) { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) .size(64) @@ -579,7 +585,7 @@ public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, in if (p.requestedReturnDataTarget().isEmpty()) { return MmuCall.nop(); } else { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .size(64) @@ -595,14 +601,14 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int final int precompileContextNumber = p.hubStamp() + 1; if (i == 2) { - return new MmuCall(MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) .sourceId(hub.currentFrame().contextNumber()) .referenceOffset(p.callDataSource().offset()) .referenceSize(p.callDataSource().length()) .limb1(m.bbs().hi()) .limb2(m.bbs().lo()); } else if (i == 3) { - return new MmuCall(MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) .sourceId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(32)) .referenceOffset(p.callDataSource().offset()) @@ -610,7 +616,7 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int .limb1(m.ebs().hi()) .limb2(m.ebs().lo()); } else if (i == 4) { - return new MmuCall(MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) .sourceId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(64)) .referenceOffset(p.callDataSource().offset()) @@ -618,14 +624,14 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int .limb1(m.mbs().hi()) .limb2(m.mbs().lo()); } else if (i == 5) { - return new MmuCall(MMU_INST_MLOAD) + return new MmuCall(hub, MMU_INST_MLOAD) .sourceId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(p.callDataSource().offset() + 96 + m.bbs().toInt())) .limb1(m.rawLeadingWord().hi()) .limb2(m.rawLeadingWord().lo()); } else if (i == 7) { if (m.extractBase()) { - return new MmuCall(MMU_INST_MODEXP_DATA) + return new MmuCall(hub, MMU_INST_MODEXP_DATA) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(96)) @@ -635,14 +641,14 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int .phase(PHASE_MODEXP_BASE) .setBlakeModexp(); } else { - return new MmuCall(MMU_INST_MODEXP_ZERO) + return new MmuCall(hub, MMU_INST_MODEXP_ZERO) .targetId(precompileContextNumber) .phase(PHASE_MODEXP_BASE) .setBlakeModexp(); } } else if (i == 8) { if (m.extractExponent()) { - return new MmuCall(MMU_INST_MODEXP_DATA) + return new MmuCall(hub, MMU_INST_MODEXP_DATA) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(96 + m.bbs().toInt())) @@ -652,13 +658,13 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int .phase(PHASE_MODEXP_EXPONENT) .setBlakeModexp(); } else { - return new MmuCall(MMU_INST_MODEXP_ZERO) + return new MmuCall(hub, MMU_INST_MODEXP_ZERO) .targetId(precompileContextNumber) .phase(PHASE_MODEXP_EXPONENT) .setBlakeModexp(); } } else if (i == 9) { - return new MmuCall(MMU_INST_MODEXP_DATA) + return new MmuCall(hub, MMU_INST_MODEXP_DATA) .sourceId(hub.currentFrame().contextNumber()) .targetId(precompileContextNumber) .sourceOffset(EWord.of(96 + m.bbs().toInt() + m.ebs().toInt())) @@ -668,14 +674,14 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int .phase(PHASE_MODEXP_MODULUS) .setBlakeModexp(); } else if (i == 10) { - return new MmuCall(MMU_INST_EXO_TO_RAM_TRANSPLANTS) + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) .size(512) .phase(PHASE_MODEXP_RESULT) .setBlakeModexp(); } else if (i == 11) { - return new MmuCall(MMU_INST_RAM_TO_RAM_SANS_PADDING) + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) .targetId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(512 - m.mbs().toInt())) @@ -689,13 +695,14 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int @Override public Trace trace(Trace trace, State.TxState.Stamps stamps) { - stamps.incrementMmuStamp(); - return trace + if (traceMe){ + stamps.incrementMmuStamp(); + return trace .pMiscMmuFlag(true) .pMiscMmuInst( - this.instruction() == -1 - ? 0 - : this.instruction()) // TODO: WTF I wanted to put -1? Only for debug? + this.instruction() == -1 + ? 0 + : this.instruction()) // TODO: WTF I wanted to put -1? Only for debug? .pMiscMmuTgtId(this.targetId()) .pMiscMmuSrcId(this.sourceId()) .pMiscMmuAuxId(this.auxId()) @@ -710,5 +717,15 @@ public Trace trace(Trace trace, State.TxState.Stamps stamps) { .pMiscMmuLimb2(this.limb2()) .pMiscMmuExoSum(this.exoSum) .pMiscMmuPhase(this.phase()); + } else { + return trace; + } + } + + @Override + public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { +if (traceMe){ + hub.mmu().call(this, hub.callStack()); +} } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java index 8049f8ce12..601548a924 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java @@ -34,7 +34,7 @@ public class CodeCopy extends MmuCall { private final ContractMetadata contract; public CodeCopy(final Hub hub) { - super(MMU_INST_ANY_TO_RAM_WITH_PADDING); + super(hub, MMU_INST_ANY_TO_RAM_WITH_PADDING); this.hub = hub; this.contract = hub.currentFrame().metadata(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java index 09f8281450..cc1f953ca5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java @@ -35,7 +35,7 @@ public class Create extends MmuCall implements RomLexDefer { private ContractMetadata contract; public Create(final Hub hub) { - super(MMU_INST_RAM_TO_EXO_WITH_PADDING); + super(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING); this.hub = hub; this.hub.romLex().createDefers().register(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java index a0fa7bdec8..f8247b1351 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java @@ -35,7 +35,7 @@ public class Create2 extends MmuCall implements RomLexDefer { private ContractMetadata contract; public Create2(final Hub hub, boolean failureCondition) { - super(MMU_INST_RAM_TO_EXO_WITH_PADDING); + super(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING); this.hub = hub; this.hub.romLex().createDefers().register(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java index 534e146b77..3ae402db31 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java @@ -35,7 +35,7 @@ public class ExtCodeCopy extends MmuCall { private final ContractMetadata contract; public ExtCodeCopy(final Hub hub) { - super(MMU_INST_ANY_TO_RAM_WITH_PADDING); + super(hub, MMU_INST_ANY_TO_RAM_WITH_PADDING); this.hub = hub; final Address sourceAddress = Words.toAddress(hub.messageFrame().getStackItem(0)); this.contract = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java index 8561165b60..6423d6cb89 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java @@ -33,7 +33,7 @@ public class ReturnFromDeployment extends MmuCall { private final ContractMetadata contract; public ReturnFromDeployment(final Hub hub) { - super(MMU_INST_RAM_TO_EXO_WITH_PADDING); + super(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING); this.hub = hub; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index fd69cea245..031f5550c3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -37,12 +37,11 @@ import org.hyperledger.besu.evm.internal.Words; import org.hyperledger.besu.evm.worldstate.WorldView; -public class CallDataLoadSection extends TraceSection implements PostTransactionDefer { +public class CallDataLoadSection extends TraceSection { final short exception; final Bytes callDataRam; final int currentContextNumber; final long callDataCN; - final ImcFragment imcFragment; final EWord sourceOffset; long callDataOffset = -1; @@ -61,47 +60,40 @@ public CallDataLoadSection(Hub hub) { this.callDataCN = hub.currentFrame().callDataInfo().callDataContextNumber(); this.callDataRam = hub.currentFrame().callDataInfo().data(); - this.imcFragment = ImcFragment.empty(hub); + final ImcFragment imcFragment = ImcFragment.empty(hub); final OobCall oobCall = new CallDataLoadOobCall(); imcFragment.callOob(oobCall); - this.addFragment(imcFragment); - - final ContextFragment context = readCurrentContextData(hub); - this.addFragment(context); - - hub.defers().scheduleForPostTransaction(this); - } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { if (Exceptions.none(exception)) { - if (Words.clampedToLong(sourceOffset) >= callDataSize) { - return; - } + if (!(Words.clampedToLong(sourceOffset) >= callDataSize)) { - final EWord read = + final EWord read = EWord.of( - Bytes.wrap( - Arrays.copyOfRange( - hub.currentFrame().callDataInfo().data().toArray(), - Words.clampedToInt(sourceOffset), - Words.clampedToInt(sourceOffset) + WORD_SIZE))); - - final MmuCall call = - new MmuCall(MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) - .sourceId((int) callDataCN) - .sourceOffset(sourceOffset) - .referenceOffset(callDataOffset) - .referenceSize(callDataSize) - .limb1(read.hi()) - .limb2(read.lo()) - .sourceRamBytes(Optional.of(callDataRam)); - - imcFragment.callMmu(call); + Bytes.wrap( + Arrays.copyOfRange( + hub.currentFrame().callDataInfo().data().toArray(), + Words.clampedToInt(sourceOffset), + Words.clampedToInt(sourceOffset) + WORD_SIZE))); + + final MmuCall call = + new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + .sourceId((int) callDataCN) + .sourceOffset(sourceOffset) + .referenceOffset(callDataOffset) + .referenceSize(callDataSize) + .limb1(read.hi()) + .limb2(read.lo()) + .sourceRamBytes(Optional.of(callDataRam)); + + imcFragment.callMmu(call); + } } + + this.addFragment(imcFragment); + + final ContextFragment context = readCurrentContextData(hub); + this.addFragment(context); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 82346f7388..43821b3a1f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -27,11 +27,7 @@ import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldView; -public class KeccakSection extends TraceSection implements PostExecDefer, PostTransactionDefer { - - final ImcFragment miscFragment; - final boolean triggerMmu; - MmuCall mmuCall; +public class KeccakSection extends TraceSection implements PostExecDefer { public KeccakSection(Hub hub) { super(hub, (short) 3); @@ -39,28 +35,22 @@ public KeccakSection(Hub hub) { hub.addTraceSection(this); - miscFragment = ImcFragment.empty(hub); - this.addStackAndFragments(hub, miscFragment); + final ImcFragment imcFragment = ImcFragment.empty(hub); + this.addStackAndFragments(hub, imcFragment); final MxpCall mxpCall = new MxpCall(hub); - miscFragment.callMxp(mxpCall); + imcFragment.callMxp(mxpCall); final boolean mayTriggerNonTrivialOperation = mxpCall.isMayTriggerNonTrivialMmuOperation(); - triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); + final boolean triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); if (triggerMmu) { hub.defers().scheduleForPostExecution(this); - hub.defers().scheduleForPostTransaction(this); - mmuCall = MmuCall.sha3(hub); + final MmuCall mmuCall = MmuCall.sha3(hub); + imcFragment.callMmu(mmuCall); } } - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - miscFragment.callMmu(mmuCall); - } - @Override public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index a038e2dc56..c7602a2e8a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -30,8 +30,6 @@ public class LogSection implements PostTransactionDefer { LogCommonSection sectionPrequel; - final boolean isStatic; - final boolean mxpX; final boolean oogX; @@ -39,19 +37,17 @@ public class LogSection implements PostTransactionDefer { LogInvocation logData; public LogSection(Hub hub) { - this.mxpX = Exceptions.memoryExpansionException(hub.pch().exceptions()); - this.oogX = Exceptions.outOfGasException(hub.pch().exceptions()); + // this.mxpX = Exceptions.memoryExpansionException(hub.pch().exceptions()); + // this.oogX = Exceptions.outOfGasException(hub.pch().exceptions()); // Static Case if (hub.currentFrame().frame().isStatic()) { - isStatic = true; hub.addTraceSection( new LogCommonSection(hub, (short) 4, ContextFragment.readCurrentContextData(hub))); return; } // General Case - isStatic = false; this.sectionPrequel = new LogCommonSection(hub, (short) 5, ContextFragment.readCurrentContextData(hub)); hub.addTraceSection(sectionPrequel); @@ -67,7 +63,6 @@ public LogSection(Hub hub) { @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (!isStatic) { if (!this.logData.reverted()) { hub.state.stamps().incrementLogStamp(); this.sectionPrequel.commonValues.logStamp(hub.state.stamps().log()); @@ -75,7 +70,6 @@ public void resolvePostTransaction( final boolean mmuTrigger = !this.logData.reverted() && this.logData.size != 0; if (mmuTrigger) { miscFragment.callMmu(MmuCall.LogX(hub, this.logData)); - } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 864c09a28a..461d556388 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -33,7 +33,7 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; -public class CodeCopySection extends TraceSection implements PostTransactionDefer { +public class CodeCopySection extends TraceSection { final ImcFragment imcFragment; boolean triggerMmu; final short exceptions; @@ -107,14 +107,6 @@ public CodeCopySection(Hub hub) { triggerMmu = mxpCall.isMayTriggerNonTrivialMmuOperation(); if (triggerMmu) { mmuCall = MmuCall.codeCopy(hub); - hub.defers().scheduleForPostTransaction(this); - } - } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (triggerMmu) { imcFragment.callMmu(mmuCall); } } From 895edb3130a781dbcbf774e9c6a300762c5c2208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 27 Jul 2024 23:44:49 +0200 Subject: [PATCH 310/461] fix(MmuCall): various - several instructions were fixed to not defer their mmuCall's to post transaction - complete revision of RETURN's --- .../consensys/linea/zktracer/ZkTracer.java | 2 + .../linea/zktracer/module/hub/Hub.java | 6 +- ...extDefer.java => ContextReEntryDefer.java} | 2 +- .../module/hub/defer/DeferRegistry.java | 42 +-- ...r.java => ImmediateContextEntryDefer.java} | 2 +- ...ostExecDefer.java => PostOpcodeDefer.java} | 2 +- .../module/hub/fragment/imc/ImcFragment.java | 5 +- .../module/hub/fragment/imc/call/MxpCall.java | 4 +- .../hub/fragment/imc/call/mmu/MmuCall.java | 77 +++--- .../hub/section/CallDataLoadSection.java | 31 +-- .../module/hub/section/KeccakSection.java | 12 +- .../module/hub/section/LogSection.java | 89 +++--- .../module/hub/section/StackRamSection.java | 122 ++++----- .../module/hub/section/call/CallSection.java | 8 +- .../PrecompileSubsection.java | 4 +- .../hub/section/copy/CallDataCopySection.java | 50 ++-- .../hub/section/copy/CodeCopySection.java | 42 ++- .../hub/section/copy/ExtCodeCopySection.java | 49 ++-- .../section/copy/ReturnDataCopySection.java | 64 ++--- .../hub/section/create/CreateSection.java | 12 +- .../hub/section/halt/ReturnSection.java | 259 ++++++++---------- .../hub/section/halt/RevertSection.java | 30 +- .../module/hub/transients/Conflation.java | 8 +- .../zktracer/module/mxp/MxpOperation.java | 4 +- .../linea/zktracer/module/romlex/RomLex.java | 4 +- .../{LogInvocation.java => LogData.java} | 8 +- 26 files changed, 442 insertions(+), 496 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/{ReEnterContextDefer.java => ContextReEntryDefer.java} (95%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/{ChildContextEntryDefer.java => ImmediateContextEntryDefer.java} (94%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/{PostExecDefer.java => PostOpcodeDefer.java} (96%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/{LogInvocation.java => LogData.java} (92%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index f92aaa6d42..911a987b6e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -217,6 +217,8 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo } } + // TODO: this isn't called anywhere ... + // @Override public void tracePrepareTransaction(WorldView worldView, Transaction transaction) { try { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index b1ee821803..57d9147e55 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -494,9 +494,9 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { /* * TODO: the ID = 0 (universal parent context) context should - * 1. be shared by all transactions in a conflation (OK) - * 2. should be the father of all root contexts - * 3. should have the current root context as its lastCallee() + * 1. be shared by all transactions in a conflation (OK) + * 2. should be the father of all root contexts + * 3. should have the current root context as its lastCallee() */ this.callStack.getById(0).universalParentReturnDataContextNumber(this.stamp() + 1); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextReEntryDefer.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextReEntryDefer.java index d935f307af..340e1874bb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ReEnterContextDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ContextReEntryDefer.java @@ -18,6 +18,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -public interface ReEnterContextDefer { +public interface ContextReEntryDefer { void resolveAtContextReEntry(final Hub hub, final CallFrame frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 04dc06c5c1..8c32058c87 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -31,26 +31,26 @@ */ // TODO: fix naming and implement the missing interfaces public class DeferRegistry - implements PostExecDefer, + implements PostOpcodeDefer, + ImmediateContextEntryDefer, + ContextExitDefer, PostRollbackDefer, PostTransactionDefer, - PostConflationDefer, - ChildContextEntryDefer, - ContextExitDefer { + PostConflationDefer { /** A list of actions deferred until the end of the current opcode execution */ - private final List postExecDefers = new ArrayList<>(); + private final List postOpcodeDefers = new ArrayList<>(); - /** A list of actions deferred until the end of the current opcode execution */ - private final List childContextEntryDefers = new ArrayList<>(); + /** A list of actions deferred to the immediate entry into a child or parent context */ + private final List immediateContextEntryDefers = new ArrayList<>(); - /** A list of actions deferred until the exit of a given context */ + /** A list of actions deferred to the end of a given context */ private final Map> contextExitDefers = new HashMap<>(); - /** A list of actions deferred until the end of the current opcode execution */ - private final Map> contextReEntryDefers = new HashMap<>(); + /** A list of actions deferred to the end of the current opcode execution */ + private final Map> contextReEntryDefers = new HashMap<>(); - /** A list of actions deferred until the end of the current transaction */ + /** A list of actions deferred to the end of the current transaction */ private final List postTransactionDefers = new ArrayList<>(); /** A list of actions deferred until the end of the current conflation execution */ @@ -64,13 +64,13 @@ public class DeferRegistry private final Map> rollbackDefers = new HashMap<>(); /** Schedule an action to be executed after the completion of the current opcode. */ - public void scheduleForImmediateContextEntry(ChildContextEntryDefer defer) { - this.childContextEntryDefers.add(defer); + public void scheduleForImmediateContextEntry(ImmediateContextEntryDefer defer) { + this.immediateContextEntryDefers.add(defer); } /** Schedule an action to be executed after the completion of the current opcode. */ - public void scheduleForPostExecution(PostExecDefer defer) { - this.postExecDefers.add(defer); + public void scheduleForPostExecution(PostOpcodeDefer defer) { + this.postOpcodeDefers.add(defer); } /** Schedule an action to be executed at the exit of a given context. */ @@ -92,7 +92,7 @@ public void scheduleForPostConflation(PostConflationDefer defer) { } /** Schedule an action to be executed at the re-entry in the current context. */ - public void scheduleForContextReEntry(ReEnterContextDefer defer, CallFrame callFrame) { + public void scheduleForContextReEntry(ContextReEntryDefer defer, CallFrame callFrame) { if (!contextReEntryDefers.containsKey(callFrame)) { contextReEntryDefers.put(callFrame, new ArrayList<>()); } @@ -154,10 +154,10 @@ public void resolvePostConflation(Hub hub, WorldView world) { */ @Override public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult result) { - for (PostExecDefer defer : this.postExecDefers) { + for (PostOpcodeDefer defer : this.postOpcodeDefers) { defer.resolvePostExecution(hub, frame, result); } - this.postExecDefers.clear(); + this.postOpcodeDefers.clear(); } /** @@ -168,7 +168,7 @@ public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.Operatio */ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { if (this.contextReEntryDefers.containsKey(callFrame)) { - for (ReEnterContextDefer defer : this.contextReEntryDefers.get(callFrame)) { + for (ContextReEntryDefer defer : this.contextReEntryDefers.get(callFrame)) { defer.resolveAtContextReEntry(hub, callFrame); } this.contextReEntryDefers.remove(callFrame); @@ -203,10 +203,10 @@ public void resolvePostRollback( @Override public void resolveUponEnteringChildContext(Hub hub) { - for (ChildContextEntryDefer defer : this.childContextEntryDefers) { + for (ImmediateContextEntryDefer defer : this.immediateContextEntryDefers) { defer.resolveUponEnteringChildContext(hub); } - this.childContextEntryDefers.clear(); + this.immediateContextEntryDefers.clear(); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ImmediateContextEntryDefer.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ImmediateContextEntryDefer.java index 7b16b12bbe..62cf3f8308 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ChildContextEntryDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ImmediateContextEntryDefer.java @@ -17,6 +17,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; -public interface ChildContextEntryDefer { +public interface ImmediateContextEntryDefer { void resolveUponEnteringChildContext(Hub hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostOpcodeDefer.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostOpcodeDefer.java index 20837638c2..d4b637fd3c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostExecDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/PostOpcodeDefer.java @@ -19,6 +19,6 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; -public interface PostExecDefer { +public interface PostOpcodeDefer { void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult operationResult); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index 8d8680c02f..c69cb0c057 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -21,7 +21,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -31,8 +30,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; /** * IMCFragments embed data required for Inter-Module Communication, i.e. data that are required to @@ -100,7 +97,7 @@ public ImcFragment callMmu(MmuCall f) { } else { mmuIsSet = true; } - // Note: the triggering of the MMU is made by the creation of the MmuCAll + // Note: the triggering of the MMU is made by the creation of the MmuCall this.moduleCalls.add(f); return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java index 973217e4a1..7004cbb45d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java @@ -39,7 +39,7 @@ public class MxpCall implements TraceSubFragment { @Getter @Setter public EWord size1 = EWord.ZERO; @Getter @Setter public EWord offset2 = EWord.ZERO; @Getter @Setter public EWord size2 = EWord.ZERO; - @Getter @Setter public boolean mayTriggerNonTrivialMmuOperation; + @Setter public boolean mayTriggerNontrivialMmuOperation; /** mxpx is short of Memory eXPansion eXception */ @Getter @Setter public boolean mxpx; @@ -73,7 +73,7 @@ public Trace trace(Trace trace, State.TxState.Stamps stamps) { .pMiscMxpOffset2Lo(this.offset2.lo()) .pMiscMxpSize2Hi(this.size2.hi()) .pMiscMxpSize2Lo(this.size2.lo()) - .pMiscMxpMtntop(this.mayTriggerNonTrivialMmuOperation) + .pMiscMxpMtntop(this.mayTriggerNontrivialMmuOperation) .pMiscMxpMxpx(this.mxpx) .pMiscMxpWords(Bytes.ofUnsignedLong(this.memorySizeInWords)) .pMiscMxpGasMxp(Bytes.ofUnsignedLong(this.gasMxp)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java index 20bbb0d3a4..442b10b43b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java @@ -82,7 +82,7 @@ import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.runtime.LogInvocation; +import net.consensys.linea.zktracer.runtime.LogData; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; @@ -130,6 +130,10 @@ public class MmuCall implements TraceSubFragment, PostTransactionDefer { protected boolean exoIsEcData = false; private int exoSum = 0; + public void dontTraceMe() { + this.traceMe = false; + } + private MmuCall updateExoSum(final int exoValue) { this.exoSum += exoValue; return this; @@ -218,20 +222,20 @@ public static int callDataContextNumber(final Hub hub) { : hub.callStack().parent().contextNumber(); } - public static MmuCall LogX(final Hub hub, final LogInvocation logInvocation) { + public static MmuCall LogX(final Hub hub, final LogData logData) { return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) - .sourceId(logInvocation.callFrame.contextNumber()) + .sourceId(logData.callFrame.contextNumber()) .targetId(hub.state.stamps().log()) - .sourceOffset(logInvocation.offset) - .size(logInvocation.size) - .referenceSize(logInvocation.size) - .sourceRamBytes(Optional.of(logInvocation.ramSourceBytes)) + .sourceOffset(logData.offset) + .size(logData.size) + .referenceSize(logData.size) + .sourceRamBytes(Optional.of(logData.ramSourceBytes)) .exoBytes( Optional.of( slice( - logInvocation.ramSourceBytes, - (int) Words.clampedToLong(logInvocation.offset), - (int) logInvocation.size))) + logData.ramSourceBytes, + (int) Words.clampedToLong(logData.offset), + (int) logData.size))) .setLog(); } @@ -533,7 +537,9 @@ public static MmuCall forEcPairing(final Hub hub, final PrecompileInvocation p, .phase(PHASE_ECPAIRING_DATA); } else if (i == 1) { if (p.callDataSource().isEmpty()) { - return new MmuCall(hub, MMU_INST_MSTORE).targetId(precompileContextNumber).limb2(Bytes.of(1)); + return new MmuCall(hub, MMU_INST_MSTORE) + .targetId(precompileContextNumber) + .limb2(Bytes.of(1)); } else { return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) @@ -695,37 +701,38 @@ public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int @Override public Trace trace(Trace trace, State.TxState.Stamps stamps) { - if (traceMe){ + if (traceMe) { stamps.incrementMmuStamp(); return trace - .pMiscMmuFlag(true) - .pMiscMmuInst( - this.instruction() == -1 - ? 0 - : this.instruction()) // TODO: WTF I wanted to put -1? Only for debug? - .pMiscMmuTgtId(this.targetId()) - .pMiscMmuSrcId(this.sourceId()) - .pMiscMmuAuxId(this.auxId()) - .pMiscMmuSrcOffsetHi(this.sourceOffset().hi()) - .pMiscMmuSrcOffsetLo(this.sourceOffset().lo()) - .pMiscMmuTgtOffsetLo(this.targetOffset().lo()) - .pMiscMmuSize(this.size()) - .pMiscMmuRefOffset(this.referenceOffset()) - .pMiscMmuRefSize(this.referenceSize()) - .pMiscMmuSuccessBit(this.successBit()) - .pMiscMmuLimb1(this.limb1()) - .pMiscMmuLimb2(this.limb2()) - .pMiscMmuExoSum(this.exoSum) - .pMiscMmuPhase(this.phase()); + .pMiscMmuFlag(true) + .pMiscMmuInst( + this.instruction() == -1 + ? 0 + : this.instruction()) // TODO: WTF I wanted to put -1? Only for debug? + .pMiscMmuTgtId(this.targetId()) + .pMiscMmuSrcId(this.sourceId()) + .pMiscMmuAuxId(this.auxId()) + .pMiscMmuSrcOffsetHi(this.sourceOffset().hi()) + .pMiscMmuSrcOffsetLo(this.sourceOffset().lo()) + .pMiscMmuTgtOffsetLo(this.targetOffset().lo()) + .pMiscMmuSize(this.size()) + .pMiscMmuRefOffset(this.referenceOffset()) + .pMiscMmuRefSize(this.referenceSize()) + .pMiscMmuSuccessBit(this.successBit()) + .pMiscMmuLimb1(this.limb1()) + .pMiscMmuLimb2(this.limb2()) + .pMiscMmuExoSum(this.exoSum) + .pMiscMmuPhase(this.phase()); } else { return trace; } } @Override - public void resolvePostTransaction(Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { -if (traceMe){ - hub.mmu().call(this, hub.callStack()); -} + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + if (traceMe) { + hub.mmu().call(this, hub.callStack()); + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index 031f5550c3..e8cf08d374 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -23,7 +23,6 @@ import java.util.Optional; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; @@ -33,9 +32,7 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.internal.Words; -import org.hyperledger.besu.evm.worldstate.WorldView; public class CallDataLoadSection extends TraceSection { final short exception; @@ -70,22 +67,22 @@ public CallDataLoadSection(Hub hub) { if (!(Words.clampedToLong(sourceOffset) >= callDataSize)) { final EWord read = - EWord.of( - Bytes.wrap( - Arrays.copyOfRange( - hub.currentFrame().callDataInfo().data().toArray(), - Words.clampedToInt(sourceOffset), - Words.clampedToInt(sourceOffset) + WORD_SIZE))); + EWord.of( + Bytes.wrap( + Arrays.copyOfRange( + hub.currentFrame().callDataInfo().data().toArray(), + Words.clampedToInt(sourceOffset), + Words.clampedToInt(sourceOffset) + WORD_SIZE))); final MmuCall call = - new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) - .sourceId((int) callDataCN) - .sourceOffset(sourceOffset) - .referenceOffset(callDataOffset) - .referenceSize(callDataSize) - .limb1(read.hi()) - .limb2(read.lo()) - .sourceRamBytes(Optional.of(callDataRam)); + new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + .sourceId((int) callDataCN) + .sourceOffset(sourceOffset) + .referenceOffset(callDataOffset) + .referenceSize(callDataSize) + .limb1(read.hi()) + .limb2(read.lo()) + .sourceRamBytes(Optional.of(callDataRam)); imcFragment.callMmu(call); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 43821b3a1f..b73bdfd43e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -16,18 +16,15 @@ package net.consensys.linea.zktracer.module.hub.section; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.WorldView; -public class KeccakSection extends TraceSection implements PostExecDefer { +public class KeccakSection extends TraceSection implements PostOpcodeDefer { public KeccakSection(Hub hub) { super(hub, (short) 3); @@ -41,8 +38,9 @@ public KeccakSection(Hub hub) { final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - final boolean mayTriggerNonTrivialOperation = mxpCall.isMayTriggerNonTrivialMmuOperation(); - final boolean triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); + final boolean mayTriggerNonTrivialOperation = mxpCall.mayTriggerNontrivialMmuOperation; + final boolean triggerMmu = + mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); if (triggerMmu) { hub.defers().scheduleForPostExecution(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index c7602a2e8a..582f75f6fa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -15,68 +15,81 @@ package net.consensys.linea.zktracer.module.hub.section; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.runtime.LogInvocation; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; +import net.consensys.linea.zktracer.runtime.LogData; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.hyperledger.besu.evm.frame.MessageFrame; -public class LogSection implements PostTransactionDefer { +public class LogSection extends TraceSection implements PostRollbackDefer { - LogCommonSection sectionPrequel; + MmuCall mmuCall; - final boolean mxpX; - final boolean oogX; + public LogSection(Hub hub) { + super(hub, maxNumberOfRows(hub)); - ImcFragment miscFragment; - LogInvocation logData; + final short exceptions = hub.pch().exceptions(); - public LogSection(Hub hub) { - // this.mxpX = Exceptions.memoryExpansionException(hub.pch().exceptions()); - // this.oogX = Exceptions.outOfGasException(hub.pch().exceptions()); + final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); + + this.addStack(hub); + this.addFragment(currentContextFragment); // Static Case if (hub.currentFrame().frame().isStatic()) { - hub.addTraceSection( - new LogCommonSection(hub, (short) 4, ContextFragment.readCurrentContextData(hub))); + Preconditions.checkArgument(Exceptions.staticFault(exceptions)); return; } - // General Case - this.sectionPrequel = - new LogCommonSection(hub, (short) 5, ContextFragment.readCurrentContextData(hub)); - hub.addTraceSection(sectionPrequel); - logData = new LogInvocation(hub); + final ImcFragment imcFragment = ImcFragment.empty(hub); + this.addFragment(imcFragment); final MxpCall mxpCall = new MxpCall(hub); - miscFragment = ImcFragment.empty(hub).callMxp(mxpCall); - this.sectionPrequel.addFragment(miscFragment); + imcFragment.callMxp(mxpCall); - hub.defers().scheduleForPostTransaction(this); - } + Preconditions.checkArgument( + mxpCall.isMxpx() == Exceptions.memoryExpansionException(exceptions)); - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (!this.logData.reverted()) { - hub.state.stamps().incrementLogStamp(); - this.sectionPrequel.commonValues.logStamp(hub.state.stamps().log()); - } - final boolean mmuTrigger = !this.logData.reverted() && this.logData.size != 0; - if (mmuTrigger) { - miscFragment.callMmu(MmuCall.LogX(hub, this.logData)); + // MXPX case + if (mxpCall.isMxpx()) { + return; + } + + // OOGX case + if (Exceptions.outOfGasException(exceptions)) { + return; + } + + // the unexceptional case + Preconditions.checkArgument(Exceptions.none(exceptions)); + + final LogData logData = new LogData(hub); + Preconditions.checkArgument( + logData.nontrivialLog() == mxpCall.mayTriggerNontrivialMmuOperation); + mmuCall = (logData.nontrivialLog()) ? MmuCall.LogX(hub, logData) : null; + + if (mmuCall != null) { + imcFragment.callMmu(mmuCall); + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); } } - public static class LogCommonSection extends TraceSection { - public LogCommonSection(Hub hub, short maxNbOfRows, ContextFragment fragment) { - super(hub, maxNbOfRows); - this.addStackAndFragments(hub, fragment); + private static short maxNumberOfRows(Hub hub) { + return (short) + (hub.opCode().numberOfStackRows() + + (Exceptions.staticFault(hub.pch().exceptions()) ? 2 : 3)); + } + + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + if (mmuCall != null) { + mmuCall.dontTraceMe(); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index 30a3fa95cf..fd176d32f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -19,94 +19,94 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MSTORE; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_MSTORE8; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; +import static net.consensys.linea.zktracer.runtime.callstack.CallFrame.extractContiguousLimbsFromMemory; import java.util.Optional; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.internal.Words; -import org.hyperledger.besu.evm.worldstate.WorldView; -public class StackRamSection extends TraceSection implements PostTransactionDefer { - final OpCode instruction; - final Bytes currentRam; - final int currentContextNumber; - final short exception; - final ImcFragment imcFragment; - final EWord offset; - final EWord value; +public class StackRamSection extends TraceSection { public StackRamSection(Hub hub) { super(hub, (short) 3); + hub.addTraceSection(this); this.addStack(hub); - this.instruction = hub.opCode(); - this.exception = hub.pch().exceptions(); - this.currentRam = - hub.currentFrame().frame().shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()); - this.currentContextNumber = hub.currentFrame().contextNumber(); + final OpCode instruction = hub.opCode(); + final short exceptions = hub.pch().exceptions(); - this.imcFragment = ImcFragment.empty(hub); - this.offset = EWord.of(hub.currentFrame().frame().getStackItem(0)); - this.value = - instruction.equals(OpCode.MLOAD) - ? EWord.of(hub.messageFrame().shadowReadMemory(Words.clampedToLong(offset), WORD_SIZE)) - : EWord.of(hub.currentFrame().frame().getStackItem(1)); + final ImcFragment imcFragment = ImcFragment.empty(hub); + this.addFragment(imcFragment); final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - this.addFragment(imcFragment); + Preconditions.checkArgument( + mxpCall.isMxpx() == Exceptions.memoryExpansionException(exceptions)); - hub.defers().scheduleForPostTransaction(this); - } + // MXPX or OOGX case + if (mxpCall.isMxpx() || Exceptions.outOfGasException(exceptions)) { + return; + } + + // the unexceptional case + Preconditions.checkArgument(Exceptions.none(exceptions)); - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (Exceptions.none(exception)) { - switch (instruction) { - case MSTORE -> { - final MmuCall call = - new MmuCall(MMU_INST_MSTORE) - .targetId(currentContextNumber) - .targetOffset(offset) - .limb1(value.hi()) - .limb2(value.lo()) - .targetRamBytes(Optional.of(currentRam)); - - imcFragment.callMmu(call); - } - case MSTORE8 -> { - final MmuCall call = - new MmuCall(MMU_INST_MSTORE8) - .targetId(currentContextNumber) - .targetOffset(offset) - .limb1(value.hi()) - .limb2(value.lo()) - .targetRamBytes(Optional.of(currentRam)); - imcFragment.callMmu(call); - } - case MLOAD -> { - final MmuCall call = - new MmuCall(MMU_INST_MLOAD) - .sourceId(currentContextNumber) - .sourceOffset(offset) - .limb1(value.hi()) - .limb2(value.lo()) - .sourceRamBytes(Optional.of(currentRam)); - imcFragment.callMmu(call); - } + final EWord offset = EWord.of(hub.currentFrame().frame().getStackItem(0)); + final long longOffset = Words.clampedToLong(offset); + final Bytes currentRam = + extractContiguousLimbsFromMemory( + hub.currentFrame().frame(), new MemorySpan(longOffset, WORD_SIZE)); + final int currentContextNumber = hub.currentFrame().contextNumber(); + final EWord value = + instruction.equals(OpCode.MLOAD) + ? EWord.of(hub.messageFrame().shadowReadMemory(Words.clampedToLong(offset), WORD_SIZE)) + : EWord.of(hub.currentFrame().frame().getStackItem(1)); + + MmuCall mmuCall; + + switch (instruction) { + case MSTORE -> { + mmuCall = + new MmuCall(hub, MMU_INST_MSTORE) + .targetId(currentContextNumber) + .targetOffset(offset) + .limb1(value.hi()) + .limb2(value.lo()) + .targetRamBytes(Optional.of(currentRam)); + } + case MSTORE8 -> { + mmuCall = + new MmuCall(hub, MMU_INST_MSTORE8) + .targetId(currentContextNumber) + .targetOffset(offset) + .limb1(value.hi()) + .limb2(value.lo()) + .targetRamBytes(Optional.of(currentRam)); } + case MLOAD -> { + mmuCall = + new MmuCall(hub, MMU_INST_MLOAD) + .sourceId(currentContextNumber) + .sourceOffset(offset) + .limb1(value.hi()) + .limb2(value.lo()) + .sourceRamBytes(Optional.of(currentRam)); + } + default -> throw new IllegalStateException("Not a STACK_RAM instruction"); } + + imcFragment.callMmu(mmuCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 02c5794214..c44aa484e3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -28,11 +28,11 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.ChildContextEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; +import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; +import net.consensys.linea.zktracer.module.hub.defer.ImmediateContextEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; @@ -57,9 +57,9 @@ import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection - implements ChildContextEntryDefer, + implements ImmediateContextEntryDefer, ContextExitDefer, - ReEnterContextDefer, + ContextReEntryDefer, PostRollbackDefer, PostTransactionDefer { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index dfbdcf6f89..8985cd1e0d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -27,9 +27,9 @@ import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; +import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; @@ -44,7 +44,7 @@ @RequiredArgsConstructor @Getter public class PrecompileSubsection - implements ContextExitDefer, ReEnterContextDefer, PostRollbackDefer, PostTransactionDefer { + implements ContextExitDefer, ContextReEntryDefer, PostRollbackDefer, PostTransactionDefer { /** List of fragments of the precompile specific subsection */ private final List fragments; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index 12636f36f0..24c9fb18cc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -15,81 +15,67 @@ package net.consensys.linea.zktracer.module.hub.section.copy; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.OUT_OF_GAS_EXCEPTION; + import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class CallDataCopySection extends TraceSection implements PostTransactionDefer { - final short exceptions; - final ImcFragment miscFragment; - boolean triggerMmu = false; - MmuCall mmuCall; +public class CallDataCopySection extends TraceSection { public CallDataCopySection(Hub hub) { // 3 = 1 + 2 - super(hub, (short) 3); - this.exceptions = hub.pch().exceptions(); - + super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); - miscFragment = ImcFragment.empty(hub); - this.addStackAndFragments(hub, miscFragment); + final ImcFragment imcFragment = ImcFragment.empty(hub); + this.addStack(hub); + this.addFragment(imcFragment); // triggerOob = false // triggerMxp = true final MxpCall mxpCall = new MxpCall(hub); - miscFragment.callMxp(mxpCall); - - Preconditions.checkArgument( - mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + imcFragment.callMxp(mxpCall); // the only allowable exceptions are // - memoryExpansionException (MXPX) // - outOfGasException OOGX //////////////////////////////////// + short exceptions = hub.pch().exceptions(); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); + // The MXPX case - //////////////// if (mxpCall.mxpx) { return; } // The OOGX case - //////////////// if (Exceptions.any(exceptions)) { - Preconditions.checkArgument(this.exceptions == Exceptions.OUT_OF_GAS_EXCEPTION); + Preconditions.checkArgument(exceptions == OUT_OF_GAS_EXCEPTION); return; } // The unexceptional case - ///////////////////////// - final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); this.addFragment(currentContext); - triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; + final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; + if (!triggerMmu) { return; } - mmuCall = MmuCall.callDataCopy(hub); - hub.defers().scheduleForPostTransaction(this); + MmuCall mmuCall = MmuCall.callDataCopy(hub); + imcFragment.callMmu(mmuCall); } - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (triggerMmu) { - miscFragment.callMmu(mmuCall); - } + private static short maxNumberOfRows(Hub hub) { + return (short) (hub.opCode().numberOfStackRows() + 2); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index 461d556388..d1ea6924f6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -18,7 +18,6 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; @@ -28,52 +27,40 @@ import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; public class CodeCopySection extends TraceSection { - final ImcFragment imcFragment; - boolean triggerMmu; - final short exceptions; - MmuCall mmuCall; public CodeCopySection(Hub hub) { - // 4 = 1 (stack row) + 3 (up to 3 non-stack rows) - super(hub, (short) 4); - this.exceptions = hub.pch().exceptions(); + super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); // Miscellaneous row - imcFragment = ImcFragment.empty(hub); - this.addStackAndFragments(hub, imcFragment); + final ImcFragment imcFragment = ImcFragment.empty(hub); + this.addStack(hub); + this.addFragment(imcFragment); // triggerOob = false // triggerMxp = true final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - final boolean mxpx = mxpCall.mxpx; - Preconditions.checkArgument(mxpx == Exceptions.memoryExpansionException(exceptions)); + + final short exceptions = hub.pch().exceptions(); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); // The MXPX case - //////////////// - if (mxpx) { + if (mxpCall.mxpx) { return; } - final boolean xahoy = Exceptions.any(exceptions); - Preconditions.checkArgument(xahoy == (exceptions == Exceptions.OUT_OF_GAS_EXCEPTION)); - // The OOGX case - //////////////// if (Exceptions.any(exceptions)) { + Preconditions.checkArgument(exceptions == Exceptions.OUT_OF_GAS_EXCEPTION); return; } - // Beyond this point we are in the xahoy = false case - - // Context row + // the unexceptional case final ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); this.addFragment(contextFragment); @@ -104,10 +91,15 @@ public CodeCopySection(Hub hub) { this.addFragment(accountReadingFragment); - triggerMmu = mxpCall.isMayTriggerNonTrivialMmuOperation(); + final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; if (triggerMmu) { - mmuCall = MmuCall.codeCopy(hub); + MmuCall mmuCall = MmuCall.codeCopy(hub); imcFragment.callMmu(mmuCall); } } + + // 4 = 1 (stack row) + 3 (up to 3 non-stack rows) + private static short maxNumberOfRows(Hub hub) { + return (short) (hub.opCode().numberOfStackRows() + 3); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 788966a202..e777064c95 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -15,14 +15,12 @@ package net.consensys.linea.zktracer.module.hub.section.copy; -import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.none; import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.outOfGasException; import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; @@ -34,59 +32,47 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; -public class ExtCodeCopySection extends TraceSection - implements PostRollbackDefer, PostTransactionDefer { +public class ExtCodeCopySection extends TraceSection implements PostRollbackDefer { - final int hubStamp; final Bytes rawAddress; final Address address; final int incomingDeploymentNumber; final boolean incomingDeploymentStatus; final boolean incomingWarmth; - final short exceptions; AccountSnapshot accountBefore; AccountSnapshot accountAfter; - final ImcFragment miscFragment; - boolean triggerMmu = false; - MmuCall mmuCall; - public ExtCodeCopySection(Hub hub) { // 4 = 1 + 3 - super(hub, (short) 4); + super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); final MessageFrame frame = hub.messageFrame(); - hubStamp = hub.stamp(); rawAddress = frame.getStackItem(0); address = Address.extract((Bytes32) rawAddress); incomingDeploymentNumber = hub.transients().conflation().deploymentInfo().number(address); incomingDeploymentStatus = hub.transients().conflation().deploymentInfo().isDeploying(address); incomingWarmth = frame.isAddressWarm(address); - exceptions = hub.pch().exceptions(); - miscFragment = ImcFragment.empty(hub); + ImcFragment imcFragment = ImcFragment.empty(hub); this.addStack(hub); - this.addFragment(miscFragment); + this.addFragment(imcFragment); // triggerExp = false // triggerOob = false // triggerStp = false // triggerMxp = true final MxpCall mxpCall = new MxpCall(hub); - miscFragment.callMxp(mxpCall); + imcFragment.callMxp(mxpCall); - Preconditions.checkArgument( - mxpCall.mxpx == Exceptions.memoryExpansionException(this.exceptions)); + short exceptions = hub.pch().exceptions(); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); // The MXPX case - //////////////// if (mxpCall.mxpx) { return; } @@ -101,7 +87,6 @@ public ExtCodeCopySection(Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); // The OOGX case - //////////////// if (outOfGasException(exceptions)) { // the last context row will be added automatically final AccountFragment accountReadingFragment = @@ -114,11 +99,12 @@ public ExtCodeCopySection(Hub hub) { } // The unexceptional case - ///////////////////////// - triggerMmu = none(exceptions) && mxpCall.mayTriggerNonTrivialMmuOperation; + Preconditions.checkArgument(Exceptions.none(exceptions)); + + final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; if (triggerMmu) { - mmuCall = MmuCall.extCodeCopy(hub); - hub.defers().scheduleForPostTransaction(this); + MmuCall mmuCall = MmuCall.extCodeCopy(hub); + imcFragment.callMmu(mmuCall); } // TODO: make sure that hasCode returns false during deployments @@ -171,7 +157,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca deploymentStatusAtRollback); final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps(hubStamp, callFrame.revertStamp(), 1); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), callFrame.revertStamp(), 1); final AccountFragment undoingAccountFragment = hub.factories() .accountFragment() @@ -180,11 +167,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca this.addFragment(undoingAccountFragment); } - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (triggerMmu) { - miscFragment.callMmu(mmuCall); - } + private static short maxNumberOfRows(Hub hub) { + return (short) (hub.opCode().numberOfStackRows() + 3); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 14bfc4a5d6..73f14b1abf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -15,9 +15,10 @@ package net.consensys.linea.zktracer.module.hub.section.copy; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.OUT_OF_GAS_EXCEPTION; + import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; @@ -25,66 +26,57 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; - -public class ReturnDataCopySection extends TraceSection implements PostTransactionDefer { - final short exceptions; - - final ImcFragment miscFragment; - boolean triggerMmu = false; - MmuCall mmuCall; +public class ReturnDataCopySection extends TraceSection { public ReturnDataCopySection(Hub hub) { - // 4 = 1 + 3 - super(hub, (short) 4); - this.exceptions = hub.pch().exceptions(); - + super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); - this.addStackAndFragments(hub, currentContext); - - miscFragment = ImcFragment.empty(hub); - this.addFragment(miscFragment); - + final ImcFragment imcFragment = ImcFragment.empty(hub); final ReturnDataCopyOobCall oobCall = new ReturnDataCopyOobCall(); - miscFragment.callOob(oobCall); + imcFragment.callOob(oobCall); + + this.addStack(hub); + this.addFragment(currentContext); + this.addFragment(imcFragment); + final short exceptions = hub.pch().exceptions(); final boolean returnDataCopyException = oobCall.isRdcx(); Preconditions.checkArgument( - returnDataCopyException == Exceptions.returnDataCopyFault(this.exceptions)); + returnDataCopyException == Exceptions.returnDataCopyFault(exceptions)); + // returnDataCopyException case if (returnDataCopyException) { return; } final MxpCall mxpCall = new MxpCall(hub); - miscFragment.callMxp(mxpCall); + imcFragment.callMxp(mxpCall); - final boolean memoryExpansionException = mxpCall.mxpx; - Preconditions.checkArgument( - memoryExpansionException == Exceptions.memoryExpansionException(this.exceptions)); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); + + // memoryExpansionException case + if (mxpCall.mxpx) { + return; + } - // if MXPX ∨ OOGX - if (Exceptions.any(this.exceptions)) { + // outOfGasException case + if (Exceptions.any(exceptions)) { + Preconditions.checkArgument(exceptions == OUT_OF_GAS_EXCEPTION); return; } // beyond this point unexceptional - triggerMmu = mxpCall.mayTriggerNonTrivialMmuOperation; + final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; if (triggerMmu) { - mmuCall = MmuCall.returnDataCopy(hub); - hub.defers().scheduleForPostTransaction(this); + MmuCall mmuCall = MmuCall.returnDataCopy(hub); + imcFragment.callMmu(mmuCall); } } - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - if (triggerMmu) { - miscFragment.callMmu(mmuCall); - } + private static short maxNumberOfRows(Hub hub) { + return (short) (hub.opCode().numberOfStackRows() + 3); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 98f8c8eba7..2d8ba051d8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -24,10 +24,10 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.ChildContextEntryDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; +import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; +import net.consensys.linea.zktracer.module.hub.defer.ImmediateContextEntryDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.defer.ReEnterContextDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; @@ -48,8 +48,12 @@ import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldView; +// TODO: should implement ContextEntryDefer public class CreateSection - implements PostExecDefer, ReEnterContextDefer, PostTransactionDefer, ChildContextEntryDefer { + implements PostOpcodeDefer, + ContextReEntryDefer, + PostTransactionDefer, + ImmediateContextEntryDefer { private FillCreateSection createSection; private int creatorContextId; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 4444aeff31..7cae394a7c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -15,12 +15,14 @@ package net.consensys.linea.zktracer.module.hub.section.halt; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment.ReturnScenario.*; -import static org.hyperledger.besu.evm.internal.Words.clampedToLong; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.OUT_OF_GAS_EXCEPTION; +import static net.consensys.linea.zktracer.module.hub.signals.Exceptions.memoryExpansionException; import com.google.common.base.Preconditions; import lombok.Getter; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; @@ -30,52 +32,45 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.Bytecode; +import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; @Getter -public class ReturnSection extends TraceSection implements PostTransactionDefer, PostRollbackDefer { +public class ReturnSection extends TraceSection + implements ContextReEntryDefer, PostRollbackDefer, PostTransactionDefer { - final int hubStamp; - final CallFrame currentFrame; - final short exceptions; + final boolean returnFromMessageCall; final boolean returnFromDeployment; - final boolean returnFromMessageCall; // not stricly speaking necessary + boolean nonemptyByteCode; final ReturnScenarioFragment returnScenarioFragment; - final ImcFragment firstImcFragment; - ImcFragment secondImcFragment; AccountFragment deploymentFragment; - AccountFragment undoingDeploymentAccountFragment; - MmuCall firstMmuCall; - MmuCall secondMmuCall; + AccountSnapshot preDeploymentAccountSnapshot; + AccountSnapshot postDeploymentAccountSnapshot; + AccountSnapshot undoingDeploymentAccountSnapshot; ContextFragment squashParentContextReturnData; - @Getter public boolean emptyDeployment; - @Getter public boolean deploymentWasReverted = false; + Address deploymentAddress; public ReturnSection(Hub hub) { - // 5 = 1 + 4 - // 8 = 1 + 7 - super(hub, Exceptions.any(hub.pch().exceptions()) ? (short) 5 : (short) 8); + super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); - hubStamp = hub.stamp(); - currentFrame = hub.currentFrame(); - exceptions = hub.pch().exceptions(); - returnFromMessageCall = hub.currentFrame().isMessageCall(); - returnFromDeployment = hub.currentFrame().isDeployment(); - firstImcFragment = ImcFragment.empty(hub); + CallFrame currentFrame = hub.currentFrame(); + returnFromMessageCall = currentFrame.isMessageCall(); + returnFromDeployment = currentFrame.isDeployment(); returnScenarioFragment = new ReturnScenarioFragment(); final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); + final ImcFragment firstImcFragment = ImcFragment.empty(hub); final MxpCall mxpCall = new MxpCall(hub); firstImcFragment.callMxp(mxpCall); @@ -84,60 +79,63 @@ public ReturnSection(Hub hub) { this.addFragment(currentContextFragment); this.addFragment(firstImcFragment); - // Exceptional RETURN's - /////////////////////// - /////////////////////// + short exceptions = hub.pch().exceptions(); if (Exceptions.any(exceptions)) { returnScenarioFragment.setScenario(RETURN_EXCEPTION); } - // Memory expansion exception (MXPX) - // Out of gas exception (OOGX) - //////////////////////////////////// - if (Exceptions.memoryExpansionException(exceptions) - || Exceptions.outOfGasException(exceptions)) { - // Note: the missing context fragment is added elsewhere + Preconditions.checkArgument(mxpCall.mxpx == memoryExpansionException(exceptions)); + + if (mxpCall.mxpx) { return; } - // Max code size exception (MAXCSX) - /////////////////////////////////// + if (Exceptions.outOfGasException(exceptions) && returnFromMessageCall) { + Preconditions.checkArgument(exceptions == OUT_OF_GAS_EXCEPTION); + return; + } + + if (Exceptions.any(exceptions)) { + // exceptional message calls are dealt with; + // if exceptions remain they must be related + // to deployments: + Preconditions.checkArgument(returnFromDeployment); + } + + // maxCodeSizeException case boolean triggerOobForMaxCodeSizeException = Exceptions.codeSizeOverflow(exceptions); if (triggerOobForMaxCodeSizeException) { - Preconditions.checkArgument(hub.currentFrame().isDeployment()); OobCall oobCall = new XCallOobCall(); firstImcFragment.callOob(oobCall); return; } - // Invalid code prefix exception (ICPX) - /////////////////////////////////////// + // invalidCodePrefixException case + final boolean nontrivialMmuOperation = mxpCall.mayTriggerNontrivialMmuOperation; final boolean triggerMmuForInvalidCodePrefix = Exceptions.invalidCodePrefix(exceptions); if (triggerMmuForInvalidCodePrefix) { - Preconditions.checkArgument(hub.currentFrame().isDeployment()); - firstMmuCall = MmuCall.invalidCodePrefix(hub); - hub.defers().scheduleForPostTransaction(this); + Preconditions.checkArgument(returnFromDeployment && nontrivialMmuOperation); + + MmuCall actuallyInvalidCodePrefixMmuCall = MmuCall.invalidCodePrefix(hub); + firstImcFragment.callMmu(actuallyInvalidCodePrefixMmuCall); + + Preconditions.checkArgument(!actuallyInvalidCodePrefixMmuCall.successBit()); return; } - Preconditions.checkArgument(Exceptions.none(exceptions)); - // Unexceptional RETURN's // (we have exceptions ≡ ∅ by the checkArgument) //////////////////////////////////////////////// - //////////////////////////////////////////////// - final boolean nontrivialMmOperation = mxpCall.isMayTriggerNonTrivialMmuOperation(); + Preconditions.checkArgument(Exceptions.none(exceptions)); // RETURN_FROM_MESSAGE_CALL cases - ///////////////////////////////// - ///////////////////////////////// if (returnFromMessageCall) { final boolean messageCallReturnTouchesRam = - !hub.currentFrame().isRoot() - && nontrivialMmOperation // [size ≠ 0] ∧ ¬MXPX - && !hub.currentFrame().parentReturnDataTarget().isEmpty(); // [r@c ≠ 0] + !currentFrame.isRoot() + && nontrivialMmuOperation // [size ≠ 0] ∧ ¬MXPX + && !currentFrame.parentReturnDataTarget().isEmpty(); // [r@c ≠ 0] returnScenarioFragment.setScenario( messageCallReturnTouchesRam @@ -145,100 +143,88 @@ public ReturnSection(Hub hub) { : RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM); if (messageCallReturnTouchesRam) { - firstMmuCall = MmuCall.returnFromMessageCall(hub); - Preconditions.checkArgument(!firstMmuCall.successBit()); - hub.defers().scheduleForPostTransaction(this); + MmuCall returnFromMessageCall = MmuCall.returnFromMessageCall(hub); + firstImcFragment.callMmu(returnFromMessageCall); } - // no need for the else case (and a nop) as per @François final ContextFragment updateCallerReturnData = ContextFragment.executionProvidesReturnData( hub, - hub.callStack().getById(hub.currentFrame().parentFrameId()).contextNumber(), - hub.currentFrame().contextNumber()); + hub.callStack().getById(currentFrame.parentFrameId()).contextNumber(), + currentFrame.contextNumber()); this.addFragment(updateCallerReturnData); return; } // RETURN_FROM_DEPLOYMENT cases - /////////////////////////////// - /////////////////////////////// if (returnFromDeployment) { - hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - final long byteCodeSize = hub.messageFrame().getStackItem(1).toLong(); - final boolean emptyDeployment = byteCodeSize == 0; - final boolean triggerOobForNonemptyDeployments = mxpCall.isMayTriggerNonTrivialMmuOperation(); - Preconditions.checkArgument(triggerOobForNonemptyDeployments == !emptyDeployment); + // TODO: @Olivier and @François: what happens when "re-entering" the root's parent context ? + // we may need to improve the triggering of the resolution to also kick in at transaction + // end for stuff that happens after the root returns ... + hub.defers() + .scheduleForContextReEntry( + this, hub.callStack().parent()); // post deployment account snapshot + hub.defers().scheduleForPostRollback(this, currentFrame); // undo deployment + hub.defers().scheduleForPostTransaction(this); // inserting the final context row; + + squashParentContextReturnData = ContextFragment.executionProvidesEmptyReturnData(hub); + deploymentAddress = hub.messageFrame().getRecipientAddress(); + nonemptyByteCode = mxpCall.mayTriggerNontrivialMmuOperation; + preDeploymentAccountSnapshot = AccountSnapshot.canonical(hub, deploymentAddress); + returnScenarioFragment.setScenario( + nonemptyByteCode + ? RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT + : RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT); - final Address deploymentAddress = hub.messageFrame().getRecipientAddress(); - final AccountSnapshot accountBeforeDeployment = - AccountSnapshot.canonical(hub, deploymentAddress); + final Bytes byteCodeSize = hub.messageFrame().getStackItem(1); + Preconditions.checkArgument(nonemptyByteCode == (!byteCodeSize.isZero())); // Empty deployments - //////////////////// - if (emptyDeployment) { - - final AccountSnapshot accountAfterEmptyDeployment = - accountBeforeDeployment.deployByteCode(Bytecode.EMPTY); - final AccountFragment emptyDeploymentAccountFragment = - hub.factories() - .accountFragment() - .make( - accountBeforeDeployment, - accountAfterEmptyDeployment, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - this.addFragment(emptyDeploymentAccountFragment); - - // Note: - // - triggerHASHINFO isn't required; - // - triggerROMLEX isn't required either; - + if (!nonemptyByteCode) { return; } - // Nonempty deployments - /////////////////////// - hub.defers().scheduleForPostTransaction(this); + MmuCall invalidCodePrefixCheckMmuCall = MmuCall.invalidCodePrefix(hub); + firstImcFragment.callMmu(invalidCodePrefixCheckMmuCall); + + DeploymentOobCall maxCodeSizeOobCall = new DeploymentOobCall(); + firstImcFragment.callOob(maxCodeSizeOobCall); - firstMmuCall = MmuCall.invalidCodePrefix(hub); - Preconditions.checkArgument(firstMmuCall.successBit()); + // sanity checks + Preconditions.checkArgument(invalidCodePrefixCheckMmuCall.successBit()); + Preconditions.checkArgument(!maxCodeSizeOobCall.isMaxCodeSizeException()); - secondImcFragment = ImcFragment.empty(hub); - secondMmuCall = MmuCall.returnFromDeployment(hub); + ImcFragment secondImcFragment = ImcFragment.empty(hub); this.addFragment(secondImcFragment); - final long offset = clampedToLong(hub.messageFrame().getStackItem(0)); - final Bytecode deploymentCode = - new Bytecode(hub.messageFrame().shadowReadMemory(offset, byteCodeSize)); + MmuCall nonemptyDeploymentMmuCall = MmuCall.returnFromDeployment(hub); + secondImcFragment.callMmu(nonemptyDeploymentMmuCall); + } + } - // TODO: we require the - // - triggerHashInfo stuff on the first stack row - // - triggerROMLEX on the deploymentAccountFragment row (done) - final AccountFragment nonemptyDeploymentAccountFragment = - hub.factories() - .accountFragment() - .make( - accountBeforeDeployment, - accountBeforeDeployment.deployByteCode(deploymentCode), - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - nonemptyDeploymentAccountFragment.requiresRomlex(true); - hub.romLex().callRomLex(hub.messageFrame()); + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) { - this.addFragment(nonemptyDeploymentAccountFragment); + postDeploymentAccountSnapshot = AccountSnapshot.canonical(hub, deploymentAddress); + final AccountFragment deploymentAccountFragment = + hub.factories() + .accountFragment() + .make( + preDeploymentAccountSnapshot, + postDeploymentAccountSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - // TODO: we need to implement the mechanism that will append the - // context row which will squash the creator's return data after - // any and all account-rows. - // - // TODO: make sure this works if the current context is the root - // context (deployment transaction) in particular the following - // ``Either.left(callStack.parent().id())'' - squashParentContextReturnData = ContextFragment.executionProvidesEmptyReturnData(hub); + if (nonemptyByteCode) { + // TODO: we require the + // - triggerHashInfo stuff on the first stack row (automatic AFAICT) + // - triggerROMLEX on the deploymentAccountFragment row (see below) + deploymentAccountFragment.requiresRomlex(true); + hub.romLex().callRomLex(hub.messageFrame()); } - // returnFromDeployment = + this.addFragment(deploymentAccountFragment); } @Override @@ -246,42 +232,37 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca // TODO Preconditions.checkArgument(returnFromDeployment); returnScenarioFragment.setScenario( - emptyDeployment - ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT - : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT); - - // TODO: do we account for updates to - // - deploymentNumber and status ? Presumably, but if so by coincidence - // - MARKED_FOR_SELF_DESTRUCT(_NEW) ? No - // - - undoingDeploymentAccountFragment = + nonemptyByteCode + ? RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT + : RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT); + + undoingDeploymentAccountSnapshot = AccountSnapshot.canonical(hub, deploymentAddress); + + // TODO: does this account for updates to + // - deploymentNumber and status ? + // - MARKED_FOR_SELF_DESTRUCT(_NEW) ? + AccountFragment undoingDeploymentAccountFragment = hub.factories() .accountFragment() .make( - deploymentFragment.newState(), - deploymentFragment.oldState(), + postDeploymentAccountSnapshot, + undoingDeploymentAccountSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - hubStamp, hub.currentFrame().revertStamp(), 1)); + this.hubStamp(), hub.callStack().current().revertStamp(), 1)); this.addFragment(undoingDeploymentAccountFragment); - deploymentWasReverted = true; } @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - // TODO - - if (returnFromDeployment && !deploymentWasReverted) { - returnScenarioFragment.setScenario( - emptyDeployment - ? RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT - : RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT); - } - - if (firstMmuCall != null) firstImcFragment.callMmu(firstMmuCall); - if (secondMmuCall != null) secondImcFragment.callMmu(secondMmuCall); + Preconditions.checkArgument(returnFromDeployment); this.addFragment(squashParentContextReturnData); } + + private static short maxNumberOfRows(Hub hub) { + return (short) + (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 4 : 7)); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index 68bc486012..46fe2e5e15 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -16,21 +16,17 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; -public class RevertSection extends TraceSection implements PostTransactionDefer { +public class RevertSection extends TraceSection { final ImcFragment imcFragment; MmuCall mmuCall; - final boolean triggerMmu; public RevertSection(Hub hub) { // up to 4 = 1 + 3 rows @@ -50,31 +46,25 @@ public RevertSection(Hub hub) { imcFragment.callMxp(mxpCall); Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); - triggerMmu = + // The XAHOY case + ///////////////// + if (Exceptions.any(exceptions)) { + return; + } + + final boolean triggerMmu = (Exceptions.none(exceptions)) && !hub.currentFrame().isRoot() - && mxpCall.isMayTriggerNonTrivialMmuOperation() // i.e. size ≠ 0 ∧ ¬MXPX + && mxpCall.mayTriggerNontrivialMmuOperation // i.e. size ≠ 0 ∧ ¬MXPX && !hub.currentFrame().parentReturnDataTarget().isEmpty(); if (triggerMmu) { mmuCall = MmuCall.revert(hub); - hub.defers().scheduleForPostTransaction(this); - } - - // The XAHOY case - ///////////////// - if (Exceptions.any(exceptions)) { - return; + imcFragment.callMmu(mmuCall); } final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); final ContextFragment parentContext = ContextFragment.executionProvidesEmptyReturnData(hub); this.addFragments(currentContext, parentContext); } - - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - imcFragment.callMmu(mmuCall); - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java index 84cdff02f2..a65ae9e5ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Conflation.java @@ -20,17 +20,17 @@ import lombok.Getter; import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.runtime.LogInvocation; +import net.consensys.linea.zktracer.runtime.LogData; /** Stores data relative to the conflation. */ @Accessors(fluent = true) @Getter public class Conflation { private final DeploymentInfo deploymentInfo = new DeploymentInfo(); - private final List logs = new ArrayList<>(100); + private final List logs = new ArrayList<>(100); - public int log(LogInvocation logInvocation) { - this.logs.add(logInvocation); + public int log(LogData logData) { + this.logs.add(logData); return this.logs.size() - 1; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java index ba69fa4592..c72b11d689 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java @@ -231,7 +231,7 @@ protected void setNoOperation() { private void setMtntop() { final boolean mxpx = mxpCall.isMxpx(); - mxpCall.setMayTriggerNonTrivialMmuOperation( + mxpCall.setMayTriggerNontrivialMmuOperation( typeMxp == MxpType.TYPE_4 && !mxpx && mxpCall.getSize1().loBigInt().signum() != 0); } @@ -608,7 +608,7 @@ final void trace(int stamp, Trace trace) { .linCost(Bytes.ofUnsignedLong(this.getLinCost())) .gasMxp(Bytes.ofUnsignedLong(this.mxpCall.getGasMxp())) .expands(this.isExpands()) - .mtntop(this.mxpCall.isMayTriggerNonTrivialMmuOperation()) + .mtntop(this.mxpCall.mayTriggerNontrivialMmuOperation) .validateRow(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 4ae08d996e..9f91f54050 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -33,7 +33,7 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostExecDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -47,7 +47,7 @@ import org.hyperledger.besu.evm.worldstate.WorldView; @Accessors(fluent = true) -public class RomLex implements Module, PostExecDefer { +public class RomLex implements Module, PostOpcodeDefer { private static final RomChunkComparator ROM_CHUNK_COMPARATOR = new RomChunkComparator(); private final Hub hub; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogInvocation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogData.java similarity index 92% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogInvocation.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogData.java index 06b3ec5235..c6c1007f69 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogInvocation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/LogData.java @@ -22,13 +22,13 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; -public class LogInvocation { +public class LogData { public final CallFrame callFrame; public final Bytes ramSourceBytes; public final EWord offset; public final long size; - public LogInvocation(Hub hub) { + public LogData(Hub hub) { this.callFrame = hub.currentFrame(); final MessageFrame messageFrame = callFrame.frame(); offset = EWord.of(messageFrame.getStackItem(0)); @@ -37,6 +37,10 @@ public LogInvocation(Hub hub) { size == 0 ? Bytes.EMPTY : messageFrame.shadowReadMemory(0, messageFrame.memoryByteSize()); } + public boolean nontrivialLog() { + return this.size != 0; + } + public boolean reverted() { return this.callFrame.hasReverted(); } From 9db1e79a7820651ad4396648882149ed6d06496e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 01:14:25 +0200 Subject: [PATCH 311/461] fix(accountSection): fixed it AccountSection didn't care about - exceptions and didn't handle rollbacks the right way --- .../linea/zktracer/module/hub/AccountSnapshot.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 0b272f52ce..e02bbe28e2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -78,12 +78,6 @@ public AccountSnapshot incrementBalance(Wei quantity) { return this; } - // Deprecated ? - // public static AccountSnapshot fromWorld(WorldView world, Address address) { - // final Account account = world.get(address); - // return fromAccount(account, true, 0, false); // TODO: implement warm, depNumber and Status - // } - public static AccountSnapshot fromAccount( Account account, boolean isWarm, int deploymentNumber, boolean deploymentStatus) { return fromAccount(Optional.ofNullable(account), isWarm, deploymentNumber, deploymentStatus); From dc8f1da9fb6bf2efcf3051ca4fe79b443cb0cbd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 01:15:17 +0200 Subject: [PATCH 312/461] fix(AccountSection): missed stuff --- .../module/hub/section/AccountSection.java | 166 ++++++++---------- 1 file changed, 70 insertions(+), 96 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index f7665ba093..2a148f2294 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub.section; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; @@ -30,124 +31,97 @@ import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; -public class AccountSection extends TraceSection implements PostRollbackDefer { +import static net.consensys.linea.zktracer.opcode.OpCode.*; - final short exceptions; - final Bytes rawTargetAddress; - final Address targetAddress; - final boolean intialWarmth; - final AccountSnapshot accountSnapshotBefore; - final AccountSnapshot accountSnapshotAfter; +public class AccountSection extends TraceSection implements PostRollbackDefer { - public void appendToTrace(Hub hub) { + Bytes rawTargetAddress; + Address targetAddress; + public AccountSection(Hub hub) { + super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); - hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - - if (hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { - this.addFragment(ContextFragment.readCurrentContextData(hub)); - } - - final DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); - - AccountFragment doingAccountFragment = - hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE) - ? hub.factories() - .accountFragment() - .make(this.accountSnapshotBefore, this.accountSnapshotAfter, doingDomSubStamps) - : hub.factories() - .accountFragment() - .makeWithTrm( - this.accountSnapshotBefore, - this.accountSnapshotAfter, - this.rawTargetAddress, - doingDomSubStamps); + this.addStack(hub); - this.addFragment(doingAccountFragment); - } + short exceptions = hub.pch().exceptions(); - private static short maxNumberOfRows(Hub hub) { - final OpCode opCode = hub.opCode(); + if (hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { + if (Exceptions.any(exceptions)) { + // the "squash parent return data" context row is all there is + return; + } - if (opCode.isAnyOf(OpCode.BALANCE, OpCode.EXTCODESIZE, OpCode.EXTCODEHASH)) { - return (short) (opCode.numberOfStackRows() + 3); + ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + this.addFragment(currentContext); } - return (short) (opCode.numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 1 : 2)); - } + final MessageFrame frame = hub.messageFrame(); - public AccountSection(Hub hub) { - super(hub, maxNumberOfRows(hub)); - hub.addTraceSection(this); - this.addStack(hub); + targetAddress = switch (hub.opCode()) { + case BALANCE, EXTCODESIZE, EXTCODEHASH -> { + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + rawTargetAddress = frame.getStackItem(0); + yield Words.toAddress(this.rawTargetAddress); + } + case SELFBALANCE -> frame.getRecipientAddress(); + case CODESIZE -> frame.getContractAddress(); + default -> throw new RuntimeException("Not an ACCOUNT instruction"); + }; - exceptions = hub.pch().exceptions(); + AccountSnapshot accountSnapshotBefore = AccountSnapshot.canonical(hub, targetAddress); + AccountSnapshot accountSnapshotAfter = accountSnapshotBefore.deepCopy().turnOnWarmth(); - final MessageFrame frame = hub.messageFrame(); - this.rawTargetAddress = - switch (hub.opCode()) { - case BALANCE, EXTCODESIZE, EXTCODEHASH -> frame.getStackItem(0); - case SELFBALANCE -> frame.getRecipientAddress(); - case CODESIZE -> frame.getContractAddress(); - default -> throw new RuntimeException("invalid opcode"); - }; - - this.targetAddress = Words.toAddress(this.rawTargetAddress); - this.intialWarmth = frame.isAddressWarm(targetAddress); - this.accountSnapshotBefore = - AccountSnapshot.fromAccount( - getTargetAccount(hub), - this.intialWarmth, - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); - this.accountSnapshotAfter = - AccountSnapshot.fromAccount( - getTargetAccount(hub), - true, // QUESTION: is this true even if we revert with the instruction ? ANSWER: yes. - hub.transients().conflation().deploymentInfo().number(targetAddress), - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress)); - } + final DomSubStampsSubFragment doingDomSubStamps = + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); - private Account getTargetAccount(Hub hub) { - return hub.messageFrame().getWorldUpdater().get(targetAddress); + AccountFragment doingAccountFragment = + switch (hub.opCode()) { + case BALANCE, EXTCODESIZE, EXTCODEHASH -> hub.factories() + .accountFragment() + .makeWithTrm( + accountSnapshotBefore, + accountSnapshotAfter, + rawTargetAddress, + doingDomSubStamps); + case SELFBALANCE, CODESIZE -> hub.factories() + .accountFragment() + .make(accountSnapshotBefore, accountSnapshotAfter, doingDomSubStamps); + default -> throw new IllegalStateException("Not an ACCOUNT instruction"); + }; + this.addFragment(doingAccountFragment); } - // TODO: make sure the resolvePostRollback method - // gets called before the final context row is - // added; simplest solution: have that final context - // row in a separate list. public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + AccountSnapshot postRollBackAccountSnapshot = AccountSnapshot.canonical(hub, targetAddress); + final DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), hub.currentFrame().revertStamp(), 0); - final int deploymentNumberAtRollback = - hub.transients().conflation().deploymentInfo().number(targetAddress); - final boolean deploymentStatusAtRollback = - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress); - AccountSnapshot revertFrom = - new AccountSnapshot( - this.accountSnapshotAfter.address(), - this.accountSnapshotAfter.nonce(), // TODO: this will blow up! - this.accountSnapshotAfter.balance(), - this.accountSnapshotAfter.isWarm(), - this.accountSnapshotAfter.code(), - deploymentNumberAtRollback, - deploymentStatusAtRollback); - - AccountSnapshot revertTo = - new AccountSnapshot( - this.accountSnapshotBefore.address(), - this.accountSnapshotBefore.nonce(), // TODO: this will blow up! - this.accountSnapshotBefore.balance(), - this.accountSnapshotBefore.isWarm(), - this.accountSnapshotBefore.code(), - deploymentNumberAtRollback, - deploymentStatusAtRollback); + AccountSnapshot preRollBackAccountSnapshot = postRollBackAccountSnapshot.deepCopy().turnOnWarmth(); + + { + // sanity check + final int deploymentNumberAtRollback = + hub.transients().conflation().deploymentInfo().number(targetAddress); + final boolean deploymentStatusAtRollback = + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress); + Preconditions.checkArgument(deploymentNumberAtRollback == postRollBackAccountSnapshot.deploymentNumber()); + Preconditions.checkArgument(deploymentStatusAtRollback == postRollBackAccountSnapshot.deploymentStatus()); + } this.addFragment( - hub.factories().accountFragment().make(revertFrom, revertTo, undoingDomSubStamps)); + hub.factories().accountFragment().make(preRollBackAccountSnapshot, postRollBackAccountSnapshot, undoingDomSubStamps)); + } + + private static short maxNumberOfRows(Hub hub) { + final OpCode opCode = hub.opCode(); + + if (opCode.isAnyOf(BALANCE, EXTCODESIZE, EXTCODEHASH)) { + return (short) (opCode.numberOfStackRows() + 3); + } + + return (short) (opCode.numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 1 : 2)); } } From af41afe2bb1f047ffee4af1234130d6ed7b46abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 01:15:40 +0200 Subject: [PATCH 313/461] fix(ExtCodeCopySection): fixed it AFAICT --- .../hub/section/copy/ExtCodeCopySection.java | 40 ++++--------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index e777064c95..7aac3f7f6f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -35,6 +35,7 @@ import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; +// TODO: implement public class ExtCodeCopySection extends TraceSection implements PostRollbackDefer { final Bytes rawAddress; @@ -79,9 +80,7 @@ public ExtCodeCopySection(Hub hub) { final Account foreignAccount = frame.getWorldUpdater().get(this.address); - this.accountBefore = - AccountSnapshot.fromAccount( - foreignAccount, incomingWarmth, incomingDeploymentNumber, incomingDeploymentStatus); + this.accountBefore = AccountSnapshot.canonical(hub, address); final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); @@ -131,38 +130,15 @@ public ExtCodeCopySection(Hub hub) { @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - final int deploymentNumberAtRollback = - hub.transients().conflation().deploymentInfo().number(address); - final boolean deploymentStatusAtRollback = - hub.transients().conflation().deploymentInfo().isDeploying(address); - - final AccountSnapshot revertFromSnapshot = - new AccountSnapshot( - accountAfter.address(), - accountAfter.nonce(), - accountAfter.balance(), - accountAfter.isWarm(), - accountAfter.code(), - deploymentNumberAtRollback, - deploymentStatusAtRollback); - - final AccountSnapshot revertToSnapshot = - new AccountSnapshot( - accountBefore.address(), - accountBefore.nonce(), - accountBefore.balance(), - accountBefore.isWarm(), - accountBefore.code(), - deploymentNumberAtRollback, - deploymentStatusAtRollback); + AccountSnapshot accountPostRollback = AccountSnapshot.canonical(hub, address); final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), callFrame.revertStamp(), 1); - final AccountFragment undoingAccountFragment = - hub.factories() + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), callFrame.revertStamp(), 1); + + final AccountFragment undoingAccountFragment = hub.factories() .accountFragment() - .make(revertFromSnapshot, revertToSnapshot, undoingDomSubStamps); + .make(accountAfter, accountPostRollback, undoingDomSubStamps); this.addFragment(undoingAccountFragment); } From ba69139e38a600591b0d4ac26db66e58d4f3ab27 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 28 Jul 2024 10:04:31 +0200 Subject: [PATCH 314/461] TRM is trigger by hand for instructions --- .../linea/zktracer/module/trm/Trm.java | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java index 1d91e4dfc0..216b81ec3d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/trm/Trm.java @@ -23,7 +23,6 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -32,14 +31,13 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.TransactionType; -import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.worldstate.WorldView; public class Trm implements Module { static final int MAX_CT = LLARGE; static final int PIVOT_BIT_FLIPS_TO_TRUE = 12; - private final StackedSet trimmings = new StackedSet<>(); + private final StackedSet operations = new StackedSet<>(); @Override public String moduleKey() { @@ -48,29 +46,16 @@ public String moduleKey() { @Override public void enterTransaction() { - this.trimmings.enter(); + this.operations.enter(); } @Override public void popTransaction() { - this.trimmings.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - switch (opCode) { - case BALANCE, EXTCODESIZE, EXTCODECOPY, EXTCODEHASH, SELFDESTRUCT -> { - this.trimmings.add(new TrmOperation(EWord.of(frame.getStackItem(0)))); - } - case CALL, CALLCODE, DELEGATECALL, STATICCALL -> { - this.trimmings.add(new TrmOperation(EWord.of(frame.getStackItem(1)))); - } - } + this.operations.pop(); } public Address callTrimming(Bytes32 rawHash) { - this.trimmings.add(new TrmOperation(EWord.of(rawHash))); + operations.add(new TrmOperation(EWord.of(rawHash))); return Address.extract(rawHash); } @@ -82,16 +67,17 @@ public Address callTrimming(Bytes addressToTrim) { @Override public void traceStartTx(WorldView world, TransactionProcessingMetadata txMetaData) { // Add effective receiver Address - this.trimmings.add(new TrmOperation(EWord.of(txMetaData.getEffectiveTo()))); + operations.add(new TrmOperation(EWord.of(txMetaData.getEffectiveTo()))); // Add Address in AccessList to warm final Transaction tx = txMetaData.getBesuTransaction(); final TransactionType txType = tx.getType(); + switch (txType) { case ACCESS_LIST, EIP1559 -> { if (tx.getAccessList().isPresent()) { for (AccessListEntry entry : tx.getAccessList().get()) { - this.trimmings.add(new TrmOperation(EWord.of(entry.address()))); + operations.add(new TrmOperation(EWord.of(entry.address()))); } } } @@ -114,7 +100,7 @@ public void commit(List buffers) { final Trace trace = new Trace(buffers); int stamp = 0; - for (TrmOperation operation : this.trimmings) { + for (TrmOperation operation : this.operations) { stamp++; operation.trace(trace, stamp); } @@ -122,6 +108,6 @@ public void commit(List buffers) { @Override public int lineCount() { - return this.trimmings.lineCount(); + return this.operations.lineCount(); } } From 11f109954f9dac067493302e367632ae4e744974 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 28 Jul 2024 10:22:04 +0200 Subject: [PATCH 315/461] ras, clean & spotless --- .../module/hub/section/AccountSection.java | 94 ++++++++++--------- .../hub/section/copy/ExtCodeCopySection.java | 11 ++- .../hub/section/halt/SelfdestructSection.java | 2 +- 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 2a148f2294..13b73dca4b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.opcode.OpCode.*; + import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -27,12 +29,9 @@ import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; -import static net.consensys.linea.zktracer.opcode.OpCode.*; - public class AccountSection extends TraceSection implements PostRollbackDefer { Bytes rawTargetAddress; @@ -43,7 +42,7 @@ public AccountSection(Hub hub) { hub.addTraceSection(this); this.addStack(hub); - short exceptions = hub.pch().exceptions(); + final short exceptions = hub.pch().exceptions(); if (hub.opCode().isAnyOf(OpCode.SELFBALANCE, OpCode.CODESIZE)) { if (Exceptions.any(exceptions)) { @@ -51,68 +50,71 @@ public AccountSection(Hub hub) { return; } - ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); + final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); this.addFragment(currentContext); } final MessageFrame frame = hub.messageFrame(); - targetAddress = switch (hub.opCode()) { - case BALANCE, EXTCODESIZE, EXTCODEHASH -> { - hub.defers().scheduleForPostRollback(this, hub.currentFrame()); - rawTargetAddress = frame.getStackItem(0); - yield Words.toAddress(this.rawTargetAddress); - } - case SELFBALANCE -> frame.getRecipientAddress(); - case CODESIZE -> frame.getContractAddress(); - default -> throw new RuntimeException("Not an ACCOUNT instruction"); - }; - - AccountSnapshot accountSnapshotBefore = AccountSnapshot.canonical(hub, targetAddress); - AccountSnapshot accountSnapshotAfter = accountSnapshotBefore.deepCopy().turnOnWarmth(); + targetAddress = + switch (hub.opCode()) { + case BALANCE, EXTCODESIZE, EXTCODEHASH -> { + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); + rawTargetAddress = frame.getStackItem(0); + yield Words.toAddress(this.rawTargetAddress); + } + case SELFBALANCE -> frame.getRecipientAddress(); + case CODESIZE -> frame.getContractAddress(); + default -> throw new RuntimeException("Not an ACCOUNT instruction"); + }; + + final AccountSnapshot accountSnapshotBefore = AccountSnapshot.canonical(hub, targetAddress); + final AccountSnapshot accountSnapshotAfter = + accountSnapshotBefore.deepCopy().turnOnWarmth(); // TODO: at postExecDefers ? final DomSubStampsSubFragment doingDomSubStamps = - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); - - AccountFragment doingAccountFragment = - switch (hub.opCode()) { - case BALANCE, EXTCODESIZE, EXTCODEHASH -> hub.factories() - .accountFragment() - .makeWithTrm( - accountSnapshotBefore, - accountSnapshotAfter, - rawTargetAddress, - doingDomSubStamps); - case SELFBALANCE, CODESIZE -> hub.factories() - .accountFragment() - .make(accountSnapshotBefore, accountSnapshotAfter, doingDomSubStamps); - default -> throw new IllegalStateException("Not an ACCOUNT instruction"); - }; + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); + + final AccountFragment doingAccountFragment = + switch (hub.opCode()) { + case BALANCE, EXTCODESIZE, EXTCODEHASH -> hub.factories() + .accountFragment() + .makeWithTrm( + accountSnapshotBefore, accountSnapshotAfter, rawTargetAddress, doingDomSubStamps); + case SELFBALANCE, CODESIZE -> hub.factories() + .accountFragment() + .make(accountSnapshotBefore, accountSnapshotAfter, doingDomSubStamps); + default -> throw new IllegalStateException("Not an ACCOUNT instruction"); + }; this.addFragment(doingAccountFragment); } public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - AccountSnapshot postRollBackAccountSnapshot = AccountSnapshot.canonical(hub, targetAddress); + final AccountSnapshot postRollBackAccountSnapshot = + AccountSnapshot.canonical(hub, targetAddress); final DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), hub.currentFrame().revertStamp(), 0); - AccountSnapshot preRollBackAccountSnapshot = postRollBackAccountSnapshot.deepCopy().turnOnWarmth(); + final AccountSnapshot preRollBackAccountSnapshot = + postRollBackAccountSnapshot.deepCopy().turnOnWarmth(); - { - // sanity check - final int deploymentNumberAtRollback = - hub.transients().conflation().deploymentInfo().number(targetAddress); - final boolean deploymentStatusAtRollback = - hub.transients().conflation().deploymentInfo().isDeploying(targetAddress); - Preconditions.checkArgument(deploymentNumberAtRollback == postRollBackAccountSnapshot.deploymentNumber()); - Preconditions.checkArgument(deploymentStatusAtRollback == postRollBackAccountSnapshot.deploymentStatus()); - } + // sanity check + final int deploymentNumberAtRollback = + hub.transients().conflation().deploymentInfo().number(targetAddress); + final boolean deploymentStatusAtRollback = + hub.transients().conflation().deploymentInfo().isDeploying(targetAddress); + Preconditions.checkArgument( + deploymentNumberAtRollback == postRollBackAccountSnapshot.deploymentNumber()); + Preconditions.checkArgument( + deploymentStatusAtRollback == postRollBackAccountSnapshot.deploymentStatus()); this.addFragment( - hub.factories().accountFragment().make(preRollBackAccountSnapshot, postRollBackAccountSnapshot, undoingDomSubStamps)); + hub.factories() + .accountFragment() + .make(preRollBackAccountSnapshot, postRollBackAccountSnapshot, undoingDomSubStamps)); } private static short maxNumberOfRows(Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 7aac3f7f6f..5373c8aec3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -58,7 +58,7 @@ public ExtCodeCopySection(Hub hub) { incomingDeploymentNumber = hub.transients().conflation().deploymentInfo().number(address); incomingDeploymentStatus = hub.transients().conflation().deploymentInfo().isDeploying(address); incomingWarmth = frame.isAddressWarm(address); - ImcFragment imcFragment = ImcFragment.empty(hub); + final ImcFragment imcFragment = ImcFragment.empty(hub); this.addStack(hub); this.addFragment(imcFragment); @@ -70,7 +70,7 @@ public ExtCodeCopySection(Hub hub) { final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); - short exceptions = hub.pch().exceptions(); + final short exceptions = hub.pch().exceptions(); Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); // The MXPX case @@ -133,10 +133,11 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca AccountSnapshot accountPostRollback = AccountSnapshot.canonical(hub, address); final DomSubStampsSubFragment undoingDomSubStamps = - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), callFrame.revertStamp(), 1); + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), callFrame.revertStamp(), 1); - final AccountFragment undoingAccountFragment = hub.factories() + final AccountFragment undoingAccountFragment = + hub.factories() .accountFragment() .make(accountAfter, accountPostRollback, undoingDomSubStamps); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index c71a99f924..5792fdd75d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -101,7 +101,7 @@ public SelfdestructSection(Hub hub) { } // CON fragment (1) - ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); + final ContextFragment contextFragment = ContextFragment.readCurrentContextData(hub); this.addFragment(contextFragment); // STATICX case From 555a97f6c069a2cbd5f27aa8ef3353bb0735bfbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 12:20:13 +0200 Subject: [PATCH 316/461] rasw --- .../hub/fragment/account/RlpAddrSubFragment.java | 12 ++++++------ .../zktracer/module/hub/section/AccountSection.java | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java index ed0c23728a..5f367772ee 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java @@ -33,11 +33,11 @@ @RequiredArgsConstructor public class RlpAddrSubFragment implements TraceSubFragment { private final short recipe; - private final Address depAddress; + private final Address deploymentAddress; private final Bytes32 salt; private final Bytes32 keccak; - public static RlpAddrSubFragment makeFragment(Hub hub, Address createdAddress) { + public static RlpAddrSubFragment makeFragment(Hub hub, Address deploymentAddress) { final OpCode currentOpCode = hub.opCode(); switch (currentOpCode) { case CREATE2 -> { @@ -45,11 +45,11 @@ public static RlpAddrSubFragment makeFragment(Hub hub, Address createdAddress) { final Bytes initCode = OperationAncillaries.callData(hub.currentFrame().frame()); final Bytes32 hash = Hash.keccak256(initCode); // TODO: could be done better, we compute the HASH two times - return new RlpAddrSubFragment((short) 2, createdAddress, salt, hash); + return new RlpAddrSubFragment((short) 2, deploymentAddress, salt, hash); } case CREATE -> { return new RlpAddrSubFragment( - (short) 1, createdAddress, (Bytes32) Bytes32.EMPTY, (Bytes32) Bytes32.EMPTY); + (short) 1, deploymentAddress, (Bytes32) Bytes32.EMPTY, (Bytes32) Bytes32.EMPTY); } default -> throw new IllegalStateException("Unexpected value: " + currentOpCode); } @@ -60,8 +60,8 @@ public Trace trace(Trace trace) { return trace .pAccountRlpaddrFlag(true) .pAccountRlpaddrRecipe(recipe) - .pAccountRlpaddrDepAddrHi(highPart(depAddress)) - .pAccountRlpaddrDepAddrLo(lowPart(depAddress)) + .pAccountRlpaddrDepAddrHi(highPart(deploymentAddress)) + .pAccountRlpaddrDepAddrLo(lowPart(deploymentAddress)) .pAccountRlpaddrSaltHi(salt.slice(0, LLARGE)) .pAccountRlpaddrSaltLo(salt.slice(LLARGE, LLARGE)) .pAccountRlpaddrKecHi(keccak.slice(0, LLARGE)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 13b73dca4b..74368e8aef 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.hub.section; -import static net.consensys.linea.zktracer.opcode.OpCode.*; - import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -29,9 +27,12 @@ import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; +import static net.consensys.linea.zktracer.opcode.OpCode.*; + public class AccountSection extends TraceSection implements PostRollbackDefer { Bytes rawTargetAddress; From b3fcdc629b1d2b751283a0492575610023e8a575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 12:24:40 +0200 Subject: [PATCH 317/461] ras --- .../linea/zktracer/module/hub/section/AccountSection.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 74368e8aef..13b73dca4b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.opcode.OpCode.*; + import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -27,12 +29,9 @@ import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; -import static net.consensys.linea.zktracer.opcode.OpCode.*; - public class AccountSection extends TraceSection implements PostRollbackDefer { Bytes rawTargetAddress; From 0638fd5adc802f6f9a6a320c02bba710b5b4292d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 16:00:02 +0200 Subject: [PATCH 318/461] fix(oob): OobCall slight redesign + SHA2 processing wip --- .../linea/zktracer/module/exp/Exp.java | 2 +- .../zktracer/module/exp/ExpOperation.java | 6 +- .../linea/zktracer/module/hub/Hub.java | 6 +- .../module/hub/fragment/imc/ImcFragment.java | 8 +- .../hub/fragment/imc/{call => }/MxpCall.java | 2 +- .../hub/fragment/imc/{call => }/StpCall.java | 2 +- .../fragment/imc/{call => }/exp/ExpCall.java | 2 +- .../imc/{call => }/exp/ExplogExpCall.java | 2 +- .../imc/{call => }/exp/ModexpLogExpCall.java | 2 +- .../fragment/imc/{call => }/mmu/MmuCall.java | 12 +- .../imc/{call => }/mmu/opcode/CodeCopy.java | 4 +- .../imc/{call => }/mmu/opcode/Create.java | 4 +- .../imc/{call => }/mmu/opcode/Create2.java | 4 +- .../{call => }/mmu/opcode/ExtCodeCopy.java | 4 +- .../mmu/opcode/ReturnFromDeployment.java | 4 +- .../fragment/imc/{call => }/oob/OobCall.java | 18 +- .../hub/fragment/imc/oob/OobInstruction.java | 49 +++ .../oob/opcodes/CallDataLoadOobCall.java | 19 +- .../{call => }/oob/opcodes/CallOobCall.java | 19 +- .../{call => }/oob/opcodes/CreateOobCall.java | 19 +- .../oob/opcodes/DeploymentOobCall.java | 19 +- .../{call => }/oob/opcodes/JumpOobCall.java | 19 +- .../{call => }/oob/opcodes/JumpiOobCall.java | 19 +- .../oob/opcodes/ReturnDataCopyOobCall.java | 19 +- .../{call => }/oob/opcodes/SstoreOobCall.java | 15 +- .../{call => }/oob/opcodes/XCallOobCall.java | 19 +- .../Blake2fCallDataSizeOobCall.java | 19 +- .../oob/precompiles/Blake2fParamsOobCall.java | 20 +- .../ModexpCallDataSizeOobCall.java | 20 +- .../oob/precompiles/ModexpExtractOobCall.java | 19 +- .../oob/precompiles/ModexpLeadOobCall.java | 19 +- .../oob/precompiles/ModexpPricingOobCall.java | 19 +- .../oob/precompiles/ModexpXbsCase.java | 2 +- .../oob/precompiles/ModexpXbsOobCall.java | 20 +- .../precompiles/PrecompileCommonOobCall.java | 32 +- .../scenario/PrecompileScenarioFragment.java | 14 +- .../precompiles/PrecompileLinesGenerator.java | 382 +++++------------- .../hub/section/CallDataLoadSection.java | 6 +- .../module/hub/section/ExpSection.java | 4 +- .../module/hub/section/JumpSection.java | 4 +- .../module/hub/section/KeccakSection.java | 4 +- .../module/hub/section/LogSection.java | 4 +- .../module/hub/section/SstoreSection.java | 2 +- .../module/hub/section/StackRamSection.java | 4 +- .../module/hub/section/call/CallSection.java | 16 +- .../PrecompileSubsection.java | 12 +- .../precompileSubsection/Sha2SubSection.java | 24 +- .../hub/section/copy/CallDataCopySection.java | 4 +- .../hub/section/copy/CodeCopySection.java | 4 +- .../hub/section/copy/ExtCodeCopySection.java | 4 +- .../section/copy/ReturnDataCopySection.java | 6 +- .../hub/section/create/CreateSection.java | 8 +- .../hub/section/halt/ReturnSection.java | 10 +- .../hub/section/halt/RevertSection.java | 4 +- .../linea/zktracer/module/limits/Keccak.java | 6 +- .../linea/zktracer/module/mmu/Mmu.java | 2 +- .../linea/zktracer/module/mmu/MmuData.java | 2 +- .../module/mmu/values/HubToMmuValues.java | 2 +- .../linea/zktracer/module/mxp/Mxp.java | 2 +- .../zktracer/module/mxp/MxpOperation.java | 2 +- .../linea/zktracer/module/oob/Oob.java | 2 +- .../zktracer/module/oob/OobOperation.java | 38 +- .../shakiradata/ShakiraDataOperation.java | 16 + .../linea/zktracer/module/stp/Stp.java | 2 +- .../zktracer/module/stp/StpOperation.java | 2 +- 65 files changed, 467 insertions(+), 593 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/MxpCall.java (97%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/StpCall.java (98%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/exp/ExpCall.java (92%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/exp/ExplogExpCall.java (95%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/exp/ModexpLogExpCall.java (96%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/mmu/MmuCall.java (98%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/mmu/opcode/CodeCopy.java (93%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/mmu/opcode/Create.java (93%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/mmu/opcode/Create2.java (93%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/mmu/opcode/ExtCodeCopy.java (94%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/mmu/opcode/ReturnFromDeployment.java (93%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/OobCall.java (67%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/CallDataLoadOobCall.java (83%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/CallOobCall.java (84%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/CreateOobCall.java (85%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/DeploymentOobCall.java (82%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/JumpOobCall.java (84%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/JumpiOobCall.java (86%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/ReturnDataCopyOobCall.java (84%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/SstoreOobCall.java (80%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/opcodes/XCallOobCall.java (83%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/Blake2fCallDataSizeOobCall.java (76%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/Blake2fParamsOobCall.java (76%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/ModexpCallDataSizeOobCall.java (75%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/ModexpExtractOobCall.java (76%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/ModexpLeadOobCall.java (76%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/ModexpPricingOobCall.java (77%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/ModexpXbsCase.java (89%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/ModexpXbsOobCall.java (76%) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/{call => }/oob/precompiles/PrecompileCommonOobCall.java (74%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java index eacf71c2c4..e3797a47f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java @@ -24,7 +24,7 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExpCall; import net.consensys.linea.zktracer.module.wcp.Wcp; @Slf4j diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index 553afd3bbe..889b409468 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -39,9 +39,9 @@ import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexpLogExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExplogExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ModexpLogExpCall; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.wcp.Wcp; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 57d9147e55..54de79f8b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -230,10 +230,10 @@ public int lineCount() { @Getter private final Mmu mmu; // precompile-linked modules - private final BlakeModexpData blakeModexpData = new BlakeModexpData(this.wcp); + @Getter private final BlakeModexpData blakeModexpData = new BlakeModexpData(this.wcp); @Getter private final EcData ecData; - private final ModexpEffectiveCall modexpEffectiveCall; - private final ShakiraData shakiraData = new ShakiraData(this.wcp); + @Getter private final ModexpEffectiveCall modexpEffectiveCall; + @Getter private final ShakiraData shakiraData = new ShakiraData(this.wcp); /* * Those modules are not traced, we just compute the number of calls to those * precompile to meet the prover limits diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java index c69cb0c057..f29361b048 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/ImcFragment.java @@ -23,11 +23,9 @@ import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/MxpCall.java similarity index 97% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/MxpCall.java index 7004cbb45d..b9e5390276 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/MxpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/MxpCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call; +package net.consensys.linea.zktracer.module.hub.fragment.imc; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java index 70ec35e2b8..908eb59435 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call; +package net.consensys.linea.zktracer.module.hub.fragment.imc; import java.math.BigInteger; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ExpCall.java similarity index 92% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ExpCall.java index 499e31489a..4e02620657 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ExpCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp; +package net.consensys.linea.zktracer.module.hub.fragment.imc.exp; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExplogExpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ExplogExpCall.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExplogExpCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ExplogExpCall.java index 3e5c3eeee8..d7848b215c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ExplogExpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ExplogExpCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp; +package net.consensys.linea.zktracer.module.hub.fragment.imc.exp; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_EXPLOG; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexpLogExpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexpLogExpCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java index 57afebb62d..b9b2139482 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/exp/ModexpLogExpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp; +package net.consensys.linea.zktracer.module.hub.fragment.imc.exp; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EXP_INST_MODEXPLOG; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java similarity index 98% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 442b10b43b..64ef3c63b6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu; +package net.consensys.linea.zktracer.module.hub.fragment.imc.mmu; import static net.consensys.linea.zktracer.module.Util.slice; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EMPTY_RIPEMD_HI; @@ -73,11 +73,11 @@ import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.CodeCopy; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.Create; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.Create2; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.ExtCodeCopy; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode.ReturnFromDeployment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.CodeCopy; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.Create; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.Create2; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ExtCodeCopy; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ReturnFromDeployment; import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/CodeCopy.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/CodeCopy.java index 601548a924..eb6d108401 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/CodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/CodeCopy.java @@ -13,14 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode; +package net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_ANY_TO_RAM_WITH_PADDING; import java.util.Optional; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.evm.internal.Words; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create.java index cc1f953ca5..c1fb726db4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create.java @@ -13,14 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode; +package net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING; import java.util.Optional; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.module.romlex.RomLexDefer; import net.consensys.linea.zktracer.types.EWord; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create2.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create2.java index f8247b1351..e69214dad3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/Create2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create2.java @@ -13,14 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode; +package net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING; import java.util.Optional; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.module.romlex.RomLexDefer; import net.consensys.linea.zktracer.types.EWord; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java index 3ae402db31..8aed2ae4e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ExtCodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java @@ -13,14 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode; +package net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_ANY_TO_RAM_WITH_PADDING; import java.util.Optional; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ReturnFromDeployment.java similarity index 93% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ReturnFromDeployment.java index 6423d6cb89..126bdea7c4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/mmu/opcode/ReturnFromDeployment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ReturnFromDeployment.java @@ -13,12 +13,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.opcode; +package net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobCall.java similarity index 67% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobCall.java index 16bc237353..fda734a553 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/OobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobCall.java @@ -13,19 +13,25 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob; +import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment; import org.apache.tuweni.bytes.Bytes; /** This interface defines the API required to execute a call to the OOB module. */ -public interface OobCall extends TraceSubFragment { +@RequiredArgsConstructor +public abstract class OobCall implements TraceSubFragment { // TODO: move these constants somewhere else - Bytes ZERO = Bytes.EMPTY; - Bytes ONE = Bytes.of(1); + public Bytes ZERO = Bytes.EMPTY; + public Bytes ONE = Bytes.of(1); - public int oobInstruction(); + final OobInstruction oobInstruction; - public net.consensys.linea.zktracer.module.oob.Trace trace( + public int oobInstructionValue() { + return oobInstruction.getValue(); + } + + public abstract net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java new file mode 100644 index 0000000000..67650e9400 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java @@ -0,0 +1,49 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; + +@Getter +@AllArgsConstructor +public enum OobInstruction { + OOB_INST_BLAKE_CDS(GlobalConstants.OOB_INST_BLAKE_CDS), + OOB_INST_BLAKE_PARAMS(GlobalConstants.OOB_INST_BLAKE_PARAMS), + OOB_INST_CALL(GlobalConstants.OOB_INST_CALL), + OOB_INST_CDL(GlobalConstants.OOB_INST_CDL), + OOB_INST_CREATE(GlobalConstants.OOB_INST_CREATE), + OOB_INST_DEPLOYMENT(GlobalConstants.OOB_INST_DEPLOYMENT), + OOB_INST_ECADD(GlobalConstants.OOB_INST_ECADD), + OOB_INST_ECMUL(GlobalConstants.OOB_INST_ECMUL), + OOB_INST_ECPAIRING(GlobalConstants.OOB_INST_ECPAIRING), + OOB_INST_ECRECOVER(GlobalConstants.OOB_INST_ECRECOVER), + OOB_INST_IDENTITY(GlobalConstants.OOB_INST_IDENTITY), + OOB_INST_JUMP(GlobalConstants.OOB_INST_JUMP), + OOB_INST_JUMPI(GlobalConstants.OOB_INST_JUMPI), + OOB_INST_MODEXP_CDS(GlobalConstants.OOB_INST_MODEXP_CDS), + OOB_INST_MODEXP_EXTRACT(GlobalConstants.OOB_INST_MODEXP_EXTRACT), + OOB_INST_MODEXP_LEAD(GlobalConstants.OOB_INST_MODEXP_LEAD), + OOB_INST_MODEXP_PRICING(GlobalConstants.OOB_INST_MODEXP_PRICING), + OOB_INST_MODEXP_XBS(GlobalConstants.OOB_INST_MODEXP_XBS), + OOB_INST_RDC(GlobalConstants.OOB_INST_RDC), + OOB_INST_RIPEMD(GlobalConstants.OOB_INST_RIPEMD), + OOB_INST_SHA2(GlobalConstants.OOB_INST_SHA2), + OOB_INST_SSTORE(GlobalConstants.OOB_INST_SSTORE), + OOB_INST_XCALL(GlobalConstants.OOB_INST_XCALL); + + private final int value; +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallDataLoadOobCall.java similarity index 83% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallDataLoadOobCall.java index 4ebf87cb98..a54178e248 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallDataLoadOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallDataLoadOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.txndata.Trace.OOB_INST_CDL; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_CDL; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,16 +24,20 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class CallDataLoadOobCall implements OobCall { +public class CallDataLoadOobCall extends OobCall { EWord offset; BigInteger cds; boolean cdlOutOfBounds; + public CallDataLoadOobCall() { + super(OOB_INST_CDL); + } + public BigInteger offsetHi() { return offset.hiBigInt(); } @@ -42,11 +46,6 @@ public BigInteger offsetLo() { return offset.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_CDL; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -65,7 +64,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(offsetHi())) .pMiscOobData2(bigIntegerToBytes(offsetLo())) .pMiscOobData3(ZERO) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java similarity index 84% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java index 10e3647870..7c9f806d19 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CallOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CALL; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_CALL; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,18 +24,22 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class CallOobCall implements OobCall { +public class CallOobCall extends OobCall { EWord value; BigInteger balance; BigInteger callStackDepth; boolean valueIsNonzero; boolean abortingCondition; + public CallOobCall() { + super(OOB_INST_CALL); + } + public BigInteger valueHi() { return value.hiBigInt(); } @@ -44,11 +48,6 @@ public BigInteger valueLo() { return value.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_CALL; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -67,7 +66,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(valueHi())) .pMiscOobData2(bigIntegerToBytes(valueLo())) .pMiscOobData3(bigIntegerToBytes(balance)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java similarity index 85% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java index 3391b1122c..050b15a837 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/CreateOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_CREATE; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,12 +24,12 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class CreateOobCall implements OobCall { +public class CreateOobCall extends OobCall { EWord value; BigInteger balance; BigInteger nonce; @@ -38,6 +38,10 @@ public class CreateOobCall implements OobCall { boolean abortingCondition; boolean failureCondition; + public CreateOobCall() { + super(OOB_INST_CREATE); + } + public BigInteger valueHi() { return value.hiBigInt(); } @@ -46,11 +50,6 @@ public BigInteger valueLo() { return value.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_CREATE; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -69,7 +68,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(valueHi())) .pMiscOobData2(bigIntegerToBytes(valueLo())) .pMiscOobData3(bigIntegerToBytes(balance)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/DeploymentOobCall.java similarity index 82% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/DeploymentOobCall.java index b1cfc6fce6..9f6de6da91 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/DeploymentOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/DeploymentOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_DEPLOYMENT; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_DEPLOYMENT; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,15 +24,19 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class DeploymentOobCall implements OobCall { +public class DeploymentOobCall extends OobCall { EWord size; boolean maxCodeSizeException; + public DeploymentOobCall() { + super(OOB_INST_DEPLOYMENT); + } + public BigInteger sizeHi() { return size.hiBigInt(); } @@ -41,11 +45,6 @@ public BigInteger sizeLo() { return size.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_DEPLOYMENT; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -64,7 +63,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(sizeHi())) .pMiscOobData2(bigIntegerToBytes(sizeLo())) .pMiscOobData3(ZERO) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpOobCall.java similarity index 84% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpOobCall.java index 89d704e425..7c97833483 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMP; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,17 +24,21 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class JumpOobCall implements OobCall { +public class JumpOobCall extends OobCall { EWord pcNew; BigInteger codeSize; boolean jumpGuaranteedException; boolean jumpMustBeAttempted; + public JumpOobCall() { + super(OOB_INST_JUMP); + } + public BigInteger pcNewHi() { return pcNew.hiBigInt(); } @@ -43,11 +47,6 @@ public BigInteger pcNewLo() { return pcNew.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_JUMP; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -66,7 +65,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(pcNewHi())) .pMiscOobData2(bigIntegerToBytes(pcNewLo())) .pMiscOobData3(ZERO) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpiOobCall.java similarity index 86% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpiOobCall.java index 3408d95829..8f8f576dc7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/JumpiOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpiOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMPI; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_JUMPI; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,12 +24,12 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class JumpiOobCall implements OobCall { +public class JumpiOobCall extends OobCall { EWord pcNew; EWord jumpCondition; BigInteger codeSize; @@ -37,6 +37,10 @@ public class JumpiOobCall implements OobCall { boolean jumpGuanranteedException; boolean jumpMustBeAttempted; + public JumpiOobCall() { + super(OOB_INST_JUMPI); + } + public BigInteger pcNewHi() { return pcNew.hiBigInt(); } @@ -53,16 +57,11 @@ public BigInteger jumpConditionLo() { return jumpCondition.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_JUMPI; - } - @Override public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(pcNewHi())) .pMiscOobData2(bigIntegerToBytes(pcNewLo())) .pMiscOobData3(bigIntegerToBytes(jumpConditionHi())) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/ReturnDataCopyOobCall.java similarity index 84% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/ReturnDataCopyOobCall.java index baf314ed1b..94a080d16e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/ReturnDataCopyOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/ReturnDataCopyOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RDC; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,17 +24,21 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class ReturnDataCopyOobCall implements OobCall { +public class ReturnDataCopyOobCall extends OobCall { EWord offset; EWord size; BigInteger rds; boolean rdcx; + public ReturnDataCopyOobCall() { + super(OOB_INST_RDC); + } + public BigInteger offsetHi() { return offset.hiBigInt(); } @@ -51,11 +55,6 @@ public BigInteger sizeLo() { return size.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_RDC; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -74,7 +73,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(offsetHi())) .pMiscOobData2(bigIntegerToBytes(offsetLo())) .pMiscOobData3(bigIntegerToBytes(sizeHi())) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/SstoreOobCall.java similarity index 80% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/SstoreOobCall.java index 9f60f435d0..6f4ae05bc9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/SstoreOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/SstoreOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SSTORE; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,17 +24,16 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; @Getter @Setter -public class SstoreOobCall implements OobCall { +public class SstoreOobCall extends OobCall { BigInteger gas; boolean sstorex; - @Override - public int oobInstruction() { - return OOB_INST_SSTORE; + public SstoreOobCall() { + super(OOB_INST_SSTORE); } @Override @@ -55,7 +54,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(ZERO) .pMiscOobData2(ZERO) .pMiscOobData3(ZERO) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/XCallOobCall.java similarity index 83% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/XCallOobCall.java index b0cd852e29..af9d72b0cc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/opcodes/XCallOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/XCallOobCall.java @@ -13,9 +13,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_XCALL; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; @@ -24,16 +24,20 @@ import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.types.EWord; @Getter @Setter -public class XCallOobCall implements OobCall { +public class XCallOobCall extends OobCall { EWord value; boolean valueIsNonzero; boolean valueIsZero; + public XCallOobCall() { + super(OOB_INST_XCALL); + } + public BigInteger valueHi() { return value.hiBigInt(); } @@ -42,11 +46,6 @@ public BigInteger valueLo() { return value.loBigInt(); } - @Override - public int oobInstruction() { - return OOB_INST_XCALL; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -65,7 +64,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(valueHi())) .pMiscOobData2(bigIntegerToBytes(valueLo())) .pMiscOobData3(ZERO) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fCallDataSizeOobCall.java similarity index 76% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fCallDataSizeOobCall.java index d64cd1e608..56248df98a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -13,34 +13,29 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_BLAKE_CDS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; @Getter @Setter -@RequiredArgsConstructor -public class Blake2fCallDataSizeOobCall implements OobCall { - final PrecompileInvocation p; +public class Blake2fCallDataSizeOobCall extends OobCall { BigInteger cds; BigInteger returnAtCapacity; boolean hubSuccess; boolean returnAtCapacityNonZero; - @Override - public int oobInstruction() { - return OOB_INST_BLAKE_CDS; + public Blake2fCallDataSizeOobCall() { + super(OOB_INST_BLAKE_CDS); } @Override @@ -61,7 +56,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(ZERO) .pMiscOobData2(bigIntegerToBytes(cds)) .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fParamsOobCall.java similarity index 76% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fParamsOobCall.java index 3536dd1e38..011a5631f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/Blake2fParamsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fParamsOobCall.java @@ -13,27 +13,22 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_BLAKE_PARAMS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; @Getter @Setter -@RequiredArgsConstructor -public class Blake2fParamsOobCall implements OobCall { - - final PrecompileInvocation p; +public class Blake2fParamsOobCall extends OobCall { BigInteger callGas; BigInteger blakeR; @@ -42,9 +37,8 @@ public class Blake2fParamsOobCall implements OobCall { boolean ramSuccess; BigInteger returnGas; - @Override - public int oobInstruction() { - return OOB_INST_BLAKE_PARAMS; + public Blake2fParamsOobCall() { + super(OOB_INST_BLAKE_PARAMS); } @Override @@ -65,7 +59,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(callGas)) .pMiscOobData2(ZERO) .pMiscOobData3(ZERO) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpCallDataSizeOobCall.java similarity index 75% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpCallDataSizeOobCall.java index 97c3a3bcff..5f4c90f0f7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpCallDataSizeOobCall.java @@ -13,36 +13,30 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_CDS; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; @Getter @Setter -@RequiredArgsConstructor -public class ModexpCallDataSizeOobCall implements OobCall { +public class ModexpCallDataSizeOobCall extends OobCall { - final PrecompileInvocation p; BigInteger cds; - boolean extractBbs; boolean extractEbs; boolean extractMbs; - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_CDS; + public ModexpCallDataSizeOobCall() { + super(OOB_INST_MODEXP_CDS); } @Override @@ -63,7 +57,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(ZERO) .pMiscOobData2(bigIntegerToBytes(cds)) .pMiscOobData3(booleanToBytes(extractBbs)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpExtractOobCall.java similarity index 76% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpExtractOobCall.java index 157d132857..5190344670 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpExtractOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpExtractOobCall.java @@ -13,27 +13,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_EXTRACT; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; @Getter @Setter -@RequiredArgsConstructor -public class ModexpExtractOobCall implements OobCall { +public class ModexpExtractOobCall extends OobCall { - final PrecompileInvocation p; BigInteger cds; BigInteger bbs; BigInteger ebs; @@ -43,9 +39,8 @@ public class ModexpExtractOobCall implements OobCall { boolean extractExponent; boolean extractModulus; - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_EXTRACT; + public ModexpExtractOobCall() { + super(OOB_INST_MODEXP_EXTRACT); } @Override @@ -66,7 +61,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(ZERO) .pMiscOobData2(bigIntegerToBytes(cds)) .pMiscOobData3(bigIntegerToBytes(bbs)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpLeadOobCall.java similarity index 76% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpLeadOobCall.java index c5edb7a71d..9d50e5eb49 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpLeadOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpLeadOobCall.java @@ -13,28 +13,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_LEAD; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import org.apache.tuweni.bytes.Bytes; @Getter @Setter -@RequiredArgsConstructor -public class ModexpLeadOobCall implements OobCall { +public class ModexpLeadOobCall extends OobCall { - final PrecompileInvocation p; BigInteger bbs; BigInteger cds; BigInteger ebs; @@ -44,9 +40,8 @@ public class ModexpLeadOobCall implements OobCall { int ebsCutoff; int subEbs32; - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_LEAD; + public ModexpLeadOobCall() { + super(OOB_INST_MODEXP_LEAD); } @Override @@ -67,7 +62,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(bbs)) .pMiscOobData2(bigIntegerToBytes(cds)) .pMiscOobData3(bigIntegerToBytes(ebs)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpPricingOobCall.java similarity index 77% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpPricingOobCall.java index 87c71412e1..7ace069354 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpPricingOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpPricingOobCall.java @@ -13,28 +13,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import org.apache.tuweni.bytes.Bytes; @Getter @Setter -@RequiredArgsConstructor -public class ModexpPricingOobCall implements OobCall { +public class ModexpPricingOobCall extends OobCall { - final PrecompileInvocation p; BigInteger callGas; BigInteger returnAtCapacity; boolean ramSuccess; @@ -44,9 +40,8 @@ public class ModexpPricingOobCall implements OobCall { BigInteger returnGas; boolean returnAtCapacityNonZero; - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_PRICING; + public ModexpPricingOobCall() { + super(OOB_INST_MODEXP_PRICING); } @Override @@ -67,7 +62,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(callGas)) .pMiscOobData2(ZERO) .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsCase.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsCase.java similarity index 89% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsCase.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsCase.java index df7519ea6b..d93e84bbcc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsCase.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsCase.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; public enum ModexpXbsCase { OOB_INST_MODEXP_BBS, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsOobCall.java similarity index 76% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsOobCall.java index 1b98b905f1..8fcc1c3357 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/ModexpXbsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsOobCall.java @@ -13,27 +13,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; @Getter @Setter -@RequiredArgsConstructor -public class ModexpXbsOobCall implements OobCall { +public class ModexpXbsOobCall extends OobCall { - final PrecompileInvocation p; final ModexpXbsCase modexpXbsCase; BigInteger xbsHi; BigInteger xbsLo; @@ -43,9 +39,9 @@ public class ModexpXbsOobCall implements OobCall { BigInteger maxXbsYbs; boolean xbsNonZero; - @Override - public int oobInstruction() { - return OOB_INST_MODEXP_XBS; + public ModexpXbsOobCall(ModexpXbsCase modexpXbsCase) { + super(OOB_INST_MODEXP_XBS); + this.modexpXbsCase = modexpXbsCase; } @Override @@ -66,7 +62,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(xbsHi)) .pMiscOobData2(bigIntegerToBytes(xbsLo)) .pMiscOobData3(bigIntegerToBytes(ybsLo)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java similarity index 74% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java index ffc946211d..d93980c643 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/call/oob/precompiles/PrecompileCommonOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java @@ -13,27 +13,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles; +package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes; import java.math.BigInteger; import lombok.Getter; -import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction; @Getter @Setter -@RequiredArgsConstructor -public class PrecompileCommonOobCall implements OobCall { +public class PrecompileCommonOobCall extends OobCall { - final PrecompileInvocation p; BigInteger callGas; BigInteger cds; BigInteger returnAtCapacity; @@ -42,6 +38,10 @@ public class PrecompileCommonOobCall implements OobCall { boolean returnAtCapacityNonZero; boolean cdsIsZero; // Necessary to compute extractCallData and emptyCallData + public PrecompileCommonOobCall(OobInstruction oobInstruction) { + super(oobInstruction); + } + public boolean getExtractCallData() { return hubSuccess && !cdsIsZero; } @@ -50,20 +50,6 @@ public boolean getCallDataIsEmpty() { return hubSuccess && cdsIsZero; } - @Override - public int oobInstruction() { - return switch (p.precompile().address.trimLeadingZeros().toInt()) { - case 1 -> OOB_INST_ECRECOVER; - case 2 -> OOB_INST_SHA2; - case 3 -> OOB_INST_RIPEMD; - case 4 -> OOB_INST_IDENTITY; - case 6 -> OOB_INST_ECADD; - case 7 -> OOB_INST_ECMUL; - case 8 -> OOB_INST_ECPAIRING; - default -> throw new RuntimeException("precompile not 'common'"); - }; - } - @Override public net.consensys.linea.zktracer.module.oob.Trace trace( net.consensys.linea.zktracer.module.oob.Trace trace) { @@ -82,7 +68,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( public Trace trace(Trace trace) { return trace .pMiscOobFlag(true) - .pMiscOobInst(oobInstruction()) + .pMiscOobInst(oobInstructionValue()) .pMiscOobData1(bigIntegerToBytes(callGas)) .pMiscOobData2(bigIntegerToBytes(cds)) .pMiscOobData3(bigIntegerToBytes(returnAtCapacity)) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 88cb43390a..fbcdcc5dd9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -82,12 +82,12 @@ public Trace trace(Trace trace) { .pScenarioPrcSuccessCallerWontRevert(scenario == PrecompileScenario.PRC_SUCCESS_WONT_REVERT) .pScenarioPrcFailureKnownToHub(scenario == PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB) .pScenarioPrcFailureKnownToRam(scenario == PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM) - .pScenarioPrcCallerGas(precompileSubSection.getCallerGas()) - .pScenarioPrcCalleeGas(precompileSubSection.getCalleeGas()) - .pScenarioPrcReturnGas(precompileSubSection.getReturnGas()) - .pScenarioPrcCdo(precompileSubSection.getCallDataMemorySpan().offset()) - .pScenarioPrcCds(precompileSubSection.getCallDataMemorySpan().length()) - .pScenarioPrcRao(precompileSubSection.getParentReturnDataTarget().offset()) - .pScenarioPrcRac(precompileSubSection.getParentReturnDataTarget().length()); + .pScenarioPrcCallerGas(precompileSubSection.callerGas()) + .pScenarioPrcCalleeGas(precompileSubSection.calleeGas()) + .pScenarioPrcReturnGas(precompileSubSection.returnGas()) + .pScenarioPrcCdo(precompileSubSection.callDataMemorySpan().offset()) + .pScenarioPrcCds(precompileSubSection.callDataMemorySpan().length()) + .pScenarioPrcRao(precompileSubSection.parentReturnDataTarget().offset()) + .pScenarioPrcRac(precompileSubSection.parentReturnDataTarget().length()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java index 93bef1c1c7..e6d26cb7fb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java @@ -15,286 +15,116 @@ package net.consensys.linea.zktracer.module.hub.precompiles; -import java.util.ArrayList; -import java.util.List; - import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ModexpLogExpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCallDataSizeOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtractOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLeadOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricingOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsCase; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobCall; // TODO: remove this class ... total annihilation :) @RequiredArgsConstructor public class PrecompileLinesGenerator { - public static List generateFor(final Hub hub, final PrecompileInvocation p) { - final List r = new ArrayList<>(10); - switch (p.precompile()) { - case EC_RECOVER -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - } else { - final boolean recoverySuccessful = - ((EcRecoverMetadata) p.metadata()).recoverySuccessful(); - - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu( - p.callDataSource().isEmpty() - ? MmuCall.nop() - : MmuCall.forEcRecover(hub, p, recoverySuccessful, 0))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() - ? MmuCall.nop() - : MmuCall.forEcRecover(hub, p, recoverySuccessful, 1))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() - ? MmuCall.nop() - : MmuCall.forEcRecover(hub, p, recoverySuccessful, 2))); - } - } - case SHA2_256 -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu( - p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forSha2(hub, p, 0))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forSha2(hub, p, 1))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forSha2(hub, p, 2))); - } - } - case RIPEMD_160 -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu( - p.callDataSource().isEmpty() - ? MmuCall.nop() - : MmuCall.forRipeMd160(hub, p, 0))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() - ? MmuCall.nop() - : MmuCall.forRipeMd160(hub, p, 1))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() - ? MmuCall.nop() - : MmuCall.forRipeMd160(hub, p, 2))); - } - } - case IDENTITY -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu(MmuCall.forIdentity(hub, p, 0))); - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forIdentity(hub, p, 1))); - } - } - case MODEXP -> { - final ModExpMetadata m = (ModExpMetadata) p.metadata(); - final int bbsInt = m.bbs().toUnsignedBigInteger().intValueExact(); - final int ebsInt = m.ebs().toUnsignedBigInteger().intValueExact(); - final int mbsInt = m.mbs().toUnsignedBigInteger().intValueExact(); - - r.add(ImcFragment.empty(hub).callOob(new ModexpCallDataSizeOobCall(p))); - r.add( - ImcFragment.empty(hub) - .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_BBS)) - .callMmu(m.extractBbs() ? MmuCall.forModExp(hub, p, 2) : MmuCall.nop())); - r.add( - ImcFragment.empty(hub) - .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_EBS)) - .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 3) : MmuCall.nop())); - r.add( - ImcFragment.empty(hub) - .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_MBS)) - .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 4) : MmuCall.nop())); - final ImcFragment line5 = - ImcFragment.empty(hub) - .callOob(new ModexpLeadOobCall(p)) - .callMmu(m.loadRawLeadingWord() ? MmuCall.forModExp(hub, p, 5) : MmuCall.nop()); - if (m.loadRawLeadingWord()) { - line5.callExp(new ModexpLogExpCall(p)); - } - r.add(line5); - r.add(ImcFragment.empty(hub).callOob(new ModexpPricingOobCall(p))); - if (p.ramFailure()) { - r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new ModexpExtractOobCall(p)) - .callMmu(m.extractModulus() ? MmuCall.forModExp(hub, p, 7) : MmuCall.nop())); - - if (m.extractModulus()) { - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 8))); - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 9))); - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 10))); - } else { - for (int i = 0; i < 4; i++) { - r.add(ImcFragment.empty(hub)); - } - } - - if (!m.mbs().isZero() && !p.requestedReturnDataTarget().isEmpty()) { - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 11))); - } - - r.add( - ContextFragment.executionProvidesReturnData( - hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); - } - } - case EC_ADD -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } else if (p.ramFailure()) { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu(MmuCall.forEcAdd(hub, p, 0))); - r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu(MmuCall.forEcAdd(hub, p, 0))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forEcAdd(hub, p, 1))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.requestedReturnDataTarget().isEmpty() - ? MmuCall.nop() - : MmuCall.forEcAdd(hub, p, 2))); - r.add( - ContextFragment.executionProvidesReturnData( - hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); - } - } - case EC_MUL -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } else if (p.ramFailure()) { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu(MmuCall.forEcMul(hub, p, 0))); - r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu(MmuCall.forEcMul(hub, p, 0))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forEcMul(hub, p, 1))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.requestedReturnDataTarget().isEmpty() - ? MmuCall.nop() - : MmuCall.forEcMul(hub, p, 2))); - r.add( - ContextFragment.executionProvidesReturnData( - hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); - } - } - case EC_PAIRING -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } else if (p.ramFailure()) { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu(MmuCall.forEcPairing(hub, p, 0))); - r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new PrecompileCommonOobCall(p)) - .callMmu(MmuCall.forEcPairing(hub, p, 0))); - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forEcPairing(hub, p, 1))); - r.add( - ImcFragment.empty(hub) - .callMmu( - p.requestedReturnDataTarget().isEmpty() - ? MmuCall.nop() - : MmuCall.forEcPairing(hub, p, 2))); - r.add( - ContextFragment.executionProvidesReturnData( - hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber())); - } - } - case BLAKE2F -> { - if (p.hubFailure()) { - r.add(ImcFragment.empty(hub).callOob(new Blake2fCallDataSizeOobCall(p))); - } else if (p.ramFailure()) { - r.add( - ImcFragment.empty(hub) - .callOob(new Blake2fCallDataSizeOobCall(p)) - .callMmu(MmuCall.forBlake2f(hub, p, 0))); - r.add(ImcFragment.empty(hub).callOob(new Blake2fParamsOobCall(p))); - } else { - r.add( - ImcFragment.empty(hub) - .callOob(new Blake2fCallDataSizeOobCall(p)) - .callMmu(MmuCall.forBlake2f(hub, p, 0))); - r.add( - ImcFragment.empty(hub) - .callOob(new Blake2fParamsOobCall(p)) - .callMmu(MmuCall.forBlake2f(hub, p, 1))); - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 2))); - r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 3))); - } - } - } - r.add( - p.success() - ? ContextFragment.executionProvidesReturnData( - hub, hub.currentFrame().contextNumber(), hub.newChildContextNumber()) - : ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); - return r; - } + /** + * public static List generateFor(final Hub hub, final PrecompileInvocation p) { + * final List r = new ArrayList<>(10); switch (p.precompile()) { case EC_RECOVER -> + * { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); + * } else { final boolean recoverySuccessful = ((EcRecoverMetadata) + * p.metadata()).recoverySuccessful(); + * + *

r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu( + * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forEcRecover(hub, p, recoverySuccessful, + * 0))); r.add( ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : + * MmuCall.forEcRecover(hub, p, recoverySuccessful, 1))); r.add( ImcFragment.empty(hub) .callMmu( + * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forEcRecover(hub, p, recoverySuccessful, + * 2))); } } case SHA2_256 -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new + * PrecompileCommonOobCall(p))); } else { r.add( ImcFragment.empty(hub) .callOob(new + * PrecompileCommonOobCall(p)) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : + * MmuCall.forSha2(hub, p, 0))); r.add( ImcFragment.empty(hub) .callMmu( + * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forSha2(hub, p, 1))); r.add( + * ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : + * MmuCall.forSha2(hub, p, 2))); } } case RIPEMD_160 -> { if (p.hubFailure()) { + * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); } else { r.add( + * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu( + * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forRipeMd160(hub, p, 0))); r.add( + * ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : + * MmuCall.forRipeMd160(hub, p, 1))); r.add( ImcFragment.empty(hub) .callMmu( + * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forRipeMd160(hub, p, 2))); } } case + * IDENTITY -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new + * PrecompileCommonOobCall(p))); } else { r.add( ImcFragment.empty(hub) .callOob(new + * PrecompileCommonOobCall(p)) .callMmu(MmuCall.forIdentity(hub, p, 0))); + * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forIdentity(hub, p, 1))); } } case MODEXP -> { + * final ModExpMetadata m = (ModExpMetadata) p.metadata(); final int bbsInt = + * m.bbs().toUnsignedBigInteger().intValueExact(); final int ebsInt = + * m.ebs().toUnsignedBigInteger().intValueExact(); final int mbsInt = + * m.mbs().toUnsignedBigInteger().intValueExact(); + * + *

r.add(ImcFragment.empty(hub).callOob(new ModexpCallDataSizeOobCall(p))); r.add( + * ImcFragment.empty(hub) .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_BBS)) + * .callMmu(m.extractBbs() ? MmuCall.forModExp(hub, p, 2) : MmuCall.nop())); r.add( + * ImcFragment.empty(hub) .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_EBS)) + * .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 3) : MmuCall.nop())); r.add( + * ImcFragment.empty(hub) .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_MBS)) + * .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 4) : MmuCall.nop())); final ImcFragment + * line5 = ImcFragment.empty(hub) .callOob(new ModexpLeadOobCall(p)) + * .callMmu(m.loadRawLeadingWord() ? MmuCall.forModExp(hub, p, 5) : MmuCall.nop()); if + * (m.loadRawLeadingWord()) { line5.callExp(new ModexpLogExpCall(p)); } r.add(line5); + * r.add(ImcFragment.empty(hub).callOob(new ModexpPricingOobCall(p))); if (p.ramFailure()) { + * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( + * ImcFragment.empty(hub) .callOob(new ModexpExtractOobCall(p)) .callMmu(m.extractModulus() ? + * MmuCall.forModExp(hub, p, 7) : MmuCall.nop())); + * + *

if (m.extractModulus()) { r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, + * 8))); r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 9))); + * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 10))); } else { for (int i = 0; + * i < 4; i++) { r.add(ImcFragment.empty(hub)); } } + * + *

if (!m.mbs().isZero() && !p.requestedReturnDataTarget().isEmpty()) { + * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 11))); } + * + *

r.add( ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), + * hub.newChildContextNumber())); } } case EC_ADD -> { if (p.hubFailure()) { + * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); + * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { + * r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) + * .callMmu(MmuCall.forEcAdd(hub, p, 0))); + * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( + * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcAdd(hub, + * p, 0))); r.add( ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : + * MmuCall.forEcAdd(hub, p, 1))); r.add( ImcFragment.empty(hub) .callMmu( + * p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcAdd(hub, p, 2))); r.add( + * ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), + * hub.newChildContextNumber())); } } case EC_MUL -> { if (p.hubFailure()) { + * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); + * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { + * r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) + * .callMmu(MmuCall.forEcMul(hub, p, 0))); + * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( + * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcMul(hub, + * p, 0))); r.add( ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : + * MmuCall.forEcMul(hub, p, 1))); r.add( ImcFragment.empty(hub) .callMmu( + * p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcMul(hub, p, 2))); r.add( + * ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), + * hub.newChildContextNumber())); } } case EC_PAIRING -> { if (p.hubFailure()) { + * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); + * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { + * r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) + * .callMmu(MmuCall.forEcPairing(hub, p, 0))); + * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( + * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) + * .callMmu(MmuCall.forEcPairing(hub, p, 0))); + * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forEcPairing(hub, p, 1))); r.add( + * ImcFragment.empty(hub) .callMmu( p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : + * MmuCall.forEcPairing(hub, p, 2))); r.add( ContextFragment.executionProvidesReturnData( hub, + * hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case BLAKE2F -> { if + * (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new Blake2fCallDataSizeOobCall(p))); } + * else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) .callOob(new + * Blake2fCallDataSizeOobCall(p)) .callMmu(MmuCall.forBlake2f(hub, p, 0))); + * r.add(ImcFragment.empty(hub).callOob(new Blake2fParamsOobCall(p))); } else { r.add( + * ImcFragment.empty(hub) .callOob(new Blake2fCallDataSizeOobCall(p)) + * .callMmu(MmuCall.forBlake2f(hub, p, 0))); r.add( ImcFragment.empty(hub) .callOob(new + * Blake2fParamsOobCall(p)) .callMmu(MmuCall.forBlake2f(hub, p, 1))); + * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 2))); + * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 3))); } } } + * + *

r.add( p.success() ? ContextFragment.executionProvidesReturnData( hub, + * hub.currentFrame().contextNumber(), hub.newChildContextNumber()) : + * ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); return r; } + */ } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index e8cf08d374..b921bcb7f2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -25,9 +25,9 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CallDataLoadOobCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java index 0baaa4a38f..deeb6cef19 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java @@ -17,8 +17,8 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.exp.ExplogExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExplogExpCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; public class ExpSection extends TraceSection { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index e1369ee839..b08217f89e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -24,8 +24,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.JumpOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.JumpiOobCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.opcode.OpCode; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index b73bdfd43e..c1692c85b3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -18,8 +18,8 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java index 582f75f6fa..f3eb560efd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/LogSection.java @@ -20,8 +20,8 @@ import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.LogData; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index ea10e411cf..ef5a0e43ae 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -23,7 +23,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.SstoreOobCall; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index fd176d32f0..a416c1a44d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -26,8 +26,8 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index c44aa484e3..db13021034 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -37,10 +37,10 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; @@ -397,6 +397,12 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca case CALL_SMC_SUCCESS_WONT_REVERT, CALL_PRC_SUCCESS_WONT_REVERT -> completeSmcSuccessWillRevertOrPrcSuccessWillRevert( factory); + case CALL_PRC_FAILURE -> { + // Note: no undoing required + // - account snapshots were taken with value transfers undone + // - precompiles are warm by definition so no warmth undoing required + return; + } default -> throw new IllegalArgumentException("Illegal CALL scenario"); } } @@ -410,7 +416,7 @@ public void resolvePostTransaction( Preconditions.checkArgument(scenario.noLongerUndefined()); if (scenario.isPrecompileScenario()) { - this.addFragments(precompileSubsection.getFragments()); + this.addFragments(precompileSubsection.fragments()); } this.addFragment(finalContextFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 8985cd1e0d..cd6ba8187f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -25,6 +25,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; +import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; @@ -43,8 +44,12 @@ /** Note: {@link PrecompileSubsection}'s are created at child context entry by the call section */ @RequiredArgsConstructor @Getter +@Accessors(fluent = true) public class PrecompileSubsection implements ContextExitDefer, ContextReEntryDefer, PostRollbackDefer, PostTransactionDefer { + + public final CallSection callSection; + /** List of fragments of the precompile specific subsection */ private final List fragments; @@ -81,17 +86,20 @@ public class PrecompileSubsection * contain. */ public PrecompileSubsection(final Hub hub, final CallSection callSection) { + this.callSection = callSection; fragments = new ArrayList<>(maxNumberOfLines()); callDataMemorySpan = hub.currentFrame().callDataInfo().memorySpan(); callData = hub.messageFrame().getInputData(); parentReturnDataTarget = hub.currentFrame().parentReturnDataTarget(); callerGas = hub.callStack().parent().frame().getRemainingGas(); calleeGas = hub.messageFrame().getRemainingGas(); - precompileScenarioFragment = - new PrecompileScenarioFragment(this, PRC_UNDEFINED_SCENARIO, PRC_UNDEFINED); final MessageFrame callerFrame = hub.callStack().parent().frame(); callerMemorySnapshot = extractContiguousLimbsFromMemory(callerFrame, callDataMemorySpan); + + precompileScenarioFragment = + new PrecompileScenarioFragment(this, PRC_UNDEFINED_SCENARIO, PRC_UNDEFINED); + fragments.add(precompileScenarioFragment); } protected short maxNumberOfLines() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java index e692d2e1d8..97a2d5ea16 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java @@ -15,10 +15,16 @@ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_SHA2; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; +import static net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType.SHA256; +import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -27,6 +33,7 @@ public class Sha2SubSection extends PrecompileSubsection { public Sha2SubSection(Hub hub, CallSection callSection) { super(hub, callSection); precompileScenarioFragment.setFlag(PRC_SHA2_256); + PrecompileCommonOobCall oobCall = new PrecompileCommonOobCall(OOB_INST_SHA2); } // 4 = 1 + 3 (scenario row + up to 3 miscellaneous fragments) @@ -41,8 +48,21 @@ public void resolveUponExitingContext(Hub hub, CallFrame frame) { } @Override - public void resolveAtContextReEntry(Hub hub, CallFrame frame) { - super.resolveAtContextReEntry(hub, frame); + public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { + super.resolveAtContextReEntry(hub, callFrame); + final boolean successBit = bytesToBoolean(callFrame.frame().getStackItem(0)); + if (successBit) { + // may get updated later + precompileScenarioFragment.setScenario( + PrecompileScenarioFragment.PrecompileScenario.PRC_SUCCESS_WONT_REVERT); + ShakiraDataOperation shakiraCall = + new ShakiraDataOperation( + this.callSection.hubStamp(), SHA256, callData, callFrame.frame().getReturnData()); + hub.shakiraData().call(shakiraCall); + } else { + precompileScenarioFragment.setScenario( + PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB); + } } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index 24c9fb18cc..e279431934 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -21,8 +21,8 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index d1ea6924f6..a498038cb4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -22,8 +22,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import org.hyperledger.besu.datatypes.Address; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 5373c8aec3..bdca9c4a3a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -24,8 +24,8 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 73f14b1abf..77201f8777 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -21,9 +21,9 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.ReturnDataCopyOobCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 2d8ba051d8..069789a281 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -31,10 +31,10 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CreateOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 7cae394a7c..dd331746f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -29,11 +29,11 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.DeploymentOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.ReturnScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index 46fe2e5e15..ec96d07bdd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -18,8 +18,8 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java index 1d2196d8c0..d17f39dd44 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.limits; +import static net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType.KECCAK; + import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; @@ -31,7 +33,6 @@ import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall; import net.consensys.linea.zktracer.module.shakiradata.ShakiraData; import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -118,8 +119,7 @@ private void callShakira( final long codeOffset = Words.clampedToLong(frame.getStackItem(codeOffsetStackItemOffset)); final Bytes byteCode = frame.shadowReadMemory(codeOffset, codeSize); - this.shakiraData.call( - new ShakiraDataOperation(hub.stamp(), ShakiraPrecompileType.KECCAK, byteCode)); + this.shakiraData.call(new ShakiraDataOperation(hub.stamp(), KECCAK, byteCode)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java index adb0221271..8a2e7c5294 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java @@ -26,7 +26,7 @@ import net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpData; import net.consensys.linea.zktracer.module.ecdata.EcData; import net.consensys.linea.zktracer.module.euc.Euc; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.mmu.values.HubToMmuValues; import net.consensys.linea.zktracer.module.rlptxn.RlpTxn; import net.consensys.linea.zktracer.module.rlptxrcpt.RlpTxnRcpt; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java index f125a6ba1d..4325ce8e3b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java @@ -27,7 +27,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.constants.GlobalConstants; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.mmio.CallStackReader; import net.consensys.linea.zktracer.module.mmu.values.HubToMmuValues; import net.consensys.linea.zktracer.module.mmu.values.MmuEucCallRecord; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/values/HubToMmuValues.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/values/HubToMmuValues.java index c26a31a1df..dcc1f6ea81 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/values/HubToMmuValues.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/values/HubToMmuValues.java @@ -20,7 +20,7 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.types.Bytes16; @Getter diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java index e8e49a7f41..e58a8c98cb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/Mxp.java @@ -22,7 +22,7 @@ import net.consensys.linea.zktracer.container.stacked.list.StackedList; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; import org.hyperledger.besu.evm.frame.MessageFrame; /** Implementation of a {@link Module} for memory expansion. */ diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java index c72b11d689..4a9f37f1c8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mxp/MxpOperation.java @@ -31,7 +31,7 @@ import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; import net.consensys.linea.zktracer.module.hub.transients.OperationAncillaries; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index cfd3aff5af..05de8664a9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -28,7 +28,7 @@ import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import org.hyperledger.besu.evm.frame.MessageFrame; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 2f01d6aebc..98f0b6e314 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -91,24 +91,24 @@ import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.OobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallDataLoadOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CallOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.CreateOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.DeploymentOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.JumpiOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.ReturnDataCopyOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.SstoreOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.opcodes.XCallOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fCallDataSizeOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.Blake2fParamsOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpCallDataSizeOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpExtractOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpLeadOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpPricingOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.ModexpXbsOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.oob.precompiles.PrecompileCommonOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CallDataLoadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CreateOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.DeploymentOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.JumpOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.JumpiOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.ReturnDataCopyOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.SstoreOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.XCallOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.Blake2fCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.Blake2fParamsOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpExtractOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpLeadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpPricingOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; @@ -213,7 +213,7 @@ public OobOperation( } private void setFlagsAndWghtSumAndIncomingInstAndMaxCt() { - switch (oobCall.oobInstruction()) { + switch (oobCall.oobInstructionValue()) { case OOB_INST_JUMP -> { isJump = true; wghtSum = OOB_INST_JUMP; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java index 6426bec648..e9dae6f6fb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java @@ -49,6 +49,7 @@ public class ShakiraDataOperation extends ModuleOperation { private final int indexMaxData; private Bytes32 result; + // TODO: deprecate in favour of the version with the return data argument public ShakiraDataOperation( final long hubStamp, final ShakiraPrecompileType precompileType, final Bytes hashInput) { this.precompileType = precompileType; @@ -60,6 +61,21 @@ public ShakiraDataOperation( this.indexMaxData = (inputSize + LLARGEMO) / LLARGE - 1; } + public ShakiraDataOperation( + final long hubStamp, + final ShakiraPrecompileType precompileType, + final Bytes hashInput, + final Bytes result) { + this.precompileType = precompileType; + this.ID = hubStamp + 1; + this.hashInput = hashInput; + this.inputSize = hashInput.size(); + this.lastNBytes = (short) (inputSize % LLARGE == 0 ? LLARGE : inputSize % LLARGE); + // this.indexMaxData = Math.ceilDiv(inputSize, LLARGE) - 1; + this.indexMaxData = (inputSize + LLARGEMO) / LLARGE - 1; + this.result = Bytes32.leftPad(result); + } + @Override protected int computeLineCount() { return indexMaxData + 1 + INDEX_MAX_RESULT + 1; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java index 4371d9181b..5a160655fa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java @@ -24,7 +24,7 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.StpCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java index d8c0ac995c..a77018dd5d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java @@ -21,7 +21,7 @@ import lombok.Getter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.hub.fragment.imc.call.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.StpCall; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; From 31a2b48a6f4d2cdc8ef20fd2a6b10ba982507dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 19:55:12 +0200 Subject: [PATCH 319/461] feat(sha2): first precompile down :) --- .../linea/zktracer/module/hub/Hub.java | 4 + .../module/hub/fragment/ContextFragment.java | 4 +- .../module/hub/fragment/imc/mmu/MmuCall.java | 79 +++++++++++-------- .../scenario/PrecompileScenarioFragment.java | 60 +++++++++++++- .../module/hub/section/call/CallSection.java | 25 +++--- .../PrecompileSubsection.java | 78 ++++++++++-------- .../precompileSubsection/Sha2SubSection.java | 78 ++++++++++++------ .../hub/section/halt/ReturnSection.java | 2 +- .../hub/section/halt/RevertSection.java | 2 +- .../linea/zktracer/module/limits/Keccak.java | 2 +- .../limits/precompiles/RipemdBlocks.java | 4 +- .../limits/precompiles/Sha256Blocks.java | 4 +- .../shakiradata/ShakiraDataOperation.java | 12 +-- ...ecompileType.java => ShakiraHashType.java} | 4 +- .../zktracer/runtime/callstack/CallFrame.java | 4 +- 15 files changed, 237 insertions(+), 125 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/{ShakiraPrecompileType.java => ShakiraHashType.java} (95%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 54de79f8b8..bde5626969 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -814,6 +814,10 @@ public int newChildContextNumber() { return 1 + this.stamp(); } + public int precompileId() { + return newChildContextNumber(); + } + public CallFrame currentFrame() { if (this.callStack().isEmpty()) { return CallFrame.EMPTY; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 3d2a3270ce..2bb361b640 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -164,8 +164,8 @@ public Trace trace(Trace trace) { .pContextCallDataContextNumber(parent.contextNumber()) .pContextCallDataOffset(callFrame.callDataInfo().memorySpan().offset()) .pContextCallDataSize(callFrame.callDataInfo().memorySpan().length()) - .pContextReturnAtOffset(callFrame.parentReturnDataTarget().offset()) - .pContextReturnAtCapacity(callFrame.parentReturnDataTarget().length()) + .pContextReturnAtOffset(callFrame.returnDataTargetInCaller().offset()) + .pContextReturnAtCapacity(callFrame.returnDataTargetInCaller().length()) .pContextUpdate(updateReturnData) .pContextReturnDataContextNumber(returnDataContextNumber) // callFrame.id() == 0 diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 64ef3c63b6..95164ee098 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -59,7 +59,10 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_SHA2_RESULT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.RLP_TXN_PHASE_DATA; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_RIPEMD_160; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; +import static org.apache.tuweni.bytes.Bytes.minimalBytes; import java.util.Optional; @@ -78,9 +81,11 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.Create2; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ExtCodeCopy; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ReturnFromDeployment; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.LogData; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -303,8 +308,8 @@ public static MmuCall revert(final Hub hub) { .targetId(hub.callStack().getById(hub.currentFrame().parentFrameId()).contextNumber()) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) .size(Words.clampedToLong(hub.messageFrame().getStackItem(1))) - .referenceOffset(hub.currentFrame().parentReturnDataTarget().offset()) - .referenceSize(hub.currentFrame().parentReturnDataTarget().length()); + .referenceOffset(hub.currentFrame().returnDataTargetInCaller().offset()) + .referenceSize(hub.currentFrame().returnDataTargetInCaller().length()); } public static MmuCall txInit(final Hub hub) { @@ -363,62 +368,68 @@ public static MmuCall forEcRecover( } } - private static MmuCall forShaTwoOrRipemdCallDataExtraction( - final Hub hub, PrecompileInvocation p, final boolean isSha) { + public static MmuCall forShaTwoOrRipemdCallDataExtraction( + final Hub hub, PrecompileSubsection precompileSubsection) { - final int precompileContextNumber = p.hubStamp() + 1; + + PrecompileScenarioFragment.PrecompileFlag flag = precompileSubsection.precompileScenarioFragment().getFlag(); + Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .size(p.callDataSource().length()) - .referenceSize(p.callDataSource().length()) - .phase(isSha ? PHASE_SHA2_DATA : PHASE_RIPEMD_DATA) + .sourceRamBytes(Optional.of(precompileSubsection.callerMemorySnapshot())) + .targetId(precompileSubsection.exoModuleOperationId()) + .exoBytes(Optional.of(precompileSubsection.callData)) + .sourceOffset(EWord.of(precompileSubsection.callDataMemorySpan.offset())) + .size(precompileSubsection.callDataMemorySpan.length()) + .referenceSize(precompileSubsection.callDataMemorySpan.length()) + .phase(flag.dataPhase()) .setRipSha(); } - private static MmuCall forShaTwoOrRipemdFullResultTransfer( - final Hub hub, PrecompileInvocation p, final boolean isSha) { + public static MmuCall forShaTwoOrRipemdFullResultTransfer( + final Hub hub, PrecompileSubsection precompileSubsection) { - final int precompileContextNumber = p.hubStamp() + 1; + PrecompileScenarioFragment.PrecompileFlag flag = + precompileSubsection.precompileScenarioFragment().getFlag(); + Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); - if (p.callDataSource().isEmpty()) { + final boolean isShaTwo = flag == PRC_SHA2_256; + + if (precompileSubsection.callDataMemorySpan.isEmpty()) { return new MmuCall(hub, MMU_INST_MSTORE) - .targetId(precompileContextNumber) + .targetId(precompileSubsection.exoModuleOperationId()) .targetOffset(EWord.ZERO) - .limb1(isSha ? bigIntegerToBytes(EMPTY_SHA2_HI) : Bytes.ofUnsignedLong(EMPTY_RIPEMD_HI)) - .limb2(isSha ? bigIntegerToBytes(EMPTY_SHA2_LO) : bigIntegerToBytes(EMPTY_RIPEMD_LO)); + .limb1(isShaTwo ? bigIntegerToBytes(EMPTY_SHA2_HI) : minimalBytes(EMPTY_RIPEMD_HI)) + .limb2(isShaTwo ? bigIntegerToBytes(EMPTY_SHA2_LO) : bigIntegerToBytes(EMPTY_RIPEMD_LO)); } else { return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(precompileContextNumber) - .targetId(precompileContextNumber) + .sourceId(precompileSubsection.exoModuleOperationId()) + .targetId(precompileSubsection.returnDataContextNumber()) + .exoBytes(Optional.of(precompileSubsection.returnData)) + .targetRamBytes(Optional.of(Bytes.EMPTY)) .size(WORD_SIZE) - .phase(isSha ? PHASE_SHA2_RESULT : PHASE_RIPEMD_RESULT) + .phase(flag.resultPhase()) .setRipSha(); } } - private static MmuCall forShaTwoOrRipemdPartialResultCopy( - final Hub hub, PrecompileInvocation p, final boolean isSha) { + public static MmuCall forShaTwoOrRipemdPartialResultCopy( + final Hub hub, PrecompileSubsection precompileSubsection) { - final int precompileContextNumber = p.hubStamp() + 1; + PrecompileScenarioFragment.PrecompileFlag flag = + precompileSubsection.precompileScenarioFragment().getFlag(); + + Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); + Preconditions.checkArgument(!precompileSubsection.parentReturnDataTarget.isEmpty()); return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) + .sourceId(precompileSubsection.returnDataContextNumber()) .targetId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.ZERO) .size(WORD_SIZE) - .referenceOffset(p.requestedReturnDataTarget().offset()) - .referenceSize(p.requestedReturnDataTarget().length()); - } - - public static MmuCall forSha2(final Hub hub, PrecompileInvocation p, int i) { - return forShaTwoOrRipemdFullResultTransfer(hub, p, true); - } - - public static MmuCall forRipeMd160(final Hub hub, PrecompileInvocation p, int i) { - return forShaTwoOrRipemdFullResultTransfer(hub, p, false); + .referenceOffset(precompileSubsection.parentReturnDataTarget.offset()) + .referenceSize(precompileSubsection.parentReturnDataTarget.length()); } public static MmuCall forIdentity(final Hub hub, final PrecompileInvocation p, int i) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index fbcdcc5dd9..1d96541744 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -15,10 +15,13 @@ package net.consensys.linea.zktracer.module.hub.fragment.scenario; +import java.util.Map; + import com.google.common.base.Preconditions; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; @@ -28,7 +31,6 @@ public class PrecompileScenarioFragment implements TraceFragment { public enum PrecompileScenario { - PRC_UNDEFINED_SCENARIO, PRC_FAILURE_KNOWN_TO_HUB, PRC_FAILURE_KNOWN_TO_RAM, PRC_SUCCESS_WILL_REVERT, @@ -45,7 +47,55 @@ public enum PrecompileFlag { PRC_ECADD, PRC_ECMUL, PRC_ECPAIRING, - PRC_BLAKE2F + PRC_BLAKE2F; + + private static final Map DATA_PHASE_MAP = + Map.of( + PRC_ECRECOVER, GlobalConstants.PHASE_ECRECOVER_DATA, + PRC_SHA2_256, GlobalConstants.PHASE_SHA2_DATA, + PRC_RIPEMD_160, GlobalConstants.PHASE_RIPEMD_DATA, + // IDENTITY not supported + // MODEXP not supported + PRC_ECADD, GlobalConstants.PHASE_ECADD_DATA, + PRC_ECMUL, GlobalConstants.PHASE_ECMUL_DATA, + PRC_ECPAIRING, GlobalConstants.PHASE_ECPAIRING_DATA + // BLAKE2f not supported + ); + + private static final Map RESULT_PHASE_MAP = + Map.of( + PRC_ECRECOVER, GlobalConstants.PHASE_ECRECOVER_RESULT, + PRC_SHA2_256, GlobalConstants.PHASE_SHA2_RESULT, + PRC_RIPEMD_160, GlobalConstants.PHASE_RIPEMD_RESULT, + // IDENTITY not supported + PRC_MODEXP, GlobalConstants.PHASE_MODEXP_RESULT, + PRC_ECADD, GlobalConstants.PHASE_ECADD_RESULT, + PRC_ECMUL, GlobalConstants.PHASE_ECMUL_RESULT, + PRC_ECPAIRING, GlobalConstants.PHASE_ECPAIRING_RESULT, + PRC_BLAKE2F, GlobalConstants.PHASE_BLAKE_RESULT); + + public int dataPhase() { + if (!DATA_PHASE_MAP.containsKey(this)) { + throw new IllegalArgumentException("Precompile not supported by the DATA_PHASE_MAP"); + } + return DATA_PHASE_MAP.get(this); + } + + public int resultPhase() { + if (!RESULT_PHASE_MAP.containsKey(this)) { + throw new IllegalArgumentException("Precompile not supported by the RESULT_PHASE_MAP"); + } + return RESULT_PHASE_MAP.get(this); + } + + public boolean isAnyOf(PrecompileFlag... flags) { + for (PrecompileFlag flag : flags) { + if (this == flag) { + return true; + } + } + return false; + } } final PrecompileSubsection precompileSubSection; @@ -61,9 +111,13 @@ public PrecompileScenarioFragment( this.scenario = scenario; } + public boolean isPrcFailure() { + return scenario == PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB + || scenario == PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM; + } + @Override public Trace trace(Trace trace) { - Preconditions.checkArgument(this.scenario != PrecompileScenario.PRC_UNDEFINED_SCENARIO); Preconditions.checkArgument(this.flag != PrecompileFlag.PRC_UNDEFINED); return trace .peekAtScenario(true) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index db13021034..a832d90b5a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -95,9 +95,6 @@ public class CallSection extends TraceSection private Wei value; - // The successBit will only be set - // if the call is acted upon i.e. if the call is un-exceptional and un-aborted - private boolean successBit; private AccountSnapshot postRollbackCalleeSnapshot; private AccountSnapshot postRollbackCallerSnapshot; @@ -180,6 +177,15 @@ public CallSection(Hub hub) { if (isPrecompile(calleeAddress)) { scenarioFragment.setScenario(CALL_PRC_UNDEFINED); + // Account rows for precompile are traced at contextReEntry + + precompileSubsection = + ADDRESS_TO_PRECOMPILE.get(preOpcodeCalleeSnapshot.address()).apply(hub, this); + + hub.defers().scheduleForImmediateContextEntry(precompileSubsection); // gas & input data, ... + hub.defers() + .scheduleForContextReEntry( + precompileSubsection, hub.callStack().parent()); // success bit & return data } else { scenarioFragment.setScenario( world.get(calleeAddress).hasCode() ? CALL_SMC_UNDEFINED : CALL_EOA_SUCCESS_WONT_REVERT); @@ -285,14 +291,7 @@ public void resolveUponEnteringChildContext(Hub hub) { this.addFragments(firstCallerAccountFragment, firstCalleeAccountFragment); } - case CALL_PRC_UNDEFINED -> { - // Account rows for precompile are traced at contextReEntry - precompileSubsection = - ADDRESS_TO_PRECOMPILE.get(preOpcodeCalleeSnapshot.address()).apply(hub, this); - - hub.defers().scheduleForContextReEntry(precompileSubsection, hub.callStack().parent()); - hub.defers().scheduleForPostTransaction(precompileSubsection); - } + case CALL_PRC_UNDEFINED -> {} case CALL_EOA_SUCCESS_WONT_REVERT -> { // Account rows for EOA calls are traced at contextReEntry @@ -326,7 +325,9 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { // TODO: what follows assumes that the caller's stack has been updated // to contain the success bit of the call at traceContextReEntry. // See issue #872. - successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); + // The successBit will only be set + // if the call is acted upon i.e. if the call is un-exceptional and un-aborted + final boolean successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); reEntryCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); reEntryCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index cd6ba8187f..c1e9b2fe53 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -22,31 +22,30 @@ import java.util.ArrayList; import java.util.List; +import com.google.common.base.Preconditions; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; -import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.defer.*; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.worldstate.WorldView; /** Note: {@link PrecompileSubsection}'s are created at child context entry by the call section */ @RequiredArgsConstructor @Getter @Accessors(fluent = true) public class PrecompileSubsection - implements ContextExitDefer, ContextReEntryDefer, PostRollbackDefer, PostTransactionDefer { + implements ImmediateContextEntryDefer, + ContextExitDefer, + ContextReEntryDefer, + PostRollbackDefer { public final CallSection callSection; @@ -54,32 +53,32 @@ public class PrecompileSubsection private final List fragments; /** The (potentially empty) call data of the precompile call */ - final Bytes callData; + public Bytes callData; /** The input data for the precompile */ - private final MemorySpan callDataMemorySpan; + public MemorySpan callDataMemorySpan; /** Where the caller wants the precompile return data to be stored */ - private final MemorySpan parentReturnDataTarget; + public MemorySpan parentReturnDataTarget; /** The (potentially empty) return data of the precompile call */ - @Setter Bytes returnData; + @Setter public Bytes returnData; /** Leftover gas of the caller */ - final long callerGas; + long callerGas; /** Available gas of the callee */ - final long calleeGas; + long calleeGas; /** The gas to return to the caller context */ long returnGas; boolean successBit; - final PrecompileScenarioFragment precompileScenarioFragment; + public final PrecompileScenarioFragment precompileScenarioFragment; /** A snapshot of the caller's memory before the execution of the precompile */ - final Bytes callerMemorySnapshot; + public Bytes callerMemorySnapshot; /** * Default creator specifying the max number of rows the precompile processing subsection can @@ -88,27 +87,30 @@ public class PrecompileSubsection public PrecompileSubsection(final Hub hub, final CallSection callSection) { this.callSection = callSection; fragments = new ArrayList<>(maxNumberOfLines()); - callDataMemorySpan = hub.currentFrame().callDataInfo().memorySpan(); - callData = hub.messageFrame().getInputData(); - parentReturnDataTarget = hub.currentFrame().parentReturnDataTarget(); - callerGas = hub.callStack().parent().frame().getRemainingGas(); - calleeGas = hub.messageFrame().getRemainingGas(); - - final MessageFrame callerFrame = hub.callStack().parent().frame(); - callerMemorySnapshot = extractContiguousLimbsFromMemory(callerFrame, callDataMemorySpan); precompileScenarioFragment = - new PrecompileScenarioFragment(this, PRC_UNDEFINED_SCENARIO, PRC_UNDEFINED); + new PrecompileScenarioFragment(this, PRC_SUCCESS_WONT_REVERT, PRC_UNDEFINED); fragments.add(precompileScenarioFragment); } protected short maxNumberOfLines() { return 0; } - ; - public void resolveUponExitingContext(Hub hub, CallFrame frame) { - returnGas = frame.frame().getRemainingGas(); + @Override + public void resolveUponEnteringChildContext(Hub hub) { + callerGas = hub.callStack().parent().frame().getRemainingGas(); + calleeGas = hub.messageFrame().getRemainingGas(); + callDataMemorySpan = hub.currentFrame().callDataInfo().memorySpan(); + callData = hub.messageFrame().getInputData(); + parentReturnDataTarget = hub.currentFrame().returnDataTargetInCaller(); + + final MessageFrame callerFrame = hub.callStack().parent().frame(); + callerMemorySnapshot = extractContiguousLimbsFromMemory(callerFrame, callDataMemorySpan); + } + + public void resolveUponExitingContext(Hub hub, CallFrame callFrame) { + returnGas = callFrame.frame().getRemainingGas(); } @Override @@ -118,17 +120,31 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { if (successBit) { hub.defers().scheduleForPostRollback(this, frame); - precompileScenarioFragment.setScenario(PRC_SUCCESS_WONT_REVERT); + } else { + // TODO: extensions of this class are responsible for setting either + // PRC_FAILURE_KNOWN_TO_HUB / PRC_FAILURE_KNOWN_TO_RAM + // in case of a failure. + // In any case, the failure scenario is required to have been set + // before context re-entry. + Preconditions.checkArgument(precompileScenarioFragment.isPrcFailure()); } } @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + // only successful PRC calls should enter here + Preconditions.checkArgument( + precompileScenarioFragment.getScenario() == PRC_SUCCESS_WONT_REVERT); + precompileScenarioFragment.setScenario(PRC_SUCCESS_WILL_REVERT); } - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + public int exoModuleOperationId() { + return this.callSection.hubStamp() + 1; + } + + public int returnDataContextNumber() { + return exoModuleOperationId(); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java index 97a2d5ea16..8913122a53 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java @@ -17,55 +17,81 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_SHA2; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType.SHA256; -import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; +import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.SHA256; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.worldstate.WorldView; public class Sha2SubSection extends PrecompileSubsection { + final ImcFragment firstImcFragment; + final PrecompileCommonOobCall oobCall; + public Sha2SubSection(Hub hub, CallSection callSection) { super(hub, callSection); + precompileScenarioFragment.setFlag(PRC_SHA2_256); - PrecompileCommonOobCall oobCall = new PrecompileCommonOobCall(OOB_INST_SHA2); - } + oobCall = new PrecompileCommonOobCall(OOB_INST_SHA2); - // 4 = 1 + 3 (scenario row + up to 3 miscellaneous fragments) - @Override - protected short maxNumberOfLines() { - return (short) (successBit ? 4 : 2); - } + firstImcFragment = ImcFragment.empty(hub); + firstImcFragment.callOob(oobCall); - @Override - public void resolveUponExitingContext(Hub hub, CallFrame frame) { - // TODO + if (!oobCall.isHubSuccess()) { + precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + } } @Override public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); - final boolean successBit = bytesToBoolean(callFrame.frame().getStackItem(0)); - if (successBit) { - // may get updated later - precompileScenarioFragment.setScenario( - PrecompileScenarioFragment.PrecompileScenario.PRC_SUCCESS_WONT_REVERT); + + // sanity check + Preconditions.checkArgument(successBit == oobCall.isHubSuccess()); + + if (!successBit) { + return; + } + + // NOTE: we trigger the SHAKIRA module for nonempty call data only + if (!callData.isEmpty()) { ShakiraDataOperation shakiraCall = new ShakiraDataOperation( - this.callSection.hubStamp(), SHA256, callData, callFrame.frame().getReturnData()); + this.callSection.hubStamp(), SHA256, callData(), callFrame.frame().getReturnData()); hub.shakiraData().call(shakiraCall); - } else { - precompileScenarioFragment.setScenario( - PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB); + + MmuCall mmuCall = MmuCall.forShaTwoOrRipemdCallDataExtraction(hub, this); + firstImcFragment.callMmu(mmuCall); + } + + // the full result transfer happens in all cases + ImcFragment secondImcFragment = ImcFragment.empty(hub); + this.fragments().add(secondImcFragment); + + MmuCall fullOutputDataTransfer = MmuCall.forShaTwoOrRipemdFullResultTransfer(hub, this); + secondImcFragment.callMmu(fullOutputDataTransfer); + + ImcFragment thirdImcFragment = ImcFragment.empty(hub); + this.fragments().add(thirdImcFragment); + + // the partial copy of return data happens only if the caller context + // provided a nonempty return data target + if (!parentReturnDataTarget.isEmpty()) { + MmuCall partialReturnDataCopy = MmuCall.forShaTwoOrRipemdPartialResultCopy(hub, this); + thirdImcFragment.callMmu(partialReturnDataCopy); } } + // 4 = 1 + 3 (scenario row + up to 3 miscellaneous fragments) @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {} + protected short maxNumberOfLines() { + return 4; + // Note: we don't have the successBit available at the moment + // and can't provide the "real" value (2 in case of FKTH.) + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index dd331746f1..11e5316be2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -135,7 +135,7 @@ public ReturnSection(Hub hub) { final boolean messageCallReturnTouchesRam = !currentFrame.isRoot() && nontrivialMmuOperation // [size ≠ 0] ∧ ¬MXPX - && !currentFrame.parentReturnDataTarget().isEmpty(); // [r@c ≠ 0] + && !currentFrame.returnDataTargetInCaller().isEmpty(); // [r@c ≠ 0] returnScenarioFragment.setScenario( messageCallReturnTouchesRam diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index ec96d07bdd..3d086e4f12 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -56,7 +56,7 @@ public RevertSection(Hub hub) { (Exceptions.none(exceptions)) && !hub.currentFrame().isRoot() && mxpCall.mayTriggerNontrivialMmuOperation // i.e. size ≠ 0 ∧ ¬MXPX - && !hub.currentFrame().parentReturnDataTarget().isEmpty(); + && !hub.currentFrame().returnDataTargetInCaller().isEmpty(); if (triggerMmu) { mmuCall = MmuCall.revert(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java index d17f39dd44..bb13e90f1a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.limits; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType.KECCAK; +import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.KECCAK; import java.util.ArrayDeque; import java.util.ArrayList; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java index 10f65ccccc..76006fd6f9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java @@ -30,7 +30,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.shakiradata.ShakiraData; import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType; +import net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; @@ -118,7 +118,7 @@ public void tracePreOpcode(MessageFrame frame) { if (hub.transients().op().gasAllowanceForCall() >= gasNeeded) { this.shakiraData.call( - new ShakiraDataOperation(hub.stamp(), ShakiraPrecompileType.RIPEMD, inputData)); + new ShakiraDataOperation(hub.stamp(), ShakiraHashType.RIPEMD, inputData)); this.counts.push(this.counts.pop() + blockCount); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java index 6851236829..d451753ef7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java @@ -30,7 +30,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.shakiradata.ShakiraData; import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType; +import net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; @@ -115,7 +115,7 @@ public void tracePreOpcode(MessageFrame frame) { if (hasEnoughGas(this.hub)) { this.shakiraData.call( - new ShakiraDataOperation(hub.stamp(), ShakiraPrecompileType.SHA256, inputData)); + new ShakiraDataOperation(hub.stamp(), ShakiraHashType.SHA256, inputData)); this.counts.push(this.counts.pop() + blockCount); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java index e9dae6f6fb..e656664807 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java @@ -24,9 +24,9 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_SHA2_DATA; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_SHA2_RESULT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType.KECCAK; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType.RIPEMD; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraPrecompileType.SHA256; +import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.KECCAK; +import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.RIPEMD; +import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.SHA256; import static net.consensys.linea.zktracer.module.shakiradata.Trace.INDEX_MAX_RESULT; import static net.consensys.linea.zktracer.types.Utils.rightPadTo; @@ -41,7 +41,7 @@ @Accessors(fluent = true) public class ShakiraDataOperation extends ModuleOperation { - private final ShakiraPrecompileType precompileType; + private final ShakiraHashType precompileType; private final Bytes hashInput; @Getter private final long ID; private final int inputSize; @@ -51,7 +51,7 @@ public class ShakiraDataOperation extends ModuleOperation { // TODO: deprecate in favour of the version with the return data argument public ShakiraDataOperation( - final long hubStamp, final ShakiraPrecompileType precompileType, final Bytes hashInput) { + final long hubStamp, final ShakiraHashType precompileType, final Bytes hashInput) { this.precompileType = precompileType; this.ID = hubStamp + 1; this.hashInput = hashInput; @@ -63,7 +63,7 @@ public ShakiraDataOperation( public ShakiraDataOperation( final long hubStamp, - final ShakiraPrecompileType precompileType, + final ShakiraHashType precompileType, final Bytes hashInput, final Bytes result) { this.precompileType = precompileType; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraPrecompileType.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraHashType.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraPrecompileType.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraHashType.java index a9502c06b3..1c8fe396e6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraPrecompileType.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraHashType.java @@ -15,8 +15,8 @@ package net.consensys.linea.zktracer.module.shakiradata; -public enum ShakiraPrecompileType { - SHA256, +public enum ShakiraHashType { KECCAK, + SHA256, RIPEMD } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 103937b6d7..eec527c613 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -136,7 +136,7 @@ public int getCodeFragmentIndex(Hub hub) { @Getter @Setter private MemorySpan outputDataSpan; /** where this frame is expected to write its outputData within its parent's memory space. */ - @Getter private MemorySpan parentReturnDataTarget = MemorySpan.empty(); + @Getter private MemorySpan returnDataTargetInCaller = MemorySpan.empty(); @Getter @Setter private boolean selfReverts = false; @Getter @Setter private boolean getsReverted = false; @@ -247,7 +247,7 @@ public static void updateParentContextReturnData( this.depth = depth; this.outputDataSpan = MemorySpan.empty(); this.returnDataSpan = MemorySpan.empty(); - this.parentReturnDataTarget = MemorySpan.empty(); // TODO: fix me Franklin + this.returnDataTargetInCaller = MemorySpan.empty(); // TODO: fix me Franklin } public boolean isRoot() { From be8d7c7f1c495408a5f0e3e734667ac2b7ddc840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 28 Jul 2024 19:55:41 +0200 Subject: [PATCH 320/461] spotless --- .../module/hub/fragment/imc/mmu/MmuCall.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 95164ee098..2a64e0f39f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -53,10 +53,6 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_EXPONENT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_MODULUS; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_RESULT; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_RIPEMD_DATA; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_RIPEMD_RESULT; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_SHA2_DATA; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_SHA2_RESULT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.RLP_TXN_PHASE_DATA; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_RIPEMD_160; @@ -371,8 +367,8 @@ public static MmuCall forEcRecover( public static MmuCall forShaTwoOrRipemdCallDataExtraction( final Hub hub, PrecompileSubsection precompileSubsection) { - - PrecompileScenarioFragment.PrecompileFlag flag = precompileSubsection.precompileScenarioFragment().getFlag(); + PrecompileScenarioFragment.PrecompileFlag flag = + precompileSubsection.precompileScenarioFragment().getFlag(); Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) @@ -415,10 +411,10 @@ public static MmuCall forShaTwoOrRipemdFullResultTransfer( } public static MmuCall forShaTwoOrRipemdPartialResultCopy( - final Hub hub, PrecompileSubsection precompileSubsection) { + final Hub hub, PrecompileSubsection precompileSubsection) { PrecompileScenarioFragment.PrecompileFlag flag = - precompileSubsection.precompileScenarioFragment().getFlag(); + precompileSubsection.precompileScenarioFragment().getFlag(); Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); Preconditions.checkArgument(!precompileSubsection.parentReturnDataTarget.isEmpty()); From e157de3c9b021c35dc3d9ad04febe534d6a23bd2 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 30 Jul 2024 00:40:25 +0200 Subject: [PATCH 321/461] feat(PRC): inverse logic where the prc limits are triggered by the call to a prc data module. All done except for KECCAK --- .../container/stacked/CountOnlyOperation.java | 48 +++ .../blake2fmodexpdata/BlakeModexpData.java | 17 +- .../BlakeModexpDataOperation.java | 15 +- .../linea/zktracer/module/ecdata/EcData.java | 33 ++ .../module/ecdata/EcDataOperation.java | 2 +- .../linea/zktracer/module/exp/Exp.java | 2 +- .../linea/zktracer/module/hub/Hub.java | 134 ++++---- .../hub/precompiles/PrecompileInvocation.java | 223 ++++++------ .../precompileSubsection/Sha2SubSection.java | 12 +- .../module/limits/CountingOnlyModule.java | 61 ++++ .../linea/zktracer/module/limits/Keccak.java | 1 + .../precompiles/BlakeEffectiveCall.java | 33 +- .../module/limits/precompiles/BlakeLimit.java | 18 - .../limits/precompiles/BlakeRounds.java | 194 +---------- .../precompiles/EcAddEffectiveCall.java | 79 +---- .../precompiles/EcMulEffectiveCall.java | 78 +---- .../EcPairingFinalExponentiations.java | 325 +----------------- .../EcPairingG2MembershipCalls.java | 41 +-- .../precompiles/EcPairingMillerLoops.java | 41 +-- .../limits/precompiles/EcPairingTallier.java | 19 - .../precompiles/EcRecoverEffectiveCall.java | 110 +----- .../precompiles/ModexpEffectiveCall.java | 196 +---------- .../limits/precompiles/RipemdBlocks.java | 117 +------ .../limits/precompiles/Sha256Blocks.java | 115 +------ .../module/shakiradata/ShakiraData.java | 15 +- .../shakiradata/ShakiraDataOperation.java | 4 +- 26 files changed, 443 insertions(+), 1490 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/CountOnlyOperation.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/CountingOnlyModule.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeLimit.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingTallier.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/CountOnlyOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/CountOnlyOperation.java new file mode 100644 index 0000000000..43c867d8f7 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/stacked/CountOnlyOperation.java @@ -0,0 +1,48 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.container.stacked; + +public class CountOnlyOperation { + + private int countSinceBeginningOfTheConflation; + private int thisTransactionCount; + + public CountOnlyOperation() { + this.countSinceBeginningOfTheConflation = 0; + this.thisTransactionCount = 0; + } + + /** + * when we enter a transaction, the previous transaction is definitely added to the block and + * can't be pop + */ + public void enterTransaction() { + countSinceBeginningOfTheConflation += thisTransactionCount; + thisTransactionCount = 0; + } + + public void popTransaction() { + thisTransactionCount = 0; + } + + public void add(final int operationCount) { + thisTransactionCount += operationCount; + } + + public int lineCount() { + return countSinceBeginningOfTheConflation + thisTransactionCount; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java index 6c0653e159..e8e1eb5753 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java @@ -31,6 +31,9 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; +import net.consensys.linea.zktracer.module.limits.precompiles.BlakeEffectiveCall; +import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds; +import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -39,6 +42,9 @@ @RequiredArgsConstructor public class BlakeModexpData implements Module { private final Wcp wcp; + private final ModexpEffectiveCall modexpEffectiveCall; + private final BlakeEffectiveCall blakeEffectiveCall; + private final BlakeRounds blakeRounds; private StackedSet operations = new StackedSet<>(); private List sortedOperations = new ArrayList<>(); private int numberOfOperationsAtStartTx = 0; @@ -89,8 +95,15 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - public void call(final BlakeModexpDataOperation operation) { - this.operations.add(operation); + public void callModexp(final ModexpComponents modexpComponents) { + operations.add(new BlakeModexpDataOperation(modexpComponents)); + modexpEffectiveCall.addPrecompileLimit(1); + } + + public void callBlake(final BlakeComponents blakeComponents) { + operations.add(new BlakeModexpDataOperation(blakeComponents)); + blakeEffectiveCall.addPrecompileLimit(1); + blakeRounds.addPrecompileLimit(blakeComponents.r().toInt()); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java index ebd2c9cbff..d9f6cd0cee 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java @@ -60,11 +60,16 @@ public class BlakeModexpDataOperation extends ModuleOperation { public final Optional modexpComponents; public final Optional blake2fComponents; - public BlakeModexpDataOperation( - long hubStamp, ModexpComponents modexpComponents, BlakeComponents blakeComponents) { - this.id = hubStamp + 1; - this.modexpComponents = Optional.ofNullable(modexpComponents); - this.blake2fComponents = Optional.ofNullable(blakeComponents); + public BlakeModexpDataOperation(final ModexpComponents modexpComponents) { + this.id = 0; // TODO + this.modexpComponents = Optional.of(modexpComponents); + this.blake2fComponents = Optional.empty(); + } + + public BlakeModexpDataOperation(final BlakeComponents blakeComponents) { + this.id = 0; // TODO + this.modexpComponents = Optional.empty(); + this.blake2fComponents = Optional.of(blakeComponents); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index 12b3e241d9..88a611210a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -15,6 +15,11 @@ package net.consensys.linea.zktracer.module.ecdata; +import static net.consensys.linea.zktracer.module.ecdata.Trace.ECADD; +import static net.consensys.linea.zktracer.module.ecdata.Trace.ECMUL; +import static net.consensys.linea.zktracer.module.ecdata.Trace.ECPAIRING; +import static net.consensys.linea.zktracer.module.ecdata.Trace.ECRECOVER; + import java.nio.MappedByteBuffer; import java.util.Comparator; import java.util.List; @@ -27,6 +32,12 @@ import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.ext.Ext; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall; +import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall; +import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingFinalExponentiations; +import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingG2MembershipCalls; +import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingMillerLoops; +import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; @@ -44,6 +55,14 @@ public class EcData implements Module { private final Wcp wcp; private final Ext ext; + private final EcAddEffectiveCall ecAddEffectiveCall; + private final EcMulEffectiveCall ecMulEffectiveCall; + private final EcRecoverEffectiveCall ecRecoverEffectiveCall; + + private final EcPairingG2MembershipCalls ecPairingG2MembershipCalls; + private final EcPairingMillerLoops ecPairingMillerLoops; + private final EcPairingFinalExponentiations ecPairingFinalExponentiations; + @Getter private EcDataOperation ecDataOperation; @Override @@ -106,4 +125,18 @@ public void commit(List buffers) { previousId = op.id(); } } + + public void callEcdata(final EcDataOperation ecDataOperation) { + this.operations.add(ecDataOperation); + + switch (ecDataOperation.ecType()) { + case ECADD -> ecAddEffectiveCall.addPrecompileLimit(1); + case ECMUL -> ecMulEffectiveCall.addPrecompileLimit(1); + case ECRECOVER -> ecRecoverEffectiveCall.addPrecompileLimit(1); + case ECPAIRING -> { + // TODO @Lorenzo + } + default -> throw new IllegalArgumentException("Operation not supported by EcData"); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 754ac2f997..43557951de 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -85,7 +85,7 @@ public class EcDataOperation extends ModuleOperation { @Getter private final long id; private final Bytes data; - private final int ecType; + @Getter private final int ecType; private final int nRows; private final int nRowsData; private final int nRowsResult; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java index e3797a47f1..b00a0fd168 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/Exp.java @@ -33,8 +33,8 @@ public class Exp implements Module { /** A list of the operations to trace */ private final StackedSet chunks = new StackedSet<>(); - private final Wcp wcp; private final Hub hub; + private final Wcp wcp; @Override public String moduleKey() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index bde5626969..6036458f9f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -79,7 +79,6 @@ import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.Transients; -import net.consensys.linea.zktracer.module.limits.Keccak; import net.consensys.linea.zktracer.module.limits.L2Block; import net.consensys.linea.zktracer.module.limits.L2L1Logs; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeEffectiveCall; @@ -151,10 +150,10 @@ public class Hub implements Module { @Getter public final State state = new State(); /** contain the factories for trace segments that need complex initialization */ - @Getter private final Factories factories; + @Getter private final Factories factories = new Factories(this); /** provides phase-related volatile information */ - @Getter Transients transients; + @Getter Transients transients = new Transients(this); /** * Long-lived states, not used in tracing per se but keeping track of data of the associated @@ -169,8 +168,9 @@ public class Hub implements Module { @Getter private final DeferRegistry defers = new DeferRegistry(); /** stores all data related to failure states & module activation */ - @Getter private final PlatformController pch; + @Getter private final PlatformController pch = new PlatformController(this); + // TODO: should die private boolean previousOperationWasCallToEcPrecompile; @Override @@ -201,7 +201,7 @@ public int lineCount() { private final Add add = new Add(); private final Bin bin = new Bin(); private final Blockhash blockhash = new Blockhash(wcp); - private final Euc euc; + private final Euc euc = new Euc(wcp); private final Ext ext = new Ext(this); private final Gas gas = new Gas(); private final Mul mul = new Mul(this); @@ -211,36 +211,84 @@ public int lineCount() { // other private final Blockdata blockdata; - private final RlpTxn rlpTxn; - private final Rom rom; - @Getter private final RomLex romLex; - @Getter private final Mxp mxp; + @Getter private final RomLex romLex = new RomLex(this); + private final Rom rom = new Rom(romLex); + private final RlpTxn rlpTxn = new RlpTxn(romLex); private final Mmio mmio; - private final RlpTxnRcpt rlpTxnRcpt; - private final LogInfo logInfo; - private final LogData logData; + private final TxnData txnData = new TxnData(wcp, euc); + private final RlpTxnRcpt rlpTxnRcpt = new RlpTxnRcpt(txnData); + private final LogInfo logInfo = new LogInfo(rlpTxnRcpt); + private final LogData logData = new LogData(rlpTxnRcpt); private final RlpAddr rlpAddr = new RlpAddr(this, trm); - private final TxnData txnData; // modules triggered by sub-fragments of the MISCELLANEOUS / IMC perspective - @Getter private final Stp stp = new Stp(wcp, mod); - @Getter private final Oob oob; - @Getter private final Exp exp; + @Getter private final Mxp mxp = new Mxp(); + @Getter private final Oob oob = new Oob(this, add, mod, wcp); @Getter private final Mmu mmu; + @Getter private final Stp stp = new Stp(wcp, mod); + @Getter private final Exp exp = new Exp(this, wcp); - // precompile-linked modules - @Getter private final BlakeModexpData blakeModexpData = new BlakeModexpData(this.wcp); - @Getter private final EcData ecData; - @Getter private final ModexpEffectiveCall modexpEffectiveCall; - @Getter private final ShakiraData shakiraData = new ShakiraData(this.wcp); /* * Those modules are not traced, we just compute the number of calls to those * precompile to meet the prover limits */ - private final List precompileLimitModules; + private final Sha256Blocks sha256Blocks = new Sha256Blocks(); + + private final EcAddEffectiveCall ecAddEffectiveCall = new EcAddEffectiveCall(); + private final EcMulEffectiveCall ecMulEffectiveCall = new EcMulEffectiveCall(); + private final EcRecoverEffectiveCall ecRecoverEffectiveCall = new EcRecoverEffectiveCall(); + + private final EcPairingG2MembershipCalls ecPairingG2MembershipCalls = + new EcPairingG2MembershipCalls(); + private final EcPairingMillerLoops ecPairingMillerLoops = new EcPairingMillerLoops(); + private final EcPairingFinalExponentiations ecPairingFinalExponentiations = + new EcPairingFinalExponentiations(); + + private final ModexpEffectiveCall modexpEffectiveCall = new ModexpEffectiveCall(); + + private final RipemdBlocks ripemdBlocks = new RipemdBlocks(); + + private final BlakeEffectiveCall blakeEffectiveCall = new BlakeEffectiveCall(); + private final BlakeRounds blakeRounds = new BlakeRounds(); + + private final List precompileLimitModules = + List.of( + sha256Blocks, + ecAddEffectiveCall, + ecMulEffectiveCall, + ecRecoverEffectiveCall, + ecPairingG2MembershipCalls, + ecPairingMillerLoops, + ecPairingFinalExponentiations, + modexpEffectiveCall, + ripemdBlocks, + blakeEffectiveCall, + blakeRounds); + + /* + * precompile-data modules + * those module are traced (and could be count) + */ + private final ShakiraData shakiraData = new ShakiraData(wcp, sha256Blocks, ripemdBlocks); + private final BlakeModexpData blakeModexpData = + new BlakeModexpData(this.wcp, modexpEffectiveCall, blakeEffectiveCall, blakeRounds); + private final EcData ecData = + new EcData( + this, + wcp, + ext, + ecAddEffectiveCall, + ecMulEffectiveCall, + ecRecoverEffectiveCall, + ecPairingG2MembershipCalls, + ecPairingMillerLoops, + ecPairingFinalExponentiations); + private final L2Block l2Block; + private final L2L1Logs l2L1Logs; + /** list of module triggered by the HUB at BESU hooks */ private final List modules; // reference table modules @@ -328,23 +376,9 @@ public List getModulesToCount() { public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic)); - this.transients = new Transients(this); - this.factories = new Factories(this); - - this.pch = new PlatformController(this); - this.mxp = new Mxp(this); - this.exp = new Exp(this.wcp, this); - this.romLex = new RomLex(this); - this.rom = new Rom(this.romLex); - this.rlpTxn = new RlpTxn(this.romLex); - this.euc = new Euc(this.wcp); - this.txnData = new TxnData(this.wcp, this.euc); + this.l2L1Logs = new L2L1Logs(l2Block); + this.blockdata = new Blockdata(this.wcp, this.txnData, this.rlpTxn); - this.rlpTxnRcpt = new RlpTxnRcpt(txnData); - this.logData = new LogData(rlpTxnRcpt); - this.logInfo = new LogInfo(rlpTxnRcpt); - this.ecData = new EcData(this, this.wcp, this.ext); - this.oob = new Oob(this, this.add, this.mod, this.wcp); this.mmu = new Mmu( this.euc, @@ -357,30 +391,6 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.callStack); this.mmio = new Mmio(this.mmu); - final EcRecoverEffectiveCall ecRec = new EcRecoverEffectiveCall(this); - this.modexpEffectiveCall = new ModexpEffectiveCall(this, this.blakeModexpData); - final EcPairingFinalExponentiations ecPairingCall = new EcPairingFinalExponentiations(this); - final L2Block l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic)); - final BlakeRounds blakeRounds = new BlakeRounds(this, this.blakeModexpData); - - this.precompileLimitModules = - List.of( - new Sha256Blocks(this, shakiraData), - ecRec, - new RipemdBlocks(this, shakiraData), - this.modexpEffectiveCall, - new EcAddEffectiveCall(this), - new EcMulEffectiveCall(this), - ecPairingCall, - new EcPairingG2MembershipCalls(ecPairingCall), - new EcPairingMillerLoops(ecPairingCall), - blakeRounds, - new BlakeEffectiveCall(blakeRounds), - // Block level limits - l2Block, - new Keccak(this, ecRec, l2Block, shakiraData), - new L2L1Logs(l2Block)); - this.refTableModules = List.of(new BinRt(), new InstructionDecoder(), new ShfRt()); this.modules = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java index 63129f09e6..b28a9ac052 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java @@ -18,18 +18,10 @@ import lombok.Builder; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds; -import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall; -import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall; -import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingFinalExponentiations; -import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall; -import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall; -import net.consensys.linea.zktracer.module.limits.precompiles.RipemdBlocks; -import net.consensys.linea.zktracer.module.limits.precompiles.Sha256Blocks; import net.consensys.linea.zktracer.types.MemorySpan; import net.consensys.linea.zktracer.types.Precompile; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.internal.Words; + +// TODO: delete me please @Accessors(fluent = true) @Builder @@ -64,114 +56,109 @@ public boolean success() { return !this.hubFailure && !this.ramFailure; } - public boolean hubSuccess() { - return !this.hubFailure; - } - - public boolean ramSuccess() { - return !this.ramFailure; - } - + // TODO: will die public static PrecompileInvocation of(final Hub hub, Precompile p) { - final boolean hubFailure = - switch (p) { - case EC_RECOVER -> !EcRecoverEffectiveCall.hasEnoughGas(hub); - case SHA2_256 -> !Sha256Blocks.hasEnoughGas(hub); - case RIPEMD_160 -> !RipemdBlocks.hasEnoughGas(hub); - case IDENTITY -> switch (hub.opCode()) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); - if (target.equals(Address.ID)) { - final long dataByteLength = hub.transients().op().callDataSegment().length(); - final long wordCount = (dataByteLength + 31) / 32; - final long gasNeeded = 15 + 3 * wordCount; - - yield hub.transients().op().gasAllowanceForCall() < gasNeeded; - } else { - throw new IllegalStateException(); - } - } - default -> throw new IllegalStateException(); - }; - case MODEXP -> false; - case EC_ADD -> hub.transients().op().gasAllowanceForCall() < 150; - case EC_MUL -> hub.transients().op().gasAllowanceForCall() < 6000; - case EC_PAIRING -> EcPairingFinalExponentiations.isHubFailure(hub); - case BLAKE2F -> BlakeRounds.isHubFailure(hub); - }; - - final boolean ramFailure = - !hubFailure - && switch (p) { - case EC_RECOVER, IDENTITY, RIPEMD_160, SHA2_256 -> false; - case MODEXP -> ModexpEffectiveCall.gasCost(hub) - > hub.transients().op().gasAllowanceForCall(); - case EC_ADD -> EcAddEffectiveCall.isRamFailure(hub); - case EC_MUL -> EcMulEffectiveCall.isRamFailure(hub); - case EC_PAIRING -> EcPairingFinalExponentiations.isRamFailure(hub); - case BLAKE2F -> BlakeRounds.isRamFailure(hub); - }; - - final long opCodeGas = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()).total(); - - final long precompilePrice = - hubFailure || ramFailure - ? hub.transients().op().gasAllowanceForCall() - : switch (p) { - case EC_RECOVER -> EcRecoverEffectiveCall.gasCost(); - case SHA2_256 -> Sha256Blocks.gasCost(hub); - case RIPEMD_160 -> RipemdBlocks.gasCost(hub); - case IDENTITY -> switch (hub.opCode()) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); - if (target.equals(Address.ID)) { - final long dataByteLength = hub.transients().op().callDataSegment().length(); - final long wordCount = (dataByteLength + 31) / 32; - yield 15 + 3 * wordCount; - } else { - throw new IllegalStateException(); - } - } - default -> throw new IllegalStateException(); - }; - case MODEXP -> ModexpEffectiveCall.gasCost(hub); - case EC_ADD -> EcAddEffectiveCall.gasCost(); - case EC_MUL -> EcMulEffectiveCall.gasCost(); - case EC_PAIRING -> EcPairingFinalExponentiations.gasCost(hub); - case BLAKE2F -> BlakeRounds.gasCost(hub); - }; - - final long returnGas = - hubFailure || ramFailure - ? 0 - : hub.transients().op().gasAllowanceForCall() - precompilePrice; - - PrecompileMetadata metadata = - switch (p) { - case EC_RECOVER -> EcRecoverMetadata.of(hub); - case SHA2_256 -> null; - case RIPEMD_160 -> null; - case IDENTITY -> null; - case MODEXP -> ModExpMetadata.of(hub); - case EC_ADD -> null; - case EC_MUL -> null; - case EC_PAIRING -> null; - case BLAKE2F -> BlakeRounds.metadata(hub); - }; - - return PrecompileInvocation.builder() - .precompile(p) - .metadata(metadata) - .callDataSource(hub.transients().op().callDataSegment()) - .requestedReturnDataTarget(hub.transients().op().returnDataRequestedSegment()) - .hubFailure(hubFailure) - .ramFailure(ramFailure) - .opCodeGas(opCodeGas) - .precompilePrice(precompilePrice) - .gasAtCall(hub.messageFrame().getRemainingGas()) - .gasAllowance(hub.transients().op().gasAllowanceForCall()) - .returnGas(returnGas) - .hubStamp(hub.stamp()) - .build(); + // final boolean hubFailure = + // switch (p) { + // case EC_RECOVER -> !EcRecoverEffectiveCall.hasEnoughGas(hub); + // case SHA2_256 -> !Sha256Blocks.hasEnoughGas(hub); + // case RIPEMD_160 -> !RipemdBlocks.hasEnoughGas(hub); + // case IDENTITY -> switch (hub.opCode()) { + // case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { + // final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); + // if (target.equals(Address.ID)) { + // final long dataByteLength = hub.transients().op().callDataSegment().length(); + // final long wordCount = (dataByteLength + 31) / 32; + // final long gasNeeded = 15 + 3 * wordCount; + // + // yield hub.transients().op().gasAllowanceForCall() < gasNeeded; + // } else { + // throw new IllegalStateException(); + // } + // } + // default -> throw new IllegalStateException(); + // }; + // case MODEXP -> false; + // case EC_ADD -> hub.transients().op().gasAllowanceForCall() < 150; + // case EC_MUL -> hub.transients().op().gasAllowanceForCall() < 6000; + // case EC_PAIRING -> EcPairingFinalExponentiations.isHubFailure(hub); + // case BLAKE2F -> BlakeRounds.isHubFailure(hub); + // }; + // + // final boolean ramFailure = + // !hubFailure + // && switch (p) { + // case EC_RECOVER, IDENTITY, RIPEMD_160, SHA2_256 -> false; + // case MODEXP -> ModexpEffectiveCall.gasCost(hub) + // > hub.transients().op().gasAllowanceForCall(); + // case EC_ADD -> EcAddEffectiveCall.isRamFailure(hub); + // case EC_MUL -> EcMulEffectiveCall.isRamFailure(hub); + // case EC_PAIRING -> EcPairingFinalExponentiations.isRamFailure(hub); + // case BLAKE2F -> BlakeRounds.isRamFailure(hub); + // }; + // + // final long opCodeGas = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()).total(); + // + // final long precompilePrice = + // hubFailure || ramFailure + // ? hub.transients().op().gasAllowanceForCall() + // : switch (p) { + // case EC_RECOVER -> EcRecoverEffectiveCall.gasCost(); + // case SHA2_256 -> Sha256Blocks.gasCost(hub); + // case RIPEMD_160 -> RipemdBlocks.gasCost(hub); + // case IDENTITY -> switch (hub.opCode()) { + // case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { + // final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); + // if (target.equals(Address.ID)) { + // final long dataByteLength = hub.transients().op().callDataSegment().length(); + // final long wordCount = (dataByteLength + 31) / 32; + // yield 15 + 3 * wordCount; + // } else { + // throw new IllegalStateException(); + // } + // } + // default -> throw new IllegalStateException(); + // }; + // case MODEXP -> ModexpEffectiveCall.gasCost(hub); + // case EC_ADD -> EcAddEffectiveCall.gasCost(); + // case EC_MUL -> EcMulEffectiveCall.gasCost(); + // case EC_PAIRING -> EcPairingFinalExponentiations.gasCost(hub); + // case BLAKE2F -> BlakeRounds.gasCost(hub); + // }; + // + // final long returnGas = + // hubFailure || ramFailure + // ? 0 + // : hub.transients().op().gasAllowanceForCall() - precompilePrice; + // + // PrecompileMetadata metadata = + // switch (p) { + // case EC_RECOVER -> EcRecoverMetadata.of(hub); + // case SHA2_256 -> null; + // case RIPEMD_160 -> null; + // case IDENTITY -> null; + // case MODEXP -> ModExpMetadata.of(hub); + // case EC_ADD -> null; + // case EC_MUL -> null; + // case EC_PAIRING -> null; + // case BLAKE2F -> BlakeRounds.metadata(hub); + // }; + // + // return PrecompileInvocation.builder() + // .precompile(p) + // .metadata(metadata) + // .callDataSource(hub.transients().op().callDataSegment()) + // .requestedReturnDataTarget(hub.transients().op().returnDataRequestedSegment()) + // .hubFailure(hubFailure) + // .ramFailure(ramFailure) + // .opCodeGas(opCodeGas) + // .precompilePrice(precompilePrice) + // .gasAtCall(hub.messageFrame().getRemainingGas()) + // .gasAllowance(hub.transients().op().gasAllowanceForCall()) + // .returnGas(returnGas) + // .hubStamp(hub.stamp()) + // .build(); + // + return PrecompileInvocation.builder().build(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java index 8913122a53..ec21a21c94 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java @@ -60,29 +60,29 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { // NOTE: we trigger the SHAKIRA module for nonempty call data only if (!callData.isEmpty()) { - ShakiraDataOperation shakiraCall = + final ShakiraDataOperation shakiraCall = new ShakiraDataOperation( this.callSection.hubStamp(), SHA256, callData(), callFrame.frame().getReturnData()); hub.shakiraData().call(shakiraCall); - MmuCall mmuCall = MmuCall.forShaTwoOrRipemdCallDataExtraction(hub, this); + final MmuCall mmuCall = MmuCall.forShaTwoOrRipemdCallDataExtraction(hub, this); firstImcFragment.callMmu(mmuCall); } // the full result transfer happens in all cases - ImcFragment secondImcFragment = ImcFragment.empty(hub); + final ImcFragment secondImcFragment = ImcFragment.empty(hub); this.fragments().add(secondImcFragment); - MmuCall fullOutputDataTransfer = MmuCall.forShaTwoOrRipemdFullResultTransfer(hub, this); + final MmuCall fullOutputDataTransfer = MmuCall.forShaTwoOrRipemdFullResultTransfer(hub, this); secondImcFragment.callMmu(fullOutputDataTransfer); - ImcFragment thirdImcFragment = ImcFragment.empty(hub); + final ImcFragment thirdImcFragment = ImcFragment.empty(hub); this.fragments().add(thirdImcFragment); // the partial copy of return data happens only if the caller context // provided a nonempty return data target if (!parentReturnDataTarget.isEmpty()) { - MmuCall partialReturnDataCopy = MmuCall.forShaTwoOrRipemdPartialResultCopy(hub, this); + final MmuCall partialReturnDataCopy = MmuCall.forShaTwoOrRipemdPartialResultCopy(hub, this); thirdImcFragment.callMmu(partialReturnDataCopy); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/CountingOnlyModule.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/CountingOnlyModule.java new file mode 100644 index 0000000000..32b91aba04 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/CountingOnlyModule.java @@ -0,0 +1,61 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.limits; + +import java.nio.MappedByteBuffer; +import java.util.List; + +import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.container.stacked.CountOnlyOperation; +import net.consensys.linea.zktracer.module.Module; + +public class CountingOnlyModule implements Module { + public final CountOnlyOperation counts = new CountOnlyOperation(); + + @Override + public String moduleKey() { + throw new IllegalStateException("must have been implemented by the extended class"); + } + + @Override + public void enterTransaction() { + counts.enterTransaction(); + } + + @Override + public void popTransaction() { + counts.popTransaction(); + } + + @Override + public int lineCount() { + return counts.lineCount(); + } + + public void addPrecompileLimit(final int input) { + throw new IllegalStateException("must have been implemented by the extended class"); + } + + @Override + public List columnsHeaders() { + throw new IllegalStateException("should never be called"); + } + + @Override + public void commit(List buffers) { + throw new IllegalStateException("should never be called"); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java index bb13e90f1a..df57fa6dd1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java @@ -83,6 +83,7 @@ private static int numKeccak(long x) { return (int) r; } + // TODO should die (but not yet implemented at the right place @Override public void tracePreOpcode(final MessageFrame frame) { final OpCode opCode = this.hub.opCode(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeEffectiveCall.java index dccbeef227..06e84a5623 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeEffectiveCall.java @@ -15,16 +15,10 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import java.util.List; +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; - -@RequiredArgsConstructor -public final class BlakeEffectiveCall implements Module { - @Getter private final BlakeRounds blakeRounds; +public final class BlakeEffectiveCall extends CountingOnlyModule { @Override public String moduleKey() { @@ -32,22 +26,9 @@ public String moduleKey() { } @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - int r = 0; - for (BlakeLimit count : this.blakeRounds.counts()) { - r += count.numberOfEffectiveCalls(); - } - return r; - } - - @Override - public List columnsHeaders() { - throw new UnsupportedOperationException("should never be called"); + public void addPrecompileLimit(final int numberEffectiveCall) { + Preconditions.checkArgument( + numberEffectiveCall == 1, "can't add more than one effective precompile call at a time"); + counts.add(numberEffectiveCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeLimit.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeLimit.java deleted file mode 100644 index d5c0e5fbb3..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeLimit.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.limits.precompiles; - -record BlakeLimit(int numberOfRounds, int numberOfEffectiveCalls) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeRounds.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeRounds.java index 2bb82e5f9b..5131147f2b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeRounds.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/BlakeRounds.java @@ -15,39 +15,9 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import java.nio.MappedByteBuffer; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.List; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeComponents; -import net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpData; -import net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpDataOperation; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileMetadata; -import net.consensys.linea.zktracer.module.hub.transients.OperationAncillaries; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.MemorySpan; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@RequiredArgsConstructor -@Accessors(fluent = true) -public final class BlakeRounds implements Module { - private static final int BLAKE2f_INPUT_SIZE = 213; - private final Hub hub; - - @Getter private final BlakeModexpData blakeModexpData; - - @Getter private final Deque counts = new ArrayDeque<>(); +public final class BlakeRounds extends CountingOnlyModule { @Override public String moduleKey() { @@ -55,163 +25,7 @@ public String moduleKey() { } @Override - public void traceStartConflation(final long blockCount) { - counts.push(new BlakeLimit(0, 0)); - } - - @Override - public void enterTransaction() { - counts.push(counts.getFirst()); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - public static boolean isHubFailure(final Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - final long length = hub.transients().op().callDataSegment().length(); - return length != BLAKE2f_INPUT_SIZE; - } - } - - return false; - } - - public static boolean isRamFailure(final Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - if (isHubFailure(hub)) { - return false; - } - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - final long offset = hub.transients().op().callDataSegment().offset(); - final int f = - frame.shadowReadMemory(offset, BLAKE2f_INPUT_SIZE).get(BLAKE2f_INPUT_SIZE - 1); - final int r = - frame - .shadowReadMemory(offset, BLAKE2f_INPUT_SIZE) - .slice(0, 4) - .toInt(); // The number of round is equal to the gas to pay - return !((f == 0 || f == 1) && hub.transients().op().gasAllowanceForCall() >= r); - } - } - - return false; - } - - public static long gasCost(final Hub hub) { - final MessageFrame frame = hub.messageFrame(); - final Address target = Words.toAddress(frame.getStackItem(1)); - - if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - final MemorySpan callData = hub.transients().op().callDataSegment(); - final int blake2fDataSize = 213; - if (callData.length() == blake2fDataSize) { - final int f = - frame.shadowReadMemory(callData.offset(), callData.length()).get(blake2fDataSize - 1); - if (f == 0 || f == 1) { - return frame - .shadowReadMemory(callData.offset(), callData.length()) - .slice(0, 4) - .toInt(); // The number of round is equal to the gas to pay - } - } - } - - return 0; - } - - public static PrecompileMetadata metadata(final Hub hub) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); - if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - final long length = hub.transients().op().callDataSegment().length(); - - if (length == BLAKE2f_INPUT_SIZE) { - final int f = hub.transients().op().callData().get(BLAKE2f_INPUT_SIZE - 1); - if (f == 0 || f == 1) { - final int r = - hub.transients() - .op() - .callData() - .slice(0, 4) - .toInt(); // The number of round is equal to the gas to pay - return new Blake2fMetadata(r, f); - } - } - } - } - - return new Blake2fMetadata(0, 0); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - - if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { - final OperationAncillaries opInfo = hub.transients().op(); - final long length = opInfo.callDataSegment().length(); - - if (length == BLAKE2f_INPUT_SIZE) { - final Bytes inputData = opInfo.callData(); - final int f = inputData.get(BLAKE2f_INPUT_SIZE - 1); - if (f == 0 || f == 1) { - final Bytes r = inputData.slice(0, 4); // The number of round is equal to the gas to pay - - final int rInt = r.toInt(); - - if (opInfo.gasAllowanceForCall() >= rInt) { - final Bytes data = inputData.slice(4, BLAKE2f_INPUT_SIZE - 5); - this.blakeModexpData.call( - new BlakeModexpDataOperation( - hub.stamp(), null, new BlakeComponents(data, r, Bytes.of(f)))); - - final BlakeLimit currentLimit = this.counts.pop(); - this.counts.push( - new BlakeLimit( - currentLimit.numberOfRounds() + rInt, - currentLimit.numberOfEffectiveCalls() + 1)); - } - } - } - } - } - } - - @Override - public int lineCount() { - final long totalR = counts.stream().mapToLong(BlakeLimit::numberOfRounds).sum(); - if (totalR > Integer.MAX_VALUE) { - throw new RuntimeException("Ludicrous BlakeLimit calls"); - } - - return (int) totalR; - } - - @Override - public List columnsHeaders() { - throw new UnsupportedOperationException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new UnsupportedOperationException("should never be called"); + public void addPrecompileLimit(final int r) { + counts.add(r); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java index e3022205e6..7f49e0817c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java @@ -15,85 +15,20 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import static net.consensys.linea.zktracer.CurveOperations.isOnC1; -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.Stack; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.MemorySpan; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@RequiredArgsConstructor -public final class EcAddEffectiveCall implements Module { - private final Hub hub; - private final Stack counts = new Stack<>(); +public final class EcAddEffectiveCall extends CountingOnlyModule { @Override public String moduleKey() { return "PRECOMPILE_ECADD_EFFECTIVE_CALLS"; } - private static final int PRECOMPILE_GAS_FEE = 150; // cf EIP-1108 - - @Override - public void enterTransaction() { - counts.push(0); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ALTBN128_ADD) - && hub.transients().op().gasAllowanceForCall() >= PRECOMPILE_GAS_FEE) { - this.counts.push(this.counts.pop() + 1); - } - } - } - - public static boolean isRamFailure(final Hub hub) { - final MessageFrame frame = hub.messageFrame(); - final MemorySpan callDataSource = hub.transients().op().callDataSegment(); - final Bytes callData = - rightPadTo( - frame.shadowReadMemory(callDataSource.offset(), Math.min(callDataSource.length(), 128)), - 128); - return !isOnC1(callData.slice(0, 64)) || !isOnC1(callData.slice(64, 64)); - } - - public static long gasCost() { - return PRECOMPILE_GAS_FEE; - } - - @Override - public int lineCount() { - return this.counts.stream().mapToInt(x -> x).sum(); - } - - @Override - public List columnsHeaders() { - throw new IllegalStateException("should never be called"); - } - @Override - public void commit(List buffers) { - throw new IllegalStateException("should never be called"); + public void addPrecompileLimit(final int numberEffectiveCall) { + Preconditions.checkArgument( + numberEffectiveCall == 1, "can't add more than one effective precompile call at a time"); + counts.add(numberEffectiveCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java index a1878520d0..6f5b1900d7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java @@ -15,86 +15,22 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import static net.consensys.linea.zktracer.CurveOperations.isOnC1; -import static net.consensys.linea.zktracer.types.Utils.rightPadTo; - -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.Stack; - +import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.MemorySpan; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; @RequiredArgsConstructor -public final class EcMulEffectiveCall implements Module { - private final Hub hub; - private final Stack counts = new Stack<>(); +public final class EcMulEffectiveCall extends CountingOnlyModule { @Override public String moduleKey() { return "PRECOMPILE_ECMUL_EFFECTIVE_CALLS"; } - private static final int PRECOMPILE_GAS_FEE = 6000; // cf EIP-1108 - - @Override - public void enterTransaction() { - counts.push(0); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ALTBN128_MUL) - && hub.transients().op().gasAllowanceForCall() >= PRECOMPILE_GAS_FEE) { - this.counts.push(this.counts.pop() + 1); - } - } - } - - public static boolean isRamFailure(final Hub hub) { - final MessageFrame frame = hub.messageFrame(); - final MemorySpan callDataSource = hub.transients().op().callDataSegment(); - - final Bytes callData = - rightPadTo( - frame.shadowReadMemory(callDataSource.offset(), Math.min(callDataSource.length(), 96)), - 96); - return !isOnC1(callData); - } - - public static long gasCost() { - return PRECOMPILE_GAS_FEE; - } - - @Override - public int lineCount() { - return this.counts.stream().mapToInt(x -> x).sum(); - } - - @Override - public List columnsHeaders() { - throw new IllegalStateException("should never be called"); - } - @Override - public void commit(List buffers) { - throw new IllegalStateException("should never be called"); + public void addPrecompileLimit(final int numberEffectiveCall) { + Preconditions.checkArgument( + numberEffectiveCall == 1, "can't add more than one effective precompile call at a time"); + this.counts.add(numberEffectiveCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingFinalExponentiations.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingFinalExponentiations.java index 3f6c9d8a49..52b7ce88e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingFinalExponentiations.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingFinalExponentiations.java @@ -17,35 +17,16 @@ import static net.consensys.linea.zktracer.CurveOperations.*; -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.Stack; - -import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.MemorySpan; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.crypto.altbn128.AltBn128Fq2Point; -import org.hyperledger.besu.crypto.altbn128.AltBn128Point; -import org.hyperledger.besu.crypto.altbn128.Fq; -import org.hyperledger.besu.crypto.altbn128.Fq2; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; @Slf4j @RequiredArgsConstructor @Accessors(fluent = true) -public final class EcPairingFinalExponentiations implements Module { - private final Hub hub; - @Getter private final Stack counts = new Stack<>(); +public final class EcPairingFinalExponentiations extends CountingOnlyModule { + private static final int PRECOMPILE_BASE_GAS_FEE = 45_000; // cf EIP-1108 private static final int PRECOMPILE_MILLER_LOOP_GAS_FEE = 34_000; // cf EIP-1108 private static final int ECPAIRING_NB_BYTES_PER_MILLER_LOOP = 192; @@ -58,303 +39,7 @@ public String moduleKey() { } @Override - public void enterTransaction() { - counts.push(new EcPairingTallier(0, 0, 0)); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public int lineCount() { - int r = 0; - for (EcPairingTallier count : this.counts) { - r += (int) count.numberOfFinalExponentiations(); - } - return r; - } - - @Override - public List columnsHeaders() { - throw new UnsupportedOperationException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new UnsupportedOperationException("should never be called"); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - - if (irrelevantOperation(frame)) { - return; - } - - final MemorySpan callDataSpan = hub.transients().op().callDataSegment(); - final long callDataSize = callDataSpan.length(); - final long callDataSizeMod192 = callDataSize % ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - final long nMillerLoop = (callDataSize / ECPAIRING_NB_BYTES_PER_MILLER_LOOP); - if (callDataSizeMod192 != 0) { - log.warn( - "[ECPAIRING] faulty call data size: {} ≡ {} mod {}", - callDataSize, - callDataSizeMod192, - ECPAIRING_NB_BYTES_PER_MILLER_LOOP); - return; - } - - final long gasAllowance = hub.transients().op().gasAllowanceForCall(); - final long precompileCost = - PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_MILLER_LOOP_GAS_FEE * nMillerLoop; - if (gasAllowance < precompileCost) { - log.warn( - "[ECPAIRING] insufficient gas: gas allowance = {}, precompile cost = {}", - gasAllowance, - precompileCost); - return; - } - - if (callDataSize == 0) { - return; - } - - /* - At this point: - - call data size is a positive multiple of 192 - - the precompile call is given sufficient gas - */ - - final EcPairingTallier currentEcpairingTallier = this.counts.pop(); - final long additionalRows = 12 * nMillerLoop + 2; - - if (!internalChecksPassed(frame, callDataSpan)) { - this.counts.push( - new EcPairingTallier( - currentEcpairingTallier.numberOfMillerLoops(), - currentEcpairingTallier.numberOfFinalExponentiations(), - currentEcpairingTallier.numberOfG2MembershipTests())); - return; - } - - if (callDataContainsMalformedLargePoint(frame, callDataSpan)) { - this.counts.push( - new EcPairingTallier( - currentEcpairingTallier.numberOfMillerLoops(), - currentEcpairingTallier.numberOfFinalExponentiations(), - currentEcpairingTallier.numberOfG2MembershipTests() + 1)); - return; - } - - EcpairingCounts preciseCount = preciseCount(frame, callDataSpan); - - this.counts.push( - new EcPairingTallier( - currentEcpairingTallier.numberOfMillerLoops() + preciseCount.nontrivialPairs(), - currentEcpairingTallier.numberOfFinalExponentiations() + preciseCount.nontrivialPairs() - == 0 - ? 0 - : 1, - currentEcpairingTallier.numberOfG2MembershipTests() + preciseCount.membershipTests())); - } - - public static boolean isHubFailure(final Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ALTBN128_PAIRING)) { - long length = hub.transients().op().callDataSegment().length(); - if (length % 192 != 0) { - return true; - } - final long pairingCount = length / ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - - return hub.transients().op().gasAllowanceForCall() - < PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_MILLER_LOOP_GAS_FEE * pairingCount; - } - } - - return false; - } - - public static boolean isRamFailure(final Hub hub) { - final MessageFrame frame = hub.messageFrame(); - long length = hub.transients().op().callDataSegment().length(); - - if (length == 0) { - return true; - } - - for (int i = 0; i < length; i += 192) { - final Bytes coordinates = frame.shadowReadMemory(i, 192); - if (!isOnC1(coordinates.slice(0, 64)) || !isOnG2(coordinates.slice(64, 128))) { - return true; - } - } - - return false; - } - - public static long gasCost(final Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - if (irrelevantOperation(hub.messageFrame())) { - return 0; - } - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ALTBN128_PAIRING)) { - final long length = hub.transients().op().callDataSegment().length(); - final long nMillerLoop = (length / ECPAIRING_NB_BYTES_PER_MILLER_LOOP); - if (nMillerLoop * ECPAIRING_NB_BYTES_PER_MILLER_LOOP != length) { - return 0; - } - - return PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_MILLER_LOOP_GAS_FEE * nMillerLoop; - } - } - - return 0; - } - - /** - * Specifies if an opcode is irrelevant to the tracing of ECPAIRING. - * - * @param frame - * @return true if the current operation is either not a call or would throw a stack exception; - * otherwise it returns true if the target of the CALL isn't the ECPAIRING precompile; - */ - static boolean irrelevantOperation(MessageFrame frame) { - final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - - if (!opCode.isCall() || frame.stackSize() < 2) { - return true; - } - - final Address target = Words.toAddress(frame.getStackItem(1)); - return !target.equals(Address.ALTBN128_PAIRING); - } - - private boolean internalChecksPassed(MessageFrame frame, MemorySpan callData) { - long offset = callData.offset(); - long nPairsOfPoints = callData.length() / ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - - for (long i = 0; i < nPairsOfPoints; i++) { - final Bytes coordinates = frame.shadowReadMemory(offset, ECPAIRING_NB_BYTES_PER_MILLER_LOOP); - - if (!isOnC1(coordinates.slice(0, ECPAIRING_NB_BYTES_PER_SMALL_POINT))) { - return false; - } - - final BigInteger pXIm = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT, 32)); - final BigInteger pXRe = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT + 32, 32)); - final BigInteger pYIm = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT + 64, 32)); - final BigInteger pYRe = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT + 96, 32)); - final Fq2 pX = Fq2.create(pXRe, pXIm); - final Fq2 pY = Fq2.create(pYRe, pYIm); - - if (!pX.isValid() || !pY.isValid()) { - return false; - } - - offset += ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - } - - return true; - } - - private boolean callDataContainsMalformedLargePoint(MessageFrame frame, MemorySpan callData) { - long offset = callData.offset(); - long nPairsOfPoints = callData.length() / ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - - for (long i = 0; i < nPairsOfPoints; i++) { - final Bytes largeCoordinates = - frame.shadowReadMemory( - offset + ECPAIRING_NB_BYTES_PER_SMALL_POINT, ECPAIRING_NB_BYTES_PER_LARGE_POINT); - - // curve membership implicitly tested - if (!isOnG2(largeCoordinates)) { - return false; - } - - offset += ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - } - - return true; - } - - @Getter - private class EcpairingCounts { - int nontrivialPairs; // a pair of the form (A, B) with [A ≠ ∞] ∧ [B ≠ ∞] - int membershipTests; // a pair of the form (A, B) with [A ≡ ∞] ∧ [B ≠ ∞] - int trivialPairs; // a pair of the form (A, B) with [B ≡ ∞]; likely useless ... - - private void incrementPairingPairs() { - this.nontrivialPairs++; - } - - private void incrementMembershipTests() { - this.membershipTests++; - } - - private void incrementTrivialPairs() { - this.trivialPairs++; - } - } - - private EcpairingCounts preciseCount(MessageFrame frame, MemorySpan callData) { - EcpairingCounts counts = new EcpairingCounts(); - - long offset = callData.offset(); - long nPairsOfPoints = callData.length() / ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - - for (long i = 0; i < nPairsOfPoints; i++) { - final Bytes coordinates = frame.shadowReadMemory(offset, ECPAIRING_NB_BYTES_PER_MILLER_LOOP); - - final BigInteger smallPointX = extractParameter(coordinates.slice(0, 32)); - final BigInteger smallPointY = extractParameter(coordinates.slice(32, 32)); - final AltBn128Point smallPoint = - new AltBn128Point(Fq.create(smallPointX), Fq.create(smallPointY)); - final boolean smallPointIsPointAtInfinity = smallPoint.isInfinity(); - - final BigInteger largePointXIm = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT, 32)); - final BigInteger largePointXRe = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT + 32, 32)); - final BigInteger largePointYIm = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT + 64, 32)); - final BigInteger largePointYRe = - extractParameter(coordinates.slice(ECPAIRING_NB_BYTES_PER_SMALL_POINT + 96, 32)); - final Fq2 largePointX = Fq2.create(largePointXRe, largePointXIm); - final Fq2 largePointY = Fq2.create(largePointYRe, largePointYIm); - AltBn128Fq2Point largePoint = new AltBn128Fq2Point(largePointX, largePointY); - final boolean largePointIsPointAtInfinity = largePoint.isInfinity(); - - if (largePointIsPointAtInfinity) { - counts.incrementTrivialPairs(); - } - - if (!smallPointIsPointAtInfinity && !largePointIsPointAtInfinity) { - counts.incrementPairingPairs(); - } - - if (smallPointIsPointAtInfinity && !largePointIsPointAtInfinity) { - counts.incrementMembershipTests(); - } - - offset += ECPAIRING_NB_BYTES_PER_MILLER_LOOP; - } - - return counts; + public void addPrecompileLimit(final int input) { + // TODO @Lorenzo } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingG2MembershipCalls.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingG2MembershipCalls.java index eda89c70f3..3a3fade6f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingG2MembershipCalls.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingG2MembershipCalls.java @@ -14,16 +14,9 @@ */ package net.consensys.linea.zktracer.module.limits.precompiles; -import java.nio.MappedByteBuffer; -import java.util.List; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; - -@RequiredArgsConstructor -public class EcPairingG2MembershipCalls implements Module { - private final EcPairingFinalExponentiations ecPairingFinalExponentiations; +public class EcPairingG2MembershipCalls extends CountingOnlyModule { @Override public String moduleKey() { @@ -31,33 +24,7 @@ public String moduleKey() { } @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - long g2MembershipTests = 0; - - for (EcPairingTallier count : this.ecPairingFinalExponentiations.counts()) { - g2MembershipTests += count.numberOfG2MembershipTests(); - } - - if (g2MembershipTests > Integer.MAX_VALUE) { - throw new RuntimeException("Ludicrous amount of " + moduleKey()); - } - - return (int) g2MembershipTests; - } - - @Override - public List columnsHeaders() { - throw new UnsupportedOperationException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new UnsupportedOperationException("should never be called"); + public void addPrecompileLimit(final int input) { + // TODO @LOrenzo } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoops.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoops.java index 15177d8b88..eff44a274d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoops.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoops.java @@ -15,16 +15,9 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import java.nio.MappedByteBuffer; -import java.util.List; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; - -@RequiredArgsConstructor -public final class EcPairingMillerLoops implements Module { - private final EcPairingFinalExponentiations ecpairingCall; +public final class EcPairingMillerLoops extends CountingOnlyModule { @Override public String moduleKey() { @@ -32,33 +25,7 @@ public String moduleKey() { } @Override - public void enterTransaction() {} - - @Override - public void popTransaction() {} - - @Override - public int lineCount() { - long r = 0; - - for (EcPairingTallier count : this.ecpairingCall.counts()) { - r += count.numberOfMillerLoops(); - } - - if (r > Integer.MAX_VALUE) { - throw new RuntimeException("Ludicrous EcPairing calls"); - } - - return (int) r; - } - - @Override - public List columnsHeaders() { - throw new UnsupportedOperationException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new UnsupportedOperationException("should never be called"); + public void addPrecompileLimit(final int input) { + // TODO @Lorenzo } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingTallier.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingTallier.java deleted file mode 100644 index 75005b0d9d..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingTallier.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.limits.precompiles; - -record EcPairingTallier( - long numberOfMillerLoops, long numberOfFinalExponentiations, long numberOfG2MembershipTests) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java index 30e540d1df..c69c757c07 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java @@ -15,118 +15,22 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import static net.consensys.linea.zktracer.module.Util.slice; - -import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.List; -import java.util.Stack; - +import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.MemorySpan; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; @RequiredArgsConstructor -public final class EcRecoverEffectiveCall implements Module { - private final Hub hub; - private final Stack counts = new Stack<>(); +public final class EcRecoverEffectiveCall extends CountingOnlyModule { @Override public String moduleKey() { return "PRECOMPILE_ECRECOVER_EFFECTIVE_CALLS"; } - private static final int ECRECOVER_GAS_FEE = 3000; - private static final int EWORD_SIZE = 32; - private static final BigInteger SECP_256_K1N = - new BigInteger( - "115792089237316195423570985008687907852837564279074904382605163141518161494337"); - - @Override - public void enterTransaction() { - counts.push(0); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - public static boolean hasEnoughGas(Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ECREC)) { - return hub.transients().op().gasAllowanceForCall() >= ECRECOVER_GAS_FEE; - } - } - } - - return false; - } - - public static boolean isValid(final Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.ECREC)) { - final MemorySpan callData = hub.transients().op().callDataSegment(); - final Bytes inputData = frame.shadowReadMemory(callData.offset(), callData.length()); - final BigInteger v = slice(inputData, EWORD_SIZE, EWORD_SIZE).toUnsignedBigInteger(); - final BigInteger r = slice(inputData, EWORD_SIZE * 2, EWORD_SIZE).toUnsignedBigInteger(); - final BigInteger s = slice(inputData, EWORD_SIZE * 3, EWORD_SIZE).toUnsignedBigInteger(); - // TODO: exclude case without valid signature - return hasEnoughGas(hub) - && (v.equals(BigInteger.valueOf(27)) || v.equals(BigInteger.valueOf(28))) - && !r.equals(BigInteger.ZERO) - && r.compareTo(SECP_256_K1N) < 0 - && !s.equals(BigInteger.ZERO) - && s.compareTo(SECP_256_K1N) < 0; - } - } - - return false; - } - - public static long gasCost() { - return ECRECOVER_GAS_FEE; - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - if (isValid(hub)) { - this.counts.push(this.counts.pop() + 1); - } - } - - @Override - public int lineCount() { - int r = 0; - for (int i = 0; i < this.counts.size(); i++) { - r += this.counts.get(i); - } - return r; - } - - @Override - public List columnsHeaders() { - throw new IllegalStateException("should never be called"); - } - @Override - public void commit(List buffers) { - throw new IllegalStateException("should never be called"); + public void addPrecompileLimit(final int numberEffectiveCall) { + Preconditions.checkArgument( + numberEffectiveCall == 1, "can't add more than one effective precompile call at a time"); + counts.add(numberEffectiveCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java index 8590bbae86..6e927ad734 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java @@ -15,39 +15,19 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import static net.consensys.linea.zktracer.module.Util.slice; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; - import java.math.BigInteger; -import java.nio.MappedByteBuffer; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.List; -import lombok.Getter; +import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpData; -import net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpDataOperation; -import net.consensys.linea.zktracer.module.blake2fmodexpdata.ModexpComponents; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; @Slf4j @RequiredArgsConstructor @Accessors(fluent = true) -public class ModexpEffectiveCall implements Module { - private final Hub hub; +public class ModexpEffectiveCall extends CountingOnlyModule { - @Getter private final BlakeModexpData blakeModexpData; - private final Deque counts = new ArrayDeque<>(); private static final BigInteger PROVER_MAX_INPUT_BYTE_SIZE = BigInteger.valueOf(4096 / 8); @Override @@ -56,171 +36,9 @@ public String moduleKey() { } @Override - public void traceStartConflation(final long blockCount) { - counts.push(0); - } - - @Override - public void enterTransaction() { - counts.push(counts.getFirst()); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.MODEXP)) { - final Bytes inputData = hub.transients().op().callData(); - - // Get the Base length - final BigInteger baseLength = slice(inputData, 0, WORD_SIZE).toUnsignedBigInteger(); - if (isOutOfProverInputBounds(baseLength)) { - log.info( - "Too big argument, base byte length = {} > {}", - baseLength, - PROVER_MAX_INPUT_BYTE_SIZE); - this.counts.pop(); - this.counts.push(Integer.MAX_VALUE); - return; - } - - // Get the Exponent length - final BigInteger expLength = slice(inputData, WORD_SIZE, WORD_SIZE).toUnsignedBigInteger(); - if (isOutOfProverInputBounds(expLength)) { - log.info( - "Too big argument, exponent byte length = {} > {}", - expLength, - PROVER_MAX_INPUT_BYTE_SIZE); - this.counts.pop(); - this.counts.push(Integer.MAX_VALUE); - return; - } - - // Get the Modulo length - final BigInteger modLength = - slice(inputData, 2 * WORD_SIZE, WORD_SIZE).toUnsignedBigInteger(); - if (isOutOfProverInputBounds(modLength)) { - log.info( - "Too big argument, modulo byte length = {} > {}", - modLength, - PROVER_MAX_INPUT_BYTE_SIZE); - this.counts.pop(); - this.counts.push(Integer.MAX_VALUE); - return; - } - - final int baseLengthInt = baseLength.intValueExact(); - final int expLengthInt = expLength.intValueExact(); - final int modLengthInt = modLength.intValueExact(); - - // Get the Base. - final Bytes baseComponent = slice(inputData, 3 * WORD_SIZE, baseLengthInt); - - // Get the Exponent. - final Bytes expComponent = - slice(inputData, 3 * WORD_SIZE + baseLengthInt, expLength.intValueExact()); - - // Get the Modulus. - final Bytes modComponent = - slice( - inputData, 3 * WORD_SIZE + baseLengthInt + expLengthInt, modLength.intValueExact()); - final long gasPrice = gasPrice(baseLengthInt, expLengthInt, modLengthInt, expComponent); - - if (hub.transients().op().gasAllowanceForCall() >= gasPrice) { - this.blakeModexpData.call( - new BlakeModexpDataOperation( - hub.stamp(), - new ModexpComponents(baseComponent, expComponent, modComponent), - null)); - this.counts.push(this.counts.pop() + 1); - } - } - } - } - - public static long gasCost(final Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.MODEXP)) { - final Bytes inputData = hub.transients().op().callData(); - - // Get the Base length - final BigInteger baseLength = slice(inputData, 0, WORD_SIZE).toUnsignedBigInteger(); - if (isOutOfProverInputBounds(baseLength)) { - return 0; - } - - // Get the Exponent length - final BigInteger expLength = slice(inputData, WORD_SIZE, WORD_SIZE).toUnsignedBigInteger(); - if (isOutOfProverInputBounds(expLength)) { - return 0; - } - - // Get the Modulo length - final BigInteger modLength = - slice(inputData, 2 * WORD_SIZE, WORD_SIZE).toUnsignedBigInteger(); - if (isOutOfProverInputBounds(modLength)) { - return 0; - } - - final int baseLengthInt = baseLength.intValueExact(); - final int expLengthInt = expLength.intValueExact(); - final int modLengthInt = modLength.intValueExact(); - - // Get the Exponent. - final Bytes expComponent = - slice(inputData, 3 * WORD_SIZE + baseLengthInt, expLength.intValueExact()); - - return gasPrice(baseLengthInt, expLengthInt, modLengthInt, expComponent); - } - } - - return 0; - } - - private static long gasPrice(int baseLength, int expLength, int moduloLength, Bytes e) { - final long maxLbLmSquared = - (long) Math.pow((double) (Math.max(baseLength, moduloLength) + 7) / 8, 2); - final long secondArg = (maxLbLmSquared * expLengthPrime(expLength, e)) / 3; - - return Math.max(200, secondArg); - } - - private static int expLengthPrime(int expLength, Bytes e) { - if (expLength <= 32) { - return e.isZero() ? 0 : e.toUnsignedBigInteger().bitLength() - 1; - } - - final Bytes leadingWord = e.slice(0, WORD_SIZE); - return 8 * (expLength - 32) + Math.max(leadingWord.bitLength() - 1, 0); - } - - private static boolean isOutOfProverInputBounds(BigInteger modexpComponentLength) { - return modexpComponentLength.compareTo(PROVER_MAX_INPUT_BYTE_SIZE) > 0; - } - - @Override - public int lineCount() { - return this.counts.getFirst(); - } - - @Override - public List columnsHeaders() { - throw new UnsupportedOperationException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new UnsupportedOperationException("should never be called"); + public void addPrecompileLimit(final int numberEffectiveCall) { + Preconditions.checkArgument( + numberEffectiveCall == 1, "can't add more than one effective precompile call at a time"); + this.counts.add(numberEffectiveCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java index 76006fd6f9..2b8228312c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/RipemdBlocks.java @@ -15,30 +15,11 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE_MO; - -import java.nio.MappedByteBuffer; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.List; - -import lombok.Getter; import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraData; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; @RequiredArgsConstructor -public final class RipemdBlocks implements Module { +public final class RipemdBlocks extends CountingOnlyModule { private static final int PRECOMPILE_BASE_GAS_FEE = 600; private static final int PRECOMPILE_GAS_FEE_PER_EWORD = 120; private static final int RIPEMD160_BLOCKSIZE = 64 * 8; @@ -46,98 +27,22 @@ public final class RipemdBlocks implements Module { private static final int RIPEMD160_LENGTH_APPEND = 64; private static final int RIPEMD160_ND_PADDED_ONE = 1; - private final Hub hub; - private final Deque counts = new ArrayDeque<>(); - @Override public String moduleKey() { return "PRECOMPILE_RIPEMD_BLOCKS"; } - @Getter private final ShakiraData shakiraData; - @Override - public void traceStartConflation(final long blockCount) { - counts.push(0); + public void addPrecompileLimit(final int input) { + final int blockCount = numberOfRipemd160locks(input); + this.counts.add(blockCount); } - @Override - public void enterTransaction() { - counts.push(counts.getFirst()); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - public static boolean hasEnoughGas(final Hub hub) { - return hub.transients().op().gasAllowanceForCall() <= gasCost(hub); - } - - public static long gasCost(final Hub hub) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); - if (target.equals(Address.RIPEMD160)) { - final long dataByteLength = hub.transients().op().callDataSegment().length(); - final long wordCount = (dataByteLength + WORD_SIZE_MO) / WORD_SIZE; - return PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_GAS_FEE_PER_EWORD * wordCount; - } - } - - return 0; - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.RIPEMD160)) { - final long dataByteLength = hub.transients().op().callDataSegment().length(); - - if (dataByteLength == 0) { - return; - } // skip trivial hash TODO: check the prover does skip it - - final int blockCount = - (int) - (dataByteLength * 8 - + RIPEMD160_ND_PADDED_ONE - + RIPEMD160_LENGTH_APPEND - + (RIPEMD160_BLOCKSIZE - 1)) - / RIPEMD160_BLOCKSIZE; - - final long wordCount = (dataByteLength + WORD_SIZE_MO) / WORD_SIZE; - final long gasNeeded = PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_GAS_FEE_PER_EWORD * wordCount; - - final Bytes inputData = hub.transients().op().callData(); - - if (hub.transients().op().gasAllowanceForCall() >= gasNeeded) { - this.shakiraData.call( - new ShakiraDataOperation(hub.stamp(), ShakiraHashType.RIPEMD, inputData)); - - this.counts.push(this.counts.pop() + blockCount); - } - } - } - } - - @Override - public int lineCount() { - return this.counts.getFirst(); - } - - @Override - public List columnsHeaders() { - throw new IllegalStateException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new IllegalStateException("should never be called"); + private static int numberOfRipemd160locks(final int dataByteLength) { + return (dataByteLength * 8 + + RIPEMD160_ND_PADDED_ONE + + RIPEMD160_LENGTH_APPEND + + (RIPEMD160_BLOCKSIZE - 1)) + / RIPEMD160_BLOCKSIZE; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java index d451753ef7..77a013c4c6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java @@ -15,30 +15,9 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE_MO; +import net.consensys.linea.zktracer.module.limits.CountingOnlyModule; -import java.nio.MappedByteBuffer; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.List; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraData; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -@RequiredArgsConstructor -public final class Sha256Blocks implements Module { +public final class Sha256Blocks extends CountingOnlyModule { private static final int PRECOMPILE_BASE_GAS_FEE = 60; private static final int PRECOMPILE_GAS_FEE_PER_EWORD = 12; @@ -47,94 +26,22 @@ public final class Sha256Blocks implements Module { private static final int SHA256_PADDING_LENGTH = 64; private static final int SHA256_NB_PADDED_ONE = 1; - private final Hub hub; - private final Deque counts = new ArrayDeque<>(); - - @Getter private final ShakiraData shakiraData; - @Override public String moduleKey() { return "PRECOMPILE_SHA2_BLOCKS"; } @Override - public void traceStartConflation(final long blockCount) { - counts.push(0); - } - - @Override - public void enterTransaction() { - counts.push(counts.getFirst()); - } - - @Override - public void popTransaction() { - counts.pop(); - } - - public static boolean hasEnoughGas(final Hub hub) { - return hub.transients().op().gasAllowanceForCall() >= gasCost(hub); - } - - public static long gasCost(final Hub hub) { - final OpCode opCode = hub.opCode(); - final MessageFrame frame = hub.messageFrame(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.SHA256)) { - final long dataByteLength = hub.transients().op().callDataSegment().length(); - final long wordCount = (dataByteLength + WORD_SIZE_MO) / WORD_SIZE; - return PRECOMPILE_BASE_GAS_FEE + PRECOMPILE_GAS_FEE_PER_EWORD * wordCount; - } - } - - return 0; - } - - @Override - public void tracePreOpcode(MessageFrame frame) { - final OpCode opCode = hub.opCode(); - - if (opCode.isCall()) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (target.equals(Address.SHA256)) { - final long dataByteLength = hub.transients().op().callDataSegment().length(); - if (dataByteLength == 0) { - return; - } - final int blockCount = - (int) - (dataByteLength * 8 - + SHA256_NB_PADDED_ONE - + SHA256_PADDING_LENGTH - + (SHA256_BLOCKSIZE - 1)) - / SHA256_BLOCKSIZE; - - final Bytes inputData = hub.transients().op().callData(); - - if (hasEnoughGas(this.hub)) { - this.shakiraData.call( - new ShakiraDataOperation(hub.stamp(), ShakiraHashType.SHA256, inputData)); - - this.counts.push(this.counts.pop() + blockCount); - } - } - } + public void addPrecompileLimit(final int input) { + final int blockCount = numberOfSha256Blocks(input); + this.counts.add(blockCount); } - @Override - public int lineCount() { - return counts.getFirst(); - } - - @Override - public List columnsHeaders() { - throw new IllegalStateException("should never be called"); - } - - @Override - public void commit(List buffers) { - throw new IllegalStateException("should never be called"); + private static int numberOfSha256Blocks(final int dataByteLength) { + return (dataByteLength * 8 + + SHA256_NB_PADDED_ONE + + SHA256_PADDING_LENGTH + + (SHA256_BLOCKSIZE - 1)) + / SHA256_BLOCKSIZE; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java index 26eb8465c0..a0de259773 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java @@ -25,6 +25,8 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; +import net.consensys.linea.zktracer.module.limits.precompiles.RipemdBlocks; +import net.consensys.linea.zktracer.module.limits.precompiles.Sha256Blocks; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -37,6 +39,9 @@ public class ShakiraData implements Module { private int numberOfOperationsAtStartTx = 0; private final ShakiraDataComparator comparator = new ShakiraDataComparator(); + private final Sha256Blocks sha256Blocks; + private final RipemdBlocks ripemdBlocks; + @Override public String moduleKey() { return "SHAKIRA_DATA"; @@ -56,7 +61,7 @@ public void popTransaction() { @Override public int lineCount() { return this.operations.lineCount() - + 1; /*because the lookup HUB -> SHAKIRA requires at least two padding rows. TODO: should be done by Corset */ + + 1; /*because the lookup HUB -> SHAKIRA requires at least two padding rows. TODO: shouldn't it be done by Corset via the spilling ? */ } @Override @@ -68,6 +73,14 @@ public void call(final ShakiraDataOperation operation) { this.operations.add(operation); this.wcp.callGT(operation.lastNBytes(), 0); this.wcp.callLEQ(operation.lastNBytes(), LLARGE); + + switch (operation.precompileType()) { + case SHA256 -> sha256Blocks.addPrecompileLimit(operation.inputSize()); + case KECCAK -> { // TODO + } + case RIPEMD -> ripemdBlocks.addPrecompileLimit(operation.inputSize()); + default -> throw new IllegalArgumentException("Precompile type not supported by SHAKIRA"); + } } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java index e656664807..e6ae1ab58b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java @@ -41,10 +41,10 @@ @Accessors(fluent = true) public class ShakiraDataOperation extends ModuleOperation { - private final ShakiraHashType precompileType; + @Getter private final ShakiraHashType precompileType; private final Bytes hashInput; @Getter private final long ID; - private final int inputSize; + @Getter private final int inputSize; @Getter private final short lastNBytes; private final int indexMaxData; private Bytes32 result; From e5674b66779961c43beafd913982b6d7da669c08 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 30 Jul 2024 16:39:18 +0530 Subject: [PATCH 322/461] implement keccak count --- .../linea/zktracer/module/hub/Hub.java | 51 +++--- .../linea/zktracer/module/limits/Keccak.java | 146 +++++------------- .../module/shakiradata/ShakiraData.java | 5 +- 3 files changed, 68 insertions(+), 134 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6036458f9f..33caf1dcc4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -79,6 +79,7 @@ import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.hub.transients.Transients; +import net.consensys.linea.zktracer.module.limits.Keccak; import net.consensys.linea.zktracer.module.limits.L2Block; import net.consensys.linea.zktracer.module.limits.L2L1Logs; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeEffectiveCall; @@ -233,6 +234,8 @@ public int lineCount() { * Those modules are not traced, we just compute the number of calls to those * precompile to meet the prover limits */ + private final Keccak keccak; + private final Sha256Blocks sha256Blocks = new Sha256Blocks(); private final EcAddEffectiveCall ecAddEffectiveCall = new EcAddEffectiveCall(); @@ -252,25 +255,28 @@ public int lineCount() { private final BlakeEffectiveCall blakeEffectiveCall = new BlakeEffectiveCall(); private final BlakeRounds blakeRounds = new BlakeRounds(); - private final List precompileLimitModules = - List.of( - sha256Blocks, - ecAddEffectiveCall, - ecMulEffectiveCall, - ecRecoverEffectiveCall, - ecPairingG2MembershipCalls, - ecPairingMillerLoops, - ecPairingFinalExponentiations, - modexpEffectiveCall, - ripemdBlocks, - blakeEffectiveCall, - blakeRounds); + private List precompileLimitModules() { + + return List.of( + keccak, + sha256Blocks, + ecAddEffectiveCall, + ecMulEffectiveCall, + ecRecoverEffectiveCall, + ecPairingG2MembershipCalls, + ecPairingMillerLoops, + ecPairingFinalExponentiations, + modexpEffectiveCall, + ripemdBlocks, + blakeEffectiveCall, + blakeRounds); + } /* * precompile-data modules * those module are traced (and could be count) */ - private final ShakiraData shakiraData = new ShakiraData(wcp, sha256Blocks, ripemdBlocks); + private final ShakiraData shakiraData; private final BlakeModexpData blakeModexpData = new BlakeModexpData(this.wcp, modexpEffectiveCall, blakeEffectiveCall, blakeRounds); private final EcData ecData = @@ -291,7 +297,7 @@ public int lineCount() { /** list of module triggered by the HUB at BESU hooks */ private final List modules; - // reference table modules + /** reference table modules */ private final List refTableModules; /** @@ -370,14 +376,15 @@ public List getModulesToCount() { this.txnData, this.wcp, this.l2Block), - this.precompileLimitModules.stream()) + this.precompileLimitModules().stream()) .toList(); } public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic)); - this.l2L1Logs = new L2L1Logs(l2Block); - + this.l2L1Logs = new L2L1Logs(l2Block); // TODO: we never use it, to delete ? + this.keccak = new Keccak(ecRecoverEffectiveCall, l2Block); + this.shakiraData = new ShakiraData(wcp, sha256Blocks, keccak, ripemdBlocks); this.blockdata = new Blockdata(this.wcp, this.txnData, this.rlpTxn); this.mmu = new Mmu( @@ -425,7 +432,7 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) { this.wcp, /* WARN: must be called BEFORE txnData */ this.txnData, this.blockdata /* WARN: must be called AFTER txnData */), - this.precompileLimitModules.stream()) + this.precompileLimitModules().stream()) .toList(); } @@ -847,12 +854,6 @@ private void handleStack(MessageFrame frame) { } void triggerModules(MessageFrame frame) { - if (Exceptions.none(this.pch.exceptions()) && this.pch.abortingConditions().none()) { - for (Module precompileLimit : this.precompileLimitModules) { - precompileLimit.tracePreOpcode(frame); - } - } - if (this.pch.signals().add()) { this.add.tracePreOpcode(frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java index df57fa6dd1..d2a0e5db04 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/Keccak.java @@ -15,137 +15,66 @@ package net.consensys.linea.zktracer.module.limits; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.KECCAK; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; import java.util.List; import com.google.common.base.Preconditions; -import lombok.Getter; import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.module.hub.signals.PlatformController; import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraData; -import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; @RequiredArgsConstructor -public class Keccak implements Module { - private static final int ADDRESS_BYTES = 20; - private static final int HASH_BYTES = 32; +public class Keccak extends CountingOnlyModule { + private static final int ADDRESS_BYTES = Address.SIZE; + private static final int HASH_BYTES = Hash.SIZE; private static final int L1_MSG_INDICES_BYTES = 8; private static final int L1_TIMESTAMPS_BYTES = 8; private static final int PUBKEY_BYTES = 64; private static final int KECCAK_BIT_RATE = 1088; private static final int KECCAK_BYTE_RATE = KECCAK_BIT_RATE / 8; // TODO: find correct name - private final Hub hub; - private final EcRecoverEffectiveCall ecRec; + private final EcRecoverEffectiveCall ecRecoverEffectiveCall; private final L2Block l2Block; - @Getter private final ShakiraData shakiraData; - - private final Deque> deployedCodeSizes = new ArrayDeque<>(); - private final Deque> sha3Sizes = new ArrayDeque<>(); - private final Deque> create2Sizes = new ArrayDeque<>(); - @Override public String moduleKey() { return "BLOCK_KECCAK"; } @Override - public void enterTransaction() { - this.deployedCodeSizes.push(new ArrayList<>()); - this.sha3Sizes.push(new ArrayList<>()); - this.create2Sizes.push(new ArrayList<>()); - } - - @Override - public void popTransaction() { - this.deployedCodeSizes.pop(); - this.sha3Sizes.pop(); - this.create2Sizes.pop(); - } - - private static int numKeccak(long x) { - final long r = (x + KECCAK_BYTE_RATE - 1) / KECCAK_BYTE_RATE; - Preconditions.checkState(r < Integer.MAX_VALUE, "demented KECCAK"); - return (int) r; - } - - // TODO should die (but not yet implemented at the right place - @Override - public void tracePreOpcode(final MessageFrame frame) { - final OpCode opCode = this.hub.opCode(); - - final PlatformController pch = this.hub.pch(); - - if (Exceptions.none(pch.exceptions())) { - // Capture calls to SHA3. - if (opCode == OpCode.SHA3) { - callShakira(frame, 0, 1, this.sha3Sizes); - } - - // Capture contract deployment - // TODO: compute the gas cost if we are under deployment. - if (opCode == OpCode.RETURN && hub.currentFrame().isDeployment()) { - callShakira(frame, 0, 1, this.deployedCodeSizes); - } - - if (opCode == OpCode.CREATE2 && pch.abortingConditions().none()) { - callShakira(frame, 1, 2, this.create2Sizes); - } - } - } - - private void callShakira( - final MessageFrame frame, - final int codeOffsetStackItemOffset, - final int codeSizeStackItemOffset, - final Deque> codeSizes) { - final long codeSize = Words.clampedToLong(frame.getStackItem(codeSizeStackItemOffset)); - codeSizes.peek().add(codeSize); - - if (codeSize != 0) { - final long codeOffset = Words.clampedToLong(frame.getStackItem(codeOffsetStackItemOffset)); - final Bytes byteCode = frame.shadowReadMemory(codeOffset, codeSize); - - this.shakiraData.call(new ShakiraDataOperation(hub.stamp(), KECCAK, byteCode)); - } + public void addPrecompileLimit(final int dataByteLength) { + final int blockCount = numberOfKeccakBloc(dataByteLength); + this.counts.add(blockCount); } @Override public int lineCount() { final int l2L1LogsCount = this.l2Block.l2l1LogSizes().stream().mapToInt(List::size).sum(); final int txCount = this.l2Block.sizesRlpEncodedTxs().size(); - final int ecRecoverCount = ecRec.lineCount(); + final int ecRecoverCount = ecRecoverEffectiveCall.lineCount(); // From tx RLPs, used both for both the signature verification and the // public input computation. - return this.l2Block.sizesRlpEncodedTxs().stream().mapToInt(Keccak::numKeccak).sum() - // From deployed contracts, - // @alex, this formula suggests that the same data is hashed twice. Is this - // accurate? If this is actually the same data then we should not need to - // prove it twice. If the second time the data is hashed with a few extra - // bytes this should be accounted for : numKeccak(l) + numKeccak(l + extra) - + this.deployedCodeSizes.stream().flatMap(List::stream).mapToInt(Keccak::numKeccak).sum() + return this.l2Block.sizesRlpEncodedTxs().stream().mapToInt(Keccak::numberOfKeccakBloc).sum() // From ecRecover precompiles, // This accounts for the keccak of the recovered public keys to derive the // addresses. This also accounts for the transactions signatures // verifications. - + (txCount + ecRecoverCount) * numKeccak(PUBKEY_BYTES) - // From SHA3 opcode - + this.sha3Sizes.stream().flatMap(List::stream).mapToInt(Keccak::numKeccak).sum() + + (txCount + ecRecoverCount) * numberOfKeccakBloc(PUBKEY_BYTES) + + // From deployed contracts, SHA3 opcode, and CREATE2 + + counts.lineCount() + + /** + * TODO: previous implem was missing CREATE2 and was the following: // From deployed + * contracts, // @alex, this formula suggests that the same data is hashed twice. Is this // + * accurate? If this is actually the same data then we should not need to // prove it twice. + * If the second time the data is hashed with a few extra // bytes this should be accounted + * for : numKeccak(l) + numKeccak(l + extra) + + * this.deployedCodeSizes.stream().flatMap(List::stream).mapToInt(Keccak::numKeccak).sum() + * // From SHA3 opcode + + * this.sha3Sizes.stream().flatMap(List::stream).mapToInt(Keccak::numKeccak).sum() + */ // From public input computation. This accounts for the hashing of: // - The block data hash: @@ -156,9 +85,11 @@ public int lineCount() { // - hashing the above resulting hashes together to obtain the hash // for the current block data + txCount - * (numKeccak(HASH_BYTES) + numKeccak(ADDRESS_BYTES) + numKeccak(L1_MSG_INDICES_BYTES)) - + l2L1LogsCount * numKeccak(HASH_BYTES) - + numKeccak(4 * HASH_BYTES) // 4 because there are 4 fields above + * (numberOfKeccakBloc(HASH_BYTES) + + numberOfKeccakBloc(ADDRESS_BYTES) + + numberOfKeccakBloc(L1_MSG_INDICES_BYTES)) + + l2L1LogsCount * numberOfKeccakBloc(HASH_BYTES) + + numberOfKeccakBloc(4 * HASH_BYTES) // 4 because there are 4 fields above // - The top-level structure (with the worst-case assumption, the // current block is alone in the conflation). This includes: @@ -171,14 +102,15 @@ public int lineCount() { // bytes). Note: it does not need to be hashed. It will just be // included directly in the final hash. // - the hash of the above fields, to obtain the final public input - + 2 * numKeccak(HASH_BYTES) // one for the parent, one for the current block - + 2 * numKeccak(L1_TIMESTAMPS_BYTES) - + numKeccak(HASH_BYTES) // for the block data hash - + numKeccak(4 * HASH_BYTES); + + 2 * numberOfKeccakBloc(HASH_BYTES) // one for the parent, one for the current block + + 2 * numberOfKeccakBloc(L1_TIMESTAMPS_BYTES) + + numberOfKeccakBloc(HASH_BYTES) // for the block data hash + + numberOfKeccakBloc(4 * HASH_BYTES); } - @Override - public List columnsHeaders() { - throw new IllegalStateException("non-tracing module"); + private static int numberOfKeccakBloc(final long dataByteLength) { + final long r = (dataByteLength + KECCAK_BYTE_RATE - 1) / KECCAK_BYTE_RATE; + Preconditions.checkState(r < Integer.MAX_VALUE, "demented KECCAK"); + return (int) r; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java index a0de259773..c447d998d4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java @@ -25,6 +25,7 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; +import net.consensys.linea.zktracer.module.limits.Keccak; import net.consensys.linea.zktracer.module.limits.precompiles.RipemdBlocks; import net.consensys.linea.zktracer.module.limits.precompiles.Sha256Blocks; import net.consensys.linea.zktracer.module.wcp.Wcp; @@ -40,6 +41,7 @@ public class ShakiraData implements Module { private final ShakiraDataComparator comparator = new ShakiraDataComparator(); private final Sha256Blocks sha256Blocks; + private final Keccak keccak; private final RipemdBlocks ripemdBlocks; @Override @@ -76,8 +78,7 @@ public void call(final ShakiraDataOperation operation) { switch (operation.precompileType()) { case SHA256 -> sha256Blocks.addPrecompileLimit(operation.inputSize()); - case KECCAK -> { // TODO - } + case KECCAK -> keccak.addPrecompileLimit(operation.inputSize()); case RIPEMD -> ripemdBlocks.addPrecompileLimit(operation.inputSize()); default -> throw new IllegalArgumentException("Precompile type not supported by SHAKIRA"); } From 21274e5dd6d7921b6c0be87dbc40e0e4473f457f Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 30 Jul 2024 18:03:53 +0530 Subject: [PATCH 323/461] feat: trigger SHAKIRA for SHA3 --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/section/KeccakSection.java | 28 ++++++++++--- .../precompileSubsection/Sha2SubSection.java | 2 +- .../hub/section/create/CreateSection.java | 1 + .../hub/section/halt/ReturnSection.java | 18 ++++---- .../{ShakiraHashType.java => HashType.java} | 2 +- .../module/shakiradata/ShakiraData.java | 2 +- .../shakiradata/ShakiraDataOperation.java | 42 +++++++++---------- 8 files changed, 59 insertions(+), 38 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/{ShakiraHashType.java => HashType.java} (95%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 33caf1dcc4..b96fedd1a9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -276,7 +276,7 @@ private List precompileLimitModules() { * precompile-data modules * those module are traced (and could be count) */ - private final ShakiraData shakiraData; + @Getter private final ShakiraData shakiraData; private final BlakeModexpData blakeModexpData = new BlakeModexpData(this.wcp, modexpEffectiveCall, blakeEffectiveCall, blakeRounds); private final EcData ecData = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index c1692c85b3..ecfa3d6b1f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -15,22 +15,29 @@ package net.consensys.linea.zktracer.module.hub.section; +import static net.consensys.linea.zktracer.module.shakiradata.HashType.KECCAK; + import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.operation.Operation; public class KeccakSection extends TraceSection implements PostOpcodeDefer { + private final boolean triggerMmu; + private Bytes hashInput; + public KeccakSection(Hub hub) { super(hub, (short) 3); hub.addTraceSection(this); - - hub.addTraceSection(this); + hub.defers().scheduleForPostExecution(this); final ImcFragment imcFragment = ImcFragment.empty(hub); this.addStackAndFragments(hub, imcFragment); @@ -39,20 +46,31 @@ public KeccakSection(Hub hub) { imcFragment.callMxp(mxpCall); final boolean mayTriggerNonTrivialOperation = mxpCall.mayTriggerNontrivialMmuOperation; - final boolean triggerMmu = - mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); + triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); if (triggerMmu) { hub.defers().scheduleForPostExecution(this); final MmuCall mmuCall = MmuCall.sha3(hub); imcFragment.callMmu(mmuCall); + hashInput = + hub.currentFrame() + .frame() + .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()); } } @Override public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + final Bytes32 hashResult = Bytes32.leftPad(frame.getStackItem(0)); + // retroactively set HASH_INFO_FLAG and HASH_INFO_KECCAK_HI, HASH_INFO_KECCAK_LO - this.triggerHashInfo(frame.getStackItem(0)); + this.triggerHashInfo(hashResult); + + if (triggerMmu) { + final ShakiraDataOperation shakiraDataOperation = + new ShakiraDataOperation(this.hubStamp(), KECCAK, hashInput, hashResult); + hub.shakiraData().call(shakiraDataOperation); + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java index ec21a21c94..a3f80580c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java @@ -18,7 +18,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_SHA2; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.SHA256; +import static net.consensys.linea.zktracer.module.shakiradata.HashType.SHA256; import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java index 069789a281..e71d71aaaa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java @@ -188,6 +188,7 @@ public CreateSection(Hub hub) { hub.opCode() == OpCode.CREATE2 ? MmuCall.create2(hub, failureCondition) : MmuCall.create(hub); + // TODO: trigger SHAKIRA to hash non empty init code for CREATE2 this.finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 11e5316be2..0a18d734cb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -60,11 +60,13 @@ public class ReturnSection extends TraceSection ContextFragment squashParentContextReturnData; Address deploymentAddress; + // TODO: trigger SHAKIRA + public ReturnSection(Hub hub) { super(hub, maxNumberOfRows(hub)); hub.addTraceSection(this); - CallFrame currentFrame = hub.currentFrame(); + final CallFrame currentFrame = hub.currentFrame(); returnFromMessageCall = currentFrame.isMessageCall(); returnFromDeployment = currentFrame.isDeployment(); @@ -117,7 +119,7 @@ public ReturnSection(Hub hub) { if (triggerMmuForInvalidCodePrefix) { Preconditions.checkArgument(returnFromDeployment && nontrivialMmuOperation); - MmuCall actuallyInvalidCodePrefixMmuCall = MmuCall.invalidCodePrefix(hub); + final MmuCall actuallyInvalidCodePrefixMmuCall = MmuCall.invalidCodePrefix(hub); firstImcFragment.callMmu(actuallyInvalidCodePrefixMmuCall); Preconditions.checkArgument(!actuallyInvalidCodePrefixMmuCall.successBit()); @@ -143,7 +145,7 @@ public ReturnSection(Hub hub) { : RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM); if (messageCallReturnTouchesRam) { - MmuCall returnFromMessageCall = MmuCall.returnFromMessageCall(hub); + final MmuCall returnFromMessageCall = MmuCall.returnFromMessageCall(hub); firstImcFragment.callMmu(returnFromMessageCall); } @@ -186,20 +188,20 @@ public ReturnSection(Hub hub) { return; } - MmuCall invalidCodePrefixCheckMmuCall = MmuCall.invalidCodePrefix(hub); + final MmuCall invalidCodePrefixCheckMmuCall = MmuCall.invalidCodePrefix(hub); firstImcFragment.callMmu(invalidCodePrefixCheckMmuCall); - DeploymentOobCall maxCodeSizeOobCall = new DeploymentOobCall(); + final DeploymentOobCall maxCodeSizeOobCall = new DeploymentOobCall(); firstImcFragment.callOob(maxCodeSizeOobCall); // sanity checks Preconditions.checkArgument(invalidCodePrefixCheckMmuCall.successBit()); Preconditions.checkArgument(!maxCodeSizeOobCall.isMaxCodeSizeException()); - ImcFragment secondImcFragment = ImcFragment.empty(hub); + final ImcFragment secondImcFragment = ImcFragment.empty(hub); this.addFragment(secondImcFragment); - MmuCall nonemptyDeploymentMmuCall = MmuCall.returnFromDeployment(hub); + final MmuCall nonemptyDeploymentMmuCall = MmuCall.returnFromDeployment(hub); secondImcFragment.callMmu(nonemptyDeploymentMmuCall); } } @@ -241,7 +243,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca // TODO: does this account for updates to // - deploymentNumber and status ? // - MARKED_FOR_SELF_DESTRUCT(_NEW) ? - AccountFragment undoingDeploymentAccountFragment = + final AccountFragment undoingDeploymentAccountFragment = hub.factories() .accountFragment() .make( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraHashType.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/HashType.java similarity index 95% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraHashType.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/HashType.java index 1c8fe396e6..e879746dd4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraHashType.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/HashType.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.shakiradata; -public enum ShakiraHashType { +public enum HashType { KECCAK, SHA256, RIPEMD diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java index c447d998d4..8b4f52fdc0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java @@ -76,7 +76,7 @@ public void call(final ShakiraDataOperation operation) { this.wcp.callGT(operation.lastNBytes(), 0); this.wcp.callLEQ(operation.lastNBytes(), LLARGE); - switch (operation.precompileType()) { + switch (operation.hashType()) { case SHA256 -> sha256Blocks.addPrecompileLimit(operation.inputSize()); case KECCAK -> keccak.addPrecompileLimit(operation.inputSize()); case RIPEMD -> ripemdBlocks.addPrecompileLimit(operation.inputSize()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java index e6ae1ab58b..e57489ad14 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java @@ -24,9 +24,9 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_SHA2_DATA; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_SHA2_RESULT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.KECCAK; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.RIPEMD; -import static net.consensys.linea.zktracer.module.shakiradata.ShakiraHashType.SHA256; +import static net.consensys.linea.zktracer.module.shakiradata.HashType.KECCAK; +import static net.consensys.linea.zktracer.module.shakiradata.HashType.RIPEMD; +import static net.consensys.linea.zktracer.module.shakiradata.HashType.SHA256; import static net.consensys.linea.zktracer.module.shakiradata.Trace.INDEX_MAX_RESULT; import static net.consensys.linea.zktracer.types.Utils.rightPadTo; @@ -41,7 +41,7 @@ @Accessors(fluent = true) public class ShakiraDataOperation extends ModuleOperation { - @Getter private final ShakiraHashType precompileType; + @Getter private final HashType hashType; private final Bytes hashInput; @Getter private final long ID; @Getter private final int inputSize; @@ -51,8 +51,8 @@ public class ShakiraDataOperation extends ModuleOperation { // TODO: deprecate in favour of the version with the return data argument public ShakiraDataOperation( - final long hubStamp, final ShakiraHashType precompileType, final Bytes hashInput) { - this.precompileType = precompileType; + final long hubStamp, final HashType precompileType, final Bytes hashInput) { + this.hashType = precompileType; this.ID = hubStamp + 1; this.hashInput = hashInput; this.inputSize = hashInput.size(); @@ -62,11 +62,11 @@ public ShakiraDataOperation( } public ShakiraDataOperation( - final long hubStamp, - final ShakiraHashType precompileType, + final int hubStamp, + final HashType precompileType, final Bytes hashInput, final Bytes result) { - this.precompileType = precompileType; + this.hashType = precompileType; this.ID = hubStamp + 1; this.hashInput = hashInput; this.inputSize = hashInput.size(); @@ -89,11 +89,11 @@ void trace(Trace trace, final int stamp) { } private void traceData(Trace trace, final int stamp) { - final boolean isShaData = precompileType == SHA256; - final boolean isKecData = precompileType == KECCAK; - final boolean isRipData = precompileType == RIPEMD; + final boolean isShaData = hashType == SHA256; + final boolean isKecData = hashType == KECCAK; + final boolean isRipData = hashType == RIPEMD; final UnsignedByte phase = - switch (precompileType) { + switch (hashType) { case SHA256 -> UnsignedByte.of(PHASE_SHA2_DATA); case KECCAK -> UnsignedByte.of(PHASE_KECCAK_DATA); case RIPEMD -> UnsignedByte.of(PHASE_RIPEMD_DATA); @@ -128,11 +128,11 @@ private void traceData(Trace trace, final int stamp) { } private void traceResult(Trace trace, final int stamp) { - final boolean isShaResult = precompileType == SHA256; - final boolean isKecResult = precompileType == KECCAK; - final boolean isRipResult = precompileType == RIPEMD; + final boolean isShaResult = hashType == SHA256; + final boolean isKecResult = hashType == KECCAK; + final boolean isRipResult = hashType == RIPEMD; final UnsignedByte phase = - switch (precompileType) { + switch (hashType) { case SHA256 -> UnsignedByte.of(PHASE_SHA2_RESULT); case KECCAK -> UnsignedByte.of(PHASE_KECCAK_RESULT); case RIPEMD -> UnsignedByte.of(PHASE_RIPEMD_RESULT); @@ -158,9 +158,9 @@ private void traceResult(Trace trace, final int stamp) { case 0 -> trace .limb(result.slice(0, LLARGE)) .nBytesAcc(LLARGE) - .selectorKeccakResHi(precompileType == KECCAK) - .selectorSha2ResHi(precompileType == SHA256) - .selectorRipemdResHi(precompileType == RIPEMD) + .selectorKeccakResHi(hashType == KECCAK) + .selectorSha2ResHi(hashType == SHA256) + .selectorRipemdResHi(hashType == RIPEMD) .validateRow(); case 1 -> trace .limb(result.slice(LLARGE, LLARGE)) @@ -174,7 +174,7 @@ private void traceResult(Trace trace, final int stamp) { } private Bytes computeResult() { - return switch (precompileType) { + return switch (hashType) { case SHA256 -> Hash.sha256(hashInput); case KECCAK -> Hash.keccak256(hashInput); case RIPEMD -> Hash.ripemd160(hashInput); From 99449f40644b8f4621832ec63521b5af14eb6eb5 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 31 Jul 2024 17:46:20 +0530 Subject: [PATCH 324/461] fix(CREATE): trigger SHAKIRA and make it as the CALLs --- .../linea/zktracer/module/hub/Hub.java | 10 +- .../module/hub/defer/DeferRegistry.java | 2 +- .../hub/fragment/imc/mmu/opcode/Create2.java | 4 +- .../module/hub/section/CreateSection.java | 356 ++++++++++++++++++ .../hub/section/create/AbortCreate.java | 59 --- .../hub/section/create/CreateSection.java | 285 -------------- .../hub/section/create/ExceptionalCreate.java | 36 -- .../create/FailureOrEmptyInitCreate.java | 119 ------ .../hub/section/create/FillCreateSection.java | 49 --- .../create/NonEmptyInitCodeCreate.java | 144 ------- .../zktracer/module/rlpaddr/RlpAddr.java | 2 +- .../zktracer/runtime/callstack/CallFrame.java | 8 +- .../zktracer/runtime/callstack/CallStack.java | 2 +- .../linea/zktracer/types/AddressUtils.java | 15 + 14 files changed, 388 insertions(+), 703 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index b96fedd1a9..74c3f6777e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -52,6 +52,7 @@ import net.consensys.linea.zktracer.module.hub.section.AccountSection; import net.consensys.linea.zktracer.module.hub.section.CallDataLoadSection; import net.consensys.linea.zktracer.module.hub.section.ContextSection; +import net.consensys.linea.zktracer.module.hub.section.CreateSection; import net.consensys.linea.zktracer.module.hub.section.ExpSection; import net.consensys.linea.zktracer.module.hub.section.JumpSection; import net.consensys.linea.zktracer.module.hub.section.KeccakSection; @@ -71,7 +72,6 @@ import net.consensys.linea.zktracer.module.hub.section.copy.CodeCopySection; import net.consensys.linea.zktracer.module.hub.section.copy.ExtCodeCopySection; import net.consensys.linea.zktracer.module.hub.section.copy.ReturnDataCopySection; -import net.consensys.linea.zktracer.module.hub.section.create.CreateSection; import net.consensys.linea.zktracer.module.hub.section.halt.ReturnSection; import net.consensys.linea.zktracer.module.hub.section.halt.RevertSection; import net.consensys.linea.zktracer.module.hub.section.halt.SelfdestructSection; @@ -279,6 +279,8 @@ private List precompileLimitModules() { @Getter private final ShakiraData shakiraData; private final BlakeModexpData blakeModexpData = new BlakeModexpData(this.wcp, modexpEffectiveCall, blakeEffectiveCall, blakeRounds); + + @Getter private final EcData ecData = new EcData( this, @@ -666,7 +668,7 @@ public void traceContextEnter(MessageFrame frame) { } public void traceContextReEnter(MessageFrame frame) { - final int latestChildId = this.currentFrame().childFrames().getLast(); + final int latestChildId = this.currentFrame().childFramesId().getLast(); this.defers.resolvePostRollback(this, frame, this.callStack.getById(latestChildId)); this.defers.resolveAtContextReEntry(this, this.currentFrame()); if (this.currentFrame().sectionToUnlatch() != null) { @@ -1128,4 +1130,8 @@ public void squashParentFrameReturnData() { parentFrame.returnData(Bytes.EMPTY); parentFrame.returnDataSpan(MemorySpan.empty()); } + + public CallFrame getLastChildCallFrame(final CallFrame parentFrame) { + return this.callStack.getById(parentFrame.childFramesId().getLast()); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 8c32058c87..037ee544ed 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -196,7 +196,7 @@ public void resolvePostRollback( // recursively roll back child call frames final CallStack callStack = hub.callStack(); - currentCallFrame.childFrames().stream() + currentCallFrame.childFramesId().stream() .map(callStack::getById) .forEach(childCallFrame -> resolvePostRollback(hub, messageFrame, childCallFrame)); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create2.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create2.java index e69214dad3..de863b5268 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create2.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/Create2.java @@ -34,7 +34,7 @@ public class Create2 extends MmuCall implements RomLexDefer { private final Hub hub; private ContractMetadata contract; - public Create2(final Hub hub, boolean failureCondition) { + public Create2(final Hub hub, final boolean failedCreate) { super(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING); this.hub = hub; this.hub.romLex().createDefers().register(this); @@ -51,7 +51,7 @@ public Create2(final Hub hub, boolean failureCondition) { .referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(2))) .setKec(); - if (!failureCondition) { + if (!failedCreate) { this.setRom(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java new file mode 100644 index 0000000000..19dd5a3f8c --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -0,0 +1,356 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section; + +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_ABORT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EMPTY_INIT_CODE_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EMPTY_INIT_CODE_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EXCEPTION; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT; +import static net.consensys.linea.zktracer.module.shakiradata.HashType.KECCAK; +import static net.consensys.linea.zktracer.opcode.OpCode.CREATE; +import static net.consensys.linea.zktracer.opcode.OpCode.CREATE2; +import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; +import static org.hyperledger.besu.crypto.Hash.keccak256; + +import java.util.Optional; + +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.AccountSnapshot; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; +import net.consensys.linea.zktracer.module.hub.defer.ImmediateContextEntryDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.StpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CreateOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; +import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; +import net.consensys.linea.zktracer.module.hub.signals.Exceptions; +import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Transaction; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.account.AccountState; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.evm.worldstate.WorldView; + +public class CreateSection extends TraceSection + implements ImmediateContextEntryDefer, + PostRollbackDefer, + ContextReEntryDefer, + PostTransactionDefer { + + private int creatorContextId; + + // Just before create + private AccountSnapshot preOpcodeCreatorSnapshot; + private AccountSnapshot preOpcodeCreateeSnapshot; + + // Just at the entry child frame + private AccountSnapshot childEntryCreatorSnapshot; + private AccountSnapshot childEntryCreateeSnapshot; + + // Just at the entry child frame + private AccountSnapshot reEntryCreatorSnapshot; + private AccountSnapshot reEntryCreateeSnapshot; + + private RlpAddrSubFragment rlpAddrSubFragment; + + // row i+0 + final CreateScenarioFragment scenarioFragment; + // row i+? + private ContextFragment finalContextFragment; + + // TODO: according to our preliminary conclusion in issue #866 + // CREATE's that raise a failure condition _do spawn a child context_. + public CreateSection(Hub hub) { + super(hub, maxNumberOfLines(hub.pch().exceptions(), hub.pch().abortingConditions())); + final short exceptions = hub.pch().exceptions(); + + hub.addTraceSection(this); + this.addStack(hub); + + // row i+ 0 + scenarioFragment = new CreateScenarioFragment(); + this.addFragment(scenarioFragment); + + // row i + 1 + final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); + this.addFragment(currentContextFragment); + + // row: i + 2 + final ImcFragment imcFragment = ImcFragment.empty(hub); + this.addFragment(imcFragment); + + // STATICX case + // Note: in the static case this imc fragment remains empty + if (Exceptions.staticFault(exceptions)) { + scenarioFragment.setScenario(CREATE_EXCEPTION); + return; + } + + final MxpCall mxpCall = new MxpCall(hub); + imcFragment.callMxp(mxpCall); + Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); + + // MXPX case + if (mxpCall.mxpx) { + scenarioFragment.setScenario(CREATE_EXCEPTION); + return; + } + + final StpCall stpCall = new StpCall(hub, mxpCall.getGasMxp()); + stpCall.stpCallForCreates(hub); + imcFragment.callStp(stpCall); + + Preconditions.checkArgument( + stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions)); + + // OOGX case + if (Exceptions.outOfGasException(exceptions)) { + scenarioFragment.setScenario(CREATE_EXCEPTION); + return; + } + + // The CREATE(2) is now unexceptional + Preconditions.checkArgument(Exceptions.none(exceptions)); + + final CreateOobCall oobCall = new CreateOobCall(); + imcFragment.callOob(oobCall); + + final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); + Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts.any()); + + final CallFrame callFrame = hub.currentFrame(); + final MessageFrame frame = callFrame.frame(); + + final Address creatorAddress = callFrame.accountAddress(); + preOpcodeCreatorSnapshot = AccountSnapshot.canonical(hub, creatorAddress); + + if (aborts.any()) { + scenarioFragment.setScenario(CREATE_ABORT); + this.finishAbortCreate(hub); + return; + } + + // The CREATE(2) is now unexceptional and unaborted + Preconditions.checkArgument(aborts.none()); + hub.defers().scheduleForImmediateContextEntry(this); // when we add the two account fragments + hub.defers().scheduleForPostRollback(this, hub.currentFrame()); // in case of Rollback + hub.defers().scheduleForPostTransaction(this); // when we add the last context row + + final Address createeAddress = getDeploymentAddress(frame); + rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createeAddress); + + preOpcodeCreateeSnapshot = AccountSnapshot.canonical(hub, createeAddress); + + final Optional deploymentAccount = + Optional.ofNullable(frame.getWorldUpdater().get(createeAddress)); + final boolean createdAddressHasNonZeroNonce = + deploymentAccount.map(a -> a.getNonce() != 0).orElse(false); + final boolean createdAddressHasNonEmptyCode = + deploymentAccount.map(AccountState::hasCode).orElse(false); + + final boolean failedCreate = createdAddressHasNonZeroNonce || createdAddressHasNonEmptyCode; + final boolean emptyInitCode = hub.transients().op().initCodeSegment().isEmpty(); + + // Trigger MMU & SHAKIRA to hash the (non-empty) InitCode of CREATE2 - even for failed CREATE2 + if (hub.opCode() == CREATE2 && !emptyInitCode) { + final MmuCall mmuCall = MmuCall.create2(hub, failedCreate); + imcFragment.callMmu(mmuCall); + + final long offset = Words.clampedToLong(hub.messageFrame().getStackItem(1)); + final long size = Words.clampedToLong(hub.messageFrame().getStackItem(2)); + final Bytes create2InitCode = frame.shadowReadMemory(offset, size); + final Bytes32 hash = keccak256(create2InitCode); + final ShakiraDataOperation shakiraDataOperation = + new ShakiraDataOperation(hub.stamp(), KECCAK, create2InitCode, hash); + hub.shakiraData().call(shakiraDataOperation); + } + + if (failedCreate || emptyInitCode) { + this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + + if (failedCreate) { + scenarioFragment.setScenario(CREATE_FAILURE_CONDITION_WONT_REVERT); + } + if (emptyInitCode) { + scenarioFragment.setScenario(CREATE_EMPTY_INIT_CODE_WONT_REVERT); + } + + return; + } + + // Finally, non-exceptional, non-aborting, non-failing, non-emptyInitCode create + hub.defers() + .scheduleForContextReEntry( + this, hub.currentFrame()); // To get the success bit of the CREATE(2) + + // Note: the case CREATE2 has been set before, we need to do it even in the failure case + if (hub.opCode() == CREATE) { + final MmuCall mmuCall = MmuCall.create(hub); + imcFragment.callMmu(mmuCall); + } + + this.finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); + } + + @Override + public void resolveUponEnteringChildContext(Hub hub) { + childEntryCreatorSnapshot = AccountSnapshot.canonical(hub, preOpcodeCreatorSnapshot.address()); + childEntryCreateeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCreateeSnapshot.address()); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final AccountFragment creatorAccountFragment = + accountFragmentFactory.make( + preOpcodeCreatorSnapshot, + childEntryCreatorSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + creatorAccountFragment.rlpAddrSubFragment(rlpAddrSubFragment); + + final AccountFragment createeAccountFragment = + accountFragmentFactory.make( + preOpcodeCreateeSnapshot, + childEntryCreateeSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); + + this.addFragments(creatorAccountFragment, createeAccountFragment); + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) { + final boolean deploymentSuccess = !frame.frame().getStackItem(0).isZero(); + + if (!deploymentSuccess) { + scenarioFragment.setScenario(CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT); + } else { + scenarioFragment.setScenario(CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT); + + reEntryCreatorSnapshot = AccountSnapshot.canonical(hub, preOpcodeCreatorSnapshot.address()); + reEntryCreateeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCreateeSnapshot.address()); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final int childRevertStamp = hub.getLastChildCallFrame(frame).revertStamp(); + + final AccountFragment undoCreator = + accountFragmentFactory.make( + reEntryCreatorSnapshot, + childEntryCreatorSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + this.hubStamp(), childRevertStamp, 2)); + + final AccountFragment undoCreatee = + accountFragmentFactory.make( + reEntryCreateeSnapshot, + childEntryCreateeSnapshot, + DomSubStampsSubFragment.revertsWithChildDomSubStamps( + this.hubStamp(), childRevertStamp, 3)); + + this.addFragments(undoCreator, undoCreatee); + } + } + + @Override + public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { + scenarioFragment.setScenario(switchToRevert(scenarioFragment.getScenario())); + + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + + final int revertStamp = callFrame.revertStamp(); + final boolean firstUndo = + scenarioFragment.getScenario() != CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; + + final AccountFragment undoCreator = + accountFragmentFactory.make( + childEntryCreatorSnapshot, + preOpcodeCreatorSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), revertStamp, firstUndo ? 2 : 4)); + + final AccountFragment undoCreatee = + accountFragmentFactory.make( + childEntryCreateeSnapshot, + preOpcodeCreateeSnapshot, + DomSubStampsSubFragment.revertWithCurrentDomSubStamps( + this.hubStamp(), revertStamp, firstUndo ? 3 : 5)); + + this.addFragments(undoCreator, undoCreatee); + } + + @Override + public void resolvePostTransaction( + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + this.addFragment(this.finalContextFragment); + } + + private static short maxNumberOfLines(final short exceptions, final AbortingConditions abort) { + if (Exceptions.any(exceptions)) { + return 6; + } + if (abort.any()) { + return 7; + } + return 11; // Note: could be lower for unreverted successful CREATE(s) + } + + private void finishAbortCreate(final Hub hub) { + final AccountFragment.AccountFragmentFactory accountFragmentFactory = + hub.factories().accountFragment(); + final AccountFragment creatorAccountFragment = + accountFragmentFactory.make( + preOpcodeCreateeSnapshot, + preOpcodeCreateeSnapshot, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); + + final ContextFragment updatedCurrentContextFragment = + ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + + this.addFragments(creatorAccountFragment, updatedCurrentContextFragment); + } + + private static CreateScenarioFragment.CreateScenario switchToRevert( + final CreateScenarioFragment.CreateScenario previousScenario) { + return switch (previousScenario) { + case CREATE_FAILURE_CONDITION_WONT_REVERT -> CREATE_FAILURE_CONDITION_WILL_REVERT; + case CREATE_EMPTY_INIT_CODE_WONT_REVERT -> CREATE_EMPTY_INIT_CODE_WILL_REVERT; + case CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT -> CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; + case CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT -> CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT; + default -> throw new IllegalArgumentException("unexpected Create scenario"); + }; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java deleted file mode 100644 index 04aa1688ca..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/AbortCreate.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.create; - -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_ABORT; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -class AbortCreate extends TraceSection { - public AbortCreate( - final Hub hub, - final ContextFragment currentContextFragment, - final ImcFragment imcFragment, - final AccountSnapshot oldCreatorSnapshot) { - super(hub, (short) 7); - hub.addTraceSection(this); - - final CreateScenarioFragment scenarioFragment = new CreateScenarioFragment(CREATE_ABORT); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - final AccountFragment creatorAccountFragment = - accountFragmentFactory.make( - oldCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - - final ContextFragment updatedCurrentContextFragment = - ContextFragment.nonExecutionProvidesEmptyReturnData(hub); - - this.addStackAndFragments( - hub, - scenarioFragment, - currentContextFragment, - imcFragment, - creatorAccountFragment, - updatedCurrentContextFragment); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java deleted file mode 100644 index e71d71aaaa..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/CreateSection.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.create; - -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EMPTY_INIT_CODE_WONT_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WONT_REVERT; -import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; - -import java.util.Optional; - -import com.google.common.base.Preconditions; -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; -import net.consensys.linea.zktracer.module.hub.defer.ImmediateContextEntryDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.StpCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CreateOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; -import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions; -import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.account.AccountState; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; -import org.hyperledger.besu.evm.worldstate.WorldView; - -// TODO: should implement ContextEntryDefer -public class CreateSection - implements PostOpcodeDefer, - ContextReEntryDefer, - PostTransactionDefer, - ImmediateContextEntryDefer { - private FillCreateSection createSection; - - private int creatorContextId; - - // Just before create - private AccountSnapshot preOpcodeCreatorSnapshot; - private AccountSnapshot preOpcodeCreateeSnapshot; - - // Just after create but before entering child frame - private AccountSnapshot midCreatorSnapshot; - private AccountSnapshot midCreateeSnapshot; - - // After return from child-context - private AccountSnapshot newCreatorSnapshot; - private AccountSnapshot newCreateeSnapshot; - - private RlpAddrSubFragment rlpAddrSubFragment; - - /** true if the CREATE was successful */ - private boolean createSuccessful = false; - - // row i+2 - private final ImcFragment imcFragment; - private MmuCall mmuCall; - - // row i+? - private ContextFragment finalContextFragment; - - // TODO: according to our preliminary conclusion in issue #866 - // CREATE's that raise a failure condition _do spawn a child context_. - public CreateSection(Hub hub) { - final short exceptions = hub.pch().exceptions(); - - // row i + 1 - final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); - - // row: i + 2 - // Note: in the static case this imc fragment remains empty - - // STATICX case - imcFragment = ImcFragment.empty(hub); - if (Exceptions.staticFault(exceptions)) { - new ExceptionalCreate(hub, currentContextFragment, imcFragment); - return; - } - - final MxpCall mxpCall = new MxpCall(hub); - imcFragment.callMxp(mxpCall); - Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); - - // MXPX case - if (Exceptions.memoryExpansionException(exceptions)) { - new ExceptionalCreate(hub, currentContextFragment, imcFragment); - return; - } - - final StpCall stpCall = new StpCall(hub, mxpCall.getGasMxp()); - stpCall.stpCallForCreates(hub); - imcFragment.callStp(stpCall); - Preconditions.checkArgument( - stpCall.outOfGasException() == Exceptions.outOfGasException(exceptions)); - - // OOGX case - if (Exceptions.outOfGasException(exceptions)) { - new ExceptionalCreate(hub, currentContextFragment, imcFragment); - return; - } - - // The CREATE(2) is now unexceptional - Preconditions.checkArgument(Exceptions.none(exceptions)); - - final CreateOobCall oobCall = new CreateOobCall(); - imcFragment.callOob(oobCall); - - final AbortingConditions aborts = hub.pch().abortingConditions().snapshot(); - Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts.any()); - - final CallFrame callFrame = hub.currentFrame(); - final MessageFrame frame = callFrame.frame(); - - final Address creatorAddress = callFrame.accountAddress(); - preOpcodeCreatorSnapshot = AccountSnapshot.canonical(hub, creatorAddress); - - if (aborts.any()) { - new AbortCreate(hub, currentContextFragment, imcFragment, preOpcodeCreatorSnapshot); - return; - } - - // The CREATE(2) is now unexceptional and unaborted - hub.defers().scheduleForPostExecution(this); - hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); - hub.defers().scheduleForPostTransaction(this); - - // Note: all future account rows will be added during the resolvePostTransaction - - this.creatorContextId = hub.currentFrame().id(); - - final Address createeAddress = getDeploymentAddress(frame); - preOpcodeCreateeSnapshot = AccountSnapshot.canonical(hub, createeAddress); - - rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createeAddress); - - final Optional deploymentAccount = - Optional.ofNullable(frame.getWorldUpdater().get(createeAddress)); - final boolean createdAddressHasNonZeroNonce = - deploymentAccount.map(a -> a.getNonce() != 0).orElse(false); - final boolean createdAddressHasNonEmptyCode = - deploymentAccount.map(AccountState::hasCode).orElse(false); - - final boolean failureCondition = createdAddressHasNonZeroNonce || createdAddressHasNonEmptyCode; - final boolean emptyInitCode = hub.transients().op().initCodeSegment().isEmpty(); - - if (failureCondition || emptyInitCode) { - final CreateScenarioFragment.CreateScenario scenario = - failureCondition - ? CREATE_FAILURE_CONDITION_WONT_REVERT - : CREATE_EMPTY_INIT_CODE_WONT_REVERT; - this.createSection = - new FailureOrEmptyInitCreate(hub, scenario, currentContextFragment, imcFragment); - this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); - - if (hub.opCode() == OpCode.CREATE2 && !emptyInitCode) { - this.mmuCall = MmuCall.create2(hub, failureCondition); - } - return; - } - - // Finally, non-exceptional, non-aborting, non-failing, non-emptyInitCode create - hub.defers().scheduleForImmediateContextEntry(this); - this.createSection = new NonEmptyInitCodeCreate(hub, currentContextFragment, imcFragment); - this.mmuCall = - hub.opCode() == OpCode.CREATE2 - ? MmuCall.create2(hub, failureCondition) - : MmuCall.create(hub); - // TODO: trigger SHAKIRA to hash non empty init code for CREATE2 - - this.finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); - } - - @Override - public void resolvePostExecution( - Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { - final Address creatorAddress = preOpcodeCreatorSnapshot.address(); - this.midCreatorSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(creatorAddress), - true, - hub.transients().conflation().deploymentInfo().number(creatorAddress), - hub.transients().conflation().deploymentInfo().isDeploying(creatorAddress)); - - final Address createdAddress = preOpcodeCreateeSnapshot.address(); - this.midCreateeSnapshot = - AccountSnapshot.fromAccount( - frame.getWorldUpdater().get(createdAddress), - true, - hub.transients().conflation().deploymentInfo().number(createdAddress), - hub.transients().conflation().deploymentInfo().isDeploying(createdAddress)); - - // Pre-emptively set new* snapshots in case we never enter the child frame. - // Will be overwritten if we enter the child frame and runNextContext is explicitly called by - // the defer registry. - // this.resolveAtContextReEntry(hub, frame); - } - - // TODO: @François: there was something around triggering the ROM_LEX module at the right time - @Override - public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - - if (this.mmuCall != null) { - this.imcFragment.callMmu(this.mmuCall); - } - - final CallFrame createCallFrame = hub.callStack().getById(this.creatorContextId); - final int childRevertStamp = - createCallFrame.childFrames().isEmpty() - ? 0 - : hub.callStack() - .getById(createCallFrame.childFrames().getFirst()) - .revertStamp(); // TODO: not sure about this - this.createSection.fillAccountFragment( - hub, - createSuccessful, - childRevertStamp, - rlpAddrSubFragment, - preOpcodeCreatorSnapshot, - midCreatorSnapshot, - newCreatorSnapshot, - preOpcodeCreateeSnapshot, - midCreateeSnapshot, - newCreateeSnapshot); - - if (createCallFrame.hasReverted()) { - final int currentRevertStamp = createCallFrame.revertStamp(); - this.createSection.fillReverting( - hub, - createSuccessful, - currentRevertStamp, - preOpcodeCreatorSnapshot, - midCreatorSnapshot, - newCreatorSnapshot, - preOpcodeCreateeSnapshot, - midCreateeSnapshot, - newCreateeSnapshot); - } - - this.createSection.fillContextFragment(this.finalContextFragment); - } - - // TODO: ensure with @Daniel.Lehrner that at contextEntry the accounts - // of both creator and createe were updated (and potentially created) - // otherwise do it later - @Override - public void resolveUponEnteringChildContext(Hub hub) {} - - @Override - public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { - - final MessageFrame frame = callFrame.frame(); - - this.createSuccessful = !frame.getStackItem(0).isZero(); // TODO: are we sure it's working ?? - - final Address creatorAddress = preOpcodeCreatorSnapshot.address(); - this.newCreatorSnapshot = AccountSnapshot.canonical(hub, creatorAddress); - - final Address createeAddress = preOpcodeCreateeSnapshot.address(); - this.newCreateeSnapshot = AccountSnapshot.canonical(hub, createeAddress); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java deleted file mode 100644 index 8b763d3cf6..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/ExceptionalCreate.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.create; - -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EXCEPTION; - -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class ExceptionalCreate extends TraceSection { - public ExceptionalCreate( - final Hub hub, final ContextFragment commonContext, final ImcFragment imcFragment) { - super(hub, (short) 6); - hub.addTraceSection(this); - - final CreateScenarioFragment scenarioFragment = new CreateScenarioFragment(CREATE_EXCEPTION); - - this.addStackAndFragments(hub, scenarioFragment, commonContext, imcFragment); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java deleted file mode 100644 index ca84bf82eb..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FailureOrEmptyInitCreate.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.create; - -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_EMPTY_INIT_CODE_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_FAILURE_CONDITION_WONT_REVERT; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class FailureOrEmptyInitCreate extends TraceSection implements FillCreateSection { - final CreateScenarioFragment scenarioFragment; - - public FailureOrEmptyInitCreate( - final Hub hub, - final CreateScenarioFragment.CreateScenario scenario, - final ContextFragment currentContextFragment, - final ImcFragment imcFragment) { - super(hub, (short) 10); - hub.addTraceSection(this); - - this.scenarioFragment = new CreateScenarioFragment(scenario); - - this.addStackAndFragments(hub, scenarioFragment, currentContextFragment, imcFragment); - } - - @Override - public void fillAccountFragment( - Hub hub, - boolean createSuccess, - int childRevertStamp, - RlpAddrSubFragment rlpAddrSubFragment, - AccountSnapshot oldCreatorSnapshot, - AccountSnapshot midCreatorSnapshot, - AccountSnapshot newCreatorSnapshot, - AccountSnapshot oldCreatedSnapshot, - AccountSnapshot midCreatedSnapshot, - AccountSnapshot newCreatedSnapshot) { - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - final AccountFragment creatorAccountFragment = - accountFragmentFactory.make( - oldCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - creatorAccountFragment.rlpAddrSubFragment(rlpAddrSubFragment); - - final AccountFragment createdAccountFragment = - accountFragmentFactory.make( - oldCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); - - this.addFragments(creatorAccountFragment, createdAccountFragment); - } - - @Override - public void fillReverting( - Hub hub, - boolean createSuccess, - int currentRevertStamp, - AccountSnapshot oldCreatorSnapshot, - AccountSnapshot midCreatorSnapshot, - AccountSnapshot newCreatorSnapshot, - AccountSnapshot oldCreatedSnapshot, - AccountSnapshot midCreatedSnapshot, - AccountSnapshot newCreatedSnapshot) { - final CreateScenarioFragment.CreateScenario newScenario = - scenarioFragment.getScenario() == CREATE_FAILURE_CONDITION_WONT_REVERT - ? CREATE_FAILURE_CONDITION_WILL_REVERT - : CREATE_EMPTY_INIT_CODE_WILL_REVERT; - this.scenarioFragment.setScenario(newScenario); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - final AccountFragment undoCreatorAccountFragment = - accountFragmentFactory.make( - newCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), currentRevertStamp, 2)); - final AccountFragment undoCreatedAccountFragment = - accountFragmentFactory.make( - newCreatedSnapshot, - oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), currentRevertStamp, 3)); - - this.addFragments(undoCreatorAccountFragment, undoCreatedAccountFragment); - } - - @Override - public void fillContextFragment(ContextFragment contextFragment) { - this.addFragment(contextFragment); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java deleted file mode 100644 index 57a2ee604f..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/FillCreateSection.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.create; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; - -public interface FillCreateSection { - - void fillAccountFragment( - final Hub hub, - final boolean createSuccess, - final int childRevertStamp, - final RlpAddrSubFragment rlpAddrSubFragment, - final AccountSnapshot oldCreatorSnapshot, - final AccountSnapshot midCreatorSnapshot, - final AccountSnapshot newCreatorSnapshot, - final AccountSnapshot oldCreatedSnapshot, - final AccountSnapshot midCreatedSnapshot, - final AccountSnapshot newCreatedSnapshot); - - void fillReverting( - final Hub hub, - final boolean createSuccess, - final int currentRevertStamp, - final AccountSnapshot oldCreatorSnapshot, - final AccountSnapshot midCreatorSnapshot, - final AccountSnapshot newCreatorSnapshot, - final AccountSnapshot oldCreatedSnapshot, - final AccountSnapshot midCreatedSnapshot, - final AccountSnapshot newCreatedSnapshot); - - void fillContextFragment(final ContextFragment contextFragment); -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java deleted file mode 100644 index 4bef594462..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/create/NonEmptyInitCodeCreate.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.section.create; - -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment.CreateScenario.CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT; - -import net.consensys.linea.zktracer.module.hub.AccountSnapshot; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.RlpAddrSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; -import net.consensys.linea.zktracer.module.hub.fragment.scenario.CreateScenarioFragment; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; - -public class NonEmptyInitCodeCreate extends TraceSection implements FillCreateSection { - final CreateScenarioFragment scenarioFragment; - - public NonEmptyInitCodeCreate( - final Hub hub, final ContextFragment commonContext, final ImcFragment imcFragment) { - super(hub, (short) 11); - hub.addTraceSection(this); - - this.scenarioFragment = new CreateScenarioFragment(); - - this.addStackAndFragments(hub, scenarioFragment, commonContext, imcFragment); - hub.romLex().callRomLex(hub.messageFrame()); - } - - @Override - public void fillAccountFragment( - Hub hub, - boolean createSuccess, - int childRevertStamp, - RlpAddrSubFragment rlpAddrSubFragment, - AccountSnapshot oldCreatorSnapshot, - AccountSnapshot midCreatorSnapshot, - AccountSnapshot newCreatorSnapshot, - AccountSnapshot oldCreatedSnapshot, - AccountSnapshot midCreatedSnapshot, - AccountSnapshot newCreatedSnapshot) { - final CreateScenarioFragment.CreateScenario scenario = - createSuccess - ? CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WONT_REVERT - : CREATE_NON_EMPTY_INIT_CODE_FAILURE_WONT_REVERT; - this.scenarioFragment.setScenario(scenario); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - final AccountFragment oldToMidCreatorAccountFragment = - accountFragmentFactory.make( - oldCreatorSnapshot, - midCreatorSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0)); - oldToMidCreatorAccountFragment.rlpAddrSubFragment(rlpAddrSubFragment); - - final AccountFragment oldToMidCreatedAccountFragment = - accountFragmentFactory.make( - oldCreatedSnapshot, - midCreatedSnapshot, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); - oldToMidCreatedAccountFragment.requiresRomlex(true); - - this.addFragments(oldToMidCreatorAccountFragment, oldToMidCreatedAccountFragment); - - if (!createSuccess) { - final AccountFragment midToNewCreatorAccountFragment = - accountFragmentFactory.make( - midCreatorSnapshot, - newCreatorSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps( - this.hubStamp(), childRevertStamp, 2)); - - final AccountFragment midToNewCreatedAccountFragment = - accountFragmentFactory.make( - midCreatedSnapshot, - newCreatedSnapshot, - DomSubStampsSubFragment.revertsWithChildDomSubStamps( - this.hubStamp(), childRevertStamp, 3)); - - this.addFragments(midToNewCreatorAccountFragment, midToNewCreatedAccountFragment); - } - } - - @Override - public void fillReverting( - Hub hub, - boolean createSuccess, - int currentRevertStamp, - AccountSnapshot oldCreatorSnapshot, - AccountSnapshot midCreatorSnapshot, - AccountSnapshot newCreatorSnapshot, - AccountSnapshot oldCreatedSnapshot, - AccountSnapshot midCreatedSnapshot, - AccountSnapshot newCreatedSnapshot) { - - final CreateScenarioFragment.CreateScenario newScenario = - createSuccess - ? CREATE_NON_EMPTY_INIT_CODE_SUCCESS_WILL_REVERT - : CREATE_NON_EMPTY_INIT_CODE_FAILURE_WILL_REVERT; - this.scenarioFragment.setScenario(newScenario); - - final AccountFragment.AccountFragmentFactory accountFragmentFactory = - hub.factories().accountFragment(); - - final AccountFragment undoCreatorAccountFragment = - accountFragmentFactory.make( - createSuccess ? midCreatorSnapshot : newCreatorSnapshot, - oldCreatorSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), currentRevertStamp, createSuccess ? 2 : 4)); - final AccountFragment undoCreatedAccountFragment = - accountFragmentFactory.make( - createSuccess ? midCreatedSnapshot : newCreatedSnapshot, - oldCreatedSnapshot, - DomSubStampsSubFragment.revertWithCurrentDomSubStamps( - this.hubStamp(), currentRevertStamp, createSuccess ? 3 : 5)); - - this.addFragments(undoCreatorAccountFragment, undoCreatedAccountFragment); - } - - @Override - public void fillContextFragment(ContextFragment contextFragment) { - this.addFragment(contextFragment); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java index 9abaeb5fd1..3a844cb838 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlpaddr/RlpAddr.java @@ -125,7 +125,7 @@ public void tracePreOpcode(MessageFrame frame) { final Bytes32 rawCreate2Address = getCreate2RawAddress(sender, salt, hash); - RlpAddrOperation chunk = + final RlpAddrOperation chunk = new RlpAddrOperation(rawCreate2Address, OpCode.CREATE2, sender, salt, hash); this.chunkList.add(chunk); this.trm.callTrimming(rawCreate2Address); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index eec527c613..51898b253d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -68,7 +68,7 @@ public boolean isMessageCall() { @Getter private int parentFrameId; /** all the {@link CallFrame} that have been called by this frame. */ - @Getter private final List childFrames = new ArrayList<>(); + @Getter private final List childFramesId = new ArrayList<>(); /** the {@link Address} of the account executing this {@link CallFrame}. */ @Getter private final Address accountAddress; @@ -284,11 +284,11 @@ public EWord codeAddressAsEWord() { * @return the ID of the latest callee */ public Optional lastCallee() { - if (this.childFrames.isEmpty()) { + if (this.childFramesId.isEmpty()) { return Optional.empty(); } - return Optional.of(this.childFrames.get(this.childFrames.size() - 1)); + return Optional.of(this.childFramesId.get(this.childFramesId.size() - 1)); } /** @@ -302,7 +302,7 @@ public ContractMetadata metadata() { } private void revertChildren(CallStack callStack, int parentRevertStamp) { - this.childFrames.stream() + this.childFramesId.stream() .map(callStack::getById) .forEach( frame -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 99d345f8a1..7ce53c86a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -260,7 +260,7 @@ public void enter( this.current = newTop; if (caller != -1) { this.callFrames.get(caller).returnData(Bytes.EMPTY); - this.callFrames.get(caller).childFrames().add(newTop); + this.callFrames.get(caller).childFramesId().add(newTop); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java index 71a9861fd3..1da9671aa8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java @@ -17,6 +17,8 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import static net.consensys.linea.zktracer.types.Utils.leftPadTo; +import static org.hyperledger.besu.crypto.Hash.keccak256; +import static org.hyperledger.besu.evm.internal.Words.clampedToLong; import java.util.List; @@ -84,6 +86,19 @@ public static Bytes32 getCreateRawAddress(final Address senderAddress, final lon })); } + public static Bytes32 gerCreate2RawAddress(final MessageFrame frame) { + final Address sender = frame.getRecipientAddress(); + + final Bytes32 salt = Bytes32.leftPad(frame.getStackItem(3)); + + final long offset = clampedToLong(frame.getStackItem(1)); + final long length = clampedToLong(frame.getStackItem(2)); + final Bytes initCode = frame.shadowReadMemory(offset, length); + final Bytes32 hash = keccak256(initCode); + + return getCreate2RawAddress(sender, salt, hash); + } + public static Bytes32 getCreate2RawAddress( final Address sender, final Bytes32 salt, final Bytes32 hash) { return Hash.keccak256(Bytes.concatenate(CREATE2_PREFIX, sender, salt, hash)); From 92fdcf18e68c337f2454ff63ec33f0f434304cd7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 31 Jul 2024 18:09:01 +0530 Subject: [PATCH 325/461] fix: debug java issues : no MessageFrame given when entering Context --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 1 + .../consensys/linea/zktracer/runtime/callstack/CallFrame.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 74c3f6777e..fd45e1bece 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -658,6 +658,7 @@ public void traceContextEnter(MessageFrame frame) { this.transients.conflation().deploymentInfo().number(codeAddress), codeDeploymentNumber, isDeployment); + this.currentFrame().initializeFrame(frame); // TODO should be done in enter this.defers.resolveUponEnteringChildContext(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 51898b253d..868106d627 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -331,6 +331,10 @@ public boolean hasReverted() { return this.selfReverts || this.getsReverted; } + public void initializeFrame(final MessageFrame frame) { + this.frame = frame; + } + public void frame(MessageFrame frame) { this.frame = frame; this.opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); From efdb63a2e19ede24767f03af2a8efdf7e1a9f72a Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 1 Aug 2024 10:03:48 +0530 Subject: [PATCH 326/461] fix java issues about initiamizing frame Signed-off-by: Francois Bojarski --- .../consensys/linea/zktracer/module/hub/Hub.java | 14 ++++++-------- .../zktracer/runtime/callstack/CallStack.java | 12 ------------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index fd45e1bece..683e7c5269 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -277,6 +277,8 @@ private List precompileLimitModules() { * those module are traced (and could be count) */ @Getter private final ShakiraData shakiraData; + + @Getter private final BlakeModexpData blakeModexpData = new BlakeModexpData(this.wcp, modexpEffectiveCall, blakeEffectiveCall, blakeRounds); @@ -296,7 +298,7 @@ private List precompileLimitModules() { private final L2Block l2Block; private final L2L1Logs l2L1Logs; - /** list of module triggered by the HUB at BESU hooks */ + /** list of module than can be modified during execution */ private final List modules; /** reference table modules */ @@ -546,7 +548,7 @@ public void traceEndTransaction( logs, selfDestructs); - if (!(this.state.getProcessingPhase() == TX_SKIP)) { + if (this.state.getProcessingPhase() != TX_SKIP) { this.state.stamps().incrementHubStamp(); } @@ -669,6 +671,7 @@ public void traceContextEnter(MessageFrame frame) { } public void traceContextReEnter(MessageFrame frame) { + this.currentFrame().initializeFrame(frame); // TODO: is it needed ? final int latestChildId = this.currentFrame().childFramesId().getLast(); this.defers.resolvePostRollback(this, frame, this.callStack.getById(latestChildId)); this.defers.resolveAtContextReEntry(this, this.currentFrame()); @@ -680,6 +683,7 @@ public void traceContextReEnter(MessageFrame frame) { @Override public void traceContextExit(MessageFrame frame) { + this.currentFrame().initializeFrame(frame); // TODO: is it needed ? if (frame.getDepth() > 0) { this.transients .conflation() @@ -969,8 +973,6 @@ void processStateExec(MessageFrame frame) { previousOperationWasCallToEcPrecompile = false; } - // TODO: delete me, we do it in the ZKTracer in every case (ie even if codeSize == 0) - // this.currentFrame().frame(frame); this.state.stamps().incrementHubStamp(); this.pch.setup(frame); @@ -1117,10 +1119,6 @@ void traceOperation(MessageFrame frame) { } } - public TraceSection getCurrentSection() { - return this.state.currentTxTrace().currentSection(); - } - public void squashCurrentFrameOutputData() { this.currentFrame().outputDataSpan(MemorySpan.empty()); this.currentFrame().outputData(Bytes.EMPTY); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java index 7ce53c86a1..23974c5c83 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallStack.java @@ -365,16 +365,4 @@ public int getParentContextNumberById(int id) { public void revert(int stamp) { this.current().revert(this, stamp); } - - public String pretty() { - StringBuilder r = new StringBuilder(2000); - for (CallFrame c : this.callFrames) { - final CallFrame parent = this.getParentCallFrameById(c.id()); - r.append(" ".repeat(c.depth())); - r.append( - "%d/%d (<- %d/%d): %s" - .formatted(c.id(), c.contextNumber(), parent.id(), parent.contextNumber(), c.type())); - } - return r.toString(); - } } From b2d512a22c86516f0e60c496e816f5b32e29288e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 1 Aug 2024 10:28:04 +0530 Subject: [PATCH 327/461] fix create failure case Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/section/CreateSection.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 19dd5a3f8c..6a16f11551 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -268,15 +268,15 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { final AccountFragment undoCreator = accountFragmentFactory.make( - reEntryCreatorSnapshot, childEntryCreatorSnapshot, + reEntryCreatorSnapshot, DomSubStampsSubFragment.revertsWithChildDomSubStamps( this.hubStamp(), childRevertStamp, 2)); final AccountFragment undoCreatee = accountFragmentFactory.make( - reEntryCreateeSnapshot, childEntryCreateeSnapshot, + reEntryCreateeSnapshot, DomSubStampsSubFragment.revertsWithChildDomSubStamps( this.hubStamp(), childRevertStamp, 3)); @@ -297,14 +297,14 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca final AccountFragment undoCreator = accountFragmentFactory.make( - childEntryCreatorSnapshot, + firstUndo ? childEntryCreatorSnapshot : reEntryCreatorSnapshot, preOpcodeCreatorSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), revertStamp, firstUndo ? 2 : 4)); final AccountFragment undoCreatee = accountFragmentFactory.make( - childEntryCreateeSnapshot, + firstUndo ? childEntryCreateeSnapshot : reEntryCreateeSnapshot, preOpcodeCreateeSnapshot, DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), revertStamp, firstUndo ? 3 : 5)); From 919c7434f72b0d22cb953d6f7015353ec7afb417 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 1 Aug 2024 11:25:16 +0530 Subject: [PATCH 328/461] feat add identity prc subsection Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/ecdata/EcData.java | 2 +- .../module/hub/fragment/imc/mmu/MmuCall.java | 59 ++++---- .../hub/precompiles/ModExpMetadata.java | 2 +- .../precompiles/PrecompileLinesGenerator.java | 130 ------------------ .../module/hub/section/CreateSection.java | 2 +- .../module/hub/section/call/CallSection.java | 6 +- .../IdentitySubsection.java | 83 +++++++++++ ...ha2SubSection.java => Sha2Subsection.java} | 7 +- .../hub/section/halt/ReturnSection.java | 2 +- .../hub/section/halt/RevertSection.java | 2 +- .../hub/transients/OperationAncillaries.java | 4 +- .../zktracer/opcode/gas/projector/Call.java | 4 +- .../zktracer/runtime/callstack/CallFrame.java | 4 +- .../linea/zktracer/types/MemorySpan.java | 2 +- 14 files changed, 131 insertions(+), 178 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/{Sha2SubSection.java => Sha2Subsection.java} (94%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index 194de772af..c7b11623ef 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -89,7 +89,7 @@ public void tracePreOpcode(MessageFrame frame) { final MemorySpan callDataSource = hub.transients().op().callDataSegment(); if (target.equals(Address.ALTBN128_PAIRING) - && (callDataSource.isEmpty() || callDataSource.length() % 192 != 0)) { + && (callDataSource.lengthNull() || callDataSource.length() % 192 != 0)) { return; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 2a64e0f39f..8d8f7251a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -348,7 +348,7 @@ public static MmuCall forEcRecover( return nop(); } } else { - if (recoverySuccessful && !p.requestedReturnDataTarget().isEmpty()) { + if (recoverySuccessful && !p.requestedReturnDataTarget().lengthNull()) { return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) @@ -392,7 +392,7 @@ public static MmuCall forShaTwoOrRipemdFullResultTransfer( final boolean isShaTwo = flag == PRC_SHA2_256; - if (precompileSubsection.callDataMemorySpan.isEmpty()) { + if (precompileSubsection.callDataMemorySpan.lengthNull()) { return new MmuCall(hub, MMU_INST_MSTORE) .targetId(precompileSubsection.exoModuleOperationId()) .targetOffset(EWord.ZERO) @@ -417,7 +417,7 @@ public static MmuCall forShaTwoOrRipemdPartialResultCopy( precompileSubsection.precompileScenarioFragment().getFlag(); Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); - Preconditions.checkArgument(!precompileSubsection.parentReturnDataTarget.isEmpty()); + Preconditions.checkArgument(!precompileSubsection.parentReturnDataTarget.lengthNull()); return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileSubsection.returnDataContextNumber()) @@ -428,36 +428,31 @@ public static MmuCall forShaTwoOrRipemdPartialResultCopy( .referenceSize(precompileSubsection.parentReturnDataTarget.length()); } - public static MmuCall forIdentity(final Hub hub, final PrecompileInvocation p, int i) { - Preconditions.checkArgument(i >= 0 && i < 2); + public static MmuCall forIdentityExtractCallData( + final Hub hub, PrecompileSubsection precompileSubsection) { - if (p.callDataSource().isEmpty()) { - return nop(); - } + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(precompileSubsection.callSection.hubStamp()) + .sourceRamBytes(Optional.of(precompileSubsection.callerMemorySnapshot)) + .targetId(precompileSubsection.exoModuleOperationId()) + .targetRamBytes(Optional.of(Bytes.EMPTY)) + .sourceOffset(EWord.of(precompileSubsection.callDataMemorySpan.offset())) + .targetOffset(EWord.ZERO) + .size(precompileSubsection.callDataMemorySpan.length()); + } - final int precompileContextNumber = p.hubStamp() + 1; + public static MmuCall forIdentityReturnData( + final Hub hub, final PrecompileSubsection precompileSubsection) { - if (i == 0) { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .size(p.callDataSource().length()) - .referenceOffset(0) - .referenceSize(p.callDataSource().length()); - } else { - if (p.requestedReturnDataTarget().isEmpty()) { - return nop(); - } else { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.ZERO) - .size(p.callDataSource().length()) - .referenceOffset(p.requestedReturnDataTarget().offset()) - .referenceSize(p.requestedReturnDataTarget().length()); - } - } + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(precompileSubsection.exoModuleOperationId()) + .sourceRamBytes(Optional.of(precompileSubsection.returnData())) + .targetId(precompileSubsection.callSection.hubStamp()) + .targetRamBytes(Optional.of(precompileSubsection.callerMemorySnapshot)) + .sourceOffset(EWord.ZERO) + .targetOffset(EWord.of(precompileSubsection.parentReturnDataTarget.offset())) + .size(precompileSubsection.parentReturnDataTarget.length()) + .referenceSize(precompileSubsection.parentReturnDataTarget.length()); } public static MmuCall forEcAdd(final Hub hub, final PrecompileInvocation p, int i) { @@ -543,7 +538,7 @@ public static MmuCall forEcPairing(final Hub hub, final PrecompileInvocation p, .setEcData() .phase(PHASE_ECPAIRING_DATA); } else if (i == 1) { - if (p.callDataSource().isEmpty()) { + if (p.callDataSource().lengthNull()) { return new MmuCall(hub, MMU_INST_MSTORE) .targetId(precompileContextNumber) .limb2(Bytes.of(1)); @@ -595,7 +590,7 @@ public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, in .setBlakeModexp() .phase(PHASE_BLAKE_RESULT); } else { - if (p.requestedReturnDataTarget().isEmpty()) { + if (p.requestedReturnDataTarget().lengthNull()) { return MmuCall.nop(); } else { return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java index 0c00c5493b..d818d40e65 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java @@ -35,7 +35,7 @@ public record ModExpMetadata( implements PrecompileMetadata { public static ModExpMetadata of(final Hub hub) { final MemorySpan callDataSource = hub.transients().op().callDataSegment(); - final boolean extractBbs = !callDataSource.isEmpty(); + final boolean extractBbs = !callDataSource.lengthNull(); final boolean extractEbs = callDataSource.length() > 32; final boolean extractMbs = callDataSource.length() > 64; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java deleted file mode 100644 index e6d26cb7fb..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileLinesGenerator.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.precompiles; - -import lombok.RequiredArgsConstructor; - -// TODO: remove this class ... total annihilation :) -@RequiredArgsConstructor -public class PrecompileLinesGenerator { - - /** - * public static List generateFor(final Hub hub, final PrecompileInvocation p) { - * final List r = new ArrayList<>(10); switch (p.precompile()) { case EC_RECOVER -> - * { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - * } else { final boolean recoverySuccessful = ((EcRecoverMetadata) - * p.metadata()).recoverySuccessful(); - * - *

r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu( - * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forEcRecover(hub, p, recoverySuccessful, - * 0))); r.add( ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : - * MmuCall.forEcRecover(hub, p, recoverySuccessful, 1))); r.add( ImcFragment.empty(hub) .callMmu( - * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forEcRecover(hub, p, recoverySuccessful, - * 2))); } } case SHA2_256 -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new - * PrecompileCommonOobCall(p))); } else { r.add( ImcFragment.empty(hub) .callOob(new - * PrecompileCommonOobCall(p)) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : - * MmuCall.forSha2(hub, p, 0))); r.add( ImcFragment.empty(hub) .callMmu( - * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forSha2(hub, p, 1))); r.add( - * ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : - * MmuCall.forSha2(hub, p, 2))); } } case RIPEMD_160 -> { if (p.hubFailure()) { - * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); } else { r.add( - * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu( - * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forRipeMd160(hub, p, 0))); r.add( - * ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : - * MmuCall.forRipeMd160(hub, p, 1))); r.add( ImcFragment.empty(hub) .callMmu( - * p.callDataSource().isEmpty() ? MmuCall.nop() : MmuCall.forRipeMd160(hub, p, 2))); } } case - * IDENTITY -> { if (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new - * PrecompileCommonOobCall(p))); } else { r.add( ImcFragment.empty(hub) .callOob(new - * PrecompileCommonOobCall(p)) .callMmu(MmuCall.forIdentity(hub, p, 0))); - * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forIdentity(hub, p, 1))); } } case MODEXP -> { - * final ModExpMetadata m = (ModExpMetadata) p.metadata(); final int bbsInt = - * m.bbs().toUnsignedBigInteger().intValueExact(); final int ebsInt = - * m.ebs().toUnsignedBigInteger().intValueExact(); final int mbsInt = - * m.mbs().toUnsignedBigInteger().intValueExact(); - * - *

r.add(ImcFragment.empty(hub).callOob(new ModexpCallDataSizeOobCall(p))); r.add( - * ImcFragment.empty(hub) .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_BBS)) - * .callMmu(m.extractBbs() ? MmuCall.forModExp(hub, p, 2) : MmuCall.nop())); r.add( - * ImcFragment.empty(hub) .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_EBS)) - * .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 3) : MmuCall.nop())); r.add( - * ImcFragment.empty(hub) .callOob(new ModexpXbsOobCall(p, ModexpXbsCase.OOB_INST_MODEXP_MBS)) - * .callMmu(m.extractEbs() ? MmuCall.forModExp(hub, p, 4) : MmuCall.nop())); final ImcFragment - * line5 = ImcFragment.empty(hub) .callOob(new ModexpLeadOobCall(p)) - * .callMmu(m.loadRawLeadingWord() ? MmuCall.forModExp(hub, p, 5) : MmuCall.nop()); if - * (m.loadRawLeadingWord()) { line5.callExp(new ModexpLogExpCall(p)); } r.add(line5); - * r.add(ImcFragment.empty(hub).callOob(new ModexpPricingOobCall(p))); if (p.ramFailure()) { - * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( - * ImcFragment.empty(hub) .callOob(new ModexpExtractOobCall(p)) .callMmu(m.extractModulus() ? - * MmuCall.forModExp(hub, p, 7) : MmuCall.nop())); - * - *

if (m.extractModulus()) { r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, - * 8))); r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 9))); - * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 10))); } else { for (int i = 0; - * i < 4; i++) { r.add(ImcFragment.empty(hub)); } } - * - *

if (!m.mbs().isZero() && !p.requestedReturnDataTarget().isEmpty()) { - * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forModExp(hub, p, 11))); } - * - *

r.add( ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), - * hub.newChildContextNumber())); } } case EC_ADD -> { if (p.hubFailure()) { - * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { - * r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) - * .callMmu(MmuCall.forEcAdd(hub, p, 0))); - * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( - * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcAdd(hub, - * p, 0))); r.add( ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : - * MmuCall.forEcAdd(hub, p, 1))); r.add( ImcFragment.empty(hub) .callMmu( - * p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcAdd(hub, p, 2))); r.add( - * ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), - * hub.newChildContextNumber())); } } case EC_MUL -> { if (p.hubFailure()) { - * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { - * r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) - * .callMmu(MmuCall.forEcMul(hub, p, 0))); - * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( - * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) .callMmu(MmuCall.forEcMul(hub, - * p, 0))); r.add( ImcFragment.empty(hub) .callMmu( p.callDataSource().isEmpty() ? MmuCall.nop() : - * MmuCall.forEcMul(hub, p, 1))); r.add( ImcFragment.empty(hub) .callMmu( - * p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : MmuCall.forEcMul(hub, p, 2))); r.add( - * ContextFragment.executionProvidesReturnData( hub, hub.currentFrame().contextNumber(), - * hub.newChildContextNumber())); } } case EC_PAIRING -> { if (p.hubFailure()) { - * r.add(ImcFragment.empty(hub).callOob(new PrecompileCommonOobCall(p))); - * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else if (p.ramFailure()) { - * r.add( ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) - * .callMmu(MmuCall.forEcPairing(hub, p, 0))); - * r.add(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } else { r.add( - * ImcFragment.empty(hub) .callOob(new PrecompileCommonOobCall(p)) - * .callMmu(MmuCall.forEcPairing(hub, p, 0))); - * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forEcPairing(hub, p, 1))); r.add( - * ImcFragment.empty(hub) .callMmu( p.requestedReturnDataTarget().isEmpty() ? MmuCall.nop() : - * MmuCall.forEcPairing(hub, p, 2))); r.add( ContextFragment.executionProvidesReturnData( hub, - * hub.currentFrame().contextNumber(), hub.newChildContextNumber())); } } case BLAKE2F -> { if - * (p.hubFailure()) { r.add(ImcFragment.empty(hub).callOob(new Blake2fCallDataSizeOobCall(p))); } - * else if (p.ramFailure()) { r.add( ImcFragment.empty(hub) .callOob(new - * Blake2fCallDataSizeOobCall(p)) .callMmu(MmuCall.forBlake2f(hub, p, 0))); - * r.add(ImcFragment.empty(hub).callOob(new Blake2fParamsOobCall(p))); } else { r.add( - * ImcFragment.empty(hub) .callOob(new Blake2fCallDataSizeOobCall(p)) - * .callMmu(MmuCall.forBlake2f(hub, p, 0))); r.add( ImcFragment.empty(hub) .callOob(new - * Blake2fParamsOobCall(p)) .callMmu(MmuCall.forBlake2f(hub, p, 1))); - * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 2))); - * r.add(ImcFragment.empty(hub).callMmu(MmuCall.forBlake2f(hub, p, 3))); } } } - * - *

r.add( p.success() ? ContextFragment.executionProvidesReturnData( hub, - * hub.currentFrame().contextNumber(), hub.newChildContextNumber()) : - * ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); return r; } - */ -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 6a16f11551..07a6e17411 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -182,7 +182,7 @@ public CreateSection(Hub hub) { deploymentAccount.map(AccountState::hasCode).orElse(false); final boolean failedCreate = createdAddressHasNonZeroNonce || createdAddressHasNonEmptyCode; - final boolean emptyInitCode = hub.transients().op().initCodeSegment().isEmpty(); + final boolean emptyInitCode = hub.transients().op().initCodeSegment().lengthNull(); // Trigger MMU & SHAKIRA to hash the (non-empty) InitCode of CREATE2 - even for failed CREATE2 if (hub.opCode() == CREATE2 && !emptyInitCode) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index a832d90b5a..3473a149a9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -19,6 +19,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.*; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; +import static org.hyperledger.besu.datatypes.Address.ID; import static org.hyperledger.besu.datatypes.Address.SHA256; import java.util.Map; @@ -43,8 +44,9 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.IdentitySubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; -import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.Sha2SubSection; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.Sha2Subsection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; @@ -65,7 +67,7 @@ public class CallSection extends TraceSection // TODO: finish this map private static final Map> - ADDRESS_TO_PRECOMPILE = Map.of(SHA256, Sha2SubSection::new); + ADDRESS_TO_PRECOMPILE = Map.of(SHA256, Sha2Subsection::new, ID, IdentitySubsection::new); // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java new file mode 100644 index 0000000000..aa941cc642 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java @@ -0,0 +1,83 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; + +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityExtractCallData; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityReturnData; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_IDENTITY; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_IDENTITY; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; + +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; +import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; + +public class IdentitySubsection extends PrecompileSubsection { + + final ImcFragment firstImcFragment; + final PrecompileCommonOobCall oobCall; + + public IdentitySubsection(final Hub hub, final CallSection callSection) { + super(hub, callSection); + + precompileScenarioFragment.setFlag(PRC_IDENTITY); + + firstImcFragment = ImcFragment.empty(hub); + oobCall = new PrecompileCommonOobCall(OOB_INST_IDENTITY); + firstImcFragment.callOob(oobCall); + + if (!oobCall.isHubSuccess()) { + precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + } + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { + super.resolveAtContextReEntry(hub, callFrame); + + // sanity check + Preconditions.checkArgument(successBit == oobCall.isHubSuccess()); + + if (!successBit) { + return; + } + + final boolean extractCallData = successBit && !callDataMemorySpan.lengthNull(); + if (extractCallData) { + final MmuCall mmuCall = forIdentityExtractCallData(hub, this); + firstImcFragment.callMmu(mmuCall); + } + + final ImcFragment secondImcFragment = ImcFragment.empty(hub); + fragments().add(secondImcFragment); + if (extractCallData && !parentReturnDataTarget().lengthNull()) { + final MmuCall mmuCall = forIdentityReturnData(hub, this); + secondImcFragment.callMmu(mmuCall); + } + } + + // 3 = 1 + 2 (scenario row + up to 2 miscellaneous fragments) + @Override + protected short maxNumberOfLines() { + return 3; + // Note: we don't have the successBit available at the moment + // and can't provide the "real" value (2 in case of FKTH.) + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java index a3f80580c7..7250629c23 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2SubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java @@ -29,17 +29,18 @@ import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -public class Sha2SubSection extends PrecompileSubsection { +public class Sha2Subsection extends PrecompileSubsection { final ImcFragment firstImcFragment; final PrecompileCommonOobCall oobCall; - public Sha2SubSection(Hub hub, CallSection callSection) { + public Sha2Subsection(Hub hub, CallSection callSection) { super(hub, callSection); precompileScenarioFragment.setFlag(PRC_SHA2_256); oobCall = new PrecompileCommonOobCall(OOB_INST_SHA2); firstImcFragment = ImcFragment.empty(hub); + this.fragments().add(firstImcFragment); firstImcFragment.callOob(oobCall); if (!oobCall.isHubSuccess()) { @@ -81,7 +82,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { // the partial copy of return data happens only if the caller context // provided a nonempty return data target - if (!parentReturnDataTarget.isEmpty()) { + if (!parentReturnDataTarget.lengthNull()) { final MmuCall partialReturnDataCopy = MmuCall.forShaTwoOrRipemdPartialResultCopy(hub, this); thirdImcFragment.callMmu(partialReturnDataCopy); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 0a18d734cb..b78d46209e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -137,7 +137,7 @@ public ReturnSection(Hub hub) { final boolean messageCallReturnTouchesRam = !currentFrame.isRoot() && nontrivialMmuOperation // [size ≠ 0] ∧ ¬MXPX - && !currentFrame.returnDataTargetInCaller().isEmpty(); // [r@c ≠ 0] + && !currentFrame.returnDataTargetInCaller().lengthNull(); // [r@c ≠ 0] returnScenarioFragment.setScenario( messageCallReturnTouchesRam diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index 3d086e4f12..4b921c76f6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -56,7 +56,7 @@ public RevertSection(Hub hub) { (Exceptions.none(exceptions)) && !hub.currentFrame().isRoot() && mxpCall.mayTriggerNontrivialMmuOperation // i.e. size ≠ 0 ∧ ¬MXPX - && !hub.currentFrame().returnDataTargetInCaller().isEmpty(); + && !hub.currentFrame().returnDataTargetInCaller().lengthNull(); if (triggerMmu) { mmuCall = MmuCall.revert(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index e0087a3493..3dc6ae84a2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -39,7 +39,7 @@ public class OperationAncillaries { private static Bytes maybeShadowReadMemory(final MemorySpan span, final MessageFrame frame) { // Accesses to huge offset with 0-length are valid - if (span.isEmpty()) { + if (span.lengthNull()) { return Bytes.EMPTY; } @@ -248,7 +248,7 @@ public Bytes outputData() { final MemorySpan outputDataSpan = outputDataSpan(); // Accesses to huge offset with 0-length are valid - if (outputDataSpan.isEmpty()) { + if (outputDataSpan.lengthNull()) { return Bytes.EMPTY; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java index f7235dae10..0d55dbab7e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java @@ -62,8 +62,8 @@ public long largestOffset() { } return Math.max( - inputData.isEmpty() ? 0 : Words.clampedAdd(inputData.offset(), inputData.length()), - returnData.isEmpty() ? 0 : Words.clampedAdd(returnData.offset(), returnData.length())); + inputData.lengthNull() ? 0 : Words.clampedAdd(inputData.offset(), inputData.length()), + returnData.lengthNull() ? 0 : Words.clampedAdd(returnData.offset(), returnData.length())); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 868106d627..79f0b4dfc3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -345,6 +345,8 @@ public void frame(MessageFrame frame) { public static Bytes extractContiguousLimbsFromMemory( final MessageFrame frame, final MemorySpan memorySpan) { // TODO: optimize me please. Need a review of the MMU operation handling. - return memorySpan.isEmpty() ? Bytes.EMPTY : frame.shadowReadMemory(0, frame.memoryByteSize()); + return memorySpan.lengthNull() + ? Bytes.EMPTY + : frame.shadowReadMemory(0, frame.memoryByteSize()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java index 454a61441d..6d61a489ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java @@ -50,7 +50,7 @@ long end() { return this.length + this.length; } - public boolean isEmpty() { + public boolean lengthNull() { return this.length == 0; } From 2aac0c53d27f5d86d257a594ad5ca6753e791f91 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 1 Aug 2024 16:16:54 +0530 Subject: [PATCH 329/461] feat modexp PRC subsection Signed-off-by: Francois Bojarski --- .../blake2fmodexpdata/BlakeModexpData.java | 15 +- .../BlakeModexpDataOperation.java | 29 +-- .../module/hub/fragment/imc/mmu/MmuCall.java | 210 +++++++++-------- .../hub/precompiles/ModExpMetadata.java | 215 ++++++++++++------ .../module/hub/section/call/CallSection.java | 12 +- .../BlakeSubsection.java} | 11 +- .../IdentitySubsection.java | 4 +- .../ModexpSubsection.java | 164 +++++++++++++ .../PrecompileSubsection.java | 12 +- .../precompileSubsection/Sha2Subsection.java | 7 +- 10 files changed, 479 insertions(+), 200 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/{blake2fmodexpdata/ModexpComponents.java => hub/section/call/precompileSubsection/BlakeSubsection.java} (63%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java index e8e1eb5753..391ac84cf2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; +import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds; import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall; @@ -45,8 +46,8 @@ public class BlakeModexpData implements Module { private final ModexpEffectiveCall modexpEffectiveCall; private final BlakeEffectiveCall blakeEffectiveCall; private final BlakeRounds blakeRounds; - private StackedSet operations = new StackedSet<>(); - private List sortedOperations = new ArrayList<>(); + private final StackedSet operations = new StackedSet<>(); + private final List sortedOperations = new ArrayList<>(); private int numberOfOperationsAtStartTx = 0; @Override @@ -95,8 +96,8 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - public void callModexp(final ModexpComponents modexpComponents) { - operations.add(new BlakeModexpDataOperation(modexpComponents)); + public void callModexp(final ModExpMetadata modexpMetaData, final int id) { + operations.add(new BlakeModexpDataOperation(modexpMetaData, id)); modexpEffectiveCall.addPrecompileLimit(1); } @@ -119,9 +120,9 @@ public void commit(List buffers) { public Bytes getInputDataByIdAndPhase(final int id, final int phase) { final BlakeModexpDataOperation op = getOperationById(id); return switch (phase) { - case PHASE_MODEXP_BASE -> op.modexpComponents.get().base(); - case PHASE_MODEXP_EXPONENT -> op.modexpComponents.get().exp(); - case PHASE_MODEXP_MODULUS -> op.modexpComponents.get().mod(); + case PHASE_MODEXP_BASE -> op.modexpMetaData.get().base(); + case PHASE_MODEXP_EXPONENT -> op.modexpMetaData.get().exp(); + case PHASE_MODEXP_MODULUS -> op.modexpMetaData.get().mod(); case PHASE_MODEXP_RESULT -> Bytes.EMPTY; // TODO case PHASE_BLAKE_DATA -> op.blake2fComponents.get().data(); case PHASE_BLAKE_RESULT -> Bytes.EMPTY; // TODO diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java index d9f6cd0cee..e16ddd7d5c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java @@ -40,6 +40,7 @@ import lombok.Getter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; +import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.Hash; @@ -57,24 +58,24 @@ public class BlakeModexpDataOperation extends ModuleOperation { @Getter public final long id; - public final Optional modexpComponents; + public final Optional modexpMetaData; public final Optional blake2fComponents; - public BlakeModexpDataOperation(final ModexpComponents modexpComponents) { - this.id = 0; // TODO - this.modexpComponents = Optional.of(modexpComponents); + public BlakeModexpDataOperation(final ModExpMetadata modexpMetaData, final int id) { + this.id = id; + this.modexpMetaData = Optional.of(modexpMetaData); this.blake2fComponents = Optional.empty(); } public BlakeModexpDataOperation(final BlakeComponents blakeComponents) { this.id = 0; // TODO - this.modexpComponents = Optional.empty(); + this.modexpMetaData = Optional.empty(); this.blake2fComponents = Optional.of(blakeComponents); } @Override protected int computeLineCount() { - return modexpComponents.isPresent() + return modexpMetaData.isPresent() ? MODEXP_COMPONENTS_LINE_COUNT : BLAKE2f_COMPONENTS_LINE_COUNT; } @@ -82,7 +83,7 @@ protected int computeLineCount() { void trace(Trace trace, final int stamp) { final UnsignedByte stampByte = UnsignedByte.of(stamp); - if (modexpComponents.isPresent()) { + if (modexpMetaData.isPresent()) { traceBase(trace, stampByte); traceExponent(trace, stampByte); traceModulus(trace, stampByte); @@ -130,7 +131,7 @@ private void traceBlakeResult(Trace trace, UnsignedByte stamp) { } private void traceBase(Trace trace, final UnsignedByte stamp) { - final Bytes input = leftPadTo(modexpComponents.get().base(), MODEXP_COMPONENT_BYTE_SIZE); + final Bytes input = leftPadTo(modexpMetaData.get().base(), MODEXP_COMPONENT_BYTE_SIZE); for (int index = 0; index <= INDEX_MAX_MODEXP_BASE; index++) { commonTrace(trace, stamp, index, input, INDEX_MAX_MODEXP_BASE); trace.phase(UnsignedByte.of(PHASE_MODEXP_BASE)).isModexpBase(true).fillAndValidateRow(); @@ -138,7 +139,7 @@ private void traceBase(Trace trace, final UnsignedByte stamp) { } private void traceExponent(Trace trace, final UnsignedByte stamp) { - final Bytes input = leftPadTo(modexpComponents.get().exp(), MODEXP_COMPONENT_BYTE_SIZE); + final Bytes input = leftPadTo(modexpMetaData.get().exp(), MODEXP_COMPONENT_BYTE_SIZE); for (int index = 0; index <= INDEX_MAX_MODEXP_EXPONENT; index++) { commonTrace(trace, stamp, index, input, INDEX_MAX_MODEXP_EXPONENT); trace @@ -149,7 +150,7 @@ private void traceExponent(Trace trace, final UnsignedByte stamp) { } private void traceModulus(Trace trace, final UnsignedByte stamp) { - final Bytes input = leftPadTo(modexpComponents.get().mod(), MODEXP_COMPONENT_BYTE_SIZE); + final Bytes input = leftPadTo(modexpMetaData.get().mod(), MODEXP_COMPONENT_BYTE_SIZE); for (int index = 0; index <= INDEX_MAX_MODEXP_MODULUS; index++) { commonTrace(trace, stamp, index, input, INDEX_MAX_MODEXP_MODULUS); trace.phase(UnsignedByte.of(PHASE_MODEXP_MODULUS)).isModexpModulus(true).fillAndValidateRow(); @@ -157,7 +158,7 @@ private void traceModulus(Trace trace, final UnsignedByte stamp) { } private void traceModexpResult(Trace trace, final UnsignedByte stamp) { - final Bytes input = leftPadTo(computeModexpResult(), MODEXP_COMPONENT_BYTE_SIZE); + final Bytes input = leftPadTo(modexpMetaData.get().rawResult(), MODEXP_COMPONENT_BYTE_SIZE); for (int index = 0; index <= INDEX_MAX_MODEXP_RESULT; index++) { commonTrace(trace, stamp, index, input, INDEX_MAX_MODEXP_RESULT); trace.phase(UnsignedByte.of(PHASE_MODEXP_RESULT)).isModexpResult(true).fillAndValidateRow(); @@ -174,9 +175,9 @@ private void commonTrace(Trace trace, UnsignedByte stamp, int index, Bytes input } private Bytes computeModexpResult() { - final BigInteger baseBigInt = modexpComponents.get().base().toUnsignedBigInteger(); - final BigInteger expBigInt = modexpComponents.get().exp().toUnsignedBigInteger(); - final BigInteger modBigInt = modexpComponents.get().mod().toUnsignedBigInteger(); + final BigInteger baseBigInt = modexpMetaData.get().base().toUnsignedBigInteger(); + final BigInteger expBigInt = modexpMetaData.get().exp().toUnsignedBigInteger(); + final BigInteger modBigInt = modexpMetaData.get().mod().toUnsignedBigInteger(); return modBigInt.equals(BigInteger.ZERO) ? Bytes.of(0) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 8d8f7251a1..a3c814d411 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -81,6 +81,7 @@ import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.LogData; @@ -603,104 +604,133 @@ public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, in } } - public static MmuCall forModExp(final Hub hub, final PrecompileInvocation p, int i) { - Preconditions.checkArgument(i >= 2 && i < 12); - final ModExpMetadata m = (ModExpMetadata) p.metadata(); - final int precompileContextNumber = p.hubStamp() + 1; + public static MmuCall forModexpExtractBbs( + final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + .sourceId(hub.currentFrame().contextNumber()) + .referenceOffset(precompileSubsection.callDataMemorySpan.offset()) + .referenceSize(precompileSubsection.callDataMemorySpan.length()) + .limb1(metaData.bbs().hi()) + .limb2(metaData.bbs().lo()); + } - if (i == 2) { - return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) - .sourceId(hub.currentFrame().contextNumber()) - .referenceOffset(p.callDataSource().offset()) - .referenceSize(p.callDataSource().length()) - .limb1(m.bbs().hi()) - .limb2(m.bbs().lo()); - } else if (i == 3) { - return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) - .sourceId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.of(32)) - .referenceOffset(p.callDataSource().offset()) - .referenceSize(p.callDataSource().length()) - .limb1(m.ebs().hi()) - .limb2(m.ebs().lo()); - } else if (i == 4) { - return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) - .sourceId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.of(64)) - .referenceOffset(p.callDataSource().offset()) - .referenceSize(p.callDataSource().length()) - .limb1(m.mbs().hi()) - .limb2(m.mbs().lo()); - } else if (i == 5) { - return new MmuCall(hub, MMU_INST_MLOAD) - .sourceId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.of(p.callDataSource().offset() + 96 + m.bbs().toInt())) - .limb1(m.rawLeadingWord().hi()) - .limb2(m.rawLeadingWord().lo()); - } else if (i == 7) { - if (m.extractBase()) { - return new MmuCall(hub, MMU_INST_MODEXP_DATA) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(96)) - .size(m.bbs().toInt()) - .referenceOffset(p.callDataSource().offset()) - .referenceSize(p.callDataSource().length()) - .phase(PHASE_MODEXP_BASE) - .setBlakeModexp(); - } else { - return new MmuCall(hub, MMU_INST_MODEXP_ZERO) - .targetId(precompileContextNumber) - .phase(PHASE_MODEXP_BASE) - .setBlakeModexp(); - } - } else if (i == 8) { - if (m.extractExponent()) { - return new MmuCall(hub, MMU_INST_MODEXP_DATA) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(96 + m.bbs().toInt())) - .size(m.ebs().toInt()) - .referenceOffset(p.callDataSource().offset()) - .referenceSize(p.callDataSource().length()) - .phase(PHASE_MODEXP_EXPONENT) - .setBlakeModexp(); - } else { - return new MmuCall(hub, MMU_INST_MODEXP_ZERO) - .targetId(precompileContextNumber) - .phase(PHASE_MODEXP_EXPONENT) - .setBlakeModexp(); - } - } else if (i == 9) { + public static MmuCall forModexpExtractEbs( + final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + .sourceId(hub.currentFrame().contextNumber()) + .sourceOffset(EWord.of(32)) + .referenceOffset(precompileSubsection.callDataMemorySpan.offset()) + .referenceSize(precompileSubsection.callDataMemorySpan.length()) + .limb1(metaData.ebs().hi()) + .limb2(metaData.ebs().lo()); + } + + public static MmuCall forModexpExtractMbs( + final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) + .sourceId(hub.currentFrame().contextNumber()) + .sourceOffset(EWord.of(64)) + .referenceOffset(precompileSubsection.callDataMemorySpan.offset()) + .referenceSize(precompileSubsection.callDataMemorySpan.length()) + .limb1(metaData.mbs().hi()) + .limb2(metaData.mbs().lo()); + } + + public static MmuCall forModexpLoadLead( + final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + return new MmuCall(hub, MMU_INST_MLOAD) + .sourceId(hub.currentFrame().contextNumber()) + .sourceOffset( + EWord.of( + precompileSubsection.callDataMemorySpan.offset() + 96 + metaData.bbs().toInt())) + .limb1(metaData.rawLeadingWord().hi()) + .limb2(metaData.rawLeadingWord().lo()); + } + + public static MmuCall forModexpExtractBase( + final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + if (modExpMetadata.extractBase()) { return new MmuCall(hub, MMU_INST_MODEXP_DATA) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(96 + m.bbs().toInt() + m.ebs().toInt())) - .size(m.mbs().toInt()) - .referenceOffset(p.callDataSource().offset()) - .referenceSize(p.callDataSource().length()) - .phase(PHASE_MODEXP_MODULUS) + .sourceId(modexpSubsection.callSection.hubStamp()) + .sourceRamBytes(Optional.of(modexpSubsection.callerMemorySnapshot)) + .targetId(modexpSubsection.exoModuleOperationId()) + .targetRamBytes(Optional.of(modExpMetadata.base())) + .sourceOffset(EWord.of(96)) + .size(modExpMetadata.bbs().toInt()) + .referenceOffset(modexpSubsection.callDataMemorySpan.offset()) + .referenceSize(modexpSubsection.callDataMemorySpan.length()) + .phase(PHASE_MODEXP_BASE) .setBlakeModexp(); - } else if (i == 10) { - return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(precompileContextNumber) - .targetId(precompileContextNumber) - .size(512) - .phase(PHASE_MODEXP_RESULT) + } else { + return new MmuCall(hub, MMU_INST_MODEXP_ZERO) + .targetId(modexpSubsection.exoModuleOperationId()) + .phase(PHASE_MODEXP_BASE) + .setBlakeModexp(); + } + } + + public static MmuCall forModexpExtractExponent( + final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + if (modExpMetadata.extractExponent()) { + return new MmuCall(hub, MMU_INST_MODEXP_DATA) + .sourceId(modexpSubsection.callSection.hubStamp()) + .sourceRamBytes(Optional.of(modexpSubsection.callerMemorySnapshot)) + .targetId(modexpSubsection.exoModuleOperationId()) + .targetRamBytes(Optional.of(modExpMetadata.exp())) + .sourceOffset(EWord.of(96 + modExpMetadata.bbs().toInt())) + .size(modExpMetadata.ebs().toInt()) + .referenceOffset(modexpSubsection.callDataMemorySpan.offset()) + .referenceSize(modexpSubsection.callDataMemorySpan.length()) + .phase(PHASE_MODEXP_EXPONENT) .setBlakeModexp(); - } else if (i == 11) { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.of(512 - m.mbs().toInt())) - .size(m.mbs().toInt()) - .referenceOffset(p.requestedReturnDataTarget().offset()) - .referenceSize(p.requestedReturnDataTarget().length()); } else { - throw new IllegalArgumentException("need a boolean"); + return new MmuCall(hub, MMU_INST_MODEXP_ZERO) + .targetId(modexpSubsection.exoModuleOperationId()) + .phase(PHASE_MODEXP_EXPONENT) + .setBlakeModexp(); } } + public static MmuCall forModexpExtractModulus( + final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + return new MmuCall(hub, MMU_INST_MODEXP_DATA) + .sourceId(modexpSubsection.callSection.hubStamp()) + .sourceRamBytes(Optional.of(modexpSubsection.callerMemorySnapshot)) + .targetId(modexpSubsection.exoModuleOperationId()) + .targetRamBytes(Optional.of(modExpMetadata.mod())) + .sourceOffset(EWord.of(96 + modExpMetadata.bbs().toInt() + modExpMetadata.ebs().toInt())) + .size(modExpMetadata.mbs().toInt()) + .referenceOffset(modexpSubsection.callDataMemorySpan.offset()) + .referenceSize(modexpSubsection.callDataMemorySpan.length()) + .phase(PHASE_MODEXP_MODULUS) + .setBlakeModexp(); + } + + public static MmuCall forModexpFullResultCopy( + final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) + .sourceId(modexpSubsection.exoModuleOperationId()) + .exoBytes(Optional.of(modexpSubsection.returnData())) + .targetId(modexpSubsection.returnDataContextNumber()) + .targetRamBytes(Optional.of(Bytes.EMPTY)) + .size(512) + .phase(PHASE_MODEXP_RESULT) + .setBlakeModexp(); + } + + public static MmuCall forModexpPartialResultCopy( + final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(modexpSubsection.exoModuleOperationId()) + .sourceRamBytes(Optional.of(modexpSubsection.returnData())) + .targetId(modexpSubsection.callSection.hubStamp()) + .targetRamBytes(Optional.of(modexpSubsection.callerMemorySnapshot)) + .sourceOffset(EWord.of(512 - modExpMetadata.mbs().toInt())) + .size(modExpMetadata.mbs().toInt()) + .referenceOffset(modexpSubsection.parentReturnDataTarget.offset()) + .referenceSize(modexpSubsection.parentReturnDataTarget.length()); + } + @Override public Trace trace(Trace trace, State.TxState.Stamps stamps) { if (traceMe) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java index d818d40e65..abe60fd83f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java @@ -15,78 +15,155 @@ package net.consensys.linea.zktracer.module.hub.precompiles; -import net.consensys.linea.zktracer.module.hub.Hub; +import static net.consensys.linea.zktracer.types.Utils.rightPadTo; + +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.evm.internal.Words; + +@Getter +@Accessors(fluent = true) +public class ModExpMetadata { + static final int EBS_MIN_OFFSET = 32; + static final int MBS_MIN_OFFSET = 64; + static final int BASE_MIN_OFFSET = 96; + + private final Bytes callData; + private final MemorySpan callDataSource; + @Setter private Bytes rawResult; + + public ModExpMetadata(final Bytes callData, final MemorySpan callDataSource) { + this.callData = callData; + this.callDataSource = callDataSource; + } + + public boolean extractBbs() { + return !callDataSource.lengthNull(); + } + + public boolean extractEbs() { + return callDataSource.length() > EBS_MIN_OFFSET; + } + + public boolean extractMbs() { + return callDataSource.length() > MBS_MIN_OFFSET; + } + + private int bbsShift() { + return EBS_MIN_OFFSET - (int) Math.min(EBS_MIN_OFFSET, callDataSource.length()); + } + + public Bytes rawBbs() { + return extractBbs() + ? callData.slice((int) callDataSource.offset(), EBS_MIN_OFFSET) + : Bytes.EMPTY; + } + + public EWord bbs() { + return EWord.of(rawBbs().shiftRight(bbsShift()).shiftLeft(bbsShift())); + } + + private int ebsShift() { + return extractEbs() + ? EBS_MIN_OFFSET - (int) Math.min(EBS_MIN_OFFSET, callDataSource.length() - EBS_MIN_OFFSET) + : 0; + } + + public Bytes rawEbs() { + return extractEbs() + ? callData.slice((int) (callDataSource.offset() + EBS_MIN_OFFSET), EBS_MIN_OFFSET) + : Bytes.EMPTY; + } + + public EWord ebs() { + return EWord.of(rawEbs().shiftRight(ebsShift()).shiftLeft(ebsShift())); + } + + private int mbsShift() { + return extractMbs() + ? EBS_MIN_OFFSET - (int) Math.min(EBS_MIN_OFFSET, callDataSource.length() - MBS_MIN_OFFSET) + : 0; + } + + public Bytes rawMbs() { + return extractMbs() + ? callData.slice((int) (callDataSource.offset() + MBS_MIN_OFFSET), EBS_MIN_OFFSET) + : Bytes.EMPTY; + } + + public EWord mbs() { + return EWord.of(rawMbs().shiftRight(mbsShift()).shiftLeft(mbsShift())); + } + + private int bbsInt() { + return bbs().toUnsignedBigInteger().intValueExact(); + } + + private int ebsInt() { + return ebs().toUnsignedBigInteger().intValueExact(); + } + + public boolean loadRawLeadingWord() { + return callDataSource.length() > BASE_MIN_OFFSET + bbsInt() && !ebs().isZero(); + } + + public EWord rawLeadingWord() { + + return loadRawLeadingWord() + ? EWord.of( + callData.slice( + (int) (callDataSource.offset() + BASE_MIN_OFFSET + bbsInt()), EBS_MIN_OFFSET)) + : EWord.ZERO; + } + + public boolean extractModulus() { + return (callDataSource.length() > MBS_MIN_OFFSET + bbsInt() + ebsInt()) && !mbs().isZero(); + } + + public boolean extractBase() { + return extractModulus() && !bbs().isZero(); + } + + public boolean extractExponent() { + return extractModulus() && !ebs().isZero(); + } + + public Bytes base() { + Bytes unpadded = Bytes.EMPTY; + if (callDataSource.length() >= BASE_MIN_OFFSET) { + final int sizeToExtract = + (int) Math.min(bbsInt(), callDataSource().length() - MBS_MIN_OFFSET); + unpadded = callData.slice(MBS_MIN_OFFSET, sizeToExtract); + } + return rightPadTo(unpadded, bbsInt()); + } + + public Bytes exp() { + Bytes unpadded = Bytes.EMPTY; + if (callDataSource.length() >= BASE_MIN_OFFSET + bbsInt()) { + final int sizeToExtract = + (int) Math.min(ebsInt(), callDataSource().length() - BASE_MIN_OFFSET - bbsInt()); + unpadded = callData.slice(BASE_MIN_OFFSET + bbsInt(), sizeToExtract); + } + return rightPadTo(unpadded, ebsInt()); + } + + public Bytes mod() { + Bytes unpadded = Bytes.EMPTY; + final int firstOffset = BASE_MIN_OFFSET + bbsInt() + ebsInt(); + if (callDataSource.length() >= firstOffset) { + final int sizeToExtract = + (int) Math.min(Words.clampedToLong(mbs()), callDataSource().length() - firstOffset); + unpadded = callData.slice(firstOffset, sizeToExtract); + } + return rightPadTo(unpadded, (int) Words.clampedToLong(mbs())); + } -public record ModExpMetadata( - boolean extractBbs, - boolean extractEbs, - boolean extractMbs, - EWord bbs, - EWord ebs, - EWord mbs, - boolean loadRawLeadingWord, - EWord rawLeadingWord, - boolean extractModulus, - boolean extractBase, - boolean extractExponent) - implements PrecompileMetadata { - public static ModExpMetadata of(final Hub hub) { - final MemorySpan callDataSource = hub.transients().op().callDataSegment(); - final boolean extractBbs = !callDataSource.lengthNull(); - final boolean extractEbs = callDataSource.length() > 32; - final boolean extractMbs = callDataSource.length() > 64; - - final int bbsShift = 32 - (int) Math.min(32, callDataSource.length()); - final Bytes rawBbs = - extractBbs ? hub.messageFrame().shadowReadMemory(callDataSource.offset(), 32) : Bytes.EMPTY; - final EWord bbs = EWord.of(rawBbs.shiftRight(bbsShift).shiftLeft(bbsShift)); - - final int ebsShift = extractEbs ? 32 - (int) Math.min(32, callDataSource.length() - 32) : 0; - final Bytes rawEbs = - extractEbs - ? hub.messageFrame().shadowReadMemory(callDataSource.offset() + 32, 32) - : Bytes.EMPTY; - final EWord ebs = EWord.of(rawEbs.shiftRight(ebsShift).shiftLeft(ebsShift)); - - final int mbsShift = extractMbs ? 32 - (int) Math.min(32, callDataSource.length() - 64) : 0; - final Bytes rawMbs = - extractMbs - ? hub.messageFrame().shadowReadMemory(callDataSource.offset() + 64, 32) - : Bytes.EMPTY; - final EWord mbs = EWord.of(rawMbs.shiftRight(mbsShift).shiftLeft(mbsShift)); - - // TODO: maybe do not use intValueExact() here and just convert to int - // TODO: checks over size may be done later - final int bbsInt = bbs.toUnsignedBigInteger().intValueExact(); - final int ebsInt = ebs.toUnsignedBigInteger().intValueExact(); - - final boolean loadRawLeadingWord = callDataSource.length() > 96 + bbsInt && !ebs.isZero(); - - final EWord rawLeadingWord = - loadRawLeadingWord - ? EWord.of( - hub.messageFrame().shadowReadMemory(callDataSource.offset() + 96 + bbsInt, 32)) - : EWord.ZERO; - - final boolean extractModulus = - (callDataSource.length() > 96 + bbsInt + ebsInt) && !mbs.isZero(); - final boolean extractBase = extractModulus && !bbs.isZero(); - final boolean extractExponent = extractModulus && !ebs.isZero(); - - return new ModExpMetadata( - extractBbs, - extractEbs, - extractMbs, - bbs, - ebs, - mbs, - loadRawLeadingWord, - rawLeadingWord, - extractModulus, - extractBase, - extractExponent); + public boolean mbsNonZero() { + return !mbs().isZero(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 3473a149a9..1cff8553cc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -20,6 +20,7 @@ import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; import static org.hyperledger.besu.datatypes.Address.ID; +import static org.hyperledger.besu.datatypes.Address.MODEXP; import static org.hyperledger.besu.datatypes.Address.SHA256; import java.util.Map; @@ -45,6 +46,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.IdentitySubsection; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.Sha2Subsection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; @@ -67,13 +69,19 @@ public class CallSection extends TraceSection // TODO: finish this map private static final Map> - ADDRESS_TO_PRECOMPILE = Map.of(SHA256, Sha2Subsection::new, ID, IdentitySubsection::new); + ADDRESS_TO_PRECOMPILE = + Map.of( + SHA256, + Sha2Subsection::new, + ID, + IdentitySubsection::new, + MODEXP, + ModexpSubsection::new); // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); // Just before call - private ContextFragment finalContextFragment; private Bytes rawCalleeAddress; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/ModexpComponents.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java similarity index 63% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/ModexpComponents.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java index 9996443607..11b207bd60 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/ModexpComponents.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java @@ -13,8 +13,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.blake2fmodexpdata; +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; -import org.apache.tuweni.bytes.Bytes; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.section.call.CallSection; -public record ModexpComponents(Bytes base, Bytes exp, Bytes mod) {} +public class BlakeSubsection extends PrecompileSubsection { + public BlakeSubsection(Hub hub, CallSection callSection) { + super(hub, callSection); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java index aa941cc642..7298c83cde 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java @@ -31,7 +31,6 @@ public class IdentitySubsection extends PrecompileSubsection { - final ImcFragment firstImcFragment; final PrecompileCommonOobCall oobCall; public IdentitySubsection(final Hub hub, final CallSection callSection) { @@ -39,7 +38,6 @@ public IdentitySubsection(final Hub hub, final CallSection callSection) { precompileScenarioFragment.setFlag(PRC_IDENTITY); - firstImcFragment = ImcFragment.empty(hub); oobCall = new PrecompileCommonOobCall(OOB_INST_IDENTITY); firstImcFragment.callOob(oobCall); @@ -56,7 +54,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { Preconditions.checkArgument(successBit == oobCall.isHubSuccess()); if (!successBit) { - return; + precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); } final boolean extractCallData = successBit && !callDataMemorySpan.lengthNull(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java new file mode 100644 index 0000000000..f44e524c2e --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -0,0 +1,164 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; + +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpExtractBase; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpExtractBbs; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpExtractEbs; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpExtractExponent; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpExtractMbs; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpExtractModulus; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpFullResultCopy; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpLoadLead; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpPartialResultCopy; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_CDS; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_EXTRACT; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_LEAD; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_PRICING; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_XBS; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_MODEXP; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; + +import com.google.common.base.Preconditions; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; +import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; +import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; + +public class ModexpSubsection extends PrecompileSubsection { + + private final ModExpMetadata modExpMetadata; + private final PrecompileCommonOobCall sixthOobCall; + + public ModexpSubsection(final Hub hub, final CallSection callSection) { + super(hub, callSection); + precompileScenarioFragment.setFlag(PRC_MODEXP); + + final PrecompileCommonOobCall firstOobCAll = new PrecompileCommonOobCall(OOB_INST_MODEXP_CDS); + firstImcFragment.callOob(firstOobCAll); + + modExpMetadata = new ModExpMetadata(callData, callDataMemorySpan); + + // TODO: sounds weird we construct all OOB Call same way ... + final ImcFragment secondImcFragment = ImcFragment.empty(hub); + fragments().add(secondImcFragment); + if (modExpMetadata.extractBbs()) { + final MmuCall mmuCall = forModexpExtractBbs(hub, this, modExpMetadata); + secondImcFragment.callMmu(mmuCall); + } + final PrecompileCommonOobCall secondOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_XBS); + secondImcFragment.callOob(secondOobCall); + + final ImcFragment thirdImcFragment = ImcFragment.empty(hub); + fragments().add(thirdImcFragment); + if (modExpMetadata.extractEbs()) { + final MmuCall mmuCall = forModexpExtractEbs(hub, this, modExpMetadata); + thirdImcFragment.callMmu(mmuCall); + } + final PrecompileCommonOobCall thirdOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_XBS); + thirdImcFragment.callOob(thirdOobCall); + + final ImcFragment fourthImcFragment = ImcFragment.empty(hub); + fragments().add(fourthImcFragment); + if (modExpMetadata.extractMbs()) { + final MmuCall mmuCall = forModexpExtractMbs(hub, this, modExpMetadata); + fourthImcFragment.callMmu(mmuCall); + } + final PrecompileCommonOobCall fourthOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_XBS); + fourthImcFragment.callOob(fourthOobCall); + + final ImcFragment fifthImcFragment = ImcFragment.empty(hub); + fragments().add(fifthImcFragment); + final PrecompileCommonOobCall fifthOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_LEAD); + fifthImcFragment.callOob(fifthOobCall); + if (modExpMetadata.loadRawLeadingWord()) { + final MmuCall mmuCall = forModexpLoadLead(hub, this, modExpMetadata); + fifthImcFragment.callMmu(mmuCall); + // final ExpCall expCall = new ModexpLogExpCall(); // TODO: to do + // fifthImcFragment.callExp(expCall); + } + + final ImcFragment sixthImcFragment = ImcFragment.empty(hub); + fragments().add(sixthImcFragment); + sixthOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_PRICING); + sixthImcFragment.callOob(sixthOobCall); + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { + super.resolveAtContextReEntry(hub, callFrame); + + // sanity check + Preconditions.checkArgument(successBit == sixthOobCall.isHubSuccess()); + + if (!successBit) { + precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + return; + } + + modExpMetadata.rawResult(returnData); + hub.blakeModexpData().callModexp(modExpMetadata, this.exoModuleOperationId()); + + final ImcFragment seventhImcFragment = ImcFragment.empty(hub); + fragments().add(seventhImcFragment); + final PrecompileCommonOobCall seventhOobCall = + new PrecompileCommonOobCall(OOB_INST_MODEXP_EXTRACT); + seventhImcFragment.callOob(seventhOobCall); + if (modExpMetadata.extractModulus()) { + final MmuCall mmuCall = forModexpExtractBase(hub, this, modExpMetadata); + seventhImcFragment.callMmu(mmuCall); + } + + final ImcFragment eighthImcFragment = ImcFragment.empty(hub); + fragments().add(eighthImcFragment); + if (modExpMetadata.extractModulus()) { + final MmuCall mmuCall = forModexpExtractExponent(hub, this, modExpMetadata); + eighthImcFragment.callMmu(mmuCall); + } + + final ImcFragment ninthImcFragment = ImcFragment.empty(hub); + fragments().add(ninthImcFragment); + if (modExpMetadata.extractModulus()) { + final MmuCall mmuCall = forModexpExtractModulus(hub, this, modExpMetadata); + ninthImcFragment.callMmu(mmuCall); + } + + final ImcFragment tenthImcFragment = ImcFragment.empty(hub); + fragments().add(tenthImcFragment); + if (modExpMetadata.extractModulus()) { + final MmuCall mmuCall = forModexpFullResultCopy(hub, this, modExpMetadata); + tenthImcFragment.callMmu(mmuCall); + } + + final ImcFragment eleventhImcFragment = ImcFragment.empty(hub); + fragments().add(eleventhImcFragment); + if (modExpMetadata.mbsNonZero() && !parentReturnDataTarget.lengthNull()) { + final MmuCall mmuCall = forModexpPartialResultCopy(hub, this, modExpMetadata); + eleventhImcFragment.callMmu(mmuCall); + } + } + + // 13 = 1 + 12 (scenario row + up to 12 miscellaneous fragments) + @Override + protected short maxNumberOfLines() { + return 13; + // Note: we don't have the successBit available at the moment + // and can't provide the "real" value (8 in case of failure.) + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index c1e9b2fe53..8c68168a40 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -30,6 +30,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.*; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -76,6 +77,7 @@ public class PrecompileSubsection boolean successBit; public final PrecompileScenarioFragment precompileScenarioFragment; + public final ImcFragment firstImcFragment; /** A snapshot of the caller's memory before the execution of the precompile */ public Bytes callerMemorySnapshot; @@ -91,6 +93,9 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { precompileScenarioFragment = new PrecompileScenarioFragment(this, PRC_SUCCESS_WONT_REVERT, PRC_UNDEFINED); fragments.add(precompileScenarioFragment); + + firstImcFragment = ImcFragment.empty(hub); + fragments().add(firstImcFragment); } protected short maxNumberOfLines() { @@ -120,13 +125,6 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { if (successBit) { hub.defers().scheduleForPostRollback(this, frame); - } else { - // TODO: extensions of this class are responsible for setting either - // PRC_FAILURE_KNOWN_TO_HUB / PRC_FAILURE_KNOWN_TO_RAM - // in case of a failure. - // In any case, the failure scenario is required to have been set - // before context re-entry. - Preconditions.checkArgument(precompileScenarioFragment.isPrcFailure()); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java index 7250629c23..dab47c37e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java @@ -30,17 +30,14 @@ import net.consensys.linea.zktracer.runtime.callstack.CallFrame; public class Sha2Subsection extends PrecompileSubsection { - final ImcFragment firstImcFragment; final PrecompileCommonOobCall oobCall; public Sha2Subsection(Hub hub, CallSection callSection) { super(hub, callSection); precompileScenarioFragment.setFlag(PRC_SHA2_256); - oobCall = new PrecompileCommonOobCall(OOB_INST_SHA2); - firstImcFragment = ImcFragment.empty(hub); - this.fragments().add(firstImcFragment); + oobCall = new PrecompileCommonOobCall(OOB_INST_SHA2); firstImcFragment.callOob(oobCall); if (!oobCall.isHubSuccess()) { @@ -56,7 +53,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { Preconditions.checkArgument(successBit == oobCall.isHubSuccess()); if (!successBit) { - return; + precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); } // NOTE: we trigger the SHAKIRA module for nonempty call data only From b6e9176672593688ed250c69acb05ea4698a1ca5 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 1 Aug 2024 17:26:54 +0530 Subject: [PATCH 330/461] fix: reject tx when arg byte size > 512 Signed-off-by: Francois Bojarski --- .../module/blake2fmodexpdata/BlakeModexpData.java | 7 +++++++ .../module/hub/precompiles/ModExpMetadata.java | 15 +++++++++------ .../limits/precompiles/ModexpEffectiveCall.java | 7 +------ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java index 391ac84cf2..cba339ebc7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java @@ -21,6 +21,7 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_EXPONENT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_MODULUS; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_RESULT; +import static net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall.PROVER_MAX_INPUT_BYTE_SIZE; import java.nio.MappedByteBuffer; import java.util.ArrayList; @@ -97,6 +98,12 @@ public List columnsHeaders() { } public void callModexp(final ModExpMetadata modexpMetaData, final int id) { + if (modexpMetaData.bbsInt() > PROVER_MAX_INPUT_BYTE_SIZE + || modexpMetaData.mbsInt() > PROVER_MAX_INPUT_BYTE_SIZE + || modexpMetaData.ebsInt() > PROVER_MAX_INPUT_BYTE_SIZE) { + modexpEffectiveCall.addPrecompileLimit(Integer.MAX_VALUE); + return; + } operations.add(new BlakeModexpDataOperation(modexpMetaData, id)); modexpEffectiveCall.addPrecompileLimit(1); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java index abe60fd83f..64b0ba5c8c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java @@ -99,12 +99,16 @@ public EWord mbs() { return EWord.of(rawMbs().shiftRight(mbsShift()).shiftLeft(mbsShift())); } - private int bbsInt() { - return bbs().toUnsignedBigInteger().intValueExact(); + public int bbsInt() { + return (int) Words.clampedToLong(bbs()); } - private int ebsInt() { - return ebs().toUnsignedBigInteger().intValueExact(); + public int ebsInt() { + return (int) Words.clampedToLong(ebs()); + } + + public int mbsInt() { + return (int) Words.clampedToLong(mbs()); } public boolean loadRawLeadingWord() { @@ -156,8 +160,7 @@ public Bytes mod() { Bytes unpadded = Bytes.EMPTY; final int firstOffset = BASE_MIN_OFFSET + bbsInt() + ebsInt(); if (callDataSource.length() >= firstOffset) { - final int sizeToExtract = - (int) Math.min(Words.clampedToLong(mbs()), callDataSource().length() - firstOffset); + final int sizeToExtract = (int) Math.min(mbsInt(), callDataSource().length() - firstOffset); unpadded = callData.slice(firstOffset, sizeToExtract); } return rightPadTo(unpadded, (int) Words.clampedToLong(mbs())); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java index 6e927ad734..56d1166a0c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java @@ -15,9 +15,6 @@ package net.consensys.linea.zktracer.module.limits.precompiles; -import java.math.BigInteger; - -import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; @@ -28,7 +25,7 @@ @Accessors(fluent = true) public class ModexpEffectiveCall extends CountingOnlyModule { - private static final BigInteger PROVER_MAX_INPUT_BYTE_SIZE = BigInteger.valueOf(4096 / 8); + public static final int PROVER_MAX_INPUT_BYTE_SIZE = 4096 / 8; @Override public String moduleKey() { @@ -37,8 +34,6 @@ public String moduleKey() { @Override public void addPrecompileLimit(final int numberEffectiveCall) { - Preconditions.checkArgument( - numberEffectiveCall == 1, "can't add more than one effective precompile call at a time"); this.counts.add(numberEffectiveCall); } } From 35ffb682681221ec336682eac98d02aee0ab805a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 2 Aug 2024 03:40:52 +0200 Subject: [PATCH 331/461] feat(precompiles): wip for ECDATA precompiles --- .../linea/zktracer/module/ecdata/EcData.java | 18 +- .../module/ecdata/EcDataOperation.java | 177 ++++++------ .../linea/zktracer/module/hub/Hub.java | 4 +- .../module/hub/fragment/imc/mmu/MmuCall.java | 273 +++++++++--------- .../scenario/PrecompileScenarioFragment.java | 33 ++- .../module/hub/section/call/CallSection.java | 28 +- .../EllipticCurvePrecompileSubsection.java | 105 +++++++ .../PrecompileSubsection.java | 27 +- ...ion.java => ShaTwoOrRipemdSubSection.java} | 33 ++- .../zktracer/module/ecdata/EcDataTest.java | 31 +- 10 files changed, 443 insertions(+), 286 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/{Sha2Subsection.java => ShaTwoOrRipemdSubSection.java} (74%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index c7b11623ef..fa0a2949ba 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -15,10 +15,7 @@ package net.consensys.linea.zktracer.module.ecdata; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECADD; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECMUL; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECPAIRING; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECRECOVER; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.addressToPrecompileFlag; import java.nio.MappedByteBuffer; import java.util.Comparator; @@ -96,7 +93,8 @@ public void tracePreOpcode(MessageFrame frame) { final Bytes data = hub.transients().op().callData(); this.ecDataOperation = - EcDataOperation.of(this.wcp, this.ext, 1 + this.hub.stamp(), target.get(19), data); + EcDataOperation.of( + this.wcp, this.ext, hub.precompileId(), addressToPrecompileFlag(target), data); this.operations.add(ecDataOperation); } @@ -133,11 +131,11 @@ public void commit(List buffers) { public void callEcdata(final EcDataOperation ecDataOperation) { this.operations.add(ecDataOperation); - switch (ecDataOperation.ecType()) { - case ECADD -> ecAddEffectiveCall.addPrecompileLimit(1); - case ECMUL -> ecMulEffectiveCall.addPrecompileLimit(1); - case ECRECOVER -> ecRecoverEffectiveCall.addPrecompileLimit(1); - case ECPAIRING -> { + switch (ecDataOperation.precompileFlag()) { + case PRC_ECADD -> ecAddEffectiveCall.addPrecompileLimit(1); + case PRC_ECMUL -> ecMulEffectiveCall.addPrecompileLimit(1); + case PRC_ECRECOVER -> ecRecoverEffectiveCall.addPrecompileLimit(1); + case PRC_ECPAIRING -> { // TODO @Lorenzo } default -> throw new IllegalArgumentException("Operation not supported by EcData"); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 89c2a9c446..5fe5df8dde 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -25,10 +25,6 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_ECRECOVER_RESULT; import static net.consensys.linea.zktracer.module.ecdata.Trace.CT_MAX_LARGE_POINT; import static net.consensys.linea.zktracer.module.ecdata.Trace.CT_MAX_SMALL_POINT; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECADD; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECMUL; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECPAIRING; -import static net.consensys.linea.zktracer.module.ecdata.Trace.ECRECOVER; import static net.consensys.linea.zktracer.module.ecdata.Trace.INDEX_MAX_ECADD_DATA; import static net.consensys.linea.zktracer.module.ecdata.Trace.INDEX_MAX_ECADD_RESULT; import static net.consensys.linea.zktracer.module.ecdata.Trace.INDEX_MAX_ECMUL_DATA; @@ -49,11 +45,11 @@ import static net.consensys.linea.zktracer.module.ecdata.Trace.TOTAL_SIZE_ECPAIRING_RESULT; import static net.consensys.linea.zktracer.module.ecdata.Trace.TOTAL_SIZE_ECRECOVER_DATA; import static net.consensys.linea.zktracer.module.ecdata.Trace.TOTAL_SIZE_ECRECOVER_RESULT; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.*; import static net.consensys.linea.zktracer.types.Containers.repeat; import static net.consensys.linea.zktracer.types.Utils.leftPadTo; import java.util.List; -import java.util.Set; import com.google.common.base.Preconditions; import lombok.Getter; @@ -61,6 +57,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.ext.Ext; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; @@ -72,7 +69,6 @@ @Accessors(fluent = true) public class EcDataOperation extends ModuleOperation { - private static final Set EC_TYPES = Set.of(ECRECOVER, ECADD, ECMUL, ECPAIRING); private static final EWord P_BN = EWord.of(P_BN_HI, P_BN_LO); public static final EWord SECP256K1N = EWord.of(SECP256K1N_HI, SECP256K1N_LO); public static final int nBYTES_OF_DELTA_BYTES = 4; @@ -85,7 +81,7 @@ public class EcDataOperation extends ModuleOperation { @Getter private final long id; private final Bytes data; - @Getter private final int ecType; + @Getter private final PrecompileScenarioFragment.PrecompileFlag precompileFlag; private final int nRows; private final int nRowsData; private final int nRowsResult; @@ -134,25 +130,32 @@ public class EcDataOperation extends ModuleOperation { // For debugging private boolean returnDataSet = false; - private EcDataOperation(Wcp wcp, Ext ext, int id, int ecType, Bytes data) { - Preconditions.checkArgument(EC_TYPES.contains(ecType), "invalid EC type"); - - final int minInputLength = ecType == ECMUL ? 96 : 128; - if (data.size() < minInputLength) { - this.data = leftPadTo(data, minInputLength); + private EcDataOperation( + Wcp wcp, + Ext ext, + int id, + final PrecompileScenarioFragment.PrecompileFlag precompileFlag, + Bytes data) { + Preconditions.checkArgument(precompileFlag.isEcdataPrecompile(), "invalid EC type"); + + this.precompileFlag = precompileFlag; + final int paddedCallDataLength = this.precompileFlag == PRC_ECMUL ? 96 : 128; + if (data.size() < paddedCallDataLength) { + this.data = leftPadTo(data, paddedCallDataLength); } else { + // TODO: why keep the entire data rather than data[0:paddedCallDataLength] ? this.data = data; } - this.ecType = ecType; - if (ecType == ECPAIRING) { + if (precompileFlag == PRC_ECPAIRING) { + Preconditions.checkArgument(data.size() % 192 == 0); totalPairings = data.size() / 192; } else { totalPairings = 0; } - nRowsData = getIndexMax(ecType, true) + 1; - nRowsResult = getIndexMax(ecType, false) + 1; + nRowsData = getIndexMax(precompileFlag, true) + 1; + nRowsResult = getIndexMax(precompileFlag, false) + 1; nRows = nRowsData + nRowsResult; this.id = id; @@ -187,20 +190,25 @@ private EcDataOperation(Wcp wcp, Ext ext, int id, int ecType, Bytes data) { notOnG2Acc = repeat(false, nRows); } - public static EcDataOperation of(Wcp wcp, Ext ext, int id, final int ecType, Bytes data) { - EcDataOperation ecDataRes = new EcDataOperation(wcp, ext, id, ecType, data); - switch (ecType) { - case ECRECOVER -> ecDataRes.handleRecover(); - case ECADD -> ecDataRes.handleAdd(); - case ECMUL -> ecDataRes.handleMul(); - case ECPAIRING -> ecDataRes.handlePairing(); + public static EcDataOperation of( + Wcp wcp, + Ext ext, + int id, + final PrecompileScenarioFragment.PrecompileFlag precompileFlag, + Bytes data) { + EcDataOperation ecDataRes = new EcDataOperation(wcp, ext, id, precompileFlag, data); + switch (precompileFlag) { + case PRC_ECRECOVER -> ecDataRes.handleRecover(); + case PRC_ECADD -> ecDataRes.handleAdd(); + case PRC_ECMUL -> ecDataRes.handleMul(); + case PRC_ECPAIRING -> ecDataRes.handlePairing(); } return ecDataRes; } public void setReturnData(Bytes returnData) { - switch (ecType) { - case ECRECOVER -> { + switch (precompileFlag) { + case PRC_ECRECOVER -> { EWord recoveredAddress = EWord.ZERO; // Extract output @@ -213,7 +221,7 @@ public void setReturnData(Bytes returnData) { limb.set(8, recoveredAddress.hi()); limb.set(9, recoveredAddress.lo()); } - case ECADD -> { + case PRC_ECADD -> { EWord resX = EWord.ZERO; EWord resY = EWord.ZERO; @@ -231,7 +239,7 @@ public void setReturnData(Bytes returnData) { limb.set(10, resY.hi()); limb.set(11, resY.lo()); } - case ECMUL -> { + case PRC_ECMUL -> { EWord resX = EWord.ZERO; EWord resY = EWord.ZERO; @@ -249,7 +257,7 @@ public void setReturnData(Bytes returnData) { limb.set(8, resY.hi()); limb.set(9, resY.lo()); } - case ECPAIRING -> { + case PRC_ECPAIRING -> { EWord pairingResult = EWord.ZERO; // Extract output @@ -261,12 +269,12 @@ public void setReturnData(Bytes returnData) { limb.set(limb.size() - 2, pairingResult.hi()); limb.set(limb.size() - 1, pairingResult.lo()); - // Set successBit + // Set callSuccess /* if (!internalChecksPassed || notOnG2AccMax) { - successBit = false; + callSuccess = false; } else { - successBit = true; + callSuccess = true; } */ if (!internalChecksPassed) { @@ -279,63 +287,66 @@ public void setReturnData(Bytes returnData) { returnDataSet = true; } - private int getTotalSize(int ecType, boolean isData) { + private int getTotalSize( + PrecompileScenarioFragment.PrecompileFlag precompileFlag, boolean isData) { Preconditions.checkArgument(returnDataSet, "returnData must be set before"); if (isData) { - return switch (ecType) { - case ECRECOVER -> TOTAL_SIZE_ECRECOVER_DATA; - case ECADD -> TOTAL_SIZE_ECADD_DATA; - case ECMUL -> TOTAL_SIZE_ECMUL_DATA; - case ECPAIRING -> TOTAL_SIZE_ECPAIRING_DATA_MIN * totalPairings; + return switch (precompileFlag) { + case PRC_ECRECOVER -> TOTAL_SIZE_ECRECOVER_DATA; + case PRC_ECADD -> TOTAL_SIZE_ECADD_DATA; + case PRC_ECMUL -> TOTAL_SIZE_ECMUL_DATA; + case PRC_ECPAIRING -> TOTAL_SIZE_ECPAIRING_DATA_MIN * totalPairings; default -> throw new IllegalArgumentException("invalid EC type"); }; } else { - return switch (ecType) { - case ECRECOVER -> successBit ? TOTAL_SIZE_ECRECOVER_RESULT : 0; - case ECADD -> successBit ? TOTAL_SIZE_ECADD_RESULT : 0; - case ECMUL -> successBit ? TOTAL_SIZE_ECMUL_RESULT : 0; - case ECPAIRING -> successBit ? TOTAL_SIZE_ECPAIRING_RESULT : 0; + return switch (precompileFlag) { + case PRC_ECRECOVER -> successBit ? TOTAL_SIZE_ECRECOVER_RESULT : 0; + case PRC_ECADD -> successBit ? TOTAL_SIZE_ECADD_RESULT : 0; + case PRC_ECMUL -> successBit ? TOTAL_SIZE_ECMUL_RESULT : 0; + case PRC_ECPAIRING -> successBit ? TOTAL_SIZE_ECPAIRING_RESULT : 0; default -> throw new IllegalArgumentException("invalid EC type"); }; } } - private static short getPhase(int ecType, boolean isData) { + private static short getPhase( + PrecompileScenarioFragment.PrecompileFlag precompileFlag, boolean isData) { if (isData) { - return switch (ecType) { - case ECRECOVER -> PHASE_ECRECOVER_DATA; - case ECADD -> PHASE_ECADD_DATA; - case ECMUL -> PHASE_ECMUL_DATA; - case ECPAIRING -> PHASE_ECPAIRING_DATA; + return switch (precompileFlag) { + case PRC_ECRECOVER -> PHASE_ECRECOVER_DATA; + case PRC_ECADD -> PHASE_ECADD_DATA; + case PRC_ECMUL -> PHASE_ECMUL_DATA; + case PRC_ECPAIRING -> PHASE_ECPAIRING_DATA; default -> throw new IllegalArgumentException("invalid EC type"); }; } else { - return switch (ecType) { - case ECRECOVER -> PHASE_ECRECOVER_RESULT; - case ECADD -> PHASE_ECADD_RESULT; - case ECMUL -> PHASE_ECMUL_RESULT; - case ECPAIRING -> PHASE_ECPAIRING_RESULT; + return switch (precompileFlag) { + case PRC_ECRECOVER -> PHASE_ECRECOVER_RESULT; + case PRC_ECADD -> PHASE_ECADD_RESULT; + case PRC_ECMUL -> PHASE_ECMUL_RESULT; + case PRC_ECPAIRING -> PHASE_ECPAIRING_RESULT; default -> throw new IllegalArgumentException("invalid EC type"); }; } } - private int getIndexMax(int ecType, boolean isData) { + private int getIndexMax( + PrecompileScenarioFragment.PrecompileFlag precompileFlag, boolean isData) { if (isData) { - return switch (ecType) { - case ECRECOVER -> INDEX_MAX_ECRECOVER_DATA; - case ECADD -> INDEX_MAX_ECADD_DATA; - case ECMUL -> INDEX_MAX_ECMUL_DATA; - case ECPAIRING -> (INDEX_MAX_ECPAIRING_DATA_MIN + 1) * totalPairings - 1; + return switch (precompileFlag) { + case PRC_ECRECOVER -> INDEX_MAX_ECRECOVER_DATA; + case PRC_ECADD -> INDEX_MAX_ECADD_DATA; + case PRC_ECMUL -> INDEX_MAX_ECMUL_DATA; + case PRC_ECPAIRING -> (INDEX_MAX_ECPAIRING_DATA_MIN + 1) * totalPairings - 1; default -> throw new IllegalArgumentException("invalid EC type"); }; } else { - return switch (ecType) { - case ECRECOVER -> INDEX_MAX_ECRECOVER_RESULT; - case ECADD -> INDEX_MAX_ECADD_RESULT; - case ECMUL -> INDEX_MAX_ECMUL_RESULT; - case ECPAIRING -> INDEX_MAX_ECPAIRING_RESULT; + return switch (precompileFlag) { + case PRC_ECRECOVER -> INDEX_MAX_ECRECOVER_RESULT; + case PRC_ECADD -> INDEX_MAX_ECADD_RESULT; + case PRC_ECMUL -> INDEX_MAX_ECMUL_RESULT; + case PRC_ECPAIRING -> INDEX_MAX_ECPAIRING_RESULT; default -> throw new IllegalArgumentException("invalid EC type"); }; } @@ -627,14 +638,14 @@ void trace(Trace trace, final int stamp, final long previousId) { for (int i = 0; i < nRows; i++) { boolean isData = i < nRowsData; // Turn isSmallPoint on if we are in the first row of a new pairing - if (ecType == ECPAIRING && isData && ct == 0 && !isSmallPoint && !isLargePoint) { + if (precompileFlag == PRC_ECPAIRING && isData && ct == 0 && !isSmallPoint && !isLargePoint) { isSmallPoint = true; smallPointIsAtInfinity = isInfinity.get(i); largePointIsAtInfinity = isInfinity.get(i + CT_MAX_SMALL_POINT + 1); } boolean notOnG2AccMax = - ecType == ECPAIRING + precompileFlag == PRC_ECPAIRING && isData && this .notOnG2AccMax; // && conditions is necessary since we want IS_ECPAIRING_DATA = 1 @@ -643,13 +654,13 @@ void trace(Trace trace, final int stamp, final long previousId) { ? isLargePoint && !largePointIsAtInfinity && notOnG2.get(i) : isLargePoint && !largePointIsAtInfinity && smallPointIsAtInfinity; boolean acceptablePairOfPointsForPairingCircuit = - ecType == ECPAIRING + precompileFlag == PRC_ECPAIRING && successBit && !notOnG2AccMax && !largePointIsAtInfinity && !smallPointIsAtInfinity; - if (ecType != ECPAIRING || !isData) { + if (precompileFlag != PRC_ECPAIRING || !isData) { Preconditions.checkArgument(ct == 0); } Preconditions.checkArgument(!(isSmallPoint && isLargePoint)); @@ -659,21 +670,21 @@ void trace(Trace trace, final int stamp, final long previousId) { .id(id) .index(isData ? UnsignedByte.of(i) : UnsignedByte.of(i - nRowsData)) .limb(limb.get(i)) - .totalSize(Bytes.ofUnsignedLong(getTotalSize(ecType, isData))) - .phase(getPhase(ecType, isData)) - .indexMax(Bytes.ofUnsignedLong(getIndexMax(ecType, isData))) + .totalSize(Bytes.ofUnsignedLong(getTotalSize(precompileFlag, isData))) + .phase(getPhase(precompileFlag, isData)) + .indexMax(Bytes.ofUnsignedLong(getIndexMax(precompileFlag, isData))) .successBit(successBit) - .isEcrecoverData(ecType == ECRECOVER && isData) - .isEcrecoverResult(ecType == ECRECOVER && !isData) - .isEcaddData(ecType == ECADD && isData) - .isEcaddResult(ecType == ECADD && !isData) - .isEcmulData(ecType == ECMUL && isData) - .isEcmulResult(ecType == ECMUL && !isData) - .isEcpairingData(ecType == ECPAIRING && isData) - .isEcpairingResult(ecType == ECPAIRING && !isData) + .isEcrecoverData(precompileFlag == PRC_ECRECOVER && isData) + .isEcrecoverResult(precompileFlag == PRC_ECRECOVER && !isData) + .isEcaddData(precompileFlag == PRC_ECADD && isData) + .isEcaddResult(precompileFlag == PRC_ECADD && !isData) + .isEcmulData(precompileFlag == PRC_ECMUL && isData) + .isEcmulResult(precompileFlag == PRC_ECMUL && !isData) + .isEcpairingData(precompileFlag == PRC_ECPAIRING && isData) + .isEcpairingResult(precompileFlag == PRC_ECPAIRING && !isData) .totalPairings(Bytes.ofUnsignedLong(totalPairings)) .accPairings( - ecType == ECPAIRING && isData + precompileFlag == PRC_ECPAIRING && isData ? Bytes.ofUnsignedLong(1 + i / (INDEX_MAX_ECPAIRING_DATA_MIN + 1)) : Bytes.of(0)) .internalChecksPassed(internalChecksPassed) @@ -690,7 +701,7 @@ void trace(Trace trace, final int stamp, final long previousId) { .notOnG2AccMax(notOnG2AccMax) .isInfinity(isInfinity.get(i)) .overallTrivialPairing( - ecType == ECPAIRING + precompileFlag == PRC_ECPAIRING && isData && overallTrivialPairing.get( i)) // && conditions necessary because default value is true @@ -721,7 +732,7 @@ void trace(Trace trace, final int stamp, final long previousId) { .validateRow(); // Update ct, isSmallPoint, isLargePoint - if (ecType == ECPAIRING && isData) { + if (precompileFlag == PRC_ECPAIRING && isData) { ct++; if (isSmallPoint && ct == CT_MAX_SMALL_POINT + 1) { isSmallPoint = false; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 683e7c5269..fff6fd5c0d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -203,7 +203,7 @@ public int lineCount() { private final Bin bin = new Bin(); private final Blockhash blockhash = new Blockhash(wcp); private final Euc euc = new Euc(wcp); - private final Ext ext = new Ext(this); + @Getter private final Ext ext = new Ext(this); private final Gas gas = new Gas(); private final Mul mul = new Mul(this); private final Mod mod = new Mod(); @@ -283,7 +283,7 @@ private List precompileLimitModules() { new BlakeModexpData(this.wcp, modexpEffectiveCall, blakeEffectiveCall, blakeRounds); @Getter - private final EcData ecData = + public final EcData ecData = new EcData( this, wcp, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index a3c814d411..450fcbdc4f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -81,6 +81,7 @@ import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.EllipticCurvePrecompileSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; @@ -318,58 +319,53 @@ public static MmuCall txInit(final Hub hub) { .setRlpTxn(); } - public static MmuCall forEcRecover( - final Hub hub, PrecompileInvocation p, boolean recoverySuccessful, int i) { - Preconditions.checkArgument(i >= 0 && i < 3); + public static MmuCall ecRecoverDataExtraction( + final Hub hub, EllipticCurvePrecompileSubsection subsection, boolean successfulRecovery) { - final int precompileContextNumber = p.hubStamp() + 1; + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) + .sourceId(hub.currentFrame().contextNumber()) // called at ContextReEntry + .targetId(subsection.exoModuleOperationId()) + .sourceOffset(EWord.of(subsection.callDataMemorySpan.offset())) + .size(subsection.callDataMemorySpan.length()) + .referenceSize(128) + .successBit(successfulRecovery) + .phase(PHASE_ECRECOVER_DATA) + .setEcData(); + } - if (i == 0) { - final long inputSize = p.callDataSource().length(); - return inputSize == 0 - ? nop() - : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .size(inputSize) - .referenceSize(128) - .successBit(recoverySuccessful) - .phase(PHASE_ECRECOVER_DATA) - .setEcData(); - } else if (i == 1) { - if (recoverySuccessful) { - return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(precompileContextNumber) - .targetId(precompileContextNumber) - .size(WORD_SIZE) - .phase(PHASE_ECRECOVER_RESULT) - .setEcData(); - } else { - return nop(); - } - } else { - if (recoverySuccessful && !p.requestedReturnDataTarget().lengthNull()) { + public static MmuCall ecRecoverFullReturnDataTransfer( + final Hub hub, EllipticCurvePrecompileSubsection subsection) { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .sourceOffset(EWord.ZERO) - .size(WORD_SIZE) - .referenceOffset(p.requestedReturnDataTarget().offset()) - .referenceSize(p.requestedReturnDataTarget().length()); + final int precompileContextNumber = subsection.exoModuleOperationId(); - } else { - return nop(); - } - } + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) + .sourceId(precompileContextNumber) + .targetId(precompileContextNumber) + .size(WORD_SIZE) + .phase(PHASE_ECRECOVER_RESULT) + .setEcData(); + } + + public static MmuCall ecrecoverPartialReturnDataCopy( + final Hub hub, EllipticCurvePrecompileSubsection subsection) { + + final int precompileContextNumber = subsection.exoModuleOperationId(); + // if (recoverySuccessful && !subsection.parentReturnDataTarget.isEmpty()) { + + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(precompileContextNumber) + .targetId(hub.currentFrame().contextNumber()) + .sourceOffset(EWord.ZERO) + .size(WORD_SIZE) + .referenceOffset(subsection.parentReturnDataTarget.offset()) + .referenceSize(subsection.parentReturnDataTarget.length()); } public static MmuCall forShaTwoOrRipemdCallDataExtraction( final Hub hub, PrecompileSubsection precompileSubsection) { PrecompileScenarioFragment.PrecompileFlag flag = - precompileSubsection.precompileScenarioFragment().getFlag(); + precompileSubsection.precompileScenarioFragment().flag; Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) @@ -388,7 +384,7 @@ public static MmuCall forShaTwoOrRipemdFullResultTransfer( final Hub hub, PrecompileSubsection precompileSubsection) { PrecompileScenarioFragment.PrecompileFlag flag = - precompileSubsection.precompileScenarioFragment().getFlag(); + precompileSubsection.precompileScenarioFragment().flag; Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); final boolean isShaTwo = flag == PRC_SHA2_256; @@ -415,7 +411,7 @@ public static MmuCall forShaTwoOrRipemdPartialResultCopy( final Hub hub, PrecompileSubsection precompileSubsection) { PrecompileScenarioFragment.PrecompileFlag flag = - precompileSubsection.precompileScenarioFragment().getFlag(); + precompileSubsection.precompileScenarioFragment().flag; Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); Preconditions.checkArgument(!precompileSubsection.parentReturnDataTarget.lengthNull()); @@ -456,109 +452,110 @@ public static MmuCall forIdentityReturnData( .referenceSize(precompileSubsection.parentReturnDataTarget.length()); } - public static MmuCall forEcAdd(final Hub hub, final PrecompileInvocation p, int i) { - Preconditions.checkArgument(i >= 0 && i < 3); - final int precompileContextNumber = p.hubStamp() + 1; - if (i == 0) { - final long inputSize = p.callDataSource().length(); - return inputSize == 0 - ? nop() - : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .size(inputSize) - .referenceSize(128) - .successBit(!p.ramFailure()) - .setEcData() - .phase(PHASE_ECADD_DATA); - } else if (i == 1) { - return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(precompileContextNumber) - .targetId(precompileContextNumber) - .size(64) - .setEcData() - .phase(PHASE_ECADD_RESULT); - } else { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .targetOffset(EWord.of(p.requestedReturnDataTarget().offset())) - .size(p.requestedReturnDataTarget().length()) - .referenceSize(64); - } + public static MmuCall callDataExtractionForEcadd( + final Hub hub, PrecompileSubsection subsection, boolean failureKnownToRam) { + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) + .sourceId(hub.currentFrame().contextNumber()) + .targetId(subsection.exoModuleOperationId()) + .sourceOffset(EWord.of(subsection.callDataMemorySpan.offset())) + .size(subsection.callDataMemorySpan.length()) + .referenceSize(128) + .successBit(!failureKnownToRam) + .setEcData() + .phase(PHASE_ECADD_DATA); } - public static MmuCall forEcMul(final Hub hub, final PrecompileInvocation p, int i) { - Preconditions.checkArgument(i >= 0 && i < 3); - final int precompileContextNumber = p.hubStamp() + 1; - if (i == 0) { - final long inputSize = p.callDataSource().length(); - return inputSize == 0 - ? nop() - : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .size(inputSize) - .referenceSize(96) - .successBit(!p.ramFailure()) - .setEcData() - .phase(PHASE_ECMUL_DATA); - } else if (i == 1) { + public static MmuCall fullReturnDataTransferForEcadd( + final Hub hub, PrecompileSubsection subsection) { + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) + .sourceId(subsection.exoModuleOperationId()) + .targetId(subsection.exoModuleOperationId()) + .size(64) + .setEcData() + .phase(PHASE_ECADD_RESULT); + } + + public static MmuCall partialCopyOfReturnDataForEcadd( + final Hub hub, PrecompileSubsection subsection) { + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(subsection.exoModuleOperationId()) + .targetId(hub.currentFrame().contextNumber()) + .targetOffset(EWord.of(subsection.parentReturnDataTarget.offset())) + .size(subsection.parentReturnDataTarget.length()) + .referenceSize(64); + } + + public static MmuCall callDataExtractionForEcmul( + final Hub hub, final PrecompileSubsection subsection, boolean failureKnownToRam) { + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) + .sourceId(hub.currentFrame().contextNumber()) + .targetId(subsection.exoModuleOperationId()) + .sourceOffset(EWord.of(subsection.callDataMemorySpan.offset())) + .size(subsection.callDataMemorySpan.length()) + .referenceSize(96) + .successBit(!failureKnownToRam) + .setEcData() + .phase(PHASE_ECMUL_DATA); + } + + public static MmuCall fullReturnDataTransferForEcmul( + final Hub hub, final PrecompileSubsection subsection) { + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) + .sourceId(subsection.exoModuleOperationId()) + .targetId(subsection.exoModuleOperationId()) + .size(64) + .setEcData() + .phase(PHASE_ECMUL_RESULT); + } + + public static MmuCall partialCopyOfReturnDataForEcmul( + final Hub hub, final PrecompileSubsection subsection) { + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(subsection.exoModuleOperationId()) + .targetId(hub.currentFrame().contextNumber()) + .targetOffset(EWord.of(subsection.parentReturnDataTarget().offset())) + .size(subsection.parentReturnDataTarget().length()) + .referenceSize(64); + } + + public static MmuCall callDataExtractionForEcpairing( + final Hub hub, PrecompileSubsection subsection, boolean failureKnownToRam) { + final int precompileContextNumber = subsection.exoModuleOperationId(); + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) + .sourceId(hub.currentFrame().contextNumber()) + .targetId(precompileContextNumber) + .sourceOffset(EWord.of(subsection.callDataMemorySpan.offset())) + .size(subsection.callDataMemorySpan.length()) + .referenceSize(subsection.callDataMemorySpan.length()) + .successBit(!failureKnownToRam) + .setEcData() + .phase(PHASE_ECPAIRING_DATA); + } + + public static MmuCall fullReturnDataTransferForEcpairing( + final Hub hub, PrecompileSubsection subsection) { + final int precompileContextNumber = subsection.exoModuleOperationId(); + if (subsection.callDataMemorySpan.lengthNull()) { + return new MmuCall(hub, MMU_INST_MSTORE).targetId(precompileContextNumber).limb2(Bytes.of(1)); + } else { return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) .targetId(precompileContextNumber) - .size(64) + .size(WORD_SIZE) .setEcData() - .phase(PHASE_ECMUL_RESULT); - } else { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .targetOffset(EWord.of(p.requestedReturnDataTarget().offset())) - .size(p.requestedReturnDataTarget().length()) - .referenceSize(64); + .phase(PHASE_ECPAIRING_RESULT); } } - public static MmuCall forEcPairing(final Hub hub, final PrecompileInvocation p, int i) { - Preconditions.checkArgument(i >= 0 && i < 3); - final int precompileContextNumber = p.hubStamp() + 1; - if (i == 0) { - final long inputSize = p.callDataSource().length(); - return inputSize == 0 - ? nop() - : new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .size(inputSize) - .referenceSize(p.callDataSource().length()) - .successBit(!p.ramFailure()) - .setEcData() - .phase(PHASE_ECPAIRING_DATA); - } else if (i == 1) { - if (p.callDataSource().lengthNull()) { - return new MmuCall(hub, MMU_INST_MSTORE) - .targetId(precompileContextNumber) - .limb2(Bytes.of(1)); - } else { - return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(precompileContextNumber) - .targetId(precompileContextNumber) - .size(WORD_SIZE) - .setEcData() - .phase(PHASE_ECPAIRING_RESULT); - } - } else { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .targetOffset(EWord.of(p.requestedReturnDataTarget().offset())) - .size(p.requestedReturnDataTarget().length()) - .referenceSize(32); - } + public static MmuCall partialReturnDataCopyForEcpairing( + final Hub hub, PrecompileSubsection subsection) { + final int precompileContextNumber = subsection.exoModuleOperationId(); + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(precompileContextNumber) + .targetId(hub.currentFrame().contextNumber()) + .targetOffset(EWord.of(subsection.parentReturnDataTarget.offset())) + .size(subsection.parentReturnDataTarget.length()) + .referenceSize(32); } public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, int i) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 1d96541744..4c77d8f310 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -17,17 +17,19 @@ import java.util.Map; -import com.google.common.base.Preconditions; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.constants.GlobalConstants; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; +import org.hyperledger.besu.datatypes.Address; @Getter @AllArgsConstructor +@Accessors(fluent = true) public class PrecompileScenarioFragment implements TraceFragment { public enum PrecompileScenario { @@ -38,7 +40,6 @@ public enum PrecompileScenario { } public enum PrecompileFlag { - PRC_UNDEFINED, PRC_ECRECOVER, PRC_SHA2_256, PRC_RIPEMD_160, @@ -49,6 +50,18 @@ public enum PrecompileFlag { PRC_ECPAIRING, PRC_BLAKE2F; + private static final Map ADDRESS_TO_FLAG_MAP = + Map.of( + Address.ECREC, PRC_ECRECOVER, + Address.SHA256, PRC_SHA2_256, + Address.RIPEMD160, PRC_RIPEMD_160, + Address.ID, PRC_IDENTITY, + Address.MODEXP, PRC_MODEXP, + Address.ALTBN128_ADD, PRC_ECADD, + Address.ALTBN128_MUL, PRC_ECMUL, + Address.ALTBN128_PAIRING, PRC_ECPAIRING, + Address.BLAKE2B_F_COMPRESSION, PRC_BLAKE2F); + private static final Map DATA_PHASE_MAP = Map.of( PRC_ECRECOVER, GlobalConstants.PHASE_ECRECOVER_DATA, @@ -74,6 +87,13 @@ public enum PrecompileFlag { PRC_ECPAIRING, GlobalConstants.PHASE_ECPAIRING_RESULT, PRC_BLAKE2F, GlobalConstants.PHASE_BLAKE_RESULT); + public static PrecompileFlag addressToPrecompileFlag(Address precompileAddress) { + if (!ADDRESS_TO_FLAG_MAP.containsKey(precompileAddress)) { + throw new IllegalArgumentException("Not valid London precompile address"); + } + return ADDRESS_TO_FLAG_MAP.get(precompileAddress); + } + public int dataPhase() { if (!DATA_PHASE_MAP.containsKey(this)) { throw new IllegalArgumentException("Precompile not supported by the DATA_PHASE_MAP"); @@ -88,6 +108,10 @@ public int resultPhase() { return RESULT_PHASE_MAP.get(this); } + public boolean isEcdataPrecompile() { + return this.isAnyOf(PRC_ECRECOVER, PRC_ECADD, PRC_ECMUL, PRC_ECPAIRING); + } + public boolean isAnyOf(PrecompileFlag... flags) { for (PrecompileFlag flag : flags) { if (this == flag) { @@ -99,8 +123,8 @@ public boolean isAnyOf(PrecompileFlag... flags) { } final PrecompileSubsection precompileSubSection; - @Setter PrecompileScenario scenario; - @Setter PrecompileFlag flag; + @Setter public PrecompileScenario scenario; + @Setter public PrecompileFlag flag; public PrecompileScenarioFragment( final PrecompileSubsection precompileSubsection, @@ -118,7 +142,6 @@ public boolean isPrcFailure() { @Override public Trace trace(Trace trace) { - Preconditions.checkArgument(this.flag != PrecompileFlag.PRC_UNDEFINED); return trace .peekAtScenario(true) // // Precompile scenarios diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 1cff8553cc..01a302a297 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -19,11 +19,10 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment.CallScenario.*; import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; -import static org.hyperledger.besu.datatypes.Address.ID; -import static org.hyperledger.besu.datatypes.Address.MODEXP; -import static org.hyperledger.besu.datatypes.Address.SHA256; +import static org.hyperledger.besu.datatypes.Address.*; import java.util.Map; +import java.util.Optional; import java.util.function.BiFunction; import com.google.common.base.Preconditions; @@ -45,10 +44,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.XCallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.scenario.CallScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; -import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.IdentitySubsection; -import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection; -import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; -import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.Sha2Subsection; +import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.*; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; @@ -71,12 +67,16 @@ public class CallSection extends TraceSection private static final Map> ADDRESS_TO_PRECOMPILE = Map.of( - SHA256, - Sha2Subsection::new, - ID, - IdentitySubsection::new, - MODEXP, - ModexpSubsection::new); + ECREC, EllipticCurvePrecompileSubsection::new, + SHA256, ShaTwoOrRipemdSubSection::new, + RIPEMD160, ShaTwoOrRipemdSubSection::new, + ID, IdentitySubsection::new, + MODEXP, ModexpSubsection::new, + ALTBN128_ADD, EllipticCurvePrecompileSubsection::new, + ALTBN128_MUL, EllipticCurvePrecompileSubsection::new, + ALTBN128_PAIRING, EllipticCurvePrecompileSubsection::new); + + public Optional

precompileAddress; // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); @@ -335,7 +335,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { // TODO: what follows assumes that the caller's stack has been updated // to contain the success bit of the call at traceContextReEntry. // See issue #872. - // The successBit will only be set + // The callSuccess will only be set // if the call is acted upon i.e. if the call is un-exceptional and un-aborted final boolean successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java new file mode 100644 index 0000000000..e829ca541e --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -0,0 +1,105 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; + +import static com.google.common.base.Preconditions.checkArgument; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM; + +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; +import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; + +public class EllipticCurvePrecompileSubsection extends PrecompileSubsection { + final ImcFragment firstImcFragment; + final PrecompileCommonOobCall oobCall; + + public EllipticCurvePrecompileSubsection(Hub hub, CallSection callSection) { + super(hub, callSection); + + oobCall = + switch (flag()) { + case PRC_ECRECOVER -> new PrecompileCommonOobCall(OOB_INST_ECRECOVER); + case PRC_ECADD -> new PrecompileCommonOobCall(OOB_INST_ECADD); + case PRC_ECMUL -> new PrecompileCommonOobCall(OOB_INST_ECMUL); + case PRC_ECPAIRING -> new PrecompileCommonOobCall(OOB_INST_ECPAIRING); + default -> throw new IllegalArgumentException( + String.format( + "Precompile address %s not supported by constructor", this.flag().toString())); + }; + + firstImcFragment = ImcFragment.empty(hub); + firstImcFragment.callOob(oobCall); + + // Recall that the default scenario is PRC_SUCCESS_WONT_REVERT + if (!oobCall.isHubSuccess()) { + this.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + } + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { + super.resolveAtContextReEntry(hub, callFrame); + + // sanity checks + switch (flag()) { + case PRC_ECRECOVER -> { + checkArgument(oobCall.isHubSuccess() == callSuccess); + checkArgument(returnData.size() == (callSuccess ? WORD_SIZE : 0)); + } + case PRC_ECPAIRING -> checkArgument(returnData.size() == (callSuccess ? WORD_SIZE : 0)); + case PRC_ECADD, PRC_ECMUL -> checkArgument( + returnData.size() == (callSuccess ? 2 * WORD_SIZE : 0)); + default -> throw new IllegalArgumentException("Not an elliptic curve precompile"); + } + + if (!oobCall.isHubSuccess()) { + return; + } + + switch (flag()) { + case PRC_ECADD, PRC_ECMUL, PRC_ECPAIRING -> { + if (oobCall.isHubSuccess() && !callSuccess) { + precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_RAM); + } + } + // ECRECOVER can only be FAILURE_KNOWN_TO_HUB ro some form of SUCCESS_XXXX_REVERT + default -> {} + } + + MmuCall firstMmuCall; + final boolean nonemptyCallData = !callData.isEmpty(); + + if (nonemptyCallData) { + switch (flag()) { + case PRC_ECRECOVER -> { + final boolean successfulRecovery = !returnData.isEmpty(); + firstMmuCall = MmuCall.ecRecoverDataExtraction(hub, this, successfulRecovery); + } + case PRC_ECADD -> firstMmuCall = MmuCall.callDataExtractionForEcadd(hub, this, callSuccess); + case PRC_ECMUL -> firstMmuCall = MmuCall.callDataExtractionForEcmul(hub, this, callSuccess); + case PRC_ECPAIRING -> firstMmuCall = + MmuCall.callDataExtractionForEcpairing(hub, this, callSuccess); + default -> throw new IllegalArgumentException("Not an elliptic curve precompile"); + } + firstImcFragment.callMmu(firstMmuCall); + } + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 8c68168a40..80d3d79678 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -14,7 +14,7 @@ */ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_UNDEFINED; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.*; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; import static net.consensys.linea.zktracer.runtime.callstack.CallFrame.extractContiguousLimbsFromMemory; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; @@ -74,7 +74,8 @@ public class PrecompileSubsection /** The gas to return to the caller context */ long returnGas; - boolean successBit; + /** The boolean pushed onto the caller's stack when it resumes execution */ + boolean callSuccess; public final PrecompileScenarioFragment precompileScenarioFragment; public final ImcFragment firstImcFragment; @@ -90,8 +91,11 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { this.callSection = callSection; fragments = new ArrayList<>(maxNumberOfLines()); + PrecompileScenarioFragment.PrecompileFlag precompileFlag = + addressToPrecompileFlag(callSection.precompileAddress.orElseThrow()); + precompileScenarioFragment = - new PrecompileScenarioFragment(this, PRC_SUCCESS_WONT_REVERT, PRC_UNDEFINED); + new PrecompileScenarioFragment(this, PRC_SUCCESS_WONT_REVERT, precompileFlag); fragments.add(precompileScenarioFragment); firstImcFragment = ImcFragment.empty(hub); @@ -120,10 +124,10 @@ public void resolveUponExitingContext(Hub hub, CallFrame callFrame) { @Override public void resolveAtContextReEntry(Hub hub, CallFrame frame) { - successBit = bytesToBoolean(hub.messageFrame().getStackItem(0)); + callSuccess = bytesToBoolean(hub.messageFrame().getStackItem(0)); returnData = frame.frame().getReturnData(); - if (successBit) { + if (callSuccess) { hub.defers().scheduleForPostRollback(this, frame); } } @@ -132,10 +136,9 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { // only successful PRC calls should enter here - Preconditions.checkArgument( - precompileScenarioFragment.getScenario() == PRC_SUCCESS_WONT_REVERT); + Preconditions.checkArgument(precompileScenarioFragment.scenario() == PRC_SUCCESS_WONT_REVERT); - precompileScenarioFragment.setScenario(PRC_SUCCESS_WILL_REVERT); + precompileScenarioFragment.scenario(PRC_SUCCESS_WILL_REVERT); } public int exoModuleOperationId() { @@ -145,4 +148,12 @@ public int exoModuleOperationId() { public int returnDataContextNumber() { return exoModuleOperationId(); } + + public PrecompileScenarioFragment.PrecompileFlag flag() { + return precompileScenarioFragment.flag; + } + + public void setScenario(PrecompileScenarioFragment.PrecompileScenario scenario) { + this.precompileScenarioFragment.scenario(scenario); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java similarity index 74% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java index dab47c37e4..332710dfae 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/Sha2Subsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java @@ -15,9 +15,11 @@ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_RIPEMD; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_SHA2; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_SHA2_256; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; +import static net.consensys.linea.zktracer.module.shakiradata.HashType.RIPEMD; import static net.consensys.linea.zktracer.module.shakiradata.HashType.SHA256; import com.google.common.base.Preconditions; @@ -29,19 +31,25 @@ import net.consensys.linea.zktracer.module.shakiradata.ShakiraDataOperation; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -public class Sha2Subsection extends PrecompileSubsection { +public class ShaTwoOrRipemdSubSection extends PrecompileSubsection { + ImcFragment firstImcFragment; final PrecompileCommonOobCall oobCall; - public Sha2Subsection(Hub hub, CallSection callSection) { + public ShaTwoOrRipemdSubSection(Hub hub, CallSection callSection) { super(hub, callSection); - precompileScenarioFragment.setFlag(PRC_SHA2_256); - - oobCall = new PrecompileCommonOobCall(OOB_INST_SHA2); + oobCall = + switch (flag()) { + case PRC_SHA2_256 -> new PrecompileCommonOobCall(OOB_INST_SHA2); + case PRC_RIPEMD_160 -> new PrecompileCommonOobCall(OOB_INST_RIPEMD); + default -> throw new IllegalArgumentException( + String.format( + "Precompile address %s not supported by constructor", this.flag().toString())); + }; firstImcFragment.callOob(oobCall); if (!oobCall.isHubSuccess()) { - precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + this.setScenario(PRC_FAILURE_KNOWN_TO_HUB); } } @@ -50,17 +58,20 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); // sanity check - Preconditions.checkArgument(successBit == oobCall.isHubSuccess()); + Preconditions.checkArgument(callSuccess == oobCall.isHubSuccess()); - if (!successBit) { - precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + if (!callSuccess) { + return; } // NOTE: we trigger the SHAKIRA module for nonempty call data only if (!callData.isEmpty()) { final ShakiraDataOperation shakiraCall = new ShakiraDataOperation( - this.callSection.hubStamp(), SHA256, callData(), callFrame.frame().getReturnData()); + callSection.hubStamp(), + this.flag() == PRC_SHA2_256 ? SHA256 : RIPEMD, + callData(), + callFrame.frame().getReturnData()); hub.shakiraData().call(shakiraCall); final MmuCall mmuCall = MmuCall.forShaTwoOrRipemdCallDataExtraction(hub, this); @@ -89,7 +100,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { @Override protected short maxNumberOfLines() { return 4; - // Note: we don't have the successBit available at the moment + // Note: we don't have the callSuccess available at the moment // and can't provide the "real" value (2 in case of FKTH.) } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java index 01dc6e1e32..4d6ab43a39 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java @@ -74,13 +74,14 @@ private static Stream ecRecoverSource() { List arguments = new ArrayList<>(); - // Test cases where ICP = successBit = 1 (first one) or ICP = successBit = 0 (all the others) + // Test cases where ICP = callSuccess = 1 (first one) or ICP = + // callSuccess = 0 (all the others) for (int i = 0; i < v.size(); i++) { for (int j = 0; j < r.size(); j++) { for (int k = 0; k < s.size(); k++) { arguments.add( Arguments.of( - i + j + k == 0 ? "[ICP = 1, successBit = 1]" : "[ICP = 0, successBit = 0]", + i + j + k == 0 ? "[ICP = 1, callSuccess = 1]" : "[ICP = 0, callSuccess = 0]", h, v.get(i), r.get(j), @@ -91,10 +92,10 @@ private static Stream ecRecoverSource() { } } - // Test cases where ICP = successBit = 1 + // Test cases where ICP = callSuccess = 1 arguments.add( argumentsFromStrings( - "[ICP = 1, successBit = 1]", + "[ICP = 1, callSuccess = 1]", "0x279d94621558f755796898fc4bd36b6d407cae77537865afe523b79c74cc680b", "0x1b", "0xc2ff96feed8749a5ad1c0714f950b5ac939d8acedbedcbc2949614ab8af06312", @@ -104,7 +105,7 @@ private static Stream ecRecoverSource() { arguments.add( argumentsFromStrings( - "[ICP = 1, successBit = 1]", + "[ICP = 1, callSuccess = 1]", "0x4be146e06cc1b37342b6b7b1fa8542ae58a62103b8af0f7d58f8a1ffffcf7914", "0x1b", "0xa7b0f504b652b3a621921c78c587fdf80a3ab590e22c304b0b0930e90c4e081d", @@ -114,7 +115,7 @@ private static Stream ecRecoverSource() { arguments.add( argumentsFromStrings( - "[ICP = 1, successBit = 1]", + "[ICP = 1, callSuccess = 1]", "0xca3e75570aea0e3dd8e7a9d38c2efa866f5ee2b18bf527a0f4e3248b7c7cf376", "0x1c", "0xf1136900c2cd16eacc676f2c7b70f3dfec13fd16a426aab4eda5d8047c30a9e9", @@ -124,7 +125,7 @@ private static Stream ecRecoverSource() { arguments.add( argumentsFromStrings( - "[ICP = 1, successBit = 1]", + "[ICP = 1, callSuccess = 1]", "0x9a3fa82837622a34408888b40af937f21f4e6d051f04326d3d7717848c434448", "0x1b", "0x52a734f01d14d161795ba3b38ce329eba468e109b4f2e330af671649ffef4e0e", @@ -132,11 +133,11 @@ private static Stream ecRecoverSource() { true, true)); - // Test cases where ICP = 1 but successBit = 0 + // Test cases where ICP = 1 but callSuccess = 0 // Failing reason QNR arguments.add( argumentsFromStrings( - "[ICP = 1, successBit = 0 due to QNR]", + "[ICP = 1, callSuccess = 0 due to QNR]", "0x94f66d57fb0a3854a44d94956447e01f8b3f09845860f18856e792c821359162", "0x1c", "0x000000000000000000000000000000014551231950b75fc4402da1722fc9baed", @@ -147,7 +148,7 @@ private static Stream ecRecoverSource() { // Failing reason INFINITY arguments.add( argumentsFromStrings( - "[ICP = 1, successBit = 0 due to INFINITY]", + "[ICP = 1, callSuccess = 0 due to INFINITY]", "0xd33cfae367f4f7413985ff82dc7db3ffbf7a027fb5dad7097b4a15cc85ab6580", "0x1c", "0xa12b54d413c4ffaaecd59468de6a7d414d2fa7f2ba700d8e0753ca226410c806", @@ -158,7 +159,7 @@ private static Stream ecRecoverSource() { // Failing reason INFINITY arguments.add( argumentsFromStrings( - "[ICP = 1, successBit = 0 due to INFINITY]", + "[ICP = 1, callSuccess = 0 due to INFINITY]", "0x6ec17edf5cecd83ed50c08adfeba8146f69769231f4b7903eba38c2e7e98e173", "0x1b", "0xaeb8ffe3655e07edd6bde0ab79edd92d4e7a155385c3d8c8ca117bfd13633516", @@ -217,10 +218,10 @@ void testEcRecover( BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); bytecodeRunner.run(); - // Retrieve recoveredAddress, internalChecksPassed, successBit - // Assert internalChecksPassed and successBit are what expected + // Retrieve recoveredAddress, internalChecksPassed, callSuccess + // Assert internalChecksPassed and callSuccess are what expected EcDataOperation ecDataOperation = - bytecodeRunner.getHub().ecData().getOperations().stream().toList().get(0); + bytecodeRunner.getHub().ecData.getOperations().stream().toList().get(0); EWord recoveredAddress = EWord.of( ecDataOperation.limb().get(8).toUnsignedBigInteger(), @@ -233,7 +234,7 @@ void testEcRecover( System.out.println("recoveredAddress: " + recoveredAddress); System.out.println("internalChecksPassed: " + internalChecksPassed); - System.out.println("successBit: " + successBit); + System.out.println("callSuccess: " + successBit); } // TODO: continue testing the other precompiles in a more structured way From afcb18adcd74dd4dcf2f897464aba4b231cf3e0f Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 2 Aug 2024 10:17:26 +0530 Subject: [PATCH 332/461] make it compile again + trivial bug fixes Signed-off-by: Francois Bojarski --- .../consensys/linea/zktracer/ZkTracer.java | 4 ---- .../blake2fmodexpdata/BlakeModexpData.java | 7 ------- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/section/call/CallSection.java | 1 + .../EllipticCurvePrecompileSubsection.java | 3 --- .../IdentitySubsection.java | 13 +++++------- .../ModexpSubsection.java | 21 ++++++++++++------- .../PrecompileSubsection.java | 2 +- .../ShaTwoOrRipemdSubSection.java | 1 - 9 files changed, 21 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index 911a987b6e..4c1fee3cf9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -268,10 +268,6 @@ public void tracePreExecution(final MessageFrame frame) { } } - // TODO: the stack at tracePostExecution (as well as the gas) seems not to have - // changed relative to tracePreExecution. In particular this is not the place to - // get BLOCKHASH or similar fields. - /** * Compare with description of {@link #tracePreExecution(MessageFrame)}. * diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java index cba339ebc7..391ac84cf2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java @@ -21,7 +21,6 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_EXPONENT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_MODULUS; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_RESULT; -import static net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall.PROVER_MAX_INPUT_BYTE_SIZE; import java.nio.MappedByteBuffer; import java.util.ArrayList; @@ -98,12 +97,6 @@ public List columnsHeaders() { } public void callModexp(final ModExpMetadata modexpMetaData, final int id) { - if (modexpMetaData.bbsInt() > PROVER_MAX_INPUT_BYTE_SIZE - || modexpMetaData.mbsInt() > PROVER_MAX_INPUT_BYTE_SIZE - || modexpMetaData.ebsInt() > PROVER_MAX_INPUT_BYTE_SIZE) { - modexpEffectiveCall.addPrecompileLimit(Integer.MAX_VALUE); - return; - } operations.add(new BlakeModexpDataOperation(modexpMetaData, id)); modexpEffectiveCall.addPrecompileLimit(1); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index fff6fd5c0d..f830065ce6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -248,7 +248,7 @@ public int lineCount() { private final EcPairingFinalExponentiations ecPairingFinalExponentiations = new EcPairingFinalExponentiations(); - private final ModexpEffectiveCall modexpEffectiveCall = new ModexpEffectiveCall(); + @Getter private final ModexpEffectiveCall modexpEffectiveCall = new ModexpEffectiveCall(); private final RipemdBlocks ripemdBlocks = new RipemdBlocks(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 01a302a297..91461f6075 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -186,6 +186,7 @@ public CallSection(Hub hub) { final WorldUpdater world = hub.messageFrame().getWorldUpdater(); if (isPrecompile(calleeAddress)) { + precompileAddress = Optional.of(calleeAddress); scenarioFragment.setScenario(CALL_PRC_UNDEFINED); // Account rows for precompile are traced at contextReEntry diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index e829ca541e..8d75a19e5d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -21,14 +21,12 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; public class EllipticCurvePrecompileSubsection extends PrecompileSubsection { - final ImcFragment firstImcFragment; final PrecompileCommonOobCall oobCall; public EllipticCurvePrecompileSubsection(Hub hub, CallSection callSection) { @@ -45,7 +43,6 @@ public EllipticCurvePrecompileSubsection(Hub hub, CallSection callSection) { "Precompile address %s not supported by constructor", this.flag().toString())); }; - firstImcFragment = ImcFragment.empty(hub); firstImcFragment.callOob(oobCall); // Recall that the default scenario is PRC_SUCCESS_WONT_REVERT diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java index 7298c83cde..7224bf71ea 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java @@ -18,7 +18,6 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityExtractCallData; import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityReturnData; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_IDENTITY; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_IDENTITY; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; import com.google.common.base.Preconditions; @@ -36,13 +35,11 @@ public class IdentitySubsection extends PrecompileSubsection { public IdentitySubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); - precompileScenarioFragment.setFlag(PRC_IDENTITY); - oobCall = new PrecompileCommonOobCall(OOB_INST_IDENTITY); firstImcFragment.callOob(oobCall); if (!oobCall.isHubSuccess()) { - precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_HUB); } } @@ -51,13 +48,13 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); // sanity check - Preconditions.checkArgument(successBit == oobCall.isHubSuccess()); + Preconditions.checkArgument(callSuccess == oobCall.isHubSuccess()); - if (!successBit) { - precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + if (!callSuccess) { + precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_HUB); } - final boolean extractCallData = successBit && !callDataMemorySpan.lengthNull(); + final boolean extractCallData = callSuccess && !callDataMemorySpan.lengthNull(); if (extractCallData) { final MmuCall mmuCall = forIdentityExtractCallData(hub, this); firstImcFragment.callMmu(mmuCall); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index f44e524c2e..94b1507047 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -29,8 +29,8 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_LEAD; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_PRICING; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_XBS; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.PRC_MODEXP; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; +import static net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall.PROVER_MAX_INPUT_BYTE_SIZE; import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; @@ -44,17 +44,22 @@ public class ModexpSubsection extends PrecompileSubsection { private final ModExpMetadata modExpMetadata; - private final PrecompileCommonOobCall sixthOobCall; + private PrecompileCommonOobCall sixthOobCall; public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); - precompileScenarioFragment.setFlag(PRC_MODEXP); + + modExpMetadata = new ModExpMetadata(callData, callDataMemorySpan); + if (modExpMetadata.bbsInt() > PROVER_MAX_INPUT_BYTE_SIZE + || modExpMetadata.mbsInt() > PROVER_MAX_INPUT_BYTE_SIZE + || modExpMetadata.ebsInt() > PROVER_MAX_INPUT_BYTE_SIZE) { + hub.modexpEffectiveCall().addPrecompileLimit(Integer.MAX_VALUE); + return; + } final PrecompileCommonOobCall firstOobCAll = new PrecompileCommonOobCall(OOB_INST_MODEXP_CDS); firstImcFragment.callOob(firstOobCAll); - modExpMetadata = new ModExpMetadata(callData, callDataMemorySpan); - // TODO: sounds weird we construct all OOB Call same way ... final ImcFragment secondImcFragment = ImcFragment.empty(hub); fragments().add(secondImcFragment); @@ -105,10 +110,10 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); // sanity check - Preconditions.checkArgument(successBit == sixthOobCall.isHubSuccess()); + Preconditions.checkArgument(callSuccess == sixthOobCall.isHubSuccess()); - if (!successBit) { - precompileScenarioFragment.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + if (!callSuccess) { + precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_HUB); return; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 80d3d79678..e09e07c303 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -91,7 +91,7 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { this.callSection = callSection; fragments = new ArrayList<>(maxNumberOfLines()); - PrecompileScenarioFragment.PrecompileFlag precompileFlag = + final PrecompileScenarioFragment.PrecompileFlag precompileFlag = addressToPrecompileFlag(callSection.precompileAddress.orElseThrow()); precompileScenarioFragment = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java index 332710dfae..ffb1882509 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java @@ -32,7 +32,6 @@ import net.consensys.linea.zktracer.runtime.callstack.CallFrame; public class ShaTwoOrRipemdSubSection extends PrecompileSubsection { - ImcFragment firstImcFragment; final PrecompileCommonOobCall oobCall; public ShaTwoOrRipemdSubSection(Hub hub, CallSection callSection) { From 65f052145250646428e4067ab686395b9266b979 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 2 Aug 2024 11:40:01 +0530 Subject: [PATCH 333/461] fix modexp prc subsection (ugly), fixed OOB Signed-off-by: Francois Bojarski --- .../hub/precompiles/ModExpMetadata.java | 52 +++++++------------ .../ModexpSubsection.java | 39 ++++++++++++-- .../PrecompileSubsection.java | 4 ++ .../zktracer/module/oob/OobOperation.java | 25 ++++----- 4 files changed, 69 insertions(+), 51 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java index 64b0ba5c8c..b07a9f79e9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java @@ -15,13 +15,13 @@ package net.consensys.linea.zktracer.module.hub.precompiles; +import static net.consensys.linea.zktracer.module.txndata.Trace.WORD_SIZE; import static net.consensys.linea.zktracer.types.Utils.rightPadTo; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.internal.Words; @@ -33,34 +33,30 @@ public class ModExpMetadata { static final int BASE_MIN_OFFSET = 96; private final Bytes callData; - private final MemorySpan callDataSource; @Setter private Bytes rawResult; - public ModExpMetadata(final Bytes callData, final MemorySpan callDataSource) { + public ModExpMetadata(final Bytes callData) { this.callData = callData; - this.callDataSource = callDataSource; } public boolean extractBbs() { - return !callDataSource.lengthNull(); + return !callData.isEmpty(); } public boolean extractEbs() { - return callDataSource.length() > EBS_MIN_OFFSET; + return callData.size() > EBS_MIN_OFFSET; } public boolean extractMbs() { - return callDataSource.length() > MBS_MIN_OFFSET; + return callData.size() > MBS_MIN_OFFSET; } private int bbsShift() { - return EBS_MIN_OFFSET - (int) Math.min(EBS_MIN_OFFSET, callDataSource.length()); + return EBS_MIN_OFFSET - Math.min(EBS_MIN_OFFSET, callData.size()); } public Bytes rawBbs() { - return extractBbs() - ? callData.slice((int) callDataSource.offset(), EBS_MIN_OFFSET) - : Bytes.EMPTY; + return extractBbs() ? callData.slice(0, EBS_MIN_OFFSET) : Bytes.EMPTY; } public EWord bbs() { @@ -69,14 +65,12 @@ public EWord bbs() { private int ebsShift() { return extractEbs() - ? EBS_MIN_OFFSET - (int) Math.min(EBS_MIN_OFFSET, callDataSource.length() - EBS_MIN_OFFSET) + ? EBS_MIN_OFFSET - Math.min(EBS_MIN_OFFSET, callData.size() - EBS_MIN_OFFSET) : 0; } public Bytes rawEbs() { - return extractEbs() - ? callData.slice((int) (callDataSource.offset() + EBS_MIN_OFFSET), EBS_MIN_OFFSET) - : Bytes.EMPTY; + return extractEbs() ? callData.slice(EBS_MIN_OFFSET, WORD_SIZE) : Bytes.EMPTY; } public EWord ebs() { @@ -85,14 +79,12 @@ public EWord ebs() { private int mbsShift() { return extractMbs() - ? EBS_MIN_OFFSET - (int) Math.min(EBS_MIN_OFFSET, callDataSource.length() - MBS_MIN_OFFSET) + ? EBS_MIN_OFFSET - Math.min(EBS_MIN_OFFSET, callData.size() - MBS_MIN_OFFSET) : 0; } public Bytes rawMbs() { - return extractMbs() - ? callData.slice((int) (callDataSource.offset() + MBS_MIN_OFFSET), EBS_MIN_OFFSET) - : Bytes.EMPTY; + return extractMbs() ? callData.slice(MBS_MIN_OFFSET, WORD_SIZE) : Bytes.EMPTY; } public EWord mbs() { @@ -112,20 +104,18 @@ public int mbsInt() { } public boolean loadRawLeadingWord() { - return callDataSource.length() > BASE_MIN_OFFSET + bbsInt() && !ebs().isZero(); + return callData.size() > BASE_MIN_OFFSET + bbsInt() && !ebs().isZero(); } public EWord rawLeadingWord() { return loadRawLeadingWord() - ? EWord.of( - callData.slice( - (int) (callDataSource.offset() + BASE_MIN_OFFSET + bbsInt()), EBS_MIN_OFFSET)) + ? EWord.of(callData.slice(BASE_MIN_OFFSET + bbsInt(), WORD_SIZE)) : EWord.ZERO; } public boolean extractModulus() { - return (callDataSource.length() > MBS_MIN_OFFSET + bbsInt() + ebsInt()) && !mbs().isZero(); + return (callData.size() > MBS_MIN_OFFSET + bbsInt() + ebsInt()) && !mbs().isZero(); } public boolean extractBase() { @@ -138,9 +128,8 @@ public boolean extractExponent() { public Bytes base() { Bytes unpadded = Bytes.EMPTY; - if (callDataSource.length() >= BASE_MIN_OFFSET) { - final int sizeToExtract = - (int) Math.min(bbsInt(), callDataSource().length() - MBS_MIN_OFFSET); + if (callData.size() >= BASE_MIN_OFFSET) { + final int sizeToExtract = Math.min(bbsInt(), callData.size() - MBS_MIN_OFFSET); unpadded = callData.slice(MBS_MIN_OFFSET, sizeToExtract); } return rightPadTo(unpadded, bbsInt()); @@ -148,9 +137,8 @@ public Bytes base() { public Bytes exp() { Bytes unpadded = Bytes.EMPTY; - if (callDataSource.length() >= BASE_MIN_OFFSET + bbsInt()) { - final int sizeToExtract = - (int) Math.min(ebsInt(), callDataSource().length() - BASE_MIN_OFFSET - bbsInt()); + if (callData.size() >= BASE_MIN_OFFSET + bbsInt()) { + final int sizeToExtract = Math.min(ebsInt(), callData.size() - BASE_MIN_OFFSET - bbsInt()); unpadded = callData.slice(BASE_MIN_OFFSET + bbsInt(), sizeToExtract); } return rightPadTo(unpadded, ebsInt()); @@ -159,8 +147,8 @@ public Bytes exp() { public Bytes mod() { Bytes unpadded = Bytes.EMPTY; final int firstOffset = BASE_MIN_OFFSET + bbsInt() + ebsInt(); - if (callDataSource.length() >= firstOffset) { - final int sizeToExtract = (int) Math.min(mbsInt(), callDataSource().length() - firstOffset); + if (callData.size() >= firstOffset) { + final int sizeToExtract = Math.min(mbsInt(), callData.size() - firstOffset); unpadded = callData.slice(firstOffset, sizeToExtract); } return rightPadTo(unpadded, (int) Words.clampedToLong(mbs())); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 94b1507047..e23c03df16 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -32,6 +32,8 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; import static net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall.PROVER_MAX_INPUT_BYTE_SIZE; +import java.math.BigInteger; + import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; @@ -39,7 +41,9 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.hyperledger.besu.evm.internal.Words; public class ModexpSubsection extends PrecompileSubsection { @@ -49,10 +53,37 @@ public class ModexpSubsection extends PrecompileSubsection { public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); - modExpMetadata = new ModExpMetadata(callData, callDataMemorySpan); - if (modExpMetadata.bbsInt() > PROVER_MAX_INPUT_BYTE_SIZE - || modExpMetadata.mbsInt() > PROVER_MAX_INPUT_BYTE_SIZE - || modExpMetadata.ebsInt() > PROVER_MAX_INPUT_BYTE_SIZE) { + // TODO: I'm not really happy with that ... @Olivier + // We have to trigger OOB at exec time, and we update the callData at childContextEntry + final OpCode opCode = hub.opCode(); + final long offset = + Words.clampedToLong( + opCode.callCanTransferValue() + ? hub.messageFrame().getStackItem(3) + : hub.messageFrame().getStackItem(2)); + final long length = + Words.clampedToLong( + opCode.callCanTransferValue() + ? hub.messageFrame().getStackItem(4) + : hub.messageFrame().getStackItem(3)); + callData = callerMemorySnapshot.slice((int) offset, (int) length); + + modExpMetadata = new ModExpMetadata(callData); + if (modExpMetadata + .bbs() + .toUnsignedBigInteger() + .compareTo(BigInteger.valueOf(PROVER_MAX_INPUT_BYTE_SIZE)) + >= 0 + || modExpMetadata + .mbs() + .toUnsignedBigInteger() + .compareTo(BigInteger.valueOf(PROVER_MAX_INPUT_BYTE_SIZE)) + >= 0 + || modExpMetadata + .ebs() + .toUnsignedBigInteger() + .compareTo(BigInteger.valueOf(PROVER_MAX_INPUT_BYTE_SIZE)) + >= 0) { hub.modexpEffectiveCall().addPrecompileLimit(Integer.MAX_VALUE); return; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index e09e07c303..cb29defdb2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -100,6 +100,10 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { firstImcFragment = ImcFragment.empty(hub); fragments().add(firstImcFragment); + + // TODO: this is ugly, but Idk how to do it better (for modexp) + callerMemorySnapshot = + extractContiguousLimbsFromMemory(hub.currentFrame().frame(), new MemorySpan(0, 1)); } protected short maxNumberOfLines() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 98f0b6e314..9f90e59c6d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -446,21 +446,16 @@ private void populateColumns(final MessageFrame frame) { setCreate(createOobCall); } } else if (isPrecompile()) { - // DELEGATECALL, STATICCALL cases - int argsOffset = 2; - // this corresponds to argsSize on evm.codes - int cdsIndex = 3; - // this corresponds to retSize on evm.codes - int returnAtCapacityIndex = 5; - // value is not part of the arguments for DELEGATECALL and STATICCALL - boolean transfersValue = false; - // CALL, CALLCODE cases - if (opCode == OpCode.CALL || opCode == OpCode.CALLCODE) { - argsOffset = 3; - cdsIndex = 4; - returnAtCapacityIndex = 6; - transfersValue = !frame.getStackItem(2).isZero(); - } + final long argsOffset = + Words.clampedToLong( + opCode.callCanTransferValue() + ? hub.messageFrame().getStackItem(3) + : hub.messageFrame().getStackItem(2)); + final int cdsIndex = opCode.callCanTransferValue() ? 4 : 3; + final int returnAtCapacityIndex = opCode.callCanTransferValue() ? 6 : 5; + + final boolean transfersValue = + opCode.callCanTransferValue() && !frame.getStackItem(2).isZero(); final BigInteger callGas = BigInteger.valueOf( From 1d4eb5c372c2db2e04e20c9ad28aa8afe75c0777 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 2 Aug 2024 12:21:14 +0530 Subject: [PATCH 334/461] fix: don't trigger resolveRollback at every context ReEntry ! Signed-off-by: Francois Bojarski --- .../java/net/consensys/linea/zktracer/module/hub/Hub.java | 6 ++++-- .../linea/zktracer/module/hub/defer/DeferRegistry.java | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f830065ce6..d892836dcd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -672,8 +672,6 @@ public void traceContextEnter(MessageFrame frame) { public void traceContextReEnter(MessageFrame frame) { this.currentFrame().initializeFrame(frame); // TODO: is it needed ? - final int latestChildId = this.currentFrame().childFramesId().getLast(); - this.defers.resolvePostRollback(this, frame, this.callStack.getById(latestChildId)); this.defers.resolveAtContextReEntry(this, this.currentFrame()); if (this.currentFrame().sectionToUnlatch() != null) { this.unlatchStack(frame, this.currentFrame().sectionToUnlatch()); @@ -726,6 +724,10 @@ public void traceContextExit(MessageFrame frame) { } this.defers.resolveUponExitingContext(this, this.currentFrame()); + // TODO: verify me please @Olivier + if (Exceptions.any(this.pch.exceptions())) { + this.defers.resolvePostRollback(this, frame, this.currentFrame()); + } } public void tracePreExecution(final MessageFrame frame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index 037ee544ed..de58893eba 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -29,7 +29,6 @@ * Stores different categories of actions whose execution must be deferred later in the normal * transaction execution process. */ -// TODO: fix naming and implement the missing interfaces public class DeferRegistry implements PostOpcodeDefer, ImmediateContextEntryDefer, @@ -116,7 +115,7 @@ public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame // TODO: should use the TransactionProcessingMetadata // TODO add docs to understand why we do two rounds of resolving (due to AccountFragment created - // at endTx which are too deferEndTx) + // at endTx which are too deferEndTx), maybe no more the case, so not needed anymore @Override public void resolvePostTransaction( Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { From a01ba1f4deed25c10773943a57a81e4f634e1a4f Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 2 Aug 2024 10:46:05 +0200 Subject: [PATCH 335/461] fix(modexpsubsection): use modexp oob calls instead of common precompile oob call --- .../hub/fragment/imc/oob/OobInstruction.java | 12 ++++++ .../precompiles/PrecompileCommonOobCall.java | 2 + .../ModexpSubsection.java | 37 ++++++++++--------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java index 67650e9400..e6898a9167 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java @@ -45,5 +45,17 @@ public enum OobInstruction { OOB_INST_SSTORE(GlobalConstants.OOB_INST_SSTORE), OOB_INST_XCALL(GlobalConstants.OOB_INST_XCALL); + public boolean isCommonPrecompile() { + return this == OOB_INST_ECRECOVER + || this == OOB_INST_SHA2 + || this == OOB_INST_RIPEMD + || this == OOB_INST_IDENTITY + || this == OOB_INST_ECADD + || this == OOB_INST_ECMUL + || this == OOB_INST_ECPAIRING; + } + + // TODO: add checks for other families of precompiles, if necessary + private final int value; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java index d93980c643..aed83feea3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java @@ -20,6 +20,7 @@ import java.math.BigInteger; +import com.google.common.base.Preconditions; import lombok.Getter; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; @@ -40,6 +41,7 @@ public class PrecompileCommonOobCall extends OobCall { public PrecompileCommonOobCall(OobInstruction oobInstruction) { super(oobInstruction); + Preconditions.checkArgument(oobInstruction.isCommonPrecompile()); } public boolean getExtractCallData() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index e23c03df16..1d52a104d6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -24,21 +24,20 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpFullResultCopy; import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpLoadLead; import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpPartialResultCopy; -import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_CDS; -import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_EXTRACT; -import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_LEAD; -import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_PRICING; -import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_XBS; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; import static net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall.PROVER_MAX_INPUT_BYTE_SIZE; import java.math.BigInteger; -import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpExtractOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpLeadOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpPricingOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsOobCall; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.opcode.OpCode; @@ -48,7 +47,7 @@ public class ModexpSubsection extends PrecompileSubsection { private final ModExpMetadata modExpMetadata; - private PrecompileCommonOobCall sixthOobCall; + private ModexpPricingOobCall sixthOobCall; public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); @@ -88,7 +87,7 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { return; } - final PrecompileCommonOobCall firstOobCAll = new PrecompileCommonOobCall(OOB_INST_MODEXP_CDS); + final ModexpCallDataSizeOobCall firstOobCAll = new ModexpCallDataSizeOobCall(); firstImcFragment.callOob(firstOobCAll); // TODO: sounds weird we construct all OOB Call same way ... @@ -98,7 +97,8 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final MmuCall mmuCall = forModexpExtractBbs(hub, this, modExpMetadata); secondImcFragment.callMmu(mmuCall); } - final PrecompileCommonOobCall secondOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_XBS); + final ModexpXbsOobCall secondOobCall = + new ModexpXbsOobCall(ModexpXbsCase.OOB_INST_MODEXP_BBS); // TODO: check this is what we want secondImcFragment.callOob(secondOobCall); final ImcFragment thirdImcFragment = ImcFragment.empty(hub); @@ -107,7 +107,8 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final MmuCall mmuCall = forModexpExtractEbs(hub, this, modExpMetadata); thirdImcFragment.callMmu(mmuCall); } - final PrecompileCommonOobCall thirdOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_XBS); + final ModexpXbsOobCall thirdOobCall = + new ModexpXbsOobCall(ModexpXbsCase.OOB_INST_MODEXP_EBS); // TODO: check this is what we want thirdImcFragment.callOob(thirdOobCall); final ImcFragment fourthImcFragment = ImcFragment.empty(hub); @@ -116,12 +117,13 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final MmuCall mmuCall = forModexpExtractMbs(hub, this, modExpMetadata); fourthImcFragment.callMmu(mmuCall); } - final PrecompileCommonOobCall fourthOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_XBS); + final ModexpXbsOobCall fourthOobCall = + new ModexpXbsOobCall(ModexpXbsCase.OOB_INST_MODEXP_MBS); // TODO: check this is what we want fourthImcFragment.callOob(fourthOobCall); final ImcFragment fifthImcFragment = ImcFragment.empty(hub); fragments().add(fifthImcFragment); - final PrecompileCommonOobCall fifthOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_LEAD); + final ModexpLeadOobCall fifthOobCall = new ModexpLeadOobCall(); fifthImcFragment.callOob(fifthOobCall); if (modExpMetadata.loadRawLeadingWord()) { final MmuCall mmuCall = forModexpLoadLead(hub, this, modExpMetadata); @@ -132,7 +134,7 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final ImcFragment sixthImcFragment = ImcFragment.empty(hub); fragments().add(sixthImcFragment); - sixthOobCall = new PrecompileCommonOobCall(OOB_INST_MODEXP_PRICING); + sixthOobCall = new ModexpPricingOobCall(); sixthImcFragment.callOob(sixthOobCall); } @@ -141,7 +143,9 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); // sanity check - Preconditions.checkArgument(callSuccess == sixthOobCall.isHubSuccess()); + // TODO: since the type of sixthOobCall is changed, this check cannot be done anymore + // see if we can do something equivalent + // Preconditions.checkArgument(callSuccess == sixthOobCall.isHubSuccess()); if (!callSuccess) { precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_HUB); @@ -153,8 +157,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { final ImcFragment seventhImcFragment = ImcFragment.empty(hub); fragments().add(seventhImcFragment); - final PrecompileCommonOobCall seventhOobCall = - new PrecompileCommonOobCall(OOB_INST_MODEXP_EXTRACT); + final ModexpExtractOobCall seventhOobCall = new ModexpExtractOobCall(); seventhImcFragment.callOob(seventhOobCall); if (modExpMetadata.extractModulus()) { final MmuCall mmuCall = forModexpExtractBase(hub, this, modExpMetadata); From 1053cb8fe5c83e383fd409277d3eb71fb46a60a7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 2 Aug 2024 14:36:59 +0530 Subject: [PATCH 336/461] add check Signed-off-by: Francois Bojarski --- .../EllipticCurvePrecompileSubsection.java | 2 +- .../ModexpSubsection.java | 36 +++++-------------- .../PrecompileSubsection.java | 34 ++++++++++++++---- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index 8d75a19e5d..c16df69b71 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -77,7 +77,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_RAM); } } - // ECRECOVER can only be FAILURE_KNOWN_TO_HUB ro some form of SUCCESS_XXXX_REVERT + // ECRECOVER can only be FAILURE_KNOWN_TO_HUB or some form of SUCCESS_XXXX_REVERT default -> {} } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 1d52a104d6..397d8ea0e4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -24,11 +24,15 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpFullResultCopy; import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpLoadLead; import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forModexpPartialResultCopy; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase.OOB_INST_MODEXP_BBS; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase.OOB_INST_MODEXP_EBS; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase.OOB_INST_MODEXP_MBS; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; import static net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall.PROVER_MAX_INPUT_BYTE_SIZE; import java.math.BigInteger; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; @@ -36,13 +40,10 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpExtractOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpLeadOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpPricingOobCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsOobCall; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; -import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import org.hyperledger.besu.evm.internal.Words; public class ModexpSubsection extends PrecompileSubsection { @@ -52,21 +53,6 @@ public class ModexpSubsection extends PrecompileSubsection { public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); - // TODO: I'm not really happy with that ... @Olivier - // We have to trigger OOB at exec time, and we update the callData at childContextEntry - final OpCode opCode = hub.opCode(); - final long offset = - Words.clampedToLong( - opCode.callCanTransferValue() - ? hub.messageFrame().getStackItem(3) - : hub.messageFrame().getStackItem(2)); - final long length = - Words.clampedToLong( - opCode.callCanTransferValue() - ? hub.messageFrame().getStackItem(4) - : hub.messageFrame().getStackItem(3)); - callData = callerMemorySnapshot.slice((int) offset, (int) length); - modExpMetadata = new ModExpMetadata(callData); if (modExpMetadata .bbs() @@ -90,15 +76,13 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final ModexpCallDataSizeOobCall firstOobCAll = new ModexpCallDataSizeOobCall(); firstImcFragment.callOob(firstOobCAll); - // TODO: sounds weird we construct all OOB Call same way ... final ImcFragment secondImcFragment = ImcFragment.empty(hub); fragments().add(secondImcFragment); if (modExpMetadata.extractBbs()) { final MmuCall mmuCall = forModexpExtractBbs(hub, this, modExpMetadata); secondImcFragment.callMmu(mmuCall); } - final ModexpXbsOobCall secondOobCall = - new ModexpXbsOobCall(ModexpXbsCase.OOB_INST_MODEXP_BBS); // TODO: check this is what we want + final ModexpXbsOobCall secondOobCall = new ModexpXbsOobCall(OOB_INST_MODEXP_BBS); secondImcFragment.callOob(secondOobCall); final ImcFragment thirdImcFragment = ImcFragment.empty(hub); @@ -107,8 +91,7 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final MmuCall mmuCall = forModexpExtractEbs(hub, this, modExpMetadata); thirdImcFragment.callMmu(mmuCall); } - final ModexpXbsOobCall thirdOobCall = - new ModexpXbsOobCall(ModexpXbsCase.OOB_INST_MODEXP_EBS); // TODO: check this is what we want + final ModexpXbsOobCall thirdOobCall = new ModexpXbsOobCall(OOB_INST_MODEXP_EBS); thirdImcFragment.callOob(thirdOobCall); final ImcFragment fourthImcFragment = ImcFragment.empty(hub); @@ -117,8 +100,7 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final MmuCall mmuCall = forModexpExtractMbs(hub, this, modExpMetadata); fourthImcFragment.callMmu(mmuCall); } - final ModexpXbsOobCall fourthOobCall = - new ModexpXbsOobCall(ModexpXbsCase.OOB_INST_MODEXP_MBS); // TODO: check this is what we want + final ModexpXbsOobCall fourthOobCall = new ModexpXbsOobCall(OOB_INST_MODEXP_MBS); fourthImcFragment.callOob(fourthOobCall); final ImcFragment fifthImcFragment = ImcFragment.empty(hub); @@ -143,9 +125,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); // sanity check - // TODO: since the type of sixthOobCall is changed, this check cannot be done anymore - // see if we can do something equivalent - // Preconditions.checkArgument(callSuccess == sixthOobCall.isHubSuccess()); + Preconditions.checkArgument(callSuccess == sixthOobCall.isRamSuccess()); if (!callSuccess) { precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_HUB); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index cb29defdb2..5e548d5757 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -18,6 +18,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; import static net.consensys.linea.zktracer.runtime.callstack.CallFrame.extractContiguousLimbsFromMemory; import static net.consensys.linea.zktracer.types.Conversions.bytesToBoolean; +import static net.consensys.linea.zktracer.types.Utils.rightPadTo; import java.util.ArrayList; import java.util.List; @@ -33,10 +34,12 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; /** Note: {@link PrecompileSubsection}'s are created at child context entry by the call section */ @RequiredArgsConstructor @@ -101,9 +104,22 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { firstImcFragment = ImcFragment.empty(hub); fragments().add(firstImcFragment); - // TODO: this is ugly, but Idk how to do it better (for modexp) + final OpCode opCode = hub.opCode(); + final long offset = + Words.clampedToLong( + opCode.callCanTransferValue() + ? hub.messageFrame().getStackItem(3) + : hub.messageFrame().getStackItem(2)); + final long length = + Words.clampedToLong( + opCode.callCanTransferValue() + ? hub.messageFrame().getStackItem(4) + : hub.messageFrame().getStackItem(3)); + callDataMemorySpan = new MemorySpan(offset, length); callerMemorySnapshot = - extractContiguousLimbsFromMemory(hub.currentFrame().frame(), new MemorySpan(0, 1)); + extractContiguousLimbsFromMemory(hub.currentFrame().frame(), callDataMemorySpan); + final int lengthToExtract = (int) Math.min(length, callerMemorySnapshot.size() - offset); + callData = rightPadTo(callerMemorySnapshot.slice((int) offset, lengthToExtract), (int) length); } protected short maxNumberOfLines() { @@ -112,14 +128,18 @@ protected short maxNumberOfLines() { @Override public void resolveUponEnteringChildContext(Hub hub) { + // Sanity check + Preconditions.checkArgument( + callDataMemorySpan.equals(hub.currentFrame().callDataInfo().memorySpan())); + Preconditions.checkArgument(callData.equals(hub.messageFrame().getInputData())); + final MessageFrame callerFrame = hub.callStack().parent().frame(); + Preconditions.checkArgument( + callerMemorySnapshot.equals( + extractContiguousLimbsFromMemory(callerFrame, callDataMemorySpan))); + callerGas = hub.callStack().parent().frame().getRemainingGas(); calleeGas = hub.messageFrame().getRemainingGas(); - callDataMemorySpan = hub.currentFrame().callDataInfo().memorySpan(); - callData = hub.messageFrame().getInputData(); parentReturnDataTarget = hub.currentFrame().returnDataTargetInCaller(); - - final MessageFrame callerFrame = hub.callStack().parent().frame(); - callerMemorySnapshot = extractContiguousLimbsFromMemory(callerFrame, callDataMemorySpan); } public void resolveUponExitingContext(Hub hub, CallFrame callFrame) { From c98f08ce0b5b01013e19611163319533c1a18064 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 2 Aug 2024 17:00:25 +0530 Subject: [PATCH 337/461] minor cleaning Signed-off-by: Francois Bojarski --- .../zktracer/module/hub/section/call/CallSection.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 91461f6075..c92c45adb1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -181,7 +181,6 @@ public CallSection(Hub hub) { } // The CALL is now unexceptional and un-aborted - hub.defers().scheduleForContextExit(this, hub.callStack().futureId()); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); @@ -215,6 +214,7 @@ public CallSection(Hub hub) { value = Wei.of(hub.messageFrame().getStackItem(2).toUnsignedBigInteger()); selfCallWithNonzeroValueTransfer = isSelfCall && callCanTransferValue && !value.isZero(); hub.romLex().callRomLex(hub.currentFrame().frame()); + hub.defers().scheduleForContextExit(this, hub.callStack().futureId()); } if (scenarioFragment.getScenario() == CALL_EOA_SUCCESS_WONT_REVERT) { @@ -316,9 +316,8 @@ public void resolveUponEnteringChildContext(Hub hub) { /** Resolution happens as the child context is about to terminate. */ @Override public void resolveUponExitingContext(Hub hub, CallFrame frame) { - if (!(scenarioFragment.getScenario() == CALL_SMC_UNDEFINED)) { - return; - } + Preconditions.checkArgument(scenarioFragment.getScenario() == CALL_SMC_UNDEFINED); + childContextExitCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); childContextExitCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); @@ -423,7 +422,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - CallScenarioFragment.CallScenario scenario = scenarioFragment.getScenario(); + final CallScenarioFragment.CallScenario scenario = scenarioFragment.getScenario(); Preconditions.checkArgument(scenario.noLongerUndefined()); From 0494ac69c60f104f6c5531c33f8353aed15328fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 2 Aug 2024 13:37:45 +0200 Subject: [PATCH 338/461] ras --- .../linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java | 2 +- .../EllipticCurvePrecompileSubsection.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 450fcbdc4f..68144ce500 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -319,7 +319,7 @@ public static MmuCall txInit(final Hub hub) { .setRlpTxn(); } - public static MmuCall ecRecoverDataExtraction( + public static MmuCall callDataExtractionForEcrecover( final Hub hub, EllipticCurvePrecompileSubsection subsection, boolean successfulRecovery) { return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index c16df69b71..5af1ff3959 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -88,12 +88,11 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { switch (flag()) { case PRC_ECRECOVER -> { final boolean successfulRecovery = !returnData.isEmpty(); - firstMmuCall = MmuCall.ecRecoverDataExtraction(hub, this, successfulRecovery); + firstMmuCall = MmuCall.callDataExtractionForEcrecover(hub, this, successfulRecovery); } case PRC_ECADD -> firstMmuCall = MmuCall.callDataExtractionForEcadd(hub, this, callSuccess); case PRC_ECMUL -> firstMmuCall = MmuCall.callDataExtractionForEcmul(hub, this, callSuccess); - case PRC_ECPAIRING -> firstMmuCall = - MmuCall.callDataExtractionForEcpairing(hub, this, callSuccess); + case PRC_ECPAIRING -> firstMmuCall = MmuCall.callDataExtractionForEcpairing(hub, this, callSuccess); default -> throw new IllegalArgumentException("Not an elliptic curve precompile"); } firstImcFragment.callMmu(firstMmuCall); From 87a379fa03d72f93c6abcba39450df7b4afe9e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 3 Aug 2024 21:01:37 +0200 Subject: [PATCH 339/461] fix(modexp): FAILURE_KNOWN_TO_RAM is the only failure mode for MODEXP --- .../precompileSubsection/ModexpSubsection.java | 4 ++-- .../zktracer/precompiles/EcrecoverTests.java | 17 +++++++++++++++++ .../linea/zktracer/precompiles/ModexpTests.java | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 397d8ea0e4..6c3b84bda9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -27,7 +27,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase.OOB_INST_MODEXP_BBS; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase.OOB_INST_MODEXP_EBS; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsCase.OOB_INST_MODEXP_MBS; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM; import static net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall.PROVER_MAX_INPUT_BYTE_SIZE; import java.math.BigInteger; @@ -128,7 +128,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { Preconditions.checkArgument(callSuccess == sixthOobCall.isRamSuccess()); if (!callSuccess) { - precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_HUB); + precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_RAM); return; } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java new file mode 100644 index 0000000000..6c22695872 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java @@ -0,0 +1,17 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.precompiles; +public class EcrecoverTests { +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java new file mode 100644 index 0000000000..8607e93979 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java @@ -0,0 +1,17 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.precompiles; +public class ModexpTests { +} From 4973ebe4d8aef2b4f488b72ee1e22661ca6839d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 3 Aug 2024 21:02:12 +0200 Subject: [PATCH 340/461] feat(tests): trivial tests for for ECRECOVER and MODEXP --- .../zktracer/precompiles/EcrecoverTests.java | 43 +++++++++++++++++++ .../zktracer/precompiles/ModexpTests.java | 26 +++++++++++ 2 files changed, 69 insertions(+) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java index 6c22695872..5b2231d9be 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java @@ -13,5 +13,48 @@ * SPDX-License-Identifier: Apache-2.0 */ package net.consensys.linea.zktracer.precompiles; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; + public class EcrecoverTests { + + // the thing fails at AccountSnapshot.canonical() + // of the precompile address 0x00...01 ≡ ECRECOVER + @Test + void basicEcrecoverTest() { + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .push(0) + .push(0) + .push(0) + .push(0x01) // address + .push(0xffff) // gas + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); + BytecodeRunner.of(bytecode).run(); + } + + @Test + void insufficientGasEcrecoverTest() { + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .push(0) + .push(0) + .push(0) + .push(0x01) // address + .push(0x0bb7) // gas; note 0x0bb8 ⇔ 3000 + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); + BytecodeRunner.of(bytecode).run(); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java index 8607e93979..6fba1764d2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java @@ -13,5 +13,31 @@ * SPDX-License-Identifier: Apache-2.0 */ package net.consensys.linea.zktracer.precompiles; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; + public class ModexpTests { + + // the thing fails at AccountSnapshot.canonical() + // of the precompile address 0x00...05 ≡ MODEXP + @Test + void basicModexpTest() { + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .push(0) + .push(0) + .push(0) + .push(0x05) // address + .push(0xffff) // gas + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); + BytecodeRunner.of(bytecode).run(); + } } From e886c072cd2366ce757638e848b3da741a74a1b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 3 Aug 2024 21:03:16 +0200 Subject: [PATCH 341/461] fix(account snapthots): amended the canonical method to handle account not in the state --- .../zktracer/module/hub/AccountSnapshot.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index e02bbe28e2..3ba897f338 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -22,7 +22,9 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.types.AddressUtils; import net.consensys.linea.zktracer.types.Bytecode; +import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.account.Account; @@ -52,16 +54,30 @@ public class AccountSnapshot { // DEFERRED, // } + // TODO: is there a "canonical" way to take a snapshot fo an account + // where getWorldUpdater().getAccount(address) return null ? public static AccountSnapshot canonical(Hub hub, Address address) { final Account account = hub.messageFrame().getWorldUpdater().getAccount(address); - return new AccountSnapshot( - address, - account.getNonce(), - account.getBalance(), - hub.messageFrame().isAddressWarm(address), - new Bytecode(account.getCode()), - hub.transients.conflation().deploymentInfo().number(address), - hub.transients.conflation().deploymentInfo().isDeploying(address)); + boolean isPrecompile = AddressUtils.isPrecompile(address); + if (account != null) { + return new AccountSnapshot( + address, + account.getNonce(), + account.getBalance(), + hub.messageFrame().isAddressWarm(address), + new Bytecode(account.getCode()), + hub.transients.conflation().deploymentInfo().number(address), + hub.transients.conflation().deploymentInfo().isDeploying(address)); + } else { + return new AccountSnapshot( + address, + 0, + Wei.ZERO, + hub.messageFrame().isAddressWarm(address), + new Bytecode(Bytes.EMPTY), + hub.transients.conflation().deploymentInfo().number(address), + hub.transients.conflation().deploymentInfo().isDeploying(address)); + } } public AccountSnapshot decrementBalance(Wei quantity) { From 1cdb6f1fb488315065d265733366078046df1c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 3 Aug 2024 21:04:16 +0200 Subject: [PATCH 342/461] feat(EC precompiles): done ? + various other minor changes --- .../linea/zktracer/module/ecdata/EcData.java | 2 +- .../linea/zktracer/module/hub/Hub.java | 32 ++++++-- .../module/hub/defer/DeferRegistry.java | 38 +++++----- .../hub/defer/ImmediateContextEntryDefer.java | 2 +- .../module/hub/fragment/imc/mmu/MmuCall.java | 24 +++--- .../scenario/CallScenarioFragment.java | 2 +- .../module/hub/section/CreateSection.java | 4 +- .../module/hub/section/call/CallSection.java | 6 +- .../EllipticCurvePrecompileSubsection.java | 73 ++++++++++++++++--- .../IdentitySubsection.java | 4 +- .../ModexpSubsection.java | 2 +- .../PrecompileSubsection.java | 2 +- .../ShaTwoOrRipemdSubSection.java | 9 ++- .../hub/section/halt/ReturnSection.java | 2 +- .../hub/section/halt/RevertSection.java | 2 +- .../hub/transients/OperationAncillaries.java | 4 +- .../zktracer/opcode/gas/projector/Call.java | 4 +- .../zktracer/runtime/callstack/CallFrame.java | 2 +- .../linea/zktracer/types/MemorySpan.java | 2 +- 19 files changed, 148 insertions(+), 68 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index fa0a2949ba..f8a5b7f040 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -86,7 +86,7 @@ public void tracePreOpcode(MessageFrame frame) { final MemorySpan callDataSource = hub.transients().op().callDataSegment(); if (target.equals(Address.ALTBN128_PAIRING) - && (callDataSource.lengthNull() || callDataSource.length() % 192 != 0)) { + && (callDataSource.isEmpty() || callDataSource.length() % 192 != 0)) { return; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index d892836dcd..c1d70ae4ff 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -20,6 +20,7 @@ import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; +import static net.consensys.linea.zktracer.opcode.InstructionFamily.CALL; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import java.nio.MappedByteBuffer; @@ -124,6 +125,7 @@ import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.runtime.stack.StackContext; import net.consensys.linea.zktracer.runtime.stack.StackLine; +import net.consensys.linea.zktracer.types.AddressUtils; import net.consensys.linea.zktracer.types.Bytecode; import net.consensys.linea.zktracer.types.MemorySpan; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -564,7 +566,7 @@ public void traceContextEnter(MessageFrame frame) { this.pch.reset(); if (frame.getDepth() == 0) { - // Bedrock... + // Root context final TransactionProcessingMetadata currentTx = transients().tx(); final Address toAddress = effectiveToAddress(currentTx.getBesuTransaction()); final boolean isDeployment = this.transients.tx().getBesuTransaction().getTo().isEmpty(); @@ -662,7 +664,7 @@ public void traceContextEnter(MessageFrame frame) { isDeployment); this.currentFrame().initializeFrame(frame); // TODO should be done in enter - this.defers.resolveUponEnteringChildContext(this); + this.defers.resolveUponImmediateContextEntry(this); for (Module m : this.modules) { m.traceContextEnter(frame); @@ -672,7 +674,7 @@ public void traceContextEnter(MessageFrame frame) { public void traceContextReEnter(MessageFrame frame) { this.currentFrame().initializeFrame(frame); // TODO: is it needed ? - this.defers.resolveAtContextReEntry(this, this.currentFrame()); + defers.resolveAtContextReEntry(this, this.currentFrame()); if (this.currentFrame().sectionToUnlatch() != null) { this.unlatchStack(frame, this.currentFrame().sectionToUnlatch()); this.currentFrame().sectionToUnlatch(null); @@ -998,7 +1000,7 @@ void processStateExec(MessageFrame frame) { if (this.pch.signals().ecData()) { this.previousOperationWasCallToEcPrecompile = true; } - this.traceOperation(frame); + this.traceOpcode(frame); } else { this.squashCurrentFrameOutputData(); @@ -1028,7 +1030,9 @@ public int cumulatedTxCount() { return this.state.txCount(); } - void traceOperation(MessageFrame frame) { + void traceOpcode(MessageFrame frame) { + boolean breakHere = this.opCodeData().instructionFamily() == CALL; + switch (this.opCodeData().instructionFamily()) { case ADD, MOD, @@ -1115,12 +1119,24 @@ void traceOperation(MessageFrame frame) { case CREATE -> new CreateSection(this); - case CALL -> new CallSection(this); + case CALL -> { + boolean breakHereAgain = + AddressUtils.isPrecompile(AddressUtils.addressFromBytes(frame.getStackItem(1))); + new CallSection(this); + } case JUMP -> new JumpSection(this); } } + /** + * 0x 0000000000000000000000000000000000000000000000000000000000000020 + * 0000000000000000000000000000000000000000000000000000000000000020 + * 0000000000000000000000000000000000000000000000000000000000000020 + * 1b0d87982c98b463c5a1058e31ea2b39022d5ed69aeca8f24153d3f2962121ed + * 0000000000000000000000000000000000000000000000000000000001000000 + * 30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001 + */ public void squashCurrentFrameOutputData() { this.currentFrame().outputDataSpan(MemorySpan.empty()); this.currentFrame().outputData(Bytes.EMPTY); @@ -1135,4 +1151,8 @@ public void squashParentFrameReturnData() { public CallFrame getLastChildCallFrame(final CallFrame parentFrame) { return this.callStack.getById(parentFrame.childFramesId().getLast()); } + + private boolean withinPrecompile(MessageFrame frame) { + return AddressUtils.isPrecompile(frame.getContractAddress()); + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index de58893eba..d16960f374 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -64,12 +64,12 @@ public class DeferRegistry /** Schedule an action to be executed after the completion of the current opcode. */ public void scheduleForImmediateContextEntry(ImmediateContextEntryDefer defer) { - this.immediateContextEntryDefers.add(defer); + immediateContextEntryDefers.add(defer); } /** Schedule an action to be executed after the completion of the current opcode. */ public void scheduleForPostExecution(PostOpcodeDefer defer) { - this.postOpcodeDefers.add(defer); + postOpcodeDefers.add(defer); } /** Schedule an action to be executed at the exit of a given context. */ @@ -82,12 +82,12 @@ public void scheduleForContextExit(ContextExitDefer defer, Integer callFrameId) /** Schedule an action to be executed at the end of the current transaction. */ public void scheduleForPostTransaction(PostTransactionDefer defer) { - this.postTransactionDefers.add(defer); + postTransactionDefers.add(defer); } /** Schedule an action to be executed at the end of the current transaction. */ public void scheduleForPostConflation(PostConflationDefer defer) { - this.postConflationDefers.add(defer); + postConflationDefers.add(defer); } /** Schedule an action to be executed at the re-entry in the current context. */ @@ -120,15 +120,15 @@ public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame public void resolvePostTransaction( Hub hub, WorldView world, Transaction tx, boolean isSuccessful) { final List postTransactionDefersFirstRound = - new ArrayList<>(this.postTransactionDefers); - this.postTransactionDefers.clear(); + new ArrayList<>(postTransactionDefers); + postTransactionDefers.clear(); for (PostTransactionDefer defer : postTransactionDefersFirstRound) { defer.resolvePostTransaction(hub, world, tx, isSuccessful); } - for (PostTransactionDefer defer : this.postTransactionDefers) { + for (PostTransactionDefer defer : postTransactionDefers) { defer.resolvePostTransaction(hub, world, tx, isSuccessful); } - this.postTransactionDefers.clear(); + postTransactionDefers.clear(); } /** @@ -138,10 +138,10 @@ public void resolvePostTransaction( */ @Override public void resolvePostConflation(Hub hub, WorldView world) { - for (PostConflationDefer defer : this.postConflationDefers) { + for (PostConflationDefer defer : postConflationDefers) { defer.resolvePostConflation(hub, world); } - this.postConflationDefers.clear(); + postConflationDefers.clear(); } /** @@ -153,10 +153,10 @@ public void resolvePostConflation(Hub hub, WorldView world) { */ @Override public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.OperationResult result) { - for (PostOpcodeDefer defer : this.postOpcodeDefers) { + for (PostOpcodeDefer defer : postOpcodeDefers) { defer.resolvePostExecution(hub, frame, result); } - this.postOpcodeDefers.clear(); + postOpcodeDefers.clear(); } /** @@ -166,11 +166,11 @@ public void resolvePostExecution(Hub hub, MessageFrame frame, Operation.Operatio * @param callFrame the {@link CallFrame} of the transaction */ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { - if (this.contextReEntryDefers.containsKey(callFrame)) { - for (ContextReEntryDefer defer : this.contextReEntryDefers.get(callFrame)) { + if (contextReEntryDefers.containsKey(callFrame)) { + for (ContextReEntryDefer defer : contextReEntryDefers.get(callFrame)) { defer.resolveAtContextReEntry(hub, callFrame); } - this.contextReEntryDefers.remove(callFrame); + contextReEntryDefers.remove(callFrame); } } @@ -201,11 +201,11 @@ public void resolvePostRollback( } @Override - public void resolveUponEnteringChildContext(Hub hub) { - for (ImmediateContextEntryDefer defer : this.immediateContextEntryDefers) { - defer.resolveUponEnteringChildContext(hub); + public void resolveUponImmediateContextEntry(Hub hub) { + for (ImmediateContextEntryDefer defer : immediateContextEntryDefers) { + defer.resolveUponImmediateContextEntry(hub); } - this.immediateContextEntryDefers.clear(); + immediateContextEntryDefers.clear(); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ImmediateContextEntryDefer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ImmediateContextEntryDefer.java index 62cf3f8308..d64bf5cffc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ImmediateContextEntryDefer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/ImmediateContextEntryDefer.java @@ -18,5 +18,5 @@ import net.consensys.linea.zktracer.module.hub.Hub; public interface ImmediateContextEntryDefer { - void resolveUponEnteringChildContext(Hub hub); + void resolveUponImmediateContextEntry(Hub hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 68144ce500..0667242243 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -333,7 +333,7 @@ public static MmuCall callDataExtractionForEcrecover( .setEcData(); } - public static MmuCall ecRecoverFullReturnDataTransfer( + public static MmuCall fullReturnDataTransferForEcrecover( final Hub hub, EllipticCurvePrecompileSubsection subsection) { final int precompileContextNumber = subsection.exoModuleOperationId(); @@ -346,7 +346,7 @@ public static MmuCall ecRecoverFullReturnDataTransfer( .setEcData(); } - public static MmuCall ecrecoverPartialReturnDataCopy( + public static MmuCall partialReturnDataCopyForEcrecover( final Hub hub, EllipticCurvePrecompileSubsection subsection) { final int precompileContextNumber = subsection.exoModuleOperationId(); @@ -361,7 +361,7 @@ public static MmuCall ecrecoverPartialReturnDataCopy( .referenceSize(subsection.parentReturnDataTarget.length()); } - public static MmuCall forShaTwoOrRipemdCallDataExtraction( + public static MmuCall callDataExtractionForShaTwoAndRipemd( final Hub hub, PrecompileSubsection precompileSubsection) { PrecompileScenarioFragment.PrecompileFlag flag = @@ -380,7 +380,7 @@ public static MmuCall forShaTwoOrRipemdCallDataExtraction( .setRipSha(); } - public static MmuCall forShaTwoOrRipemdFullResultTransfer( + public static MmuCall fullResultTransferForShaTwoAndRipemd( final Hub hub, PrecompileSubsection precompileSubsection) { PrecompileScenarioFragment.PrecompileFlag flag = @@ -389,7 +389,7 @@ public static MmuCall forShaTwoOrRipemdFullResultTransfer( final boolean isShaTwo = flag == PRC_SHA2_256; - if (precompileSubsection.callDataMemorySpan.lengthNull()) { + if (precompileSubsection.callDataMemorySpan.isEmpty()) { return new MmuCall(hub, MMU_INST_MSTORE) .targetId(precompileSubsection.exoModuleOperationId()) .targetOffset(EWord.ZERO) @@ -407,14 +407,14 @@ public static MmuCall forShaTwoOrRipemdFullResultTransfer( } } - public static MmuCall forShaTwoOrRipemdPartialResultCopy( + public static MmuCall partialReturnDataCopyForShaTwoAndRipemd( final Hub hub, PrecompileSubsection precompileSubsection) { PrecompileScenarioFragment.PrecompileFlag flag = precompileSubsection.precompileScenarioFragment().flag; Preconditions.checkArgument(flag.isAnyOf(PRC_SHA2_256, PRC_RIPEMD_160)); - Preconditions.checkArgument(!precompileSubsection.parentReturnDataTarget.lengthNull()); + Preconditions.checkArgument(!precompileSubsection.parentReturnDataTarget.isEmpty()); return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileSubsection.returnDataContextNumber()) @@ -532,10 +532,14 @@ public static MmuCall callDataExtractionForEcpairing( .phase(PHASE_ECPAIRING_DATA); } + /** + * Note that {@link MmuCall#fullReturnDataTransferForEcpairing} handles both cases of interest: + * empty call data and nonempty call data. + */ public static MmuCall fullReturnDataTransferForEcpairing( final Hub hub, PrecompileSubsection subsection) { final int precompileContextNumber = subsection.exoModuleOperationId(); - if (subsection.callDataMemorySpan.lengthNull()) { + if (subsection.callDataMemorySpan.isEmpty()) { return new MmuCall(hub, MMU_INST_MSTORE).targetId(precompileContextNumber).limb2(Bytes.of(1)); } else { return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) @@ -547,7 +551,7 @@ public static MmuCall fullReturnDataTransferForEcpairing( } } - public static MmuCall partialReturnDataCopyForEcpairing( + public static MmuCall partialCopyOfReturnDataForEcpairing( final Hub hub, PrecompileSubsection subsection) { final int precompileContextNumber = subsection.exoModuleOperationId(); return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) @@ -588,7 +592,7 @@ public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, in .setBlakeModexp() .phase(PHASE_BLAKE_RESULT); } else { - if (p.requestedReturnDataTarget().lengthNull()) { + if (p.requestedReturnDataTarget().isEmpty()) { return MmuCall.nop(); } else { return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java index 6e1c0c87d7..127e0f6668 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -71,7 +71,7 @@ public boolean noLongerUndefined() { public Trace trace(Trace trace) { Preconditions.checkArgument( - !illegalTracingScenario.contains(this.scenario), "Final Scenario hasn't been set"); + this.scenario.noLongerUndefined(), "Final Scenario hasn't been set"); return trace .peekAtScenario(true) // // CALL scenarios diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 07a6e17411..fff0a35b63 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -182,7 +182,7 @@ public CreateSection(Hub hub) { deploymentAccount.map(AccountState::hasCode).orElse(false); final boolean failedCreate = createdAddressHasNonZeroNonce || createdAddressHasNonEmptyCode; - final boolean emptyInitCode = hub.transients().op().initCodeSegment().lengthNull(); + final boolean emptyInitCode = hub.transients().op().initCodeSegment().isEmpty(); // Trigger MMU & SHAKIRA to hash the (non-empty) InitCode of CREATE2 - even for failed CREATE2 if (hub.opCode() == CREATE2 && !emptyInitCode) { @@ -226,7 +226,7 @@ public CreateSection(Hub hub) { } @Override - public void resolveUponEnteringChildContext(Hub hub) { + public void resolveUponImmediateContextEntry(Hub hub) { childEntryCreatorSnapshot = AccountSnapshot.canonical(hub, preOpcodeCreatorSnapshot.address()); childEntryCreateeSnapshot = AccountSnapshot.canonical(hub, preOpcodeCreateeSnapshot.address()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index c92c45adb1..46d53c8093 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -171,7 +171,6 @@ public CallSection(Hub hub) { final boolean aborts = hub.pch().abortingConditions().any(); Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts); - hub.defers().scheduleForImmediateContextEntry(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); hub.defers().scheduleForPostTransaction(this); @@ -181,6 +180,7 @@ public CallSection(Hub hub) { } // The CALL is now unexceptional and un-aborted + hub.defers().scheduleForImmediateContextEntry(this); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); @@ -195,7 +195,7 @@ public CallSection(Hub hub) { hub.defers().scheduleForImmediateContextEntry(precompileSubsection); // gas & input data, ... hub.defers() .scheduleForContextReEntry( - precompileSubsection, hub.callStack().parent()); // success bit & return data + precompileSubsection, hub.currentFrame()); // success bit & return data } else { scenarioFragment.setScenario( world.get(calleeAddress).hasCode() ? CALL_SMC_UNDEFINED : CALL_EOA_SUCCESS_WONT_REVERT); @@ -262,7 +262,7 @@ private void abortingCall(Hub hub) { } @Override - public void resolveUponEnteringChildContext(Hub hub) { + public void resolveUponImmediateContextEntry(Hub hub) { switch (scenarioFragment.getScenario()) { case CALL_SMC_UNDEFINED -> { postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index 5af1ff3959..b2d599ad4f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -17,10 +17,12 @@ import static com.google.common.base.Preconditions.checkArgument; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.*; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; @@ -71,17 +73,17 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { return; } - switch (flag()) { - case PRC_ECADD, PRC_ECMUL, PRC_ECPAIRING -> { - if (oobCall.isHubSuccess() && !callSuccess) { - precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_RAM); - } + // NOTE: from here on out + // hubSuccess ≡ true + + // ECRECOVER can only be FAILURE_KNOWN_TO_HUB or some form of SUCCESS_XXXX_REVERT + if (flag().isAnyOf(PRC_ECADD, PRC_ECMUL, PRC_ECPAIRING)) { + if (oobCall.isHubSuccess() && !callSuccess) { // hub success is implicitly true + precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_RAM); } - // ECRECOVER can only be FAILURE_KNOWN_TO_HUB or some form of SUCCESS_XXXX_REVERT - default -> {} } - MmuCall firstMmuCall; + final MmuCall firstMmuCall; final boolean nonemptyCallData = !callData.isEmpty(); if (nonemptyCallData) { @@ -92,10 +94,63 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { } case PRC_ECADD -> firstMmuCall = MmuCall.callDataExtractionForEcadd(hub, this, callSuccess); case PRC_ECMUL -> firstMmuCall = MmuCall.callDataExtractionForEcmul(hub, this, callSuccess); - case PRC_ECPAIRING -> firstMmuCall = MmuCall.callDataExtractionForEcpairing(hub, this, callSuccess); + case PRC_ECPAIRING -> firstMmuCall = + MmuCall.callDataExtractionForEcpairing(hub, this, callSuccess); default -> throw new IllegalArgumentException("Not an elliptic curve precompile"); } firstImcFragment.callMmu(firstMmuCall); } + + final ImcFragment secondImcFragment = ImcFragment.empty(hub); + this.fragments().add(secondImcFragment); + + final ImcFragment thirdImcFragment = ImcFragment.empty(hub); + this.fragments().add(thirdImcFragment); + + MmuCall secondMmuCall = null; + MmuCall thirdMmuCall = null; + final boolean producesNonemptyReturnData = !returnData.isEmpty(); + final boolean callerMayReceiveReturnData = !parentReturnDataTarget.isEmpty(); + + if (producesNonemptyReturnData) { + switch (flag()) { + case PRC_ECRECOVER -> { + secondMmuCall = MmuCall.fullReturnDataTransferForEcrecover(hub, this); + if (callerMayReceiveReturnData) { + thirdMmuCall = MmuCall.partialReturnDataCopyForEcrecover(hub, this); + } + } + case PRC_ECADD -> { + if (nonemptyCallData) { + secondMmuCall = MmuCall.fullReturnDataTransferForEcadd(hub, this); + } + if (callerMayReceiveReturnData) { + thirdMmuCall = MmuCall.partialCopyOfReturnDataForEcadd(hub, this); + } + } + case PRC_ECMUL -> { + if (nonemptyCallData) { + secondMmuCall = MmuCall.fullReturnDataTransferForEcmul(hub, this); + } + if (callerMayReceiveReturnData) { + thirdMmuCall = MmuCall.partialCopyOfReturnDataForEcmul(hub, this); + } + } + case PRC_ECPAIRING -> { + secondMmuCall = MmuCall.fullReturnDataTransferForEcpairing(hub, this); + + if (callerMayReceiveReturnData) { + thirdMmuCall = MmuCall.partialCopyOfReturnDataForEcpairing(hub, this); + } + } + default -> throw new IllegalArgumentException("Not an elliptic curve precompile"); + } + if (secondMmuCall != null) { + secondImcFragment.callMmu(secondMmuCall); + } + if (thirdMmuCall != null) { + thirdImcFragment.callMmu(thirdMmuCall); + } + } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java index 7224bf71ea..a7956c1d99 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/IdentitySubsection.java @@ -54,7 +54,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { precompileScenarioFragment.scenario(PRC_FAILURE_KNOWN_TO_HUB); } - final boolean extractCallData = callSuccess && !callDataMemorySpan.lengthNull(); + final boolean extractCallData = callSuccess && !callDataMemorySpan.isEmpty(); if (extractCallData) { final MmuCall mmuCall = forIdentityExtractCallData(hub, this); firstImcFragment.callMmu(mmuCall); @@ -62,7 +62,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { final ImcFragment secondImcFragment = ImcFragment.empty(hub); fragments().add(secondImcFragment); - if (extractCallData && !parentReturnDataTarget().lengthNull()) { + if (extractCallData && !parentReturnDataTarget().isEmpty()) { final MmuCall mmuCall = forIdentityReturnData(hub, this); secondImcFragment.callMmu(mmuCall); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 6c3b84bda9..9d1ee4668e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -167,7 +167,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { final ImcFragment eleventhImcFragment = ImcFragment.empty(hub); fragments().add(eleventhImcFragment); - if (modExpMetadata.mbsNonZero() && !parentReturnDataTarget.lengthNull()) { + if (modExpMetadata.mbsNonZero() && !parentReturnDataTarget.isEmpty()) { final MmuCall mmuCall = forModexpPartialResultCopy(hub, this, modExpMetadata); eleventhImcFragment.callMmu(mmuCall); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 5e548d5757..9f9b9319f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -127,7 +127,7 @@ protected short maxNumberOfLines() { } @Override - public void resolveUponEnteringChildContext(Hub hub) { + public void resolveUponImmediateContextEntry(Hub hub) { // Sanity check Preconditions.checkArgument( callDataMemorySpan.equals(hub.currentFrame().callDataInfo().memorySpan())); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java index ffb1882509..31e403e522 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ShaTwoOrRipemdSubSection.java @@ -73,7 +73,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { callFrame.frame().getReturnData()); hub.shakiraData().call(shakiraCall); - final MmuCall mmuCall = MmuCall.forShaTwoOrRipemdCallDataExtraction(hub, this); + final MmuCall mmuCall = MmuCall.callDataExtractionForShaTwoAndRipemd(hub, this); firstImcFragment.callMmu(mmuCall); } @@ -81,7 +81,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { final ImcFragment secondImcFragment = ImcFragment.empty(hub); this.fragments().add(secondImcFragment); - final MmuCall fullOutputDataTransfer = MmuCall.forShaTwoOrRipemdFullResultTransfer(hub, this); + final MmuCall fullOutputDataTransfer = MmuCall.fullResultTransferForShaTwoAndRipemd(hub, this); secondImcFragment.callMmu(fullOutputDataTransfer); final ImcFragment thirdImcFragment = ImcFragment.empty(hub); @@ -89,8 +89,9 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { // the partial copy of return data happens only if the caller context // provided a nonempty return data target - if (!parentReturnDataTarget.lengthNull()) { - final MmuCall partialReturnDataCopy = MmuCall.forShaTwoOrRipemdPartialResultCopy(hub, this); + if (!parentReturnDataTarget.isEmpty()) { + final MmuCall partialReturnDataCopy = + MmuCall.partialReturnDataCopyForShaTwoAndRipemd(hub, this); thirdImcFragment.callMmu(partialReturnDataCopy); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index b78d46209e..0a18d734cb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -137,7 +137,7 @@ public ReturnSection(Hub hub) { final boolean messageCallReturnTouchesRam = !currentFrame.isRoot() && nontrivialMmuOperation // [size ≠ 0] ∧ ¬MXPX - && !currentFrame.returnDataTargetInCaller().lengthNull(); // [r@c ≠ 0] + && !currentFrame.returnDataTargetInCaller().isEmpty(); // [r@c ≠ 0] returnScenarioFragment.setScenario( messageCallReturnTouchesRam diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index 4b921c76f6..3d086e4f12 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -56,7 +56,7 @@ public RevertSection(Hub hub) { (Exceptions.none(exceptions)) && !hub.currentFrame().isRoot() && mxpCall.mayTriggerNontrivialMmuOperation // i.e. size ≠ 0 ∧ ¬MXPX - && !hub.currentFrame().returnDataTargetInCaller().lengthNull(); + && !hub.currentFrame().returnDataTargetInCaller().isEmpty(); if (triggerMmu) { mmuCall = MmuCall.revert(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index 3dc6ae84a2..e0087a3493 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -39,7 +39,7 @@ public class OperationAncillaries { private static Bytes maybeShadowReadMemory(final MemorySpan span, final MessageFrame frame) { // Accesses to huge offset with 0-length are valid - if (span.lengthNull()) { + if (span.isEmpty()) { return Bytes.EMPTY; } @@ -248,7 +248,7 @@ public Bytes outputData() { final MemorySpan outputDataSpan = outputDataSpan(); // Accesses to huge offset with 0-length are valid - if (outputDataSpan.lengthNull()) { + if (outputDataSpan.isEmpty()) { return Bytes.EMPTY; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java index 0d55dbab7e..f7235dae10 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/gas/projector/Call.java @@ -62,8 +62,8 @@ public long largestOffset() { } return Math.max( - inputData.lengthNull() ? 0 : Words.clampedAdd(inputData.offset(), inputData.length()), - returnData.lengthNull() ? 0 : Words.clampedAdd(returnData.offset(), returnData.length())); + inputData.isEmpty() ? 0 : Words.clampedAdd(inputData.offset(), inputData.length()), + returnData.isEmpty() ? 0 : Words.clampedAdd(returnData.offset(), returnData.length())); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 79f0b4dfc3..0d7932cb80 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -345,7 +345,7 @@ public void frame(MessageFrame frame) { public static Bytes extractContiguousLimbsFromMemory( final MessageFrame frame, final MemorySpan memorySpan) { // TODO: optimize me please. Need a review of the MMU operation handling. - return memorySpan.lengthNull() + return memorySpan.isEmpty() ? Bytes.EMPTY : frame.shadowReadMemory(0, frame.memoryByteSize()); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java index 6d61a489ab..454a61441d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySpan.java @@ -50,7 +50,7 @@ long end() { return this.length + this.length; } - public boolean lengthNull() { + public boolean isEmpty() { return this.length == 0; } From dc3a4fba869bc044e73b69118ff996acc51609df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sun, 4 Aug 2024 05:23:45 +0200 Subject: [PATCH 343/461] fix(oob): partial (?) fix for callGas in OobOperation's populateColumns method The issue was that ZkTracer.gasCalculator.gasAvailableForChildCall deducts gas from the frame and shouldn't be used otherwise we find ourselves deducting gas twice --- .../consensys/linea/zktracer/module/hub/Hub.java | 3 --- .../precompileSubsection/ModexpSubsection.java | 4 ++-- .../consensys/linea/zktracer/module/oob/Oob.java | 3 ++- .../linea/zktracer/module/oob/OobOperation.java | 16 ++++++++++++---- .../zktracer/runtime/callstack/CallFrame.java | 4 +--- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c1d70ae4ff..e02d9a0870 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1031,7 +1031,6 @@ public int cumulatedTxCount() { } void traceOpcode(MessageFrame frame) { - boolean breakHere = this.opCodeData().instructionFamily() == CALL; switch (this.opCodeData().instructionFamily()) { case ADD, @@ -1120,8 +1119,6 @@ void traceOpcode(MessageFrame frame) { case CREATE -> new CreateSection(this); case CALL -> { - boolean breakHereAgain = - AddressUtils.isPrecompile(AddressUtils.addressFromBytes(frame.getStackItem(1))); new CallSection(this); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 9d1ee4668e..c3b96313f9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -73,8 +73,8 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { return; } - final ModexpCallDataSizeOobCall firstOobCAll = new ModexpCallDataSizeOobCall(); - firstImcFragment.callOob(firstOobCAll); + final ModexpCallDataSizeOobCall firstOobCall = new ModexpCallDataSizeOobCall(); + firstImcFragment.callOob(firstOobCall); final ImcFragment secondImcFragment = ImcFragment.empty(hub); fragments().add(secondImcFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 05de8664a9..65a5ed4fa9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -53,7 +53,8 @@ public String moduleKey() { } public void call(OobCall oobCall) { - this.chunks.add(new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub)); + OobOperation oobOperation = new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub); + this.chunks.add(oobOperation); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 9f90e59c6d..9990a344f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -19,6 +19,7 @@ import static java.lang.Byte.toUnsignedInt; import static java.lang.Math.max; import static java.lang.Math.min; +import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_ADD; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_DIV; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_EQ; @@ -457,10 +458,17 @@ private void populateColumns(final MessageFrame frame) { final boolean transfersValue = opCode.callCanTransferValue() && !frame.getStackItem(2).isZero(); - final BigInteger callGas = - BigInteger.valueOf( - ZkTracer.gasCalculator.gasAvailableForChildCall( - frame, Words.clampedToLong(frame.getStackItem(0)), transfersValue)); + // shameless copy from gasAvailableForChildCall found in TangerineWhistleGasCalculator + // TODO: @Olivier and @François: find out whether frame.getRemainingGas was already + // decremented by the upfront cost. If not we must replace remainingGas with the + // decremented version + long remainingGas = frame.getRemainingGas(); + long gasCap = + Words.unsignedMin( + allButOneSixtyFourth(remainingGas), Words.clampedToLong(frame.getStackItem(0))); + long callGasLong = + transfersValue ? gasCap + ZkTracer.gasCalculator.getAdditionalCallStipend() : gasCap; + final BigInteger callGas = BigInteger.valueOf(callGasLong); final BigInteger cds = EWord.of(frame.getStackItem(cdsIndex)).toUnsignedBigInteger(); // Note that this check will disappear since it will be the MXP module taking care of it diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 0d7932cb80..868106d627 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -345,8 +345,6 @@ public void frame(MessageFrame frame) { public static Bytes extractContiguousLimbsFromMemory( final MessageFrame frame, final MemorySpan memorySpan) { // TODO: optimize me please. Need a review of the MMU operation handling. - return memorySpan.isEmpty() - ? Bytes.EMPTY - : frame.shadowReadMemory(0, frame.memoryByteSize()); + return memorySpan.isEmpty() ? Bytes.EMPTY : frame.shadowReadMemory(0, frame.memoryByteSize()); } } From 9c50526002e9c11ab833b1b8ae96bf48db40621a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 5 Aug 2024 22:42:00 +0200 Subject: [PATCH 344/461] fix(oob): just some refactoring and removing of fields --- .../module/hub/fragment/imc/oob/OobCall.java | 2 +- .../hub/fragment/imc/oob/OobInstruction.java | 52 +- .../fragment/imc/oob/opcodes/CallOobCall.java | 7 +- .../linea/zktracer/module/oob/Oob.java | 101 +-- .../zktracer/module/oob/OobOperation.java | 638 +++++++----------- .../linea/zktracer/module/oob/OobRdcTest.java | 40 +- 6 files changed, 375 insertions(+), 465 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobCall.java index fda734a553..7fe4f88049 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobCall.java @@ -26,7 +26,7 @@ public abstract class OobCall implements TraceSubFragment { public Bytes ZERO = Bytes.EMPTY; public Bytes ONE = Bytes.of(1); - final OobInstruction oobInstruction; + public final OobInstruction oobInstruction; public int oobInstructionValue() { return oobInstruction.getValue(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java index e6898a9167..854ca99a56 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/OobInstruction.java @@ -45,14 +45,52 @@ public enum OobInstruction { OOB_INST_SSTORE(GlobalConstants.OOB_INST_SSTORE), OOB_INST_XCALL(GlobalConstants.OOB_INST_XCALL); + public boolean isEvmInstruction() { + return this.isAnyOf( + OOB_INST_CALL, + OOB_INST_CDL, + OOB_INST_CREATE, + OOB_INST_DEPLOYMENT, + OOB_INST_JUMP, + OOB_INST_JUMPI, + OOB_INST_RDC, + OOB_INST_SSTORE, + OOB_INST_XCALL); + } + public boolean isCommonPrecompile() { - return this == OOB_INST_ECRECOVER - || this == OOB_INST_SHA2 - || this == OOB_INST_RIPEMD - || this == OOB_INST_IDENTITY - || this == OOB_INST_ECADD - || this == OOB_INST_ECMUL - || this == OOB_INST_ECPAIRING; + return this.isAnyOf( + OOB_INST_ECRECOVER, + OOB_INST_SHA2, + OOB_INST_RIPEMD, + OOB_INST_IDENTITY, + OOB_INST_ECADD, + OOB_INST_ECMUL, + OOB_INST_ECPAIRING); + } + + public boolean isModexp() { + return this.isAnyOf( + OOB_INST_MODEXP_CDS, + OOB_INST_MODEXP_EXTRACT, + OOB_INST_MODEXP_LEAD, + OOB_INST_MODEXP_PRICING, + OOB_INST_MODEXP_XBS); + } + + public boolean isBlake() { + return this.isAnyOf(OOB_INST_BLAKE_PARAMS, OOB_INST_BLAKE_CDS); + } + + public boolean isPrecompile() { + return this.isCommonPrecompile() || this.isModexp() || this.isBlake(); + } + + public boolean isAnyOf(OobInstruction... oobInstructions) { + for (OobInstruction oobInstruction : oobInstructions) { + if (this == oobInstruction) return true; + } + return false; } // TODO: add checks for other families of precompiles, if necessary diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java index 7c9f806d19..a3040695fe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java @@ -30,10 +30,9 @@ @Getter @Setter public class CallOobCall extends OobCall { - EWord value; + public EWord value; BigInteger balance; BigInteger callStackDepth; - boolean valueIsNonzero; boolean abortingCondition; public CallOobCall() { @@ -58,7 +57,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data4(ZERO) .data5(ZERO) .data6(bigIntegerToBytes(callStackDepth)) - .data7(booleanToBytes(valueIsNonzero)) + .data7(booleanToBytes(!value.isZero())) .data8(booleanToBytes(abortingCondition)); } @@ -73,7 +72,7 @@ public Trace trace(Trace trace) { .pMiscOobData4(ZERO) .pMiscOobData5(ZERO) .pMiscOobData6(bigIntegerToBytes(callStackDepth)) - .pMiscOobData7(booleanToBytes(valueIsNonzero)) + .pMiscOobData7(booleanToBytes(!value.isZero())) .pMiscOobData8(booleanToBytes(abortingCondition)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 65a5ed4fa9..5da482cc11 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.oob; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; import java.math.BigInteger; @@ -29,6 +30,7 @@ import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -38,7 +40,7 @@ public class Oob implements Module { /** A list of the operations to trace */ - @Getter private final StackedList chunks = new StackedList<>(); + @Getter private final StackedList oobOperations = new StackedList<>(); private final Hub hub; private final Add add; @@ -54,14 +56,14 @@ public String moduleKey() { public void call(OobCall oobCall) { OobOperation oobOperation = new OobOperation(oobCall, hub.messageFrame(), add, mod, wcp, hub); - this.chunks.add(oobOperation); + this.oobOperations.add(oobOperation); } @Override public void tracePreOpcode(MessageFrame frame) { // TODO: maybe move in the hub /* oobOperation = new OobOperation(frame, add, mod, wcp, hub, false, 0, 0); - this.chunks.add(oobOperation); + this.oobOperations.add(oobOperation); OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); if (opCode.isCall()) { @@ -70,96 +72,97 @@ public void tracePreOpcode(MessageFrame frame) { // TODO: maybe move in the hub if (PRECOMPILES_HANDLED_BY_OOB.contains(target)) { if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 1, 0); - this.chunks.add(oobOperation); + this.oobOperations.add(oobOperation); boolean validCds = oobOperation.getOutgoingResLo()[0].equals(BigInteger.ONE); if (validCds) { oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 2, 0); - this.chunks.add(oobOperation); + this.oobOperations.add(oobOperation); } } else if (target.equals(Address.MODEXP)) { for (int i = 1; i <= 7; i++) { oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 0, i); - this.chunks.add(oobOperation); + this.oobOperations.add(oobOperation); } } else { // Other precompiles case oobOperation = new OobOperation(frame, add, mod, wcp, hub, true, 0, 0); - this.chunks.add(oobOperation); + this.oobOperations.add(oobOperation); } } } */ } - final void traceChunk(final OobOperation chunk, int stamp, Trace trace) { - int nRows = chunk.nRows(); + final void traceChunk(final OobOperation oobOperation, int stamp, Trace trace) { + int nRows = oobOperation.nRows(); + OobInstruction oobInstruction = oobOperation.oobCall.oobInstruction; for (int ct = 0; ct < nRows; ct++) { - trace = chunk.getOobCall().trace(trace); + trace = oobOperation.getOobCall().trace(trace); // Note: if a value is bigger than 128, do not use Bytes.of and use Bytes.ofUnsignedType // instead (according to size) trace .stamp(stamp) .ct((short) ct) - .ctMax((short) chunk.getMaxCt()) - .oobInst(bigIntegerToBytes(BigInteger.valueOf(chunk.getOobInst()))) - .isJump(chunk.isJump()) - .isJumpi(chunk.isJumpi()) - .isRdc(chunk.isRdc()) - .isCdl(chunk.isCdl()) - .isXcall(chunk.isXCall()) - .isCall(chunk.isCall()) - .isCreate(chunk.isCreate()) - .isSstore(chunk.isSstore()) - .isDeployment(chunk.isDeployment()) - .isEcrecover(chunk.isEcRecover()) - .isSha2(chunk.isSha2()) - .isRipemd(chunk.isRipemd()) - .isIdentity(chunk.isIdentity()) - .isEcadd(chunk.isEcadd()) - .isEcmul(chunk.isEcmul()) - .isEcpairing(chunk.isEcpairing()) - .isBlake2FCds(chunk.isBlake2FCds()) - .isBlake2FParams(chunk.isBlake2FParams()) - .isModexpCds(chunk.isModexpCds()) - .isModexpXbs(chunk.isModexpXbs()) - .isModexpLead(chunk.isModexpLead()) - .isModexpPricing(chunk.isPrcModexpPricing()) - .isModexpExtract(chunk.isPrcModexpExtract()) - .addFlag(chunk.getAddFlag()[ct]) - .modFlag(chunk.getModFlag()[ct]) - .wcpFlag(chunk.getWcpFlag()[ct]) - .outgoingInst(chunk.getOutgoingInst()[ct]) - .outgoingData1(bigIntegerToBytes(chunk.getOutgoingData1()[ct])) - .outgoingData2(bigIntegerToBytes(chunk.getOutgoingData2()[ct])) - .outgoingData3(bigIntegerToBytes(chunk.getOutgoingData3()[ct])) - .outgoingData4(bigIntegerToBytes(chunk.getOutgoingData4()[ct])) - .outgoingResLo(bigIntegerToBytes(chunk.getOutgoingResLo()[ct])) + .ctMax((short) oobOperation.ctMax()) + .oobInst(bigIntegerToBytes(BigInteger.valueOf(oobInstruction.getValue()))) + .isJump(oobInstruction == OOB_INST_JUMP) + .isJumpi(oobInstruction == OOB_INST_JUMPI) + .isRdc(oobInstruction == OOB_INST_RDC) + .isCdl(oobInstruction == OOB_INST_CDL) + .isXcall(oobInstruction == OOB_INST_XCALL) + .isCall(oobInstruction == OOB_INST_CALL) + .isCreate(oobInstruction == OOB_INST_CREATE) + .isSstore(oobInstruction == OOB_INST_SSTORE) + .isDeployment(oobInstruction == OOB_INST_DEPLOYMENT) + .isEcrecover(oobInstruction == OOB_INST_ECRECOVER) + .isSha2(oobInstruction == OOB_INST_SHA2) + .isRipemd(oobInstruction == OOB_INST_RIPEMD) + .isIdentity(oobInstruction == OOB_INST_IDENTITY) + .isEcadd(oobInstruction == OOB_INST_ECADD) + .isEcmul(oobInstruction == OOB_INST_ECMUL) + .isEcpairing(oobInstruction == OOB_INST_ECPAIRING) + .isBlake2FCds(oobInstruction == OOB_INST_BLAKE_CDS) + .isBlake2FParams(oobInstruction == OOB_INST_BLAKE_CDS) + .isModexpCds(oobInstruction == OOB_INST_MODEXP_CDS) + .isModexpXbs(oobInstruction == OOB_INST_MODEXP_XBS) + .isModexpLead(oobInstruction == OOB_INST_MODEXP_LEAD) + .isModexpPricing(oobInstruction == OOB_INST_MODEXP_PRICING) + .isModexpExtract(oobInstruction == OOB_INST_MODEXP_EXTRACT) + .addFlag(oobOperation.getAddFlag()[ct]) + .modFlag(oobOperation.getModFlag()[ct]) + .wcpFlag(oobOperation.getWcpFlag()[ct]) + .outgoingInst(oobOperation.getOutgoingInst()[ct]) + .outgoingData1(bigIntegerToBytes(oobOperation.getOutgoingData1()[ct])) + .outgoingData2(bigIntegerToBytes(oobOperation.getOutgoingData2()[ct])) + .outgoingData3(bigIntegerToBytes(oobOperation.getOutgoingData3()[ct])) + .outgoingData4(bigIntegerToBytes(oobOperation.getOutgoingData4()[ct])) + .outgoingResLo(bigIntegerToBytes(oobOperation.getOutgoingResLo()[ct])) .validateRow(); } } @Override public void enterTransaction() { - this.chunks.enter(); + this.oobOperations.enter(); } @Override public void popTransaction() { - this.chunks.pop(); + this.oobOperations.pop(); } @Override public int lineCount() { - return this.chunks.stream().mapToInt(OobOperation::nRows).sum(); + return this.oobOperations.stream().mapToInt(OobOperation::nRows).sum(); } @Override public void commit(List buffers) { Trace trace = new Trace(buffers); - for (int i = 0; i < this.chunks.size(); i++) { - this.traceChunk(this.chunks.get(i), i + 1, trace); + for (int i = 0; i < this.oobOperations.size(); i++) { + this.traceChunk(this.oobOperations.get(i), i + 1, trace); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 9990a344f0..18a8897898 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -19,6 +19,7 @@ import static java.lang.Byte.toUnsignedInt; import static java.lang.Math.max; import static java.lang.Math.min; +import static java.util.Map.entry; import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_ADD; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_DIV; @@ -28,29 +29,7 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_LT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_MOD; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.GAS_CONST_G_CALL_STIPEND; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_CDS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_BLAKE_PARAMS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CALL; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CDL; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_CREATE; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_DEPLOYMENT; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECADD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECMUL; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECPAIRING; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_ECRECOVER; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_IDENTITY; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMP; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_JUMPI; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_CDS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_EXTRACT; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_LEAD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_PRICING; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_MODEXP_XBS; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RDC; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_RIPEMD; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SHA2; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_SSTORE; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.OOB_INST_XCALL; +import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.module.oob.Trace.CT_MAX_BLAKE2F_CDS; import static net.consensys.linea.zktracer.module.oob.Trace.CT_MAX_BLAKE2F_PARAMS; import static net.consensys.linea.zktracer.module.oob.Trace.CT_MAX_CALL; @@ -78,11 +57,11 @@ import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBoolean; import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; -import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; import static net.consensys.linea.zktracer.types.Utils.rightPadTo; import java.math.BigInteger; import java.math.RoundingMode; +import java.util.Map; import com.google.common.base.Preconditions; import lombok.EqualsAndHashCode; @@ -93,6 +72,7 @@ import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CallDataLoadOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CallOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CreateOobCall; @@ -124,38 +104,7 @@ @Getter @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) public class OobOperation extends ModuleOperation { - @EqualsAndHashCode.Include private int oobInst; - @EqualsAndHashCode.Include @Setter private OobCall oobCall; - - private int maxCt; - private boolean isJump; - private boolean isJumpi; - private boolean isRdc; - private boolean isCdl; - private boolean isXCall; - private boolean isCall; - private boolean isCreate; - private boolean isSstore; - private boolean isDeployment; - - private boolean isEcRecover; - private boolean isSha2; - private boolean isRipemd; - private boolean isIdentity; - private boolean isEcadd; - private boolean isEcmul; - private boolean isEcpairing; - private boolean isBlake2FCds; - private boolean isBlake2FParams; - private boolean isModexpCds; - private boolean isModexpXbs; - private boolean isModexpLead; - private boolean prcModexpPricing; - private boolean prcModexpExtract; - - private boolean isModexpBbs; - private boolean isModexpEbs; - private boolean isModexpMbs; + @EqualsAndHashCode.Include @Setter public OobCall oobCall; private final boolean[] addFlag; private final boolean[] modFlag; @@ -170,8 +119,6 @@ public class OobOperation extends ModuleOperation { private final BigInteger[] outgoingResLo; - private int wghtSum; - private BigInteger precompileCost; // Modules for lookups @@ -180,6 +127,40 @@ public class OobOperation extends ModuleOperation { private final Wcp wcp; private final Hub hub; + private static final Map CT_MAX_MAP = + Map.ofEntries( + entry(OOB_INST_JUMP, CT_MAX_JUMP), + entry(OOB_INST_JUMPI, CT_MAX_JUMPI), + entry(OOB_INST_RDC, CT_MAX_RDC), + entry(OOB_INST_CDL, CT_MAX_CDL), + entry(OOB_INST_CALL, CT_MAX_CALL), + entry(OOB_INST_XCALL, CT_MAX_XCALL), + entry(OOB_INST_CREATE, CT_MAX_CREATE), + entry(OOB_INST_SSTORE, CT_MAX_SSTORE), + entry(OOB_INST_DEPLOYMENT, CT_MAX_DEPLOYMENT), + entry(OOB_INST_ECRECOVER, CT_MAX_ECRECOVER), + entry(OOB_INST_SHA2, CT_MAX_SHA2), + entry(OOB_INST_RIPEMD, CT_MAX_RIPEMD), + entry(OOB_INST_IDENTITY, CT_MAX_IDENTITY), + entry(OOB_INST_ECADD, CT_MAX_ECADD), + entry(OOB_INST_ECMUL, CT_MAX_ECMUL), + entry(OOB_INST_ECPAIRING, CT_MAX_ECPAIRING), + entry(OOB_INST_BLAKE_CDS, CT_MAX_BLAKE2F_CDS), + entry(OOB_INST_BLAKE_PARAMS, CT_MAX_BLAKE2F_PARAMS), + entry(OOB_INST_MODEXP_CDS, CT_MAX_MODEXP_CDS), + entry(OOB_INST_MODEXP_XBS, CT_MAX_MODEXP_XBS), + entry(OOB_INST_MODEXP_LEAD, CT_MAX_MODEXP_LEAD), + entry(OOB_INST_MODEXP_PRICING, CT_MAX_MODEXP_PRICING), + entry(OOB_INST_MODEXP_EXTRACT, CT_MAX_MODEXP_EXTRACT)); + + public int ctMax() { + return CT_MAX_MAP.get(oobCall.oobInstruction); + } + + public int nRows() { + return ctMax() + 1; + } + public OobOperation( OobCall oobCall, final MessageFrame frame, @@ -194,8 +175,6 @@ public OobOperation( this.wcp = wcp; this.hub = hub; - setFlagsAndWghtSumAndIncomingInstAndMaxCt(); - // Init arrays int nRows = nRows(); addFlag = new boolean[nRows]; @@ -213,230 +192,85 @@ public OobOperation( populateColumns(frame); } - private void setFlagsAndWghtSumAndIncomingInstAndMaxCt() { - switch (oobCall.oobInstructionValue()) { - case OOB_INST_JUMP -> { - isJump = true; - wghtSum = OOB_INST_JUMP; - maxCt = CT_MAX_JUMP; - } - case OOB_INST_JUMPI -> { - isJumpi = true; - wghtSum = OOB_INST_JUMPI; - maxCt = CT_MAX_JUMPI; - } - case OOB_INST_RDC -> { - isRdc = true; - wghtSum = OOB_INST_RDC; - maxCt = CT_MAX_RDC; - } - case OOB_INST_CDL -> { - isCdl = true; - wghtSum = OOB_INST_CDL; - maxCt = CT_MAX_CDL; - } - case OOB_INST_CALL -> { - isCall = true; - wghtSum = OOB_INST_CALL; - maxCt = CT_MAX_CALL; - } - case OOB_INST_XCALL -> { - isXCall = true; - wghtSum = OOB_INST_XCALL; - maxCt = CT_MAX_XCALL; - } - case OOB_INST_CREATE -> { - isCreate = true; - wghtSum = OOB_INST_CREATE; - maxCt = CT_MAX_CREATE; - } - case OOB_INST_SSTORE -> { - isSstore = true; - wghtSum = OOB_INST_SSTORE; - maxCt = CT_MAX_SSTORE; - } - case OOB_INST_DEPLOYMENT -> { - isDeployment = true; - wghtSum = OOB_INST_DEPLOYMENT; - maxCt = CT_MAX_DEPLOYMENT; - } - case OOB_INST_ECRECOVER -> { - isEcRecover = true; - wghtSum = OOB_INST_ECRECOVER; - maxCt = CT_MAX_ECRECOVER; - } - case OOB_INST_SHA2 -> { - isSha2 = true; - wghtSum = OOB_INST_SHA2; - maxCt = CT_MAX_SHA2; - } - case OOB_INST_RIPEMD -> { - isRipemd = true; - wghtSum = OOB_INST_RIPEMD; - maxCt = CT_MAX_RIPEMD; - } - case OOB_INST_IDENTITY -> { - isIdentity = true; - wghtSum = OOB_INST_IDENTITY; - maxCt = CT_MAX_IDENTITY; - } - case OOB_INST_ECADD -> { - isEcadd = true; - wghtSum = OOB_INST_ECADD; - maxCt = CT_MAX_ECADD; - } - case OOB_INST_ECMUL -> { - isEcmul = true; - wghtSum = OOB_INST_ECMUL; - maxCt = CT_MAX_ECMUL; - } - case OOB_INST_ECPAIRING -> { - isEcpairing = true; - wghtSum = OOB_INST_ECPAIRING; - maxCt = CT_MAX_ECPAIRING; - } - case OOB_INST_BLAKE_CDS -> { - isBlake2FCds = true; - wghtSum = OOB_INST_BLAKE_CDS; - maxCt = CT_MAX_BLAKE2F_CDS; - } - case OOB_INST_BLAKE_PARAMS -> { - isBlake2FParams = true; - wghtSum = OOB_INST_BLAKE_PARAMS; - maxCt = CT_MAX_BLAKE2F_PARAMS; - } - case OOB_INST_MODEXP_CDS -> { - isModexpCds = true; - wghtSum = OOB_INST_MODEXP_CDS; - maxCt = CT_MAX_MODEXP_CDS; - } - case OOB_INST_MODEXP_XBS -> { - isModexpXbs = true; - - switch (((ModexpXbsOobCall) oobCall).getModexpXbsCase()) { - case OOB_INST_MODEXP_BBS -> isModexpBbs = true; - case OOB_INST_MODEXP_EBS -> isModexpEbs = true; - case OOB_INST_MODEXP_MBS -> isModexpMbs = true; - } - - wghtSum = OOB_INST_MODEXP_XBS; - maxCt = CT_MAX_MODEXP_XBS; - } - case OOB_INST_MODEXP_LEAD -> { - isModexpLead = true; - wghtSum = OOB_INST_MODEXP_LEAD; - maxCt = CT_MAX_MODEXP_LEAD; - } - case OOB_INST_MODEXP_PRICING -> { - prcModexpPricing = true; - wghtSum = OOB_INST_MODEXP_PRICING; - maxCt = CT_MAX_MODEXP_PRICING; - } - case OOB_INST_MODEXP_EXTRACT -> { - prcModexpExtract = true; - wghtSum = OOB_INST_MODEXP_EXTRACT; - maxCt = CT_MAX_MODEXP_EXTRACT; - } - } - oobInst = wghtSum; - } - - public boolean isInst() { - return isJump - || isJumpi - || isRdc - || isCdl - || isCall - || isXCall - || isCreate - || isSstore - || isDeployment; + public boolean isEvmInstruction() { + return oobCall.oobInstruction.isEvmInstruction(); } public boolean isCommonPrecompile() { - return isEcRecover || isSha2 || isRipemd || isIdentity || isEcadd || isEcmul || isEcpairing; + return oobCall.oobInstruction.isCommonPrecompile(); } public boolean isBlakePrecompile() { - return isBlake2FCds || isBlake2FParams; + return oobCall.oobInstruction.isBlake(); } public boolean isModexpPrecompile() { - return isModexpCds || isModexpXbs || isModexpLead || prcModexpPricing || prcModexpExtract; + return oobCall.oobInstruction.isModexp(); } public boolean isPrecompile() { - return isCommonPrecompile() || isBlakePrecompile() || isModexpPrecompile(); + return oobCall.oobInstruction.isPrecompile(); } - public int nRows() { - return maxCt + 1; + private void populateColumns(final MessageFrame frame) { + if (isEvmInstruction()) populateColumnsForEvmInstruction(frame); + if (isPrecompile()) populateColumnsForPrecompile(frame); } - private void populateColumns(final MessageFrame frame) { - final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); + private void populateColumnsForEvmInstruction(MessageFrame frame) { - if (isInst()) { - if (isJump) { + switch (oobCall.oobInstruction) { + case OOB_INST_JUMP -> { JumpOobCall jumpOobCall = (JumpOobCall) oobCall; jumpOobCall.setPcNew(EWord.of(frame.getStackItem(0))); jumpOobCall.setCodeSize(BigInteger.valueOf(frame.getCode().getSize())); setJump(jumpOobCall); - } else if (isJumpi) { + } + case OOB_INST_JUMPI -> { JumpiOobCall jumpiOobCall = (JumpiOobCall) oobCall; jumpiOobCall.setPcNew(EWord.of(frame.getStackItem(0))); jumpiOobCall.setJumpCondition(EWord.of(frame.getStackItem(1))); jumpiOobCall.setCodeSize(BigInteger.valueOf(frame.getCode().getSize())); setJumpi(jumpiOobCall); - } else if (isRdc) { + } + case OOB_INST_RDC -> { ReturnDataCopyOobCall rdcOobCall = (ReturnDataCopyOobCall) oobCall; rdcOobCall.setOffset(EWord.of(frame.getStackItem(1))); rdcOobCall.setSize(EWord.of(frame.getStackItem(2))); rdcOobCall.setRds(BigInteger.valueOf(frame.getReturnData().size())); setRdc(rdcOobCall); - } else if (isCdl) { + } + case OOB_INST_CDL -> { CallDataLoadOobCall cdlOobCall = (CallDataLoadOobCall) oobCall; cdlOobCall.setOffset(EWord.of(frame.getStackItem(0))); cdlOobCall.setCds(BigInteger.valueOf(frame.getInputData().size())); setCdl(cdlOobCall); - } else if (isSstore) { - final SstoreOobCall sstoreOobCall = (SstoreOobCall) oobCall; - sstoreOobCall.setGas(BigInteger.valueOf(frame.getRemainingGas())); - setSstore(sstoreOobCall); - } else if (isDeployment) { - final DeploymentOobCall deploymentOobCall = (DeploymentOobCall) oobCall; - deploymentOobCall.setSize(EWord.of(frame.getStackItem(0))); - setDeployment(deploymentOobCall); - } else if (isXCall) { - XCallOobCall xCallOobCall = (XCallOobCall) oobCall; - xCallOobCall.setValue(EWord.of(frame.getStackItem(2))); - setXCall(xCallOobCall); - } else if (isCall) { + } + case OOB_INST_CALL -> { final Account callerAccount = frame.getWorldUpdater().get(frame.getRecipientAddress()); - // DELEGATECALL, STATICCALL cases - EWord value = EWord.ZERO; - boolean nonZeroValue = false; - // CALL, CALLCODE cases - if (opCode == OpCode.CALL || opCode == OpCode.CALLCODE) { - value = EWord.of(frame.getStackItem(2)); - nonZeroValue = !frame.getStackItem(2).isZero(); - } + final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); + + // DELEGATECALL, STATICCALL can't trasfer value, + // CALL, CALLCODE may transfer value + EWord value = opCode.callCanTransferValue() ? EWord.of(frame.getStackItem(2)) : EWord.ZERO; CallOobCall callOobCall = (CallOobCall) oobCall; callOobCall.setValue(value); callOobCall.setBalance(callerAccount.getBalance().toUnsignedBigInteger()); callOobCall.setCallStackDepth(BigInteger.valueOf(frame.getDepth())); setCall(callOobCall); - } else if (isCreate) { + } + case OOB_INST_XCALL -> { + XCallOobCall xCallOobCall = (XCallOobCall) oobCall; + xCallOobCall.setValue(EWord.of(frame.getStackItem(2))); + setXCall(xCallOobCall); + } + case OOB_INST_CREATE -> { final Account creatorAccount = frame.getWorldUpdater().get(frame.getRecipientAddress()); final Address deploymentAddress = getDeploymentAddress(frame); final Account deployedAccount = frame.getWorldUpdater().get(deploymentAddress); - long nonce = 0; - boolean hasCode = false; - if (deployedAccount != null) { - nonce = deployedAccount.getNonce(); - hasCode = deployedAccount.hasCode(); - } + long nonce = (deployedAccount != null) ? deployedAccount.getNonce() : 0; + boolean hasCode = deployedAccount != null && deployedAccount.hasCode(); final CreateOobCall createOobCall = (CreateOobCall) oobCall; createOobCall.setValue(EWord.of(frame.getStackItem(0))); @@ -446,162 +280,192 @@ private void populateColumns(final MessageFrame frame) { createOobCall.setCallStackDepth(BigInteger.valueOf(frame.getDepth())); setCreate(createOobCall); } - } else if (isPrecompile()) { - final long argsOffset = - Words.clampedToLong( - opCode.callCanTransferValue() - ? hub.messageFrame().getStackItem(3) - : hub.messageFrame().getStackItem(2)); - final int cdsIndex = opCode.callCanTransferValue() ? 4 : 3; - final int returnAtCapacityIndex = opCode.callCanTransferValue() ? 6 : 5; - - final boolean transfersValue = - opCode.callCanTransferValue() && !frame.getStackItem(2).isZero(); - - // shameless copy from gasAvailableForChildCall found in TangerineWhistleGasCalculator - // TODO: @Olivier and @François: find out whether frame.getRemainingGas was already - // decremented by the upfront cost. If not we must replace remainingGas with the - // decremented version - long remainingGas = frame.getRemainingGas(); - long gasCap = - Words.unsignedMin( - allButOneSixtyFourth(remainingGas), Words.clampedToLong(frame.getStackItem(0))); - long callGasLong = - transfersValue ? gasCap + ZkTracer.gasCalculator.getAdditionalCallStipend() : gasCap; - final BigInteger callGas = BigInteger.valueOf(callGasLong); - - final BigInteger cds = EWord.of(frame.getStackItem(cdsIndex)).toUnsignedBigInteger(); - // Note that this check will disappear since it will be the MXP module taking care of it - /* TODO: reenable this check */ - // if (cds.compareTo(EWord.of(frame.getStackItem(cdsIndex)).loBigInt()) > 0) { - // throw new IllegalArgumentException("cds hi part is non-zero"); - // } - - final BigInteger returnAtCapacity = - EWord.of(frame.getStackItem(returnAtCapacityIndex)).toUnsignedBigInteger(); - - if (isCommonPrecompile()) { - PrecompileCommonOobCall prcCommonOobCall = (PrecompileCommonOobCall) oobCall; - - prcCommonOobCall.setCallGas(callGas); - prcCommonOobCall.setCds(cds); - prcCommonOobCall.setReturnAtCapacity(returnAtCapacity); - setPrcCommon(prcCommonOobCall); - if (isEcRecover || isEcadd || isEcmul) { - setPrcEcRecoverPrcEcaddPrcEcmul(prcCommonOobCall); - } else if (isSha2 || isRipemd || isIdentity) { - setPrcSha2PrcRipemdPrcIdentity(prcCommonOobCall); - } else if (isEcpairing) { - setEcpairing(prcCommonOobCall); - } - } else if (isModexpPrecompile()) { - final Bytes unpaddedCallData = frame.shadowReadMemory(argsOffset, cds.longValue()); - // pad unpaddedCallData to 96 - final Bytes paddedCallData = - cds.intValue() < 96 ? rightPadTo(unpaddedCallData, 96) : unpaddedCallData; - - // cds and the data below can be int when compared (after size check) - final BigInteger bbs = paddedCallData.slice(0, 32).toUnsignedBigInteger(); - final BigInteger ebs = paddedCallData.slice(32, 32).toUnsignedBigInteger(); - final BigInteger mbs = paddedCallData.slice(64, 32).toUnsignedBigInteger(); - - // Check if bbs, ebs and mbs are <= 512 - if (bbs.compareTo(BigInteger.valueOf(512)) > 0 - || ebs.compareTo(BigInteger.valueOf(512)) > 0 - || mbs.compareTo(BigInteger.valueOf(512)) > 0) { - throw new IllegalArgumentException("byte sizes are too big"); - } + case OOB_INST_SSTORE -> { + final SstoreOobCall sstoreOobCall = (SstoreOobCall) oobCall; + sstoreOobCall.setGas(BigInteger.valueOf(frame.getRemainingGas())); + setSstore(sstoreOobCall); + } + case OOB_INST_DEPLOYMENT -> { + final DeploymentOobCall deploymentOobCall = (DeploymentOobCall) oobCall; + deploymentOobCall.setSize(EWord.of(frame.getStackItem(0))); + setDeployment(deploymentOobCall); + } + } + } - // pad paddedCallData to 96 + bbs + ebs - final Bytes doublePaddedCallData = - cds.intValue() < 96 + bbs.intValue() + ebs.intValue() - ? rightPadTo(paddedCallData, 96 + bbs.intValue() + ebs.intValue()) - : paddedCallData; - - final BigInteger leadingBytesOfExponent = - doublePaddedCallData - .slice(96 + bbs.intValue(), min(ebs.intValue(), 32)) - .toUnsignedBigInteger(); - - BigInteger exponentLog; - if (ebs.intValue() <= 32 && leadingBytesOfExponent.signum() == 0) { - exponentLog = BigInteger.ZERO; - } else if (ebs.intValue() <= 32 && leadingBytesOfExponent.signum() != 0) { - exponentLog = BigInteger.valueOf(log2(leadingBytesOfExponent, RoundingMode.FLOOR)); - } else if (ebs.intValue() > 32 && leadingBytesOfExponent.signum() != 0) { - exponentLog = - BigInteger.valueOf(8) - .multiply(ebs.subtract(BigInteger.valueOf(32))) - .add(BigInteger.valueOf(log2(leadingBytesOfExponent, RoundingMode.FLOOR))); - } else { - exponentLog = BigInteger.valueOf(8).multiply(ebs.subtract(BigInteger.valueOf(32))); - } - if (isModexpCds) { + public void populateColumnsForPrecompile(MessageFrame frame) { + final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); + final long argsOffset = + Words.clampedToLong( + opCode.callCanTransferValue() + ? hub.messageFrame().getStackItem(3) + : hub.messageFrame().getStackItem(2)); + final int cdsIndex = opCode.callCanTransferValue() ? 4 : 3; + final int returnAtCapacityIndex = opCode.callCanTransferValue() ? 6 : 5; + + final boolean transfersValue = + opCode.callCanTransferValue() && !frame.getStackItem(2).isZero(); + + // shameless copy from gasAvailableForChildCall found in TangerineWhistleGasCalculator + // TODO: @Olivier and @François: find out whether frame.getRemainingGas was already + // decremented by the upfront cost. If not we must replace remainingGas with the + // decremented version + long remainingGas = frame.getRemainingGas(); + long gasCap = + Words.unsignedMin( + allButOneSixtyFourth(remainingGas), Words.clampedToLong(frame.getStackItem(0))); + long callGasLong = + transfersValue ? gasCap + ZkTracer.gasCalculator.getAdditionalCallStipend() : gasCap; + final BigInteger callGas = BigInteger.valueOf(callGasLong); + + final BigInteger cds = EWord.of(frame.getStackItem(cdsIndex)).toUnsignedBigInteger(); + // Note that this check will disappear since it will be the MXP module taking care of it + /* TODO: reenable this check */ + // if (cds.compareTo(EWord.of(frame.getStackItem(cdsIndex)).loBigInt()) > 0) { + // throw new IllegalArgumentException("cds hi part is non-zero"); + // } + + final BigInteger returnAtCapacity = + EWord.of(frame.getStackItem(returnAtCapacityIndex)).toUnsignedBigInteger(); + + if (isCommonPrecompile()) { + PrecompileCommonOobCall commonOobCall = (PrecompileCommonOobCall) oobCall; + + commonOobCall.setCallGas(callGas); + commonOobCall.setCds(cds); + commonOobCall.setReturnAtCapacity(returnAtCapacity); + setPrcCommon(commonOobCall); + + switch (oobCall.oobInstruction) { + case OOB_INST_ECRECOVER, OOB_INST_ECADD, OOB_INST_ECMUL -> setEcrecoverEcaddEcmul(commonOobCall); + case OOB_INST_SHA2, OOB_INST_RIPEMD, OOB_INST_IDENTITY -> setShaTwoRipemdIdentity(commonOobCall); + case OOB_INST_ECPAIRING -> setEcpairing(commonOobCall); + } + } + + if (isModexpPrecompile()) { + final Bytes unpaddedCallData = frame.shadowReadMemory(argsOffset, cds.longValue()); + // pad unpaddedCallData to 96 + final Bytes paddedCallData = + cds.intValue() < 96 ? rightPadTo(unpaddedCallData, 96) : unpaddedCallData; + + // cds and the data below can be int when compared (after size check) + final BigInteger bbs = paddedCallData.slice(0, 32).toUnsignedBigInteger(); + final BigInteger ebs = paddedCallData.slice(32, 32).toUnsignedBigInteger(); + final BigInteger mbs = paddedCallData.slice(64, 32).toUnsignedBigInteger(); + + // Check if bbs, ebs and mbs are <= 512 + if (bbs.compareTo(BigInteger.valueOf(512)) > 0 + || ebs.compareTo(BigInteger.valueOf(512)) > 0 + || mbs.compareTo(BigInteger.valueOf(512)) > 0) { + throw new IllegalArgumentException("byte sizes are too big"); + } + + // pad paddedCallData to 96 + bbs + ebs + final Bytes doublePaddedCallData = + cds.intValue() < 96 + bbs.intValue() + ebs.intValue() + ? rightPadTo(paddedCallData, 96 + bbs.intValue() + ebs.intValue()) + : paddedCallData; + + final BigInteger leadingBytesOfExponent = + doublePaddedCallData + .slice(96 + bbs.intValue(), min(ebs.intValue(), 32)) + .toUnsignedBigInteger(); + + BigInteger exponentLog; + if (ebs.intValue() <= 32 && leadingBytesOfExponent.signum() == 0) { + exponentLog = BigInteger.ZERO; + } else if (ebs.intValue() <= 32 && leadingBytesOfExponent.signum() != 0) { + exponentLog = BigInteger.valueOf(log2(leadingBytesOfExponent, RoundingMode.FLOOR)); + } else if (ebs.intValue() > 32 && leadingBytesOfExponent.signum() != 0) { + exponentLog = + BigInteger.valueOf(8) + .multiply(ebs.subtract(BigInteger.valueOf(32))) + .add(BigInteger.valueOf(log2(leadingBytesOfExponent, RoundingMode.FLOOR))); + } else { + exponentLog = BigInteger.valueOf(8).multiply(ebs.subtract(BigInteger.valueOf(32))); + } + + switch (oobCall.oobInstruction) { + case OOB_INST_MODEXP_CDS -> { final ModexpCallDataSizeOobCall prcModexpCdsCall = (ModexpCallDataSizeOobCall) oobCall; prcModexpCdsCall.setCds(cds); setModexpCds(prcModexpCdsCall); - } else if (isModexpXbs) { + } + case OOB_INST_MODEXP_XBS -> { final ModexpXbsOobCall prcModexpXbsOobCall; - if (isModexpBbs) { - prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; - prcModexpXbsOobCall.setXbsHi(EWord.of(bbs).hiBigInt()); - prcModexpXbsOobCall.setXbsLo(EWord.of(bbs).loBigInt()); - prcModexpXbsOobCall.setYbsLo(BigInteger.ZERO); - prcModexpXbsOobCall.setComputeMax(false); - } else if (isModexpEbs) { - prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; - prcModexpXbsOobCall.setXbsHi(EWord.of(ebs).hiBigInt()); - prcModexpXbsOobCall.setXbsLo(EWord.of(ebs).loBigInt()); - prcModexpXbsOobCall.setYbsLo(BigInteger.ZERO); - prcModexpXbsOobCall.setComputeMax(false); - } else if (isModexpMbs) { - prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; - prcModexpXbsOobCall.setXbsHi(EWord.of(mbs).hiBigInt()); - prcModexpXbsOobCall.setXbsLo(EWord.of(mbs).loBigInt()); - prcModexpXbsOobCall.setYbsLo(EWord.of(bbs).loBigInt()); - prcModexpXbsOobCall.setComputeMax(true); - } else { - throw new RuntimeException("modexpXbsCase is not set to a valid value"); + switch (((ModexpXbsOobCall) oobCall).getModexpXbsCase()) { + case OOB_INST_MODEXP_BBS -> { + prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; + prcModexpXbsOobCall.setXbsHi(EWord.of(bbs).hiBigInt()); + prcModexpXbsOobCall.setXbsLo(EWord.of(bbs).loBigInt()); + prcModexpXbsOobCall.setYbsLo(BigInteger.ZERO); + prcModexpXbsOobCall.setComputeMax(false); + } + case OOB_INST_MODEXP_EBS -> { + prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; + prcModexpXbsOobCall.setXbsHi(EWord.of(ebs).hiBigInt()); + prcModexpXbsOobCall.setXbsLo(EWord.of(ebs).loBigInt()); + prcModexpXbsOobCall.setYbsLo(BigInteger.ZERO); + prcModexpXbsOobCall.setComputeMax(false); + } + case OOB_INST_MODEXP_MBS -> { + prcModexpXbsOobCall = (ModexpXbsOobCall) oobCall; + prcModexpXbsOobCall.setXbsHi(EWord.of(mbs).hiBigInt()); + prcModexpXbsOobCall.setXbsLo(EWord.of(mbs).loBigInt()); + prcModexpXbsOobCall.setYbsLo(EWord.of(bbs).loBigInt()); + prcModexpXbsOobCall.setComputeMax(true); + } + default -> throw new RuntimeException("modexpXbsCase is not set to a valid value"); } setModexpXbs(prcModexpXbsOobCall); - } else if (isModexpLead) { + } + case OOB_INST_MODEXP_LEAD -> { final ModexpLeadOobCall prcModexpLeadOobCall = (ModexpLeadOobCall) oobCall; prcModexpLeadOobCall.setBbs(bbs); prcModexpLeadOobCall.setCds(cds); prcModexpLeadOobCall.setEbs(ebs); setModexpLead(prcModexpLeadOobCall); - } else if (prcModexpPricing) { + } + case OOB_INST_MODEXP_PRICING -> { int maxMbsBbs = max(mbs.intValue(), bbs.intValue()); final ModexpPricingOobCall prcModexpPricingOobCall = (ModexpPricingOobCall) oobCall; prcModexpPricingOobCall.setCallGas(callGas); prcModexpPricingOobCall.setReturnAtCapacity(returnAtCapacity); prcModexpPricingOobCall.setExponentLog(exponentLog); prcModexpPricingOobCall.setMaxMbsBbs(maxMbsBbs); - setPrcModexpPricing(prcModexpPricingOobCall); - } else if (prcModexpExtract) { + setModexpPricing(prcModexpPricingOobCall); + } + case OOB_INST_MODEXP_EXTRACT -> { final ModexpExtractOobCall prcModexpExtractOobCall = (ModexpExtractOobCall) oobCall; prcModexpExtractOobCall.setCds(cds); prcModexpExtractOobCall.setBbs(bbs); prcModexpExtractOobCall.setEbs(ebs); prcModexpExtractOobCall.setMbs(mbs); - setPrcModexpExtract(prcModexpExtractOobCall); + setModexpExtract(prcModexpExtractOobCall); } - } else if (isBlakePrecompile()) { - if (isBlake2FCds) { + default -> throw new IllegalArgumentException("not a valid precompile OOB instruction"); + } + } + + if (isBlakePrecompile()) { + switch (oobCall.oobInstruction) { + case OOB_INST_BLAKE_CDS -> { final Blake2fCallDataSizeOobCall prcBlake2FCdsCall = (Blake2fCallDataSizeOobCall) oobCall; prcBlake2FCdsCall.setCds(cds); prcBlake2FCdsCall.setReturnAtCapacity(returnAtCapacity); setBlake2FCds(prcBlake2FCdsCall); - } else if (isBlake2FParams) { + } + case OOB_INST_BLAKE_PARAMS -> { final BigInteger blakeR = - frame - .shadowReadMemory(argsOffset, cds.longValue()) - .slice(0, 4) - .toUnsignedBigInteger(); + frame + .shadowReadMemory(argsOffset, cds.longValue()) + .slice(0, 4) + .toUnsignedBigInteger(); final BigInteger blakeF = - BigInteger.valueOf( - toUnsignedInt(frame.shadowReadMemory(argsOffset, cds.longValue()).get(212))); + BigInteger.valueOf( + toUnsignedInt(frame.shadowReadMemory(argsOffset, cds.longValue()).get(212))); final Blake2fParamsOobCall prcBlake2FParamsOobCall = (Blake2fParamsOobCall) oobCall; prcBlake2FParamsOobCall.setCallGas(callGas); @@ -610,9 +474,9 @@ private void populateColumns(final MessageFrame frame) { setBlake2FParams(prcBlake2FParamsOobCall); } - } else { - throw new RuntimeException("no opcode or precompile flag was set to true"); } + } else { + throw new RuntimeException("no opcode or precompile flag was set to true"); } } @@ -914,10 +778,7 @@ private void setCall(CallOobCall callOobCall) { BigInteger.valueOf(1024)); // row i + 2 - boolean valueIsZero = callToISZERO(2, callOobCall.valueHi(), callOobCall.valueLo()); - - // Set valueIsNonzero - callOobCall.setValueIsNonzero(!valueIsZero); + callToISZERO(2, callOobCall.valueHi(), callOobCall.valueLo()); // Set abortingCondition callOobCall.setAbortingCondition(insufficientBalanceAbort || callStackDepthAbort); @@ -968,12 +829,16 @@ private void setPrcCommon(PrecompileCommonOobCall prcOobCall) { prcOobCall.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); } - private void setPrcEcRecoverPrcEcaddPrcEcmul(PrecompileCommonOobCall prcCommonOobCall) { + private void setEcrecoverEcaddEcmul(PrecompileCommonOobCall prcCommonOobCall) { + long precompileCostLong = + switch (oobCall.oobInstruction) { + case OOB_INST_ECRECOVER -> 3000; + case OOB_INST_ECADD -> 150; + case OOB_INST_ECMUL -> 6000; + default -> throw new IllegalArgumentException("Precompile isn't any of ECRECOVER, ECADD, ECMUL"); + }; precompileCost = - BigInteger.valueOf( - 3000L * booleanToInt(isEcRecover) - + 150L * booleanToInt(isEcadd) - + 6000L * booleanToInt(isEcmul)); + BigInteger.valueOf(precompileCostLong); // row i + 2 final boolean insufficientGas = @@ -990,9 +855,9 @@ private void setPrcEcRecoverPrcEcaddPrcEcmul(PrecompileCommonOobCall prcCommonOo prcCommonOobCall.setReturnGas(returnGas); } - private void setPrcSha2PrcRipemdPrcIdentity(PrecompileCommonOobCall prcCommonOobCall) { + private void setShaTwoRipemdIdentity(PrecompileCommonOobCall prcCommonOobCall) { // row i + 2 - final BigInteger ceil = + final BigInteger ceiling = callToDIV( 2, BigInteger.ZERO, @@ -1000,13 +865,18 @@ private void setPrcSha2PrcRipemdPrcIdentity(PrecompileCommonOobCall prcCommonOob BigInteger.ZERO, BigInteger.valueOf(32)); + long factor = + switch (oobCall.oobInstruction) { + case OOB_INST_SHA2 -> 12L; + case OOB_INST_RIPEMD -> 120L; + case OOB_INST_IDENTITY -> 3L; + default -> throw new IllegalArgumentException("precompile ought to be one of SHA2-256, RIPEMD-160 or IDENTITY"); + }; + precompileCost = - (BigInteger.valueOf(5).add(ceil)) + (BigInteger.valueOf(5).add(ceiling)) .multiply( - BigInteger.valueOf( - 12L * booleanToInt(isSha2) - + 120L * booleanToInt(isRipemd) - + 3L * booleanToInt(isIdentity))); + BigInteger.valueOf(factor)); // row i + 3 final boolean insufficientGas = @@ -1187,7 +1057,7 @@ private void setModexpLead(ModexpLeadOobCall prcModexpLeadOobCall) { ebsLessThan32 ? 0 : prcModexpLeadOobCall.getEbs().intValue() - 32); } - private void setPrcModexpPricing(ModexpPricingOobCall prcModexpPricingOobCall) { + private void setModexpPricing(ModexpPricingOobCall prcModexpPricingOobCall) { // row i final boolean returnAtCapacityIsZero = callToISZERO(0, BigInteger.ZERO, prcModexpPricingOobCall.getReturnAtCapacity()); @@ -1248,7 +1118,7 @@ private void setPrcModexpPricing(ModexpPricingOobCall prcModexpPricingOobCall) { prcModexpPricingOobCall.setReturnAtCapacityNonZero(!returnAtCapacityIsZero); } - private void setPrcModexpExtract(ModexpExtractOobCall prcModexpExtractOobCall) { + private void setModexpExtract(ModexpExtractOobCall prcModexpExtractOobCall) { // row i final boolean bbsIsZero = callToISZERO(0, BigInteger.ZERO, prcModexpExtractOobCall.getBbs()); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java index 3b39d8c1cc..be476c1c5f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java @@ -307,7 +307,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosZero() { // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -329,7 +329,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosRds() { // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -350,7 +350,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosSmallerThanRds() { // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -371,7 +371,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosSmallerThanRdsAndOffsetZero( // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -392,7 +392,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosSmallerThanRdsAndSizeZero() // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -417,7 +417,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetSmall // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -438,7 +438,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetSmall // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -459,7 +459,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetSmall // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -482,7 +482,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetSmall // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -504,7 +504,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetSmall // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -525,7 +525,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetSmall // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -546,7 +546,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetSmall // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -567,7 +567,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigLe // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -587,7 +587,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigLe // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -608,7 +608,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigLe // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -629,7 +629,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigLe // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -650,7 +650,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigRi // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -671,7 +671,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigRi // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -692,7 +692,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigRi // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } @@ -713,7 +713,7 @@ void TestReturnDataCopyUsingIdentityPrecompileMaxPosGreaterThanRdsAndOffsetBigRi // precompileCost = (5 + ceil) * 3 where ceil = 1 // cds is trivially 0 in initReturnDataCopyProgramUsingIdentityPrecompile assertEquals( - bytecodeRunner.getHub().oob().getChunks().get(1).getPrecompileCost(), + bytecodeRunner.getHub().oob().getOobOperations().get(1).getPrecompileCost(), BigInteger.valueOf(18)); } From 60213d5e119d0a6bea88169bb21e2af2d493521e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 6 Aug 2024 16:44:05 +0200 Subject: [PATCH 345/461] feat(blake): implemented BLAKE precompile --- .../module/hub/fragment/imc/mmu/MmuCall.java | 93 +++++++++-------- .../scenario/PrecompileScenarioFragment.java | 10 +- .../module/hub/section/call/CallSection.java | 3 +- .../precompileSubsection/BlakeSubsection.java | 95 ++++++++++++++++++ .../PrecompileSubsection.java | 20 +++- .../zktracer/module/oob/OobOperation.java | 99 +++++++++---------- 6 files changed, 220 insertions(+), 100 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 0667242243..ca48d12480 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -78,9 +78,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ExtCodeCopy; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ReturnFromDeployment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; -import net.consensys.linea.zktracer.module.hub.precompiles.Blake2fMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.EllipticCurvePrecompileSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; @@ -562,47 +560,56 @@ public static MmuCall partialCopyOfReturnDataForEcpairing( .referenceSize(32); } - public static MmuCall forBlake2f(final Hub hub, final PrecompileInvocation p, int i) { - Preconditions.checkArgument(i >= 0 && i < 4); - final int precompileContextNumber = p.hubStamp() + 1; - if (i == 0) { - return new MmuCall(hub, MMU_INST_BLAKE) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset())) - .successBit(!p.ramFailure()) - .limb1(EWord.of(((Blake2fMetadata) p.metadata()).r())) - .limb2(EWord.of(((Blake2fMetadata) p.metadata()).f())) - .setBlakeModexp() - .phase(PHASE_BLAKE_PARAMS); - } else if (i == 1) { - return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) - .sourceId(hub.currentFrame().contextNumber()) - .targetId(precompileContextNumber) - .sourceOffset(EWord.of(p.callDataSource().offset() + 4)) - .size(208) - .referenceSize(208) - .setBlakeModexp() - .phase(PHASE_BLAKE_DATA); - } else if (i == 2) { - return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) - .sourceId(precompileContextNumber) - .targetId(precompileContextNumber) - .size(64) - .setBlakeModexp() - .phase(PHASE_BLAKE_RESULT); - } else { - if (p.requestedReturnDataTarget().isEmpty()) { - return MmuCall.nop(); - } else { - return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) - .sourceId(precompileContextNumber) - .targetId(hub.currentFrame().contextNumber()) - .size(64) - .referenceOffset(p.requestedReturnDataTarget().offset()) - .referenceSize(p.requestedReturnDataTarget().length()); - } - } + public static MmuCall parameterExtractionForBlake( + final Hub hub, + PrecompileSubsection subsection, + boolean blakeSuccess, + Bytes blakeR, + Bytes blakeF) { + final int precompileContextNumber = subsection.exoModuleOperationId(); + return new MmuCall(hub, MMU_INST_BLAKE) + .sourceId(hub.currentFrame().contextNumber()) + .targetId(precompileContextNumber) + .sourceOffset(EWord.of(subsection.callDataMemorySpan.offset())) + .successBit(blakeSuccess) + .limb1(blakeR) + .limb2(blakeF) + .setBlakeModexp() + .phase(PHASE_BLAKE_PARAMS); + } + + public static MmuCall callDataExtractionforBlake(final Hub hub, PrecompileSubsection subsection) { + final int precompileContextNumber = subsection.exoModuleOperationId(); + return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) + .sourceId(hub.currentFrame().contextNumber()) + .targetId(precompileContextNumber) + .sourceOffset(EWord.of(subsection.callDataMemorySpan.offset() + 4)) + .size(208) + .referenceSize(208) + .setBlakeModexp() + .phase(PHASE_BLAKE_DATA); + } + + public static MmuCall fullReturnDataTransferForBlake( + final Hub hub, PrecompileSubsection subsection) { + final int precompileContextNumber = subsection.exoModuleOperationId(); + return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) + .sourceId(precompileContextNumber) + .targetId(precompileContextNumber) + .size(64) + .setBlakeModexp() + .phase(PHASE_BLAKE_RESULT); + } + + public static MmuCall partialCopyOfReturnDataforBlake( + final Hub hub, PrecompileSubsection subsection) { + final int precompileContextNumber = subsection.exoModuleOperationId(); + return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) + .sourceId(precompileContextNumber) + .targetId(hub.currentFrame().contextNumber()) + .size(64) + .referenceOffset(subsection.parentReturnDataTarget.offset()) + .referenceSize(subsection.parentReturnDataTarget.length()); } public static MmuCall forModexpExtractBbs( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 4c77d8f310..9e14f75f1e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -36,7 +36,15 @@ public enum PrecompileScenario { PRC_FAILURE_KNOWN_TO_HUB, PRC_FAILURE_KNOWN_TO_RAM, PRC_SUCCESS_WILL_REVERT, - PRC_SUCCESS_WONT_REVERT + PRC_SUCCESS_WONT_REVERT; + + public boolean isFailure() { + return this == PRC_FAILURE_KNOWN_TO_HUB || this == PRC_FAILURE_KNOWN_TO_RAM; + } + + public boolean isSuccess() { + return this == PRC_SUCCESS_WILL_REVERT || this == PRC_SUCCESS_WONT_REVERT; + } } public enum PrecompileFlag { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 46d53c8093..1dbc464d91 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -74,7 +74,8 @@ public class CallSection extends TraceSection MODEXP, ModexpSubsection::new, ALTBN128_ADD, EllipticCurvePrecompileSubsection::new, ALTBN128_MUL, EllipticCurvePrecompileSubsection::new, - ALTBN128_PAIRING, EllipticCurvePrecompileSubsection::new); + ALTBN128_PAIRING, EllipticCurvePrecompileSubsection::new, + BLAKE2B_F_COMPRESSION, BlakeSubsection::new); public Optional
precompileAddress; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java index 11b207bd60..a280d303f8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java @@ -15,11 +15,106 @@ package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection; +import static com.google.common.base.Preconditions.checkArgument; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; +import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM; + import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.Blake2fCallDataSizeOobCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.Blake2fParamsOobCall; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.apache.tuweni.bytes.Bytes; public class BlakeSubsection extends PrecompileSubsection { + final Blake2fCallDataSizeOobCall blakeCdsOobCall; + ImcFragment secondImcFragment; + Blake2fParamsOobCall blake2fParamsOobCall; + final boolean blakeSuccess; + public BlakeSubsection(Hub hub, CallSection callSection) { super(hub, callSection); + + blakeCdsOobCall = new Blake2fCallDataSizeOobCall(); + firstImcFragment.callOob(blakeCdsOobCall); + + hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); + + if (!blakeCdsOobCall.isHubSuccess()) { + this.setScenario(PRC_FAILURE_KNOWN_TO_HUB); + blakeSuccess = false; + return; + } + + Bytes blakeR = callData.slice(0, 4); + Bytes blakeF = callData.slice(212, 1); + + { + boolean wellFormedF = blakeF.get(0) == 0 || blakeF.get(0) == 1; + long rounds = blakeR.toLong(); + boolean sufficientGas = calleeGas >= rounds; + blakeSuccess = wellFormedF && sufficientGas; + } + + if (!blakeSuccess) { + this.setScenario(PRC_FAILURE_KNOWN_TO_RAM); + } + + MmuCall blakeParameterExtractionMmuCall = + MmuCall.parameterExtractionForBlake(hub, this, blakeSuccess, blakeR, blakeF); + firstImcFragment.callMmu(blakeParameterExtractionMmuCall); + + secondImcFragment = ImcFragment.empty(hub); + fragments.add(secondImcFragment); + + blake2fParamsOobCall = new Blake2fParamsOobCall(); + secondImcFragment.callOob(blake2fParamsOobCall); + + checkArgument(blake2fParamsOobCall.isRamSuccess() == blakeSuccess); + } + + @Override + public void resolveAtContextReEntry(Hub hub, CallFrame frame) { + super.resolveAtContextReEntry(hub, frame); + + // sanity checks + checkArgument(blakeCdsOobCall.isHubSuccess() == (callDataMemorySpan.length() == 213)); + checkArgument(callSuccess == blakeSuccess); + this.sanityCheck(); + + if (!callSuccess) { + return; + } + + // finish 2nd MISC row + MmuCall callDataExtractionforBlake = MmuCall.callDataExtractionforBlake(hub, this); + secondImcFragment.callMmu(callDataExtractionforBlake); + + // 3rd MISC row + ImcFragment thirdImcFragment = ImcFragment.empty(hub); + fragments.add(thirdImcFragment); + + MmuCall returnDataFullTransferForBlake = MmuCall.fullReturnDataTransferForBlake(hub, this); + thirdImcFragment.callMmu(returnDataFullTransferForBlake); + + // 3rd MISC row + ImcFragment fourthImcFragment = ImcFragment.empty(hub); + fragments.add(fourthImcFragment); + + if (!this.parentReturnDataTarget.isEmpty()) { + MmuCall partialReturnDataCopyForBlake = MmuCall.partialCopyOfReturnDataforBlake(hub, this); + fourthImcFragment.callMmu(partialReturnDataCopyForBlake); + } + } + + @Override + protected short maxNumberOfLines() { + // 3 = SCEN + MISC + CON (squash caller return data): if size != 213 + // 4 = SCEN + MISC + MISC + CON (squash caller return data): if insufficient gas / f not a bit + // 6 = SCEN + MISC + (3 * MISC) + CON (provide caller with return data): if success + // we don't optimize as BLAKE calls are rare + return 6; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 9f9b9319f1..2459b5b416 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -54,7 +54,7 @@ public class PrecompileSubsection public final CallSection callSection; /** List of fragments of the precompile specific subsection */ - private final List fragments; + public final List fragments; /** The (potentially empty) call data of the precompile call */ public Bytes callData; @@ -102,7 +102,7 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { fragments.add(precompileScenarioFragment); firstImcFragment = ImcFragment.empty(hub); - fragments().add(firstImcFragment); + fragments.add(firstImcFragment); final OpCode opCode = hub.opCode(); final long offset = @@ -140,6 +140,14 @@ public void resolveUponImmediateContextEntry(Hub hub) { callerGas = hub.callStack().parent().frame().getRemainingGas(); calleeGas = hub.messageFrame().getRemainingGas(); parentReturnDataTarget = hub.currentFrame().returnDataTargetInCaller(); + + // TODO: @françois: I've added this here as I believe that we will want + // to resolve at context exit in all cases and my impression is that + // we weren't doing so currently. + // This actually raises the question if we should pre-emptively schedule + // everything for ContextExit as soon as it has been scheduled for + // ContextEntry ... + hub.defers().scheduleForContextExit(this, hub.currentFrame().id()); } public void resolveUponExitingContext(Hub hub, CallFrame callFrame) { @@ -156,6 +164,14 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { } } + public void sanityCheck() { + if (callSuccess) { + Preconditions.checkArgument(precompileScenarioFragment.scenario.isSuccess()); + } else { + Preconditions.checkArgument(precompileScenarioFragment.scenario.isFailure()); + } + } + @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 18a8897898..5b0734d9fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -296,15 +296,14 @@ private void populateColumnsForEvmInstruction(MessageFrame frame) { public void populateColumnsForPrecompile(MessageFrame frame) { final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); final long argsOffset = - Words.clampedToLong( - opCode.callCanTransferValue() - ? hub.messageFrame().getStackItem(3) - : hub.messageFrame().getStackItem(2)); + Words.clampedToLong( + opCode.callCanTransferValue() + ? hub.messageFrame().getStackItem(3) + : hub.messageFrame().getStackItem(2)); final int cdsIndex = opCode.callCanTransferValue() ? 4 : 3; final int returnAtCapacityIndex = opCode.callCanTransferValue() ? 6 : 5; - final boolean transfersValue = - opCode.callCanTransferValue() && !frame.getStackItem(2).isZero(); + final boolean transfersValue = opCode.callCanTransferValue() && !frame.getStackItem(2).isZero(); // shameless copy from gasAvailableForChildCall found in TangerineWhistleGasCalculator // TODO: @Olivier and @François: find out whether frame.getRemainingGas was already @@ -312,10 +311,10 @@ public void populateColumnsForPrecompile(MessageFrame frame) { // decremented version long remainingGas = frame.getRemainingGas(); long gasCap = - Words.unsignedMin( - allButOneSixtyFourth(remainingGas), Words.clampedToLong(frame.getStackItem(0))); + Words.unsignedMin( + allButOneSixtyFourth(remainingGas), Words.clampedToLong(frame.getStackItem(0))); long callGasLong = - transfersValue ? gasCap + ZkTracer.gasCalculator.getAdditionalCallStipend() : gasCap; + transfersValue ? gasCap + ZkTracer.gasCalculator.getAdditionalCallStipend() : gasCap; final BigInteger callGas = BigInteger.valueOf(callGasLong); final BigInteger cds = EWord.of(frame.getStackItem(cdsIndex)).toUnsignedBigInteger(); @@ -326,7 +325,7 @@ public void populateColumnsForPrecompile(MessageFrame frame) { // } final BigInteger returnAtCapacity = - EWord.of(frame.getStackItem(returnAtCapacityIndex)).toUnsignedBigInteger(); + EWord.of(frame.getStackItem(returnAtCapacityIndex)).toUnsignedBigInteger(); if (isCommonPrecompile()) { PrecompileCommonOobCall commonOobCall = (PrecompileCommonOobCall) oobCall; @@ -337,8 +336,10 @@ public void populateColumnsForPrecompile(MessageFrame frame) { setPrcCommon(commonOobCall); switch (oobCall.oobInstruction) { - case OOB_INST_ECRECOVER, OOB_INST_ECADD, OOB_INST_ECMUL -> setEcrecoverEcaddEcmul(commonOobCall); - case OOB_INST_SHA2, OOB_INST_RIPEMD, OOB_INST_IDENTITY -> setShaTwoRipemdIdentity(commonOobCall); + case OOB_INST_ECRECOVER, OOB_INST_ECADD, OOB_INST_ECMUL -> setEcrecoverEcaddEcmul( + commonOobCall); + case OOB_INST_SHA2, OOB_INST_RIPEMD, OOB_INST_IDENTITY -> setShaTwoRipemdIdentity( + commonOobCall); case OOB_INST_ECPAIRING -> setEcpairing(commonOobCall); } } @@ -347,7 +348,7 @@ public void populateColumnsForPrecompile(MessageFrame frame) { final Bytes unpaddedCallData = frame.shadowReadMemory(argsOffset, cds.longValue()); // pad unpaddedCallData to 96 final Bytes paddedCallData = - cds.intValue() < 96 ? rightPadTo(unpaddedCallData, 96) : unpaddedCallData; + cds.intValue() < 96 ? rightPadTo(unpaddedCallData, 96) : unpaddedCallData; // cds and the data below can be int when compared (after size check) final BigInteger bbs = paddedCallData.slice(0, 32).toUnsignedBigInteger(); @@ -356,21 +357,21 @@ public void populateColumnsForPrecompile(MessageFrame frame) { // Check if bbs, ebs and mbs are <= 512 if (bbs.compareTo(BigInteger.valueOf(512)) > 0 - || ebs.compareTo(BigInteger.valueOf(512)) > 0 - || mbs.compareTo(BigInteger.valueOf(512)) > 0) { + || ebs.compareTo(BigInteger.valueOf(512)) > 0 + || mbs.compareTo(BigInteger.valueOf(512)) > 0) { throw new IllegalArgumentException("byte sizes are too big"); } // pad paddedCallData to 96 + bbs + ebs final Bytes doublePaddedCallData = - cds.intValue() < 96 + bbs.intValue() + ebs.intValue() - ? rightPadTo(paddedCallData, 96 + bbs.intValue() + ebs.intValue()) - : paddedCallData; + cds.intValue() < 96 + bbs.intValue() + ebs.intValue() + ? rightPadTo(paddedCallData, 96 + bbs.intValue() + ebs.intValue()) + : paddedCallData; final BigInteger leadingBytesOfExponent = - doublePaddedCallData - .slice(96 + bbs.intValue(), min(ebs.intValue(), 32)) - .toUnsignedBigInteger(); + doublePaddedCallData + .slice(96 + bbs.intValue(), min(ebs.intValue(), 32)) + .toUnsignedBigInteger(); BigInteger exponentLog; if (ebs.intValue() <= 32 && leadingBytesOfExponent.signum() == 0) { @@ -379,9 +380,9 @@ public void populateColumnsForPrecompile(MessageFrame frame) { exponentLog = BigInteger.valueOf(log2(leadingBytesOfExponent, RoundingMode.FLOOR)); } else if (ebs.intValue() > 32 && leadingBytesOfExponent.signum() != 0) { exponentLog = - BigInteger.valueOf(8) - .multiply(ebs.subtract(BigInteger.valueOf(32))) - .add(BigInteger.valueOf(log2(leadingBytesOfExponent, RoundingMode.FLOOR))); + BigInteger.valueOf(8) + .multiply(ebs.subtract(BigInteger.valueOf(32))) + .add(BigInteger.valueOf(log2(leadingBytesOfExponent, RoundingMode.FLOOR))); } else { exponentLog = BigInteger.valueOf(8).multiply(ebs.subtract(BigInteger.valueOf(32))); } @@ -457,15 +458,10 @@ public void populateColumnsForPrecompile(MessageFrame frame) { setBlake2FCds(prcBlake2FCdsCall); } case OOB_INST_BLAKE_PARAMS -> { - final BigInteger blakeR = - frame - .shadowReadMemory(argsOffset, cds.longValue()) - .slice(0, 4) - .toUnsignedBigInteger(); + Bytes callData = frame.shadowReadMemory(argsOffset, 213); + final BigInteger blakeR = callData.slice(0, 4).toUnsignedBigInteger(); - final BigInteger blakeF = - BigInteger.valueOf( - toUnsignedInt(frame.shadowReadMemory(argsOffset, cds.longValue()).get(212))); + final BigInteger blakeF = BigInteger.valueOf(toUnsignedInt(callData.get(212))); final Blake2fParamsOobCall prcBlake2FParamsOobCall = (Blake2fParamsOobCall) oobCall; prcBlake2FParamsOobCall.setCallGas(callGas); @@ -474,9 +470,8 @@ public void populateColumnsForPrecompile(MessageFrame frame) { setBlake2FParams(prcBlake2FParamsOobCall); } + default -> throw new RuntimeException("no opcode or precompile flag was set to true"); } - } else { - throw new RuntimeException("no opcode or precompile flag was set to true"); } } @@ -831,14 +826,14 @@ private void setPrcCommon(PrecompileCommonOobCall prcOobCall) { private void setEcrecoverEcaddEcmul(PrecompileCommonOobCall prcCommonOobCall) { long precompileCostLong = - switch (oobCall.oobInstruction) { - case OOB_INST_ECRECOVER -> 3000; - case OOB_INST_ECADD -> 150; - case OOB_INST_ECMUL -> 6000; - default -> throw new IllegalArgumentException("Precompile isn't any of ECRECOVER, ECADD, ECMUL"); - }; - precompileCost = - BigInteger.valueOf(precompileCostLong); + switch (oobCall.oobInstruction) { + case OOB_INST_ECRECOVER -> 3000; + case OOB_INST_ECADD -> 150; + case OOB_INST_ECMUL -> 6000; + default -> throw new IllegalArgumentException( + "Precompile isn't any of ECRECOVER, ECADD, ECMUL"); + }; + precompileCost = BigInteger.valueOf(precompileCostLong); // row i + 2 final boolean insufficientGas = @@ -866,17 +861,15 @@ private void setShaTwoRipemdIdentity(PrecompileCommonOobCall prcCommonOobCall) { BigInteger.valueOf(32)); long factor = - switch (oobCall.oobInstruction) { - case OOB_INST_SHA2 -> 12L; - case OOB_INST_RIPEMD -> 120L; - case OOB_INST_IDENTITY -> 3L; - default -> throw new IllegalArgumentException("precompile ought to be one of SHA2-256, RIPEMD-160 or IDENTITY"); - }; - - precompileCost = - (BigInteger.valueOf(5).add(ceiling)) - .multiply( - BigInteger.valueOf(factor)); + switch (oobCall.oobInstruction) { + case OOB_INST_SHA2 -> 12L; + case OOB_INST_RIPEMD -> 120L; + case OOB_INST_IDENTITY -> 3L; + default -> throw new IllegalArgumentException( + "precompile ought to be one of SHA2-256, RIPEMD-160 or IDENTITY"); + }; + + precompileCost = (BigInteger.valueOf(5).add(ceiling)).multiply(BigInteger.valueOf(factor)); // row i + 3 final boolean insufficientGas = From 57bdf4a91f7d9c0a6b63ddfaf46516f24c29aac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 9 Aug 2024 15:57:11 +0200 Subject: [PATCH 346/461] fix(postRollbackDefers): fixed nullpointer exception when resolving post rollback defers --- .../zktracer/module/hub/defer/DeferRegistry.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java index d16960f374..95de7eba4c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/defer/DeferRegistry.java @@ -187,11 +187,13 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { public void resolvePostRollback( final Hub hub, final MessageFrame messageFrame, CallFrame currentCallFrame) { - // roll back current context - for (PostRollbackDefer defer : hub.defers().rollbackDefers.get(currentCallFrame)) { - defer.resolvePostRollback(hub, messageFrame, currentCallFrame); - } - hub.defers().rollbackDefers.get(currentCallFrame).clear(); + Optional.ofNullable(hub.defers().rollbackDefers.get(currentCallFrame)) + .ifPresent( + defers -> { + defers.forEach( + defer -> defer.resolvePostRollback(hub, messageFrame, currentCallFrame)); + defers.clear(); + }); // recursively roll back child call frames final CallStack callStack = hub.callStack(); From d09b61c9ac5cc114ae073e1196ca9529f7905f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 9 Aug 2024 15:58:01 +0200 Subject: [PATCH 347/461] TODO: failing JumpiTest because --- .../linea/zktracer/instructionprocessing/JumpiTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java index 176a70af82..391abb49f7 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java @@ -118,5 +118,8 @@ private static List provideJumpiScenarioForJumpiCondition(String jump addOffsetToHexString( jumpiConditionByteOffset, "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); + // TODO: @lorenzo + // this returns "1000000000000000000000000000000000000000000000000000000000000001e", a 65 character long hex string + // this in turn blows up the push instruction } -} +} \ No newline at end of file From fc44852b6a66050d22d554f0af41a14ee16e3a4f Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 9 Aug 2024 16:26:52 +0200 Subject: [PATCH 348/461] test(jumpi): fixed test cases --- .../instructionprocessing/JumpiTest.java | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java index 391abb49f7..e97b340db5 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/JumpiTest.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.stream.Stream; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; @@ -43,6 +44,7 @@ public class JumpiTest { @ParameterizedTest @MethodSource("provideJumpiScenario") void jumpiScenarioTest(String description, String jumpiCondition, String pcNew) { + Preconditions.checkArgument(pcNew.length() <= 64, "pcNew must be at most 32 bytes long"); final Bytes bytecode = BytecodeCompiler.newProgram() .push(jumpiCondition) @@ -96,30 +98,20 @@ private static List provideJumpiScenarioForJumpiCondition(String jump "jumpiOntoJumpDestByteOwnedBySomePush", jumpiCondition, addOffsetToHexString(jumpiConditionByteOffset, "8")), + Arguments.of("jumpiOutOfBoundsSmall", jumpiCondition, "ff"), Arguments.of( - "jumpiOutOfBoundsSmall", - jumpiCondition, - addOffsetToHexString(jumpiConditionByteOffset, "ff")), - Arguments.of( - "jumpiOutOfBoundsMaxUint128", - jumpiCondition, - addOffsetToHexString(jumpiConditionByteOffset, "ffffffffffffffffffffffffffffffff")), + "jumpiOutOfBoundsMaxUint128", jumpiCondition, "ffffffffffffffffffffffffffffffff"), Arguments.of( - "jumpiOutOfBoundsTwoToThe128", - jumpiCondition, - addOffsetToHexString(jumpiConditionByteOffset, "0100000000000000000000000000000000")), + "jumpiOutOfBoundsTwoToThe128", jumpiCondition, "0100000000000000000000000000000000"), Arguments.of( "jumpiOutOfBoundsTwoToThe128Plus4", jumpiCondition, - addOffsetToHexString(jumpiConditionByteOffset, "0100000000000000000000000000000004")), + "0100000000000000000000000000000004"), Arguments.of( "jumpiOutOfBoundsMaxUint256", jumpiCondition, - addOffsetToHexString( - jumpiConditionByteOffset, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))); - // TODO: @lorenzo - // this returns "1000000000000000000000000000000000000000000000000000000000000001e", a 65 character long hex string - // this in turn blows up the push instruction + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + // In the out of bound cases we do not add jumpiConditionByteOffset since it is out of + // bound anyway and we want to test those specific values of pcNew } -} \ No newline at end of file +} From 051abb99b0b03f11688dc468e03c7b6628dae5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 9 Aug 2024 16:36:05 +0200 Subject: [PATCH 349/461] fix(CallSection): fixed null pointer exception + spotless --- .../module/hub/section/call/CallSection.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 1dbc464d91..ee42bdba45 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -198,8 +198,19 @@ public CallSection(Hub hub) { .scheduleForContextReEntry( precompileSubsection, hub.currentFrame()); // success bit & return data } else { - scenarioFragment.setScenario( - world.get(calleeAddress).hasCode() ? CALL_SMC_UNDEFINED : CALL_EOA_SUCCESS_WONT_REVERT); + Optional.ofNullable(world.get(calleeAddress)) + .ifPresentOrElse( + account -> { + scenarioFragment.setScenario( + account.hasCode() ? CALL_SMC_UNDEFINED : CALL_EOA_SUCCESS_WONT_REVERT); + }, + () -> { + scenarioFragment.setScenario(CALL_EOA_SUCCESS_WONT_REVERT); + }); + + // TODO is world == worldUpdater & what happen if get doesn't work ? + + ; // TODO is world == worldUpdater & what happen if get // doesn't work ? From 38f3562adba3d9ffe53a326d91ac0d034be3a4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 9 Aug 2024 18:17:08 +0200 Subject: [PATCH 350/461] fix(call stack pattern): fixed wrong stack stamp offset --- .../linea/zktracer/runtime/stack/Stack.java | 12 ++++++------ .../CallTrivialCasesTest.java | 18 ++++++++++++++++++ zkevm-constraints | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) 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 f0d78c0eb6..e375a095a0 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 @@ -278,10 +278,9 @@ private void call(MessageFrame frame, StackContext pending) { Bytes val5 = getStack(frame, 4); Bytes val6 = getStack(frame, 5); - boolean sevenItems = - this.currentOpcodeData.stackSettings().flag1() - || this.currentOpcodeData.stackSettings().flag2(); - if (sevenItems) { + boolean callCanTransferValue = this.currentOpcodeData.mnemonic().callCanTransferValue(); + + if (callCanTransferValue) { Bytes val7 = getStack(frame, 6); pending.addLine( @@ -301,7 +300,7 @@ private void call(MessageFrame frame, StackContext pending) { new IndexedStackOperation( 3, StackOperation.pop(this.height - 2, val3, stackStampWithOffset(2))), new IndexedStackOperation( - 4, StackOperation.push(this.height - 6, stackStampWithOffset(6)))); + 4, StackOperation.push(this.height - 6, stackStampWithOffset(7)))); } else { pending.addLine( @@ -315,7 +314,8 @@ private void call(MessageFrame frame, StackContext pending) { 4, StackOperation.pop(this.height - 5, val6, stackStampWithOffset(6)))); pending.addArmingLine( - new IndexedStackOperation(1, StackOperation.pop(this.height, val1, this.stamp)), + new IndexedStackOperation( + 1, StackOperation.pop(this.height, val1, stackStampWithOffset(0))), new IndexedStackOperation( 2, StackOperation.pop(this.height - 1, val2, stackStampWithOffset(1))), new IndexedStackOperation( diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java index f6b1012765..4e4a2e56e4 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java @@ -37,4 +37,22 @@ void eoaCallScenarioTest() { .compile(); BytecodeRunner.of(bytecode).run(); } + + + @Test + void eoaCallScenarioTestZeroCalleeGas() { + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .push(0) + .push(0) + .push(0) + .push(0x0add7e55) + .push(0) + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); + BytecodeRunner.of(bytecode).run(); + } } diff --git a/zkevm-constraints b/zkevm-constraints index 7c44e4b9c5..05fcb41f1a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 7c44e4b9c5e8488d4e3694618b1f2159c01bdd6b +Subproject commit 05fcb41f1a3f4f5ab5420761c96e5bac9cc561da From 5c1aa7fa147798b0e2c6fcd42d3bcf5c9e87e3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 9 Aug 2024 20:36:00 +0200 Subject: [PATCH 351/461] fix(tracing): fixed bug with CallScenarioFragment tracing - also added simplistic ADD test --- .../linea/zktracer/module/hub/Hub.java | 2 ++ .../scenario/CallScenarioFragment.java | 8 ++--- .../BasicAdditionTest.java | 30 +++++++++++++++++++ .../CallTrivialCasesTest.java | 25 ++++++++-------- 4 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/BasicAdditionTest.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index e02d9a0870..43684115d7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -675,6 +675,7 @@ public void traceContextEnter(MessageFrame frame) { public void traceContextReEnter(MessageFrame frame) { this.currentFrame().initializeFrame(frame); // TODO: is it needed ? defers.resolveAtContextReEntry(this, this.currentFrame()); + // TODO: now we unlatch if != null ? if (this.currentFrame().sectionToUnlatch() != null) { this.unlatchStack(frame, this.currentFrame().sectionToUnlatch()); this.currentFrame().sectionToUnlatch(null); @@ -793,6 +794,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.ecData.getEcDataOperation().returnData(frame.getReturnData()); } + // TODO: we unlatch if section == null ???? if (this.currentFrame().sectionToUnlatch() == null) { this.unlatchStack(frame); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java index 127e0f6668..6f77655c67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/CallScenarioFragment.java @@ -88,13 +88,13 @@ public Trace trace(Trace trace) { this.scenario.equals(CallScenario.CALL_SMC_FAILURE_WILL_REVERT)) .pScenarioCallSmcFailureCallerWontRevert( this.scenario.equals(CallScenario.CALL_SMC_FAILURE_WONT_REVERT)) - .pScenarioCallSmcSuccessCallerWontRevert( - this.scenario.equals(CallScenario.CALL_SMC_SUCCESS_WILL_REVERT)) .pScenarioCallSmcSuccessCallerWillRevert( + this.scenario.equals(CallScenario.CALL_SMC_SUCCESS_WILL_REVERT)) + .pScenarioCallSmcSuccessCallerWontRevert( this.scenario.equals(CallScenario.CALL_SMC_SUCCESS_WONT_REVERT)) - .pScenarioCallEoaSuccessCallerWontRevert( - this.scenario.equals(CallScenario.CALL_EOA_SUCCESS_WILL_REVERT)) .pScenarioCallEoaSuccessCallerWillRevert( + this.scenario.equals(CallScenario.CALL_EOA_SUCCESS_WILL_REVERT)) + .pScenarioCallEoaSuccessCallerWontRevert( this.scenario.equals(CallScenario.CALL_EOA_SUCCESS_WONT_REVERT)); } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/BasicAdditionTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/BasicAdditionTest.java new file mode 100644 index 0000000000..1021811afe --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/BasicAdditionTest.java @@ -0,0 +1,30 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package net.consensys.linea.zktracer.instructionprocessing; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; + +public class BasicAdditionTest { + @Test + void basicAdditionTest() { + final Bytes bytecode = + BytecodeCompiler.newProgram().push(1).push(2).op(OpCode.ADD).op(OpCode.POP).compile(); + BytecodeRunner.of(bytecode).run(); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java index 4e4a2e56e4..2c78fa2524 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java @@ -31,28 +31,27 @@ void eoaCallScenarioTest() { .push(0) .push(0) .push(0x0add7e55) - .push(0xffff) + .push(0xff) .op(OpCode.CALL) .op(OpCode.POP) .compile(); BytecodeRunner.of(bytecode).run(); } - @Test void eoaCallScenarioTestZeroCalleeGas() { final Bytes bytecode = - BytecodeCompiler.newProgram() - .push(0) - .push(0) - .push(0) - .push(0) - .push(0) - .push(0x0add7e55) - .push(0) - .op(OpCode.CALL) - .op(OpCode.POP) - .compile(); + BytecodeCompiler.newProgram() + .push(0) + .push(0) + .push(0) + .push(0) + .push(0) + .push(0x0add7e55) + .push(0) + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); BytecodeRunner.of(bytecode).run(); } } From 43ae8508de557bcbe09248c788adf4ecd3bcfc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 9 Aug 2024 21:49:35 +0200 Subject: [PATCH 352/461] fix(call): success bit of CALL's fix ? Not sure if complete fix, but correct success bit for CALL's to EOA's --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 12 +++--------- .../linea/zktracer/runtime/callstack/CallFrame.java | 2 -- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 43684115d7..b8f7b830b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -675,11 +675,7 @@ public void traceContextEnter(MessageFrame frame) { public void traceContextReEnter(MessageFrame frame) { this.currentFrame().initializeFrame(frame); // TODO: is it needed ? defers.resolveAtContextReEntry(this, this.currentFrame()); - // TODO: now we unlatch if != null ? - if (this.currentFrame().sectionToUnlatch() != null) { - this.unlatchStack(frame, this.currentFrame().sectionToUnlatch()); - this.currentFrame().sectionToUnlatch(null); - } + this.unlatchStack(frame); } @Override @@ -794,10 +790,8 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.ecData.getEcDataOperation().returnData(frame.getReturnData()); } - // TODO: we unlatch if section == null ???? - if (this.currentFrame().sectionToUnlatch() == null) { - this.unlatchStack(frame); - } + // TODO: special care for CALL/CREATE instructions ? + this.unlatchStack(frame); switch (this.opCodeData().instructionFamily()) { case ADD -> {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 868106d627..6851152aa1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -62,8 +62,6 @@ public boolean isMessageCall() { return !isDeployment; } - @Getter @Setter private TraceSection sectionToUnlatch = null; - /** the ID of this {@link CallFrame} parent in the {@link CallStack}. */ @Getter private int parentFrameId; From 2e92e67c996edf2ba36ed63eb7976774d7c286e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 9 Aug 2024 22:26:39 +0200 Subject: [PATCH 353/461] feat(test): added simple test for STP triggered by CALL instruction --- .../CallTrivialCasesTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java index 2c78fa2524..834d965d3f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java @@ -38,6 +38,23 @@ void eoaCallScenarioTest() { BytecodeRunner.of(bytecode).run(); } + @Test + void eoaCallWithCallDataAndReturnDataCapacityTest() { + final Bytes bytecode = + BytecodeCompiler.newProgram() + .push(0x31) + .push(0x11) + .push(0x22) + .push(0x90) + .push(0) + .push(0x0add7e55) + .push(0xff) + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); + BytecodeRunner.of(bytecode).run(); + } + @Test void eoaCallScenarioTestZeroCalleeGas() { final Bytes bytecode = From 1cd599b8c26f1156bd66f85ffbc2a72bdfe19f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 10 Aug 2024 15:00:30 +0200 Subject: [PATCH 354/461] fix(misc/STP): sign shenanigans when setting the STP instruction --- .../linea/zktracer/module/hub/fragment/imc/StpCall.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java index 908eb59435..e524575968 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java @@ -137,7 +137,7 @@ private long upfrontGasCostForCalls(boolean isCALL, boolean nonzeroValueTransfer public Trace trace(Trace trace) { return trace .pMiscStpFlag(true) - .pMiscStpInstruction(opCode.byteValue()) + .pMiscStpInstruction(opCode.byteValue() & 0xff) .pMiscStpGasHi(gas.hi()) .pMiscStpGasLo(gas.lo()) .pMiscStpValueHi(value.hi()) From b7c51099982f7db6b8ed4c1e87b598053f6c58cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 10 Aug 2024 15:11:42 +0200 Subject: [PATCH 355/461] fix(stpCall): STP_GAS_MXP tracing fixed the constraint call-instruction---setting-STP-instruction-parameters --- .../linea/zktracer/module/hub/fragment/imc/StpCall.java | 1 + 1 file changed, 1 insertion(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java index e524575968..d11837671d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/StpCall.java @@ -145,6 +145,7 @@ public Trace trace(Trace trace) { .pMiscStpExists(exists) .pMiscStpWarmth(warm) .pMiscStpOogx(outOfGasException) + .pMiscStpGasMxp(Bytes.ofUnsignedLong(memoryExpansionGas)) .pMiscStpGasUpfrontGasCost(Bytes.ofUnsignedLong(upfrontGasCost)) .pMiscStpGasPaidOutOfPocket(Bytes.ofUnsignedLong(gasPaidOutOfPocket)) .pMiscStpGasStipend(stipend); From fd6dc17369ec192d4d732c782df9298bed0047e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 12 Aug 2024 04:12:30 +0200 Subject: [PATCH 356/461] ras --- .../zktracer/module/add/AddOperation.java | 2 +- .../zktracer/runtime/callstack/CallFrame.java | 1 - .../CallTrivialCasesTest.java | 22 +++++++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/AddOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/AddOperation.java index 4b0e3b6b3f..d1317828c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/AddOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/AddOperation.java @@ -124,7 +124,7 @@ void trace(int stamp, Trace trace) { .byte2(UnsignedByte.of(resLo.get(ct))) .ct(UnsignedByte.of(ct)) .ctMax(UnsignedByte.of(this.ctMax)) - .inst(UnsignedByte.of(opCode.byteValue())) + .inst(UnsignedByte.of(opCode.byteValue() & 0xff)) .overflow(overflowBit(ct, overflowHi, overflowLo)) .resHi(resHi) .resLo(resLo) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 6851152aa1..7c7c3043ca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -24,7 +24,6 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java index 834d965d3f..2fc4e5ca42 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/CallTrivialCasesTest.java @@ -41,17 +41,17 @@ void eoaCallScenarioTest() { @Test void eoaCallWithCallDataAndReturnDataCapacityTest() { final Bytes bytecode = - BytecodeCompiler.newProgram() - .push(0x31) - .push(0x11) - .push(0x22) - .push(0x90) - .push(0) - .push(0x0add7e55) - .push(0xff) - .op(OpCode.CALL) - .op(OpCode.POP) - .compile(); + BytecodeCompiler.newProgram() + .push(0x31) + .push(0x11) + .push(0x22) + .push(0x90) + .push(0) + .push(0x0add7e55) + .push(0xff) + .op(OpCode.CALL) + .op(OpCode.POP) + .compile(); BytecodeRunner.of(bytecode).run(); } From 928212627f0f394192c26fddb04b7dc7f70ab074 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 12 Aug 2024 13:55:55 +0530 Subject: [PATCH 357/461] ras: cleaning Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 8 ++--- .../module/hub/fragment/StackFragment.java | 26 -------------- .../linea/zktracer/runtime/stack/Stack.java | 3 +- .../zktracer/runtime/stack/StackContext.java | 9 ++--- .../zktracer/runtime/stack/StackLine.java | 2 +- .../zktracer/types/MemorySegmentSnapshot.java | 34 ------------------- 6 files changed, 7 insertions(+), 75 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index b8f7b830b8..7bc4db65cb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -49,7 +49,6 @@ import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.section.AccountSection; import net.consensys.linea.zktracer.module.hub.section.CallDataLoadSection; import net.consensys.linea.zktracer.module.hub.section.ContextSection; @@ -929,10 +928,6 @@ TraceSection currentTraceSection() { return this.state.currentTxTrace().currentSection(); } - public void addFragmentsAndStack(TraceFragment... fragments) { - currentTraceSection().addStackAndFragments(this, fragments); - } - public void addTraceSection(TraceSection section) { this.state.currentTxTrace().add(section); } @@ -948,7 +943,7 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { final StackContext pending = this.currentFrame().pending(); for (int i = 0; i < pending.lines().size(); i++) { - StackLine line = pending.lines().get(i); + final StackLine line = pending.lines().get(i); if (line.needsResult()) { Bytes result = Bytes.EMPTY; @@ -958,6 +953,7 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { } // This works because we are certain that the stack chunks are the first. + final boolean breakHere = !(section.fragments().get(i) instanceof StackFragment); ((StackFragment) section.fragments().get(i)) .stackOps() .get(line.resultColumn() - 1) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java index 96efa59c3d..10678fecb1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java @@ -39,10 +39,7 @@ import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.evm.account.AccountState; -import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; @Accessors(fluent = true) @@ -151,29 +148,6 @@ public static StackFragment prepare( willRevert); } - public void feedHashedValue(MessageFrame frame) { - if (hashInfoFlag) { - switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { - case SHA3 -> this.hashInfoKeccak = EWord.of(frame.getStackItem(0)); - case CREATE2 -> { - Address newAddress = EWord.of(frame.getStackItem(0)).toAddress(); - // zero address indicates a failed deployment - if (!newAddress.isZero()) { - this.hashInfoKeccak = - EWord.of( - Optional.ofNullable(frame.getWorldUpdater().get(newAddress)) - .map(AccountState::getCodeHash) - .orElse(Hash.EMPTY)); - } - } - case RETURN -> { - /* already set at opcode invocation */ - } - default -> throw new IllegalStateException("unexpected opcode"); - } - } - } - private boolean traceLog() { return this.opCode.isLog() && Exceptions.none( 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 e375a095a0..a74a35eba9 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 @@ -394,7 +394,8 @@ public void processInstruction(final Hub hub, MessageFrame frame, int stackStamp this.status = Status.OVERFLOW; } - hub.wcp().callLT(this.height, this.currentOpcodeData.stackSettings().delta()); + // CALL WCP for the SUX/SOX lookup + hub.wcp().callLT(this.height, delta); if (!this.isUnderflow()) { hub.wcp().callGT(this.height - delta + alpha, MAX_STACK_SIZE); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackContext.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackContext.java index 65705b47fd..0903cc5016 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackContext.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackContext.java @@ -20,13 +20,10 @@ import java.util.List; import lombok.Getter; -import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.MemorySegmentSnapshot; -import net.consensys.linea.zktracer.types.UnsignedByte; /** * A StackContext encode the stack-related information pertaining to the execution of an opcode @@ -35,13 +32,12 @@ */ @Accessors(fluent = true) public final class StackContext { - @Getter @Setter MemorySegmentSnapshot memorySegmentSnapshot; /** The opcode that triggered the stack operations. */ - OpCode opCode; + final OpCode opCode; /** One or two lines to be traced, representing the stack operations performed by the opcode. */ - @Getter final List lines = new ArrayList<>(4); + @Getter final List lines = new ArrayList<>(4); // TODO: why not 2 ??? /** * The default constructor for a valid, albeit empty line. @@ -50,7 +46,6 @@ public final class StackContext { */ public StackContext(OpCode opCode) { this.opCode = opCode; - this.memorySegmentSnapshot = new MemorySegmentSnapshot(UnsignedByte.EMPTY_BYTES16); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackLine.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackLine.java index da464e181e..cde4db762d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackLine.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/StackLine.java @@ -45,7 +45,7 @@ public StackLine(List items, int resultColumn) { /** The default constructor, an empty stack line. */ public StackLine() { - this(new ArrayList<>(4), -1); + this(new ArrayList<>(2), -1); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java deleted file mode 100644 index 5c2f28d597..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/MemorySegmentSnapshot.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.types; - -import lombok.Getter; -import lombok.experimental.Accessors; - -@Accessors(fluent = true) -public class MemorySegmentSnapshot { - @Getter private UnsignedByte[] memory; - private boolean clean; - - public MemorySegmentSnapshot(UnsignedByte[] memory) { - this(memory, true); - } - - private MemorySegmentSnapshot(UnsignedByte[] memory, boolean clean) { - this.memory = memory; - this.clean = clean; - } -} From d714f60c3ed343c3f997dafde192889d991dc6ff Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 13 Aug 2024 09:49:28 +0530 Subject: [PATCH 358/461] fix unlatching stack mechanism for CALLs and CREATEs Signed-off-by: Francois Bojarski --- .../consensys/linea/zktracer/ZkTracer.java | 3 --- .../linea/zktracer/module/hub/Hub.java | 24 +++++++------------ .../module/hub/section/CreateSection.java | 1 + .../module/hub/section/call/CallSection.java | 1 + .../zktracer/runtime/callstack/CallFrame.java | 12 ++++++---- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index 4c1fee3cf9..8cf5d82e2c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -217,9 +217,6 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo } } - // TODO: this isn't called anywhere ... - - // @Override public void tracePrepareTransaction(WorldView worldView, Transaction transaction) { try { hashOfLastTransactionTraced = transaction.getHash(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 7bc4db65cb..f68e62c502 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -124,7 +124,6 @@ import net.consensys.linea.zktracer.runtime.callstack.CallStack; import net.consensys.linea.zktracer.runtime.stack.StackContext; import net.consensys.linea.zktracer.runtime.stack.StackLine; -import net.consensys.linea.zktracer.types.AddressUtils; import net.consensys.linea.zktracer.types.Bytecode; import net.consensys.linea.zktracer.types.MemorySpan; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -672,9 +671,10 @@ public void traceContextEnter(MessageFrame frame) { } public void traceContextReEnter(MessageFrame frame) { + // Note: the update of the current call frame is made during traceContextExit of the child frame this.currentFrame().initializeFrame(frame); // TODO: is it needed ? defers.resolveAtContextReEntry(this, this.currentFrame()); - this.unlatchStack(frame); + this.unlatchStack(frame, this.currentFrame().childSpanningSection()); } @Override @@ -785,12 +785,14 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.defers.resolvePostExecution(this, frame, operationResult); + // TODO this should die if (this.previousOperationWasCallToEcPrecompile) { this.ecData.getEcDataOperation().returnData(frame.getReturnData()); } - // TODO: special care for CALL/CREATE instructions ? - this.unlatchStack(frame); + if (!this.currentFrame().opCode().isCall() && !this.currentFrame().opCode().isCreate()) { + this.unlatchStack(frame); + } switch (this.opCodeData().instructionFamily()) { case ADD -> {} @@ -1041,10 +1043,8 @@ void traceOpcode(MessageFrame frame) { switch (this.opCode()) { case OpCode.EXP -> new ExpSection(this); case OpCode.MUL -> new StackOnlySection(this); - default -> { - throw new IllegalStateException( - String.format("opcode %s not part of the MUL instruction family", this.opCode())); - } + default -> throw new IllegalStateException( + String.format("opcode %s not part of the MUL instruction family", this.opCode())); } } case HALT -> { @@ -1110,9 +1110,7 @@ void traceOpcode(MessageFrame frame) { case CREATE -> new CreateSection(this); - case CALL -> { - new CallSection(this); - } + case CALL -> new CallSection(this); case JUMP -> new JumpSection(this); } @@ -1140,8 +1138,4 @@ public void squashParentFrameReturnData() { public CallFrame getLastChildCallFrame(final CallFrame parentFrame) { return this.callStack.getById(parentFrame.childFramesId().getLast()); } - - private boolean withinPrecompile(MessageFrame frame) { - return AddressUtils.isPrecompile(frame.getContractAddress()); - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index fff0a35b63..874e5f565d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -144,6 +144,7 @@ public CreateSection(Hub hub) { // The CREATE(2) is now unexceptional Preconditions.checkArgument(Exceptions.none(exceptions)); + hub.currentFrame().childSpanningSection(this); final CreateOobCall oobCall = new CreateOobCall(); imcFragment.callOob(oobCall); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index ee42bdba45..f3a1ce646e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -165,6 +165,7 @@ public CallSection(Hub hub) { // The CALL is now unexceptional Preconditions.checkArgument(Exceptions.none(exceptions)); + hub.currentFrame().childSpanningSection(this); final CallOobCall oobCall = new CallOobCall(); firstImcFragment.callOob(oobCall); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 7c7c3043ca..528a5022c2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -24,6 +24,7 @@ import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.OpCodeData; @@ -138,7 +139,7 @@ public int getCodeFragmentIndex(Hub hub) { @Getter @Setter private boolean selfReverts = false; @Getter @Setter private boolean getsReverted = false; - // the hub stamp at which this frame reverts (0 means it does not revert) + /** the hub stamp at which this frame reverts (0 means it does not revert) */ @Getter @Setter private int revertStamp = 0; /** this frame {@link Stack}. */ @@ -147,9 +148,11 @@ public int getCodeFragmentIndex(Hub hub) { /** the latched context of this callframe stack. */ @Getter @Setter private StackContext pending; - public static void provideParentContextWithEmptyReturnData(Hub hub) { - updateParentContextReturnData(hub, Bytes.EMPTY, MemorySpan.empty()); - } + /** + * the section responsible for the creation of a child context, either a CALL or a CREATE + * instruction + */ + @Getter @Setter private TraceSection childSpanningSection; public static void updateParentContextReturnData( Hub hub, Bytes outputData, MemorySpan returnDataSource) { @@ -167,6 +170,7 @@ public static void updateParentContextReturnData( this.callDataInfo = new CallDataInfo(callData, 0, callData.size(), contextNumber); } + // TODO: should die ? /** Create a PRECOMPILE_RETURN_DATA callFrame */ CallFrame( final int contextNumber, From eefc6c99c3727a54b438e571fabc8ea3108158a8 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 13 Aug 2024 09:52:49 +0530 Subject: [PATCH 359/461] fix casting java issues Signed-off-by: Francois Bojarski --- .../module/hub/fragment/account/RlpAddrSubFragment.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java index 5f367772ee..bf875969c1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java @@ -48,8 +48,7 @@ public static RlpAddrSubFragment makeFragment(Hub hub, Address deploymentAddress return new RlpAddrSubFragment((short) 2, deploymentAddress, salt, hash); } case CREATE -> { - return new RlpAddrSubFragment( - (short) 1, deploymentAddress, (Bytes32) Bytes32.EMPTY, (Bytes32) Bytes32.EMPTY); + return new RlpAddrSubFragment((short) 1, deploymentAddress, Bytes32.ZERO, Bytes32.ZERO); } default -> throw new IllegalStateException("Unexpected value: " + currentOpCode); } From 7775aa2fc51f66c73a2c2daa25dedf230114b702 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 13 Aug 2024 10:09:33 +0530 Subject: [PATCH 360/461] fix java issues Signed-off-by: Francois Bojarski --- .../consensys/linea/zktracer/module/hub/Hub.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index f68e62c502..1b515cd21a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -617,6 +617,7 @@ public void traceContextEnter(MessageFrame frame) { } } else { // ...or CALL or CREATE + final OpCode currentOpCode = callStack.current().opCode(); final boolean isDeployment = frame.getType() == MessageFrame.Type.CONTRACT_CREATION; final Address codeAddress = frame.getContractAddress(); final CallFrameType frameType = @@ -627,20 +628,23 @@ public void traceContextEnter(MessageFrame frame) { final int codeDeploymentNumber = this.transients.conflation().deploymentInfo().number(codeAddress); - final int callDataOffsetStackArgument = - callStack.current().opCode().callMayNotTransferValue() ? 2 : 3; - final long callDataOffset = isDeployment ? 0 : Words.clampedToLong( - callStack.current().frame().getStackItem(callDataOffsetStackArgument)); + callStack + .current() + .frame() + .getStackItem(currentOpCode.callMayNotTransferValue() ? 2 : 3)); final long callDataSize = isDeployment ? 0 : Words.clampedToLong( - callStack.current().frame().getStackItem(callDataOffsetStackArgument + 1)); + callStack + .current() + .frame() + .getStackItem(currentOpCode.callMayNotTransferValue() ? 3 : 4)); final long callDataContextNumber = this.callStack.current().contextNumber(); From 9b9c42bda45b7b819391432ab54d291a9a64696d Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 13 Aug 2024 15:51:07 +0530 Subject: [PATCH 361/461] fix missing account snapshot for EOA reverted successfull call Signed-off-by: Francois Bojarski --- .../module/hub/section/call/CallSection.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index f3a1ce646e..90c8f9314c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -117,9 +117,9 @@ public CallSection(Hub hub) { hub.addTraceSection(this); final short exceptions = hub.pch().exceptions(); - // row i, i + 1 and i + 2 + // row i + 1 final ContextFragment currentContextFragment = ContextFragment.readCurrentContextData(hub); - // row i+2 + // row i + 2 final ImcFragment firstImcFragment = ImcFragment.empty(hub); this.addStackAndFragments(hub, scenarioFragment, currentContextFragment, firstImcFragment); @@ -276,11 +276,11 @@ private void abortingCall(Hub hub) { @Override public void resolveUponImmediateContextEntry(Hub hub) { + postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); + postOpcodeCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); + switch (scenarioFragment.getScenario()) { case CALL_SMC_UNDEFINED -> { - postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); - postOpcodeCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); - if (selfCallWithNonzeroValueTransfer) { // In case of a self-call that transfers value, the balance of the caller // is decremented by the value transferred. This becomes the initial state @@ -403,7 +403,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { this.addFragments(postReEntryCallerAccountFragment, postReEntryCalleeAccountFragment); } - default -> {} + default -> throw new IllegalArgumentException("Illegal CALL scenario"); } } From 8fb4af6fa7713dea98ec351cd14626a181acd798 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 13 Aug 2024 14:31:31 +0200 Subject: [PATCH 362/461] docs(storage): add comment --- .../instructionprocessing/ContractModifyingStorageTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index 2b06531338..e1d45bcbbb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -175,6 +175,7 @@ void temporaryTest() { Bytes initCode = randData(true); world.accounts(List.of(account1, account2, account3, account4, account5)); + // TODO: deployment transaction fails in our ToyWorld /* txList.add( ToyTransaction.builder() From c5b2da5d4bac5d37e76448034839cf0c8ce0fb11 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 13 Aug 2024 17:49:15 +0200 Subject: [PATCH 363/461] feat: MessageFrame tests and generalised ByteCodeRunner to add additionalAccounts (#932) --- .../zktracer/module/hub/MessageFrameTest.java | 72 +++++++++++++++++++ .../zktracer/testing/BytecodeRunner.java | 26 +++++-- 2 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/MessageFrameTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/MessageFrameTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/MessageFrameTest.java new file mode 100644 index 0000000000..7e37aeab7b --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/MessageFrameTest.java @@ -0,0 +1,72 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.module.hub; + +import java.util.List; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import net.consensys.linea.zktracer.testing.ToyAccount; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +public class MessageFrameTest { + + @Test + void TestCreate() { + // The pc is not updated as expected + // We do not execute the init code of the created smart contract + // TODO: fix this! + BytecodeCompiler program = BytecodeCompiler.newProgram(); + + program + .push("63deadbeef000000000000000000000000000000000000000000000000000000") + .push(0) + .op(OpCode.MSTORE) + .push(0x05) + .push(0) + .push(0) + .op(OpCode.CREATE) + .op(OpCode.DUP1); + + BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); + bytecodeRunner.run(); + } + + @Test + void TestCall() { + // Interestingly for CALL the pc is updated as expected + // We execute the bytecode of the called smart contract + BytecodeCompiler program = BytecodeCompiler.newProgram(); + + program.push(0).push(0).push(0).push(0).push(0x01).push("ca11ee").push(0xffff).op(OpCode.CALL); + + BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); + + final ToyAccount smartContractAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(7) + .address(Address.fromHexString("0xca11ee")) + .code(Bytes.fromHexString("0x63deadbeef00")) + .build(); + + bytecodeRunner.run(List.of(smartContractAccount)); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java index 22532c91e9..f31407e9b0 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.testing; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Consumer; @@ -56,15 +57,28 @@ public static BytecodeRunner of(Bytes byteCode) { @Setter private Consumer zkTracerValidator = zkTracer -> {}; + // Default run method public void run() { - this.run(Wei.fromEth(1), (long) GlobalConstants.LINEA_BLOCK_GAS_LIMIT); + this.run(Wei.fromEth(1), (long) GlobalConstants.LINEA_BLOCK_GAS_LIMIT, List.of()); } + // Ad-hoc senderBalance public void run(Wei senderBalance) { - this.run(senderBalance, (long) GlobalConstants.LINEA_BLOCK_GAS_LIMIT); + this.run(senderBalance, (long) GlobalConstants.LINEA_BLOCK_GAS_LIMIT, List.of()); } + // Ad-hoc senderBalance and gasLimit public void run(Wei senderBalance, Long gasLimit) { + this.run(senderBalance, gasLimit, List.of()); + } + + // Ad-hoc accounts + public void run(List additionalAccounts) { + this.run(Wei.fromEth(1), (long) GlobalConstants.LINEA_BLOCK_GAS_LIMIT, additionalAccounts); + } + + // Ad-hoc senderBalance, gasLimit and accounts + public void run(Wei senderBalance, Long gasLimit, List additionalAccounts) { Preconditions.checkArgument(byteCode != null, "byteCode cannot be empty"); KeyPair keyPair = new SECP256K1().generateKeyPair(); @@ -91,8 +105,12 @@ public void run(Wei senderBalance, Long gasLimit) { .gasLimit(selectedGasLimit) .build(); - final ToyWorld toyWorld = - ToyWorld.builder().accounts(List.of(senderAccount, receiverAccount)).build(); + List accounts = new ArrayList<>(); + accounts.add(senderAccount); + accounts.add(receiverAccount); + accounts.addAll(additionalAccounts); + + final ToyWorld toyWorld = ToyWorld.builder().accounts(accounts).build(); toyExecutionEnvironment = ToyExecutionEnvironment.builder() From ccc2d06b4e4e6fb4adde33780854fff0334d2d98 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 14 Aug 2024 11:46:12 +0530 Subject: [PATCH 364/461] fix(prc): missing last context rows Signed-off-by: Francois Bojarski --- .../zktracer/module/hub/fragment/ContextFragment.java | 11 +++++++++++ .../zktracer/module/hub/section/call/CallSection.java | 8 ++++---- .../precompileSubsection/PrecompileSubsection.java | 5 +++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java index 2bb361b640..1e68588873 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/ContextFragment.java @@ -134,6 +134,17 @@ public static ContextFragment executionProvidesReturnData( // also: will the latestReturnData have been updated ? } + public static ContextFragment updateReturnData( + final Hub hub, final int returnDataContextNumber, final MemorySpan returnDataMetaInfo) { + return new ContextFragment( + hub, + hub.callStack(), + Either.right(hub.callStack().current().contextNumber()), + returnDataContextNumber, + returnDataMetaInfo, + true); + } + @Override public Trace trace(Trace trace) { final CallFrame callFrame = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 90c8f9314c..b9451e28fd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -26,6 +26,7 @@ import java.util.function.BiFunction; import com.google.common.base.Preconditions; +import lombok.Setter; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Factories; import net.consensys.linea.zktracer.module.hub.Hub; @@ -82,8 +83,9 @@ public class CallSection extends TraceSection // row i+0 private final CallScenarioFragment scenarioFragment = new CallScenarioFragment(); - // Just before call - private ContextFragment finalContextFragment; + // last row + @Setter private ContextFragment finalContextFragment; + private Bytes rawCalleeAddress; // Just before the CALL Opcode @@ -218,8 +220,6 @@ public CallSection(Hub hub) { // TODO: write a test where the recipient of the call does not exist in the state } - // TODO: lastContextFragment for PRC - if (scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { finalContextFragment = ContextFragment.initializeNewExecutionContext(hub); final boolean callCanTransferValue = hub.currentFrame().opCode().callCanTransferValue(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 2459b5b416..d9c43525cc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -30,6 +30,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.*; +import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; @@ -161,6 +162,10 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { if (callSuccess) { hub.defers().scheduleForPostRollback(this, frame); + callSection.setFinalContextFragment( + ContextFragment.updateReturnData(hub, returnDataContextNumber(), parentReturnDataTarget)); + } else { + callSection.setFinalContextFragment(ContextFragment.nonExecutionProvidesEmptyReturnData(hub)); } } From 4434ac21a6118edb69192f1577b5f3096dca2f75 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 14 Aug 2024 14:47:54 +0530 Subject: [PATCH 365/461] fix returnData for successfull ecrecover can be empty Signed-off-by: Francois Bojarski --- .../EllipticCurvePrecompileSubsection.java | 6 +++++- .../call/precompileSubsection/PrecompileSubsection.java | 7 ++----- .../linea/zktracer/module/blockhash/BlockhashTest.java | 3 ++- arithmetization/src/test/resources/replays/8044060.json.gz | 0 4 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 arithmetization/src/test/resources/replays/8044060.json.gz diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index b2d599ad4f..c4e10d39fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -27,6 +27,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.PrecompileCommonOobCall; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import org.apache.tuweni.bytes.Bytes; public class EllipticCurvePrecompileSubsection extends PrecompileSubsection { final PrecompileCommonOobCall oobCall; @@ -61,7 +62,10 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { switch (flag()) { case PRC_ECRECOVER -> { checkArgument(oobCall.isHubSuccess() == callSuccess); - checkArgument(returnData.size() == (callSuccess ? WORD_SIZE : 0)); + checkArgument( + callSuccess + ? (returnData == Bytes.EMPTY || returnData.size() == WORD_SIZE) + : returnData == Bytes.EMPTY); } case PRC_ECPAIRING -> checkArgument(returnData.size() == (callSuccess ? WORD_SIZE : 0)); case PRC_ECADD, PRC_ECMUL -> checkArgument( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index d9c43525cc..7e053b9242 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -119,7 +119,8 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { callDataMemorySpan = new MemorySpan(offset, length); callerMemorySnapshot = extractContiguousLimbsFromMemory(hub.currentFrame().frame(), callDataMemorySpan); - final int lengthToExtract = (int) Math.min(length, callerMemorySnapshot.size() - offset); + final int lengthToExtract = + (int) Math.min(length, Math.max(callerMemorySnapshot.size() - offset, 0)); callData = rightPadTo(callerMemorySnapshot.slice((int) offset, lengthToExtract), (int) length); } @@ -133,10 +134,6 @@ public void resolveUponImmediateContextEntry(Hub hub) { Preconditions.checkArgument( callDataMemorySpan.equals(hub.currentFrame().callDataInfo().memorySpan())); Preconditions.checkArgument(callData.equals(hub.messageFrame().getInputData())); - final MessageFrame callerFrame = hub.callStack().parent().frame(); - Preconditions.checkArgument( - callerMemorySnapshot.equals( - extractContiguousLimbsFromMemory(callerFrame, callDataMemorySpan))); callerGas = hub.callStack().parent().frame().getRemainingGas(); calleeGas = hub.messageFrame().getRemainingGas(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java index 1327774769..ee2ea6f294 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java @@ -21,11 +21,12 @@ import net.consensys.linea.zktracer.testing.BytecodeCompiler; import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class BlockhashTest { - // @Disabled("in our framework, BLOCKNUMBER is 0 thus breaking the wcp_lower_bound lookup") + @Disabled("Not possible to test yet, ToyWorld issue, see #934") @Test void someBlockhash() { BytecodeRunner.of( diff --git a/arithmetization/src/test/resources/replays/8044060.json.gz b/arithmetization/src/test/resources/replays/8044060.json.gz new file mode 100644 index 0000000000..e69de29bb2 From 7246b38cf449d0fc1c354e2778d3a9aef1087b7c Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 14 Aug 2024 16:00:52 +0530 Subject: [PATCH 366/461] fix: need to give ram snapshot to MMU Signed-off-by: Francois Bojarski --- .../zktracer/module/hub/fragment/imc/mmu/MmuCall.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index ca48d12480..525cda4b2e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -312,6 +312,7 @@ public static MmuCall txInit(final Hub hub) { return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(hub.txStack().current().getAbsoluteTransactionNumber()) .targetId(hub.stamp()) + .targetRamBytes(Optional.of(Bytes.EMPTY)) .size(hub.txStack().current().getBesuTransaction().getData().map(Bytes::size).orElse(0)) .phase(RLP_TXN_PHASE_DATA) .setRlpTxn(); @@ -322,7 +323,9 @@ public static MmuCall callDataExtractionForEcrecover( return new MmuCall(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING) .sourceId(hub.currentFrame().contextNumber()) // called at ContextReEntry + .sourceRamBytes(Optional.of(subsection.callerMemorySnapshot())) .targetId(subsection.exoModuleOperationId()) + .targetRamBytes(Optional.of(subsection.callData)) .sourceOffset(EWord.of(subsection.callDataMemorySpan.offset())) .size(subsection.callDataMemorySpan.length()) .referenceSize(128) @@ -338,7 +341,9 @@ public static MmuCall fullReturnDataTransferForEcrecover( return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(precompileContextNumber) + .exoBytes(Optional.of(subsection.returnData())) .targetId(precompileContextNumber) + .targetRamBytes(Optional.of(Bytes.EMPTY)) .size(WORD_SIZE) .phase(PHASE_ECRECOVER_RESULT) .setEcData(); @@ -352,7 +357,9 @@ public static MmuCall partialReturnDataCopyForEcrecover( return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(precompileContextNumber) + .sourceRamBytes(Optional.of(subsection.returnData)) .targetId(hub.currentFrame().contextNumber()) + .targetRamBytes(Optional.of(subsection.callerMemorySnapshot())) .sourceOffset(EWord.ZERO) .size(WORD_SIZE) .referenceOffset(subsection.parentReturnDataTarget.offset()) From 7c9f8545e1e0a20496db8918b818716650a093da Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 15 Aug 2024 10:03:44 +0530 Subject: [PATCH 367/461] cleaning Signed-off-by: Francois Bojarski --- .../consensys/linea/zktracer/ZkTracer.java | 2 - .../module/hub/transients/Operation.java | 206 ------------------ .../zktracer/module/hub/transients/Tx.java | 117 ---------- .../linea/zktracer/module/stp/Stp.java | 14 +- .../zktracer/module/stp/StpOperation.java | 26 +-- zkevm-constraints | 2 +- 6 files changed, 14 insertions(+), 353 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java index 8cf5d82e2c..1b7e8b921d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java @@ -46,7 +46,6 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.PendingTransaction; import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator; @@ -62,7 +61,6 @@ public class ZkTracer implements ConflationAwareOperationTracer { /** The {@link GasCalculator} used in this version of the arithmetization */ public static final GasCalculator gasCalculator = new LondonGasCalculator(); - public static final FeeMarket feeMarket = FeeMarket.london(-1); private static final Map spillings; static { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java deleted file mode 100644 index 5f30845f28..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Operation.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.transients; - -import static net.consensys.linea.zktracer.module.UtilCalculator.allButOneSixtyFourth; - -import lombok.RequiredArgsConstructor; -import net.consensys.linea.zktracer.module.constants.GlobalConstants; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.MemorySpan; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; - -/** This class provides facilities to access data that are opcode-lived. */ -@RequiredArgsConstructor -public class Operation { - private final Hub hub; - - /** - * Compute the gas allowance for the child context if in a CALL, throws otherwise. - * - * @return the CALL gas allowance - */ - public long gasAllowanceForCall() { - final OpCode opCode = hub.opCode(); - - switch (opCode) { - case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - final long gas = Words.clampedToLong(hub.messageFrame().getStackItem(0)); - EWord value = EWord.ZERO; - if (opCode == OpCode.CALL || opCode == OpCode.CALLCODE) { - value = EWord.of(hub.messageFrame().getStackItem(2)); - } - final long stipend = value.isZero() ? 0 : GlobalConstants.GAS_CONST_G_CALL_STIPEND; - final long upfrontCost = Hub.GAS_PROJECTOR.of(hub.messageFrame(), opCode).total(); - return stipend - + Math.max( - Words.unsignedMin( - allButOneSixtyFourth(hub.messageFrame().getRemainingGas() - upfrontCost), gas), - 0); - } - default -> throw new IllegalStateException("not a CALL"); - } - } - - /** - * Returns the RAM segment of the caller containing the calldata if the {@link MessageFrame} - * operation is a call, throws otherwise. - * - * @param frame the execution context - * @return the input data segment - */ - public static MemorySpan callDataSegment(final MessageFrame frame) { - switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { - case CALL, CALLCODE -> { - long offset = Words.clampedToLong(frame.getStackItem(3)); - long length = Words.clampedToLong(frame.getStackItem(4)); - return MemorySpan.fromStartLength(offset, length); - } - case DELEGATECALL, STATICCALL -> { - long offset = Words.clampedToLong(frame.getStackItem(2)); - long length = Words.clampedToLong(frame.getStackItem(3)); - return MemorySpan.fromStartLength(offset, length); - } - case CREATE, CREATE2 -> { - long offset = Words.clampedToLong(frame.getStackItem(1)); - long length = Words.clampedToLong(frame.getStackItem(2)); - return MemorySpan.fromStartLength(offset, length); - } - default -> throw new IllegalArgumentException("callDataSegment called outside of a *CALL"); - } - } - - /** - * Returns the RAM segment of the caller containing the calldata if the current operation is a - * call, throws otherwise. - * - * @return the input data segment - */ - public MemorySpan callDataSegment() { - return callDataSegment(hub.messageFrame()); - } - - /** - * Return the bytes of the calldata if the current operation is a call, throws otherwise. - * - * @return the calldata content - */ - public Bytes callData() { - final MemorySpan callDataSegment = callDataSegment(); - return hub.messageFrame().shadowReadMemory(callDataSegment.offset(), callDataSegment.length()); - } - - /** - * Return the bytes of the calldata if the current operation is a call, throws otherwise. - * - * @param frame the execution context - * @return the calldata content - */ - public static Bytes callData(final MessageFrame frame) { - final MemorySpan callDataSegment = callDataSegment(frame); - return frame.shadowReadMemory(callDataSegment.offset(), callDataSegment.length()); - } - - /** - * Returns the RAM segment offered by the caller for the return data if the current operation is a - * call, throws otherwise. - * - * @param frame the execution context - * @return the return data target - */ - public static MemorySpan returnDataRequestedSegment(final MessageFrame frame) { - switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { - case CALL, CALLCODE -> { - long offset = Words.clampedToLong(frame.getStackItem(5)); - long length = Words.clampedToLong(frame.getStackItem(6)); - return MemorySpan.fromStartLength(offset, length); - } - case DELEGATECALL, STATICCALL -> { - long offset = Words.clampedToLong(frame.getStackItem(4)); - long length = Words.clampedToLong(frame.getStackItem(5)); - return MemorySpan.fromStartLength(offset, length); - } - default -> throw new IllegalArgumentException( - "returnDataRequestedSegment called outside of a *CALL"); - } - } - - /** - * Returns the RAM segment offered by the caller for the return data if the current operation is a - * call, throws otherwise. - * - * @return the return data target - */ - public MemorySpan returnDataRequestedSegment() { - return returnDataRequestedSegment(hub.messageFrame()); - } - - /** - * Returns the RAM segment offered by the callee for the return data if the current operation is a - * RETURN/REVERT, throws otherwise. - * - * @param frame the execution context - * @return the return data segment - */ - public static MemorySpan returnDataSegment(final MessageFrame frame) { - switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { - case RETURN, REVERT -> { - long offset = Words.clampedToLong(frame.getStackItem(0)); - long length = Words.clampedToLong(frame.getStackItem(1)); - return MemorySpan.fromStartLength(offset, length); - } - default -> throw new IllegalArgumentException( - "returnDataRequestedSegment called outside of a RETURN/REVERT"); - } - } - - /** - * Returns the RAM segment offered by the caller for the return data if the current operation is a - * call, throws otherwise. - * - * @return the return data target - */ - public MemorySpan returnDataSegment() { - return returnDataSegment(hub.messageFrame()); - } - - /** - * Return the bytes of the calldata if the current operation is a call, throws otherwise. - * - * @return the calldata content - */ - public Bytes returnData() { - final MemorySpan returnDataSegment = returnDataSegment(); - return hub.messageFrame() - .shadowReadMemory(returnDataSegment.offset(), returnDataSegment.length()); - } - - /** - * Return the bytes of the returndata if the current operation is a return/revert, throws - * otherwise. - * - * @param frame the execution context - * @return the returndata content - */ - public static Bytes returnData(final MessageFrame frame) { - final MemorySpan returnDataSegment = returnDataSegment(frame); - return frame.shadowReadMemory(returnDataSegment.offset(), returnDataSegment.length()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java deleted file mode 100644 index 156415eab2..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Tx.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright Consensys Software Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.transients; - -import static net.consensys.linea.zktracer.types.AddressUtils.isPrecompile; - -import java.math.BigInteger; -import java.util.Optional; - -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.ZkTracer; -import net.consensys.linea.zktracer.container.StackedContainer; -import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Quantity; -import org.hyperledger.besu.datatypes.Transaction; -import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.evm.worldstate.WorldView; - -/** Stores transaction-specific information. */ -@Accessors(fluent = true) -@Getter -public class Tx implements StackedContainer { - private int preExecNumber = 0; - - private int number = 0; - private Transaction transaction; - @Setter private HubProcessingPhase state; - @Setter private Boolean status; - private long initialGas; - StorageInitialValues storage; - - /** - * Returns the transaction result, or throws an exception if it is being accessed outside of its - * specified lifetime -- between the conclusion of a transaction and the start of a new one. - * - * @return the transaction final status - */ - public boolean status() { - if (this.status == null) { - throw new RuntimeException("TX state can not be queried for now."); - } - - return this.status; - } - - public boolean isDeployment() { - return this.transaction.getTo().isPresent(); - } - - public Optional callData() { - return this.transaction.getData(); - } - - public boolean shouldSkip(WorldView world) { - return (this.transaction.getTo().isPresent() - && Optional.ofNullable(world.get(this.transaction.getTo().get())) - .map(a -> a.getCode().isEmpty()) - .orElse(true)) // pure transaction - || (this.transaction.getTo().isEmpty() - && this.transaction.getInit().isEmpty()); // contract creation without init code - } - - public Wei gasPrice() { - return Wei.of( - this.transaction.getGasPrice().map(Quantity::getAsBigInteger).orElse(BigInteger.ZERO)); - } - - public static long computeInitGas(Transaction tx) { - boolean isDeployment = tx.getTo().isEmpty(); - return tx.getGasLimit() - - ZkTracer.gasCalculator.transactionIntrinsicGasCost(tx.getPayload(), isDeployment) - - tx.getAccessList().map(ZkTracer.gasCalculator::accessListGasCost).orElse(0L); - } - - /** - * Update transaction-specific information on new transaction start. - * - * @param tx the new transaction - */ - public void update(final Transaction tx) { - if (tx.getTo().isPresent() && isPrecompile(tx.getTo().get())) { - throw new RuntimeException("Call to precompile forbidden"); - } else { - this.number++; - } - this.storage = new StorageInitialValues(); - this.status = null; - this.transaction = tx; - this.initialGas = tx.getGasLimit(); - } - - @Override - public void enter() { - this.preExecNumber = this.number; - } - - @Override - public void pop() { - this.number = this.preExecNumber; - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java index 5a160655fa..944d9c776e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Stp.java @@ -20,6 +20,7 @@ import java.nio.MappedByteBuffer; import java.util.List; +import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.set.StackedSet; @@ -27,7 +28,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.StpCall; import net.consensys.linea.zktracer.module.mod.Mod; import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes32; @RequiredArgsConstructor @@ -39,9 +39,13 @@ public class Stp implements Module { private final Mod mod; public void call(StpCall stpCall) { - StpOperation stpOperation = new StpOperation(stpCall); + final StpOperation stpOperation = new StpOperation(stpCall); this.operations.add(stpOperation); + Preconditions.checkArgument( + stpCall.opCode().isCall() || stpCall.opCode().isCreate(), + "STP handles only Calls and CREATEs"); + if (stpCall.opCode().isCreate()) { this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); @@ -52,7 +56,7 @@ public void call(StpCall stpCall) { if (stpCall.opCode().isCall()) { this.wcp.callLT(longToBytes32(stpCall.gasActual()), Bytes32.ZERO); - if (callCanTransferValue(stpCall.opCode())) { + if (stpCall.opCode().callCanTransferValue()) { this.wcp.callISZERO(Bytes32.leftPad(stpCall.value())); } this.wcp.callLT(longToBytes32(stpCall.gasActual()), longToBytes32(stpCall.upfrontGasCost())); @@ -88,10 +92,6 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - static boolean callCanTransferValue(OpCode opCode) { - return (opCode == OpCode.CALL) || (opCode == OpCode.CALLCODE); - } - @Override public void commit(List buffers) { final Trace trace = new Trace(buffers); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java index a77018dd5d..a962f11061 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java @@ -35,16 +35,6 @@ public StpOperation(StpCall stpCall) { this.stpCall = stpCall; } - private boolean isCallType() { - return stpCall - .opCode() - .isAnyOf(OpCode.CALL, OpCode.CALLCODE, OpCode.DELEGATECALL, OpCode.STATICCALL); - } - - private boolean callCanTransferValue() { - return stpCall.opCode().isAnyOf(OpCode.CALL, OpCode.CALLCODE); - } - private boolean isCall() { return stpCall.opCode() == OpCode.CALL; } @@ -61,10 +51,6 @@ private boolean isStaticCall() { return stpCall.opCode() == OpCode.STATICCALL; } - private boolean isCreateType() { - return stpCall.opCode().isAnyOf(OpCode.CREATE, OpCode.CREATE2); - } - private boolean isCreate() { return stpCall.opCode() == OpCode.CREATE; } @@ -106,10 +92,10 @@ private void traceCreate(Trace trace, int stamp) { .instruction(UnsignedByte.of(stpCall.opCode().byteValue())) .isCreate(isCreate()) .isCreate2(isCreate2()) - .isCall(isCall()) - .isCallcode(isCallCode()) - .isDelegatecall(isDelegateCall()) - .isStaticcall(isStaticCall()) + .isCall(false) + .isCallcode(false) + .isDelegatecall(false) + .isStaticcall(false) // .gasHi(Bytes.EMPTY) // redundant // .gasLo(Bytes.EMPTY) // redundant .valHi(stpCall.value().slice(0, 16)) @@ -162,8 +148,8 @@ private void traceCall(Trace trace, int stamp) { .ct(UnsignedByte.of(ct)) .ctMax(UnsignedByte.of(ctMax)) .instruction(UnsignedByte.of(stpCall.opCode().byteValue())) - .isCreate(isCreate()) - .isCreate2(isCreate2()) + .isCreate(false) + .isCreate2(false) .isCall(isCall()) .isCallcode(isCallCode()) .isDelegatecall(isDelegateCall()) diff --git a/zkevm-constraints b/zkevm-constraints index 538a586fc5..99c667611f 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 538a586fc52596cdd264fbd35b4801dc592c27a0 +Subproject commit 99c667611f4ac1ba96cc4f0d991036e3a906bfcd From fc1addfc866e38cb2eeed178e39e9403ab36774a Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 15 Aug 2024 14:04:39 +0530 Subject: [PATCH 368/461] fix: add seen storage keys in sstore and sload section + add trivial sstore sload test Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 6 +-- .../linea/zktracer/module/hub/State.java | 5 +-- .../module/hub/section/SloadSection.java | 16 ++++++-- .../module/hub/section/SstoreSection.java | 10 ++++- .../hub/section/TxPreWarmingMacroSection.java | 6 +-- .../module/hub/section/call/CallSection.java | 1 - .../instructionprocessing/StorageTest.java | 37 +++++++++++++++++++ .../zktracer/precompiles/EcrecoverTests.java | 2 - .../zktracer/precompiles/ModexpTests.java | 2 - zkevm-constraints | 2 +- 10 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StorageTest.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 1b515cd21a..c846c3fb62 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -727,9 +727,9 @@ public void traceContextExit(MessageFrame frame) { this.defers.resolveUponExitingContext(this, this.currentFrame()); // TODO: verify me please @Olivier - if (Exceptions.any(this.pch.exceptions())) { - this.defers.resolvePostRollback(this, frame, this.currentFrame()); - } + // if (Exceptions.any(this.pch.exceptions())) { + // this.defers.resolvePostRollback(this, frame, this.currentFrame()); + // } } public void tracePreExecution(final MessageFrame frame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java index ae24379f30..972a13591f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/State.java @@ -54,9 +54,8 @@ public static class StorageSlotIdentifier { public void updateOrInsertStorageSlotOccurrence( StorageSlotIdentifier slotIdentifier, StorageFragment storageFragment) { - int size = firstAndLastStorageSlotOccurrences.size(); - HashMap current = - firstAndLastStorageSlotOccurrences.get(size - 1); + final HashMap current = + firstAndLastStorageSlotOccurrences.getLast(); if (current.containsKey(slotIdentifier)) { current.get(slotIdentifier).update(storageFragment); } else { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 6e55e79a3b..0cfca1fa74 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -49,7 +49,7 @@ public SloadSection(Hub hub, WorldView world) { super( hub, (short) - (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); + (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 5 : 4))); this.world = world; this.address = hub.messageFrame().getRecipientAddress(); @@ -68,9 +68,17 @@ public SloadSection(Hub hub, WorldView world) { // - stackUnderflowException // - outOfGasException // in the present case we don't have a stack exception - ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); - ImcFragment miscFragmentForSload = ImcFragment.empty(hub); - StorageFragment doingSload = doingSload(hub); + final ContextFragment readCurrentContext = ContextFragment.readCurrentContextData(hub); + final ImcFragment miscFragmentForSload = ImcFragment.empty(hub); + final StorageFragment doingSload = doingSload(hub); + + // Update the First Last time seen map of storage keys + final State.StorageSlotIdentifier storageSlotIdentifier = + new State.StorageSlotIdentifier( + address, + hub.transients().conflation().deploymentInfo().number(address), + EWord.of(storageKey)); + hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingSload); this.addStackAndFragments(hub, readCurrentContext, miscFragmentForSload, doingSload); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index ef5a0e43ae..911e39330b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -50,7 +50,7 @@ public SstoreSection(Hub hub, WorldView world) { super( hub, (short) - (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 6 : 5))); + (hub.opCode().numberOfStackRows() + (Exceptions.any(hub.pch().exceptions()) ? 5 : 4))); this.world = world; this.address = hub.messageFrame().getRecipientAddress(); @@ -95,6 +95,14 @@ public SstoreSection(Hub hub, WorldView world) { final StorageFragment doingSstore = this.doingSstore(hub); this.addFragment(doingSstore); + // Update the First Last time seen map of storage keys + final State.StorageSlotIdentifier storageSlotIdentifier = + new State.StorageSlotIdentifier( + address, + hub.transients().conflation().deploymentInfo().number(address), + EWord.of(storageKey)); + hub.state.updateOrInsertStorageSlotOccurrence(storageSlotIdentifier, doingSstore); + // set the refundDelta this.commonValues.refundDelta( Hub.GAS_PROJECTOR diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 269ffc9809..6d55eadfd7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -53,8 +53,8 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { .ifPresent( accessList -> { if (!accessList.isEmpty()) { - Set
seenAddresses = new HashSet<>(precompileAddress); - HashMap> seenKeys = new HashMap<>(); + final Set
seenAddresses = new HashSet<>(precompileAddress); + final HashMap> seenKeys = new HashMap<>(); for (AccessListEntry entry : accessList) { hub.state.stamps().incrementHubStamp(); @@ -105,7 +105,7 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { .map(account -> EWord.of(account.getStorageValue(key))) .orElse(EWord.ZERO); - State.StorageSlotIdentifier storageSlotIdentifier = + final State.StorageSlotIdentifier storageSlotIdentifier = new State.StorageSlotIdentifier( address, deploymentInfo.number(address), EWord.of(k)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index b9451e28fd..d7a219240e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -64,7 +64,6 @@ public class CallSection extends TraceSection PostRollbackDefer, PostTransactionDefer { - // TODO: finish this map private static final Map> ADDRESS_TO_PRECOMPILE = Map.of( diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StorageTest.java new file mode 100644 index 0000000000..be0dd5602f --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/StorageTest.java @@ -0,0 +1,37 @@ +/* + * Copyright ConsenSys Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.zktracer.instructionprocessing; + +import net.consensys.linea.zktracer.opcode.OpCode; +import net.consensys.linea.zktracer.testing.BytecodeCompiler; +import net.consensys.linea.zktracer.testing.BytecodeRunner; +import org.junit.jupiter.api.Test; + +public class StorageTest { + + @Test + void simpleSstoreSload() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push(0x666) // value + .push(0xca7) // key + .op(OpCode.SSTORE) + .push(0xca7) // key + .op(OpCode.SLOAD) + .compile()) + .run(); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java index 5b2231d9be..7b9fc01815 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/EcrecoverTests.java @@ -22,8 +22,6 @@ public class EcrecoverTests { - // the thing fails at AccountSnapshot.canonical() - // of the precompile address 0x00...01 ≡ ECRECOVER @Test void basicEcrecoverTest() { final Bytes bytecode = diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java index 6fba1764d2..609dcce64f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java @@ -22,8 +22,6 @@ public class ModexpTests { - // the thing fails at AccountSnapshot.canonical() - // of the precompile address 0x00...05 ≡ MODEXP @Test void basicModexpTest() { final Bytes bytecode = diff --git a/zkevm-constraints b/zkevm-constraints index 99c667611f..5014f30b63 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 99c667611f4ac1ba96cc4f0d991036e3a906bfcd +Subproject commit 5014f30b6305d9da6d2b53a26cea574a86ee6d5b From ad009ee22b72dc69745d26d162765638a2ef2307 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 15 Aug 2024 15:05:30 +0530 Subject: [PATCH 369/461] fix: resolve exit & rollback defers before exitint the calldrame Signed-off-by: Francois Bojarski --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 12 +++++++----- .../module/hub/section/call/CallSection.java | 4 +--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index c846c3fb62..0c86b93642 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -698,8 +698,6 @@ public void traceContextExit(MessageFrame frame) { this.callStack.revert(this.state.stamps().hub()); // TODO: Duplicate s? } - this.callStack.exit(); - for (Module m : this.modules) { m.traceContextExit(frame); } @@ -727,9 +725,13 @@ public void traceContextExit(MessageFrame frame) { this.defers.resolveUponExitingContext(this, this.currentFrame()); // TODO: verify me please @Olivier - // if (Exceptions.any(this.pch.exceptions())) { - // this.defers.resolvePostRollback(this, frame, this.currentFrame()); - // } + if (Exceptions.any(this.pch.exceptions())) { + this.defers.resolvePostRollback(this, frame, this.currentFrame()); + } + + if (frame.getDepth() > 0) { + this.callStack.exit(); + } } public void tracePreExecution(final MessageFrame frame) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index d7a219240e..17056e0001 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -307,9 +307,7 @@ public void resolveUponImmediateContextEntry(Hub hub) { rawCalleeAddress, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 1)); - if (scenarioFragment.getScenario() == CALL_SMC_UNDEFINED) { - firstCalleeAccountFragment.requiresRomlex(true); - } + firstCalleeAccountFragment.requiresRomlex(true); this.addFragments(firstCallerAccountFragment, firstCalleeAccountFragment); } From 22c11cdf69be4a695bd102b1127cfaa9c6a61342 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 15 Aug 2024 12:40:23 +0200 Subject: [PATCH 370/461] feat(exp): update --- .../zktracer/module/exp/ExpOperation.java | 62 +++++++------------ 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index 889b409468..9d3be8bdaf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -171,18 +171,6 @@ public void preComputeForModexpLog(ModexpLogExpCall modexplogExpCall) { initArrays(CT_MAX_PRPRC_MODEXP_LOG + 1); // Preprocessing - EWord trim = - EWord.of( - LeadLogTrimLead.fromArgs( - modexplogExpCall.getRawLeadingWord(), - modexplogExpCall.getCdsCutoff(), - modexplogExpCall.getEbsCutoff()) - .trim()); - - final BigInteger trimLimb = trim.hi().isZero() ? trim.loBigInt() : trim.hiBigInt(); - final int trimLog = trimLimb.signum() == 0 ? 0 : log2(trimLimb, RoundingMode.FLOOR); - final int nBitsOfLeadingByteExcludingLeadingBit = trimLog % 8; - final int nBytesExcludingLeadingByte = trimLog / 8; // First row pPreprocessingWcpFlag[0] = true; @@ -213,47 +201,35 @@ public void preComputeForModexpLog(ModexpLogExpCall modexplogExpCall) { pPreprocessingWcpArg2Hi[2] = Bytes.of(0); pPreprocessingWcpArg2Lo[2] = Bytes.of(LLARGEPO); pPreprocessingWcpInst[2] = UnsignedByte.of(EVM_INST_LT); - pPreprocessingWcpRes[2] = + final boolean ebsCutoffLeq16 = wcp.callLT(Bytes.of(modexplogExpCall.getEbsCutoff()), Bytes.of(LLARGEPO)); + pPreprocessingWcpRes[2] = ebsCutoffLeq16; // Fourth row + final EWord rawLead = modexplogExpCall.getRawLeadingWord(); + final Bytes rawLeadHi = rawLead.hi(); + final Bytes rawLeadLo = rawLead.lo(); pPreprocessingWcpFlag[3] = true; pPreprocessingWcpArg1Hi[3] = Bytes.of(0); - pPreprocessingWcpArg1Lo[3] = modexplogExpCall.getRawLeadingWord().hi(); + pPreprocessingWcpArg1Lo[3] = rawLeadHi; pPreprocessingWcpArg2Hi[3] = Bytes.of(0); pPreprocessingWcpArg2Lo[3] = Bytes.of(0); pPreprocessingWcpInst[3] = UnsignedByte.of(EVM_INST_ISZERO); - final boolean rawHiPartIsZero = wcp.callISZERO(modexplogExpCall.getRawLeadingWord().hi()); - pPreprocessingWcpRes[3] = rawHiPartIsZero; + final boolean rawLeadHiIsZero = wcp.callISZERO(rawLeadHi); + pPreprocessingWcpRes[3] = rawLeadHiIsZero; - // Fifth row - final int paddedBase2Log = - 8 * nBytesExcludingLeadingByte + nBitsOfLeadingByteExcludingLeadingBit; - - pPreprocessingWcpFlag[4] = true; - pPreprocessingWcpArg1Hi[4] = Bytes.of(0); - pPreprocessingWcpArg1Lo[4] = Bytes.of(paddedBase2Log); - pPreprocessingWcpArg2Hi[4] = Bytes.of(0); - pPreprocessingWcpArg2Lo[4] = Bytes.of(0); - pPreprocessingWcpInst[4] = UnsignedByte.of(EVM_INST_ISZERO); - pPreprocessingWcpRes[4] = wcp.callISZERO(Bytes.of(paddedBase2Log)); + // Fifth row is filled later since we need pComputationTrimAcc - // Linking constraints and fill rawAcc - if (minCutoffLeq16) { - pComputationRawAcc = leftPadTo(modexplogExpCall.getRawLeadingWord().hi(), LLARGE); - } else if (!rawHiPartIsZero) { - pComputationRawAcc = leftPadTo(modexplogExpCall.getRawLeadingWord().hi(), LLARGE); - } else { - pComputationRawAcc = leftPadTo(modexplogExpCall.getRawLeadingWord().lo(), LLARGE); - } - - // Fill pltJmp + // Linking constraints and fill rawAcc and pltJmp if (minCutoffLeq16) { + pComputationRawAcc = leftPadTo(rawLeadHi, LLARGE); pComputationPltJmp = (short) minCutoff; } else { - if (!rawHiPartIsZero) { + if (!rawLeadHiIsZero) { + pComputationRawAcc = leftPadTo(rawLeadHi, LLARGE); pComputationPltJmp = (short) 16; } else { + pComputationRawAcc = leftPadTo(rawLeadLo, LLARGE); pComputationPltJmp = (short) (minCutoff - 16); } } @@ -270,6 +246,16 @@ public void preComputeForModexpLog(ModexpLogExpCall modexplogExpCall) { pComputationMsb = UnsignedByte.of(trimByte); } } + + // Fifth row + pPreprocessingWcpFlag[4] = true; + pPreprocessingWcpArg1Hi[4] = Bytes.of(0); + pPreprocessingWcpArg1Lo[4] = pComputationTrimAcc; + pPreprocessingWcpArg2Hi[4] = Bytes.of(0); + pPreprocessingWcpArg2Lo[4] = Bytes.of(0); + pPreprocessingWcpInst[4] = UnsignedByte.of(EVM_INST_ISZERO); + final boolean trimAccIsZero = wcp.callISZERO(pComputationTrimAcc); + pPreprocessingWcpRes[4] = trimAccIsZero; } final void traceComputation(int stamp, Trace trace) { From dfa0d64bbebd2fd321c6ed143133d572efa4a153 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 15 Aug 2024 17:21:02 +0530 Subject: [PATCH 371/461] fix: missing call to ROMLEX for CREATEs Signed-off-by: Francois Bojarski --- .../module/hub/section/CreateSection.java | 2 + .../linea/zktracer/module/romlex/RomLex.java | 40 ++++++------------- .../linea/zktracer/types/AddressUtils.java | 7 ++-- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 874e5f565d..f0a0925abe 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -217,6 +217,8 @@ public CreateSection(Hub hub) { .scheduleForContextReEntry( this, hub.currentFrame()); // To get the success bit of the CREATE(2) + hub.romLex().callRomLex(frame); + // Note: the case CREATE2 has been set before, we need to do it even in the failure case if (hub.opCode() == CREATE) { final MmuCall mmuCall = MmuCall.create(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 9f91f54050..f57e5149c7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -16,14 +16,13 @@ package net.consensys.linea.zktracer.module.romlex; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; -import static net.consensys.linea.zktracer.types.AddressUtils.getCreate2Address; -import static net.consensys.linea.zktracer.types.AddressUtils.getCreateAddress; +import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; +import static net.consensys.linea.zktracer.types.AddressUtils.highPart; +import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; import java.nio.MappedByteBuffer; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; import com.google.common.base.Preconditions; @@ -54,7 +53,6 @@ public class RomLex implements Module, PostOpcodeDefer { @Getter private final StackedSet chunks = new StackedSet<>(); @Getter private final List sortedChunks = new ArrayList<>(); - @Getter private final Map addressRomChunkMap = new HashMap<>(); private Bytes byteCode = Bytes.EMPTY; private Address address = Address.ZERO; @@ -122,7 +120,6 @@ public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMe ContractMetadata.underDeployment(calledAddress, 1), false, false, tx.getInit().get()); this.chunks.add(chunk); - this.addressRomChunkMap.put(calledAddress, chunk); } // Call to an account with bytecode @@ -134,9 +131,9 @@ public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMe if (!code.isEmpty()) { final Address calledAddress = tx.getTo().get(); - int depNumber = + final int depNumber = hub.transients().conflation().deploymentInfo().number(calledAddress); - boolean depStatus = + final boolean depStatus = hub.transients().conflation().deploymentInfo().isDeploying(calledAddress); final RomChunk chunk = @@ -147,27 +144,20 @@ public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMe code); this.chunks.add(chunk); - this.addressRomChunkMap.put(calledAddress, chunk); } }); } public void callRomLex(final MessageFrame frame) { switch (OpCode.of(frame.getCurrentOperation().getOpcode())) { - case CREATE -> { + case CREATE, CREATE2 -> { hub.defers().scheduleForPostExecution(this); - this.byteCode = this.hub.transients().op().callData(); - if (!this.byteCode.isEmpty()) { - this.address = getCreateAddress(frame); - } - } - case CREATE2 -> { - hub.defers().scheduleForPostExecution(this); - this.byteCode = this.hub.transients().op().callData(); - if (!this.byteCode.isEmpty()) { - this.address = getCreate2Address(frame); - } + final long offset = Words.clampedToLong(frame.getStackItem(1)); + final long length = Words.clampedToLong(frame.getStackItem(2)); + byteCode = frame.shadowReadMemory(offset, length); + address = getDeploymentAddress(frame); } + case RETURN -> { Preconditions.checkArgument(frame.getType() != MessageFrame.Type.CONTRACT_CREATION); Preconditions.checkArgument( @@ -189,7 +179,6 @@ public void callRomLex(final MessageFrame frame) { final RomChunk chunk = new RomChunk(contractMetadata, true, false, code); this.chunks.add(chunk); - this.addressRomChunkMap.put(contractMetadata.address(), chunk); } } @@ -212,7 +201,6 @@ public void callRomLex(final MessageFrame frame) { false, byteCode); chunks.add(chunk); - this.addressRomChunkMap.put(calledAddress, chunk); } }); } @@ -241,7 +229,6 @@ public void callRomLex(final MessageFrame frame) { byteCode); this.chunks.add(chunk); - this.addressRomChunkMap.put(calledAddress, chunk); } }); } @@ -261,7 +248,6 @@ public void resolvePostExecution( final RomChunk chunk = new RomChunk(contractMetadata, true, false, this.byteCode); this.chunks.add(chunk); this.createDefers.trigger(contractMetadata); - this.addressRomChunkMap.put(this.address, chunk); } // This is the tracing for ROMLEX module @@ -273,8 +259,8 @@ private void traceChunk( .codeFragmentIndex(cfi) .codeFragmentIndexInfty(codeFragmentIndexInfinity) .codeSize(chunk.byteCode().size()) - .addressHi(chunk.metadata().address().slice(0, 4).toLong()) - .addressLo(chunk.metadata().address().slice(4, LLARGE)) + .addressHi(highPart(chunk.metadata().address())) + .addressLo(lowPart(chunk.metadata().address())) .commitToState(chunk.commitToTheState()) .deploymentNumber(chunk.metadata().deploymentNumber()) .deploymentStatus(chunk.metadata().underDeployment()) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java index 1da9671aa8..5649aac6f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java @@ -22,6 +22,7 @@ import java.util.List; +import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.transients.OperationAncillaries; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; @@ -114,10 +115,8 @@ public static Address getCreate2Address(final MessageFrame frame) { public static Address getDeploymentAddress(final MessageFrame frame) { final OpCode opcode = OpCode.of(frame.getCurrentOperation().getOpcode()); - if (opcode.isAnyOf(OpCode.CREATE, OpCode.CREATE2)) { - return opcode.equals(OpCode.CREATE) ? getCreateAddress(frame) : getCreate2Address(frame); - } - throw new IllegalArgumentException("Must be called only for CREATE/CREATE2 opcode"); + Preconditions.checkArgument(opcode.isCreate(), "Must be called only for CREATE/CREATE2 opcode"); + return opcode.equals(OpCode.CREATE) ? getCreateAddress(frame) : getCreate2Address(frame); } public static Address addressFromBytes(final Bytes input) { From 83710fea8b3438a70e9e966a26f4fb1bfe3473c6 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 15 Aug 2024 18:24:25 +0530 Subject: [PATCH 372/461] add TODOs for @Lorenzo Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/ecdata/EcDataOperation.java | 1 + .../EllipticCurvePrecompileSubsection.java | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 24c3d8f1fe..4ef33e6a4d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -206,6 +206,7 @@ public static EcDataOperation of( return ecDataRes; } + //TODO @Lorenzo this is not needed anymore as we have the output from ecDataCall public void setReturnData(Bytes returnData) { switch (precompileFlag) { case PRC_ECRECOVER -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index c4e10d39fc..8376dbce29 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -58,6 +58,14 @@ public EllipticCurvePrecompileSubsection(Hub hub, CallSection callSection) { public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); + //TODO Lorenzo + //callEcDAta here, when you're here we have input and output of the EcDAta precompile + + // input == callData() + // ouptut == returnData + + // @ Lorenzo hub.ecData.callEcdata(inoyt, output, maybe more stuff); + // sanity checks switch (flag()) { case PRC_ECRECOVER -> { From 88e7607c52046411dcc42251a7a27e98e0747ab5 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 15 Aug 2024 15:33:50 +0200 Subject: [PATCH 373/461] feat(ecdata): update trigger using callEcData instead tracePreOpCode --- .../linea/zktracer/module/ecdata/EcData.java | 13 +++--- .../module/ecdata/EcDataOperation.java | 40 +++++++++---------- .../EllipticCurvePrecompileSubsection.java | 8 +--- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index f8a5b7f040..dd75186e0e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.ecdata; -import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.addressToPrecompileFlag; - import java.nio.MappedByteBuffer; import java.util.Comparator; import java.util.List; @@ -29,6 +27,7 @@ import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.ext.Ext; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingFinalExponentiations; @@ -36,11 +35,9 @@ import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingMillerLoops; import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall; import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.types.MemorySpan; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; @RequiredArgsConstructor public class EcData implements Module { @@ -79,6 +76,7 @@ public void popTransaction() { @Override public void tracePreOpcode(MessageFrame frame) { + /* final Address target = Words.toAddress(frame.getStackItem(1)); if (!EC_PRECOMPILES.contains(target)) { return; @@ -96,6 +94,7 @@ public void tracePreOpcode(MessageFrame frame) { EcDataOperation.of( this.wcp, this.ext, hub.precompileId(), addressToPrecompileFlag(target), data); this.operations.add(ecDataOperation); + */ } @Override @@ -128,7 +127,11 @@ public void commit(List buffers) { } } - public void callEcdata(final EcDataOperation ecDataOperation) { + public void callEcdata( + PrecompileScenarioFragment.PrecompileFlag precompileFlag, Bytes callData, Bytes returnData) { + this.ecDataOperation = + EcDataOperation.of( + this.wcp, this.ext, hub.precompileId(), precompileFlag, callData, returnData); this.operations.add(ecDataOperation); switch (ecDataOperation.precompileFlag()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 4ef33e6a4d..326a5836bd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -135,21 +135,22 @@ private EcDataOperation( Ext ext, int id, final PrecompileScenarioFragment.PrecompileFlag precompileFlag, - Bytes data) { + Bytes callData, + Bytes returnData) { Preconditions.checkArgument(precompileFlag.isEcdataPrecompile(), "invalid EC type"); this.precompileFlag = precompileFlag; final int paddedCallDataLength = this.precompileFlag == PRC_ECMUL ? 96 : 128; - if (data.size() < paddedCallDataLength) { - this.data = leftPadTo(data, paddedCallDataLength); + if (callData.size() < paddedCallDataLength) { + this.data = leftPadTo(callData, paddedCallDataLength); } else { // TODO: why keep the entire data rather than data[0:paddedCallDataLength] ? - this.data = data; + this.data = callData; } if (precompileFlag == PRC_ECPAIRING) { - Preconditions.checkArgument(data.size() % 192 == 0); - totalPairings = data.size() / 192; + Preconditions.checkArgument(callData.size() % 192 == 0); + totalPairings = callData.size() / 192; } else { totalPairings = 0; } @@ -188,6 +189,9 @@ private EcDataOperation( overallTrivialPairing = repeat(true, nRows); notOnG2 = repeat(false, nRows); notOnG2Acc = repeat(false, nRows); + + // Set returnData + setReturnData(returnData); } public static EcDataOperation of( @@ -195,18 +199,19 @@ public static EcDataOperation of( Ext ext, int id, final PrecompileScenarioFragment.PrecompileFlag precompileFlag, - Bytes data) { - EcDataOperation ecDataRes = new EcDataOperation(wcp, ext, id, precompileFlag, data); + Bytes callData, + Bytes returnData) { + EcDataOperation ecDataOperation = + new EcDataOperation(wcp, ext, id, precompileFlag, callData, returnData); switch (precompileFlag) { - case PRC_ECRECOVER -> ecDataRes.handleRecover(); - case PRC_ECADD -> ecDataRes.handleAdd(); - case PRC_ECMUL -> ecDataRes.handleMul(); - case PRC_ECPAIRING -> ecDataRes.handlePairing(); + case PRC_ECRECOVER -> ecDataOperation.handleRecover(); + case PRC_ECADD -> ecDataOperation.handleAdd(); + case PRC_ECMUL -> ecDataOperation.handleMul(); + case PRC_ECPAIRING -> ecDataOperation.handlePairing(); } - return ecDataRes; + return ecDataOperation; } - //TODO @Lorenzo this is not needed anymore as we have the output from ecDataCall public void setReturnData(Bytes returnData) { switch (precompileFlag) { case PRC_ECRECOVER -> { @@ -271,13 +276,6 @@ public void setReturnData(Bytes returnData) { limb.set(limb.size() - 1, pairingResult.lo()); // Set callSuccess - /* - if (!internalChecksPassed || notOnG2AccMax) { - callSuccess = false; - } else { - callSuccess = true; - } - */ if (!internalChecksPassed) { successBit = false; } else { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index 8376dbce29..86a5dbe9da 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -58,13 +58,7 @@ public EllipticCurvePrecompileSubsection(Hub hub, CallSection callSection) { public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); - //TODO Lorenzo - //callEcDAta here, when you're here we have input and output of the EcDAta precompile - - // input == callData() - // ouptut == returnData - - // @ Lorenzo hub.ecData.callEcdata(inoyt, output, maybe more stuff); + hub.ecData.callEcdata(flag(), callData(), returnData()); // sanity checks switch (flag()) { From 36c044bfdb421a778c46649e3cdbb9ccd47e9e0a Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 15 Aug 2024 17:57:49 +0200 Subject: [PATCH 374/461] fix(ecdata): remove tracePreOpCode completely --- .../linea/zktracer/module/ecdata/EcData.java | 12 +++++------- .../EllipticCurvePrecompileSubsection.java | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index dd75186e0e..ee81425896 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -37,7 +37,6 @@ import net.consensys.linea.zktracer.module.wcp.Wcp; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.frame.MessageFrame; @RequiredArgsConstructor public class EcData implements Module { @@ -74,15 +73,14 @@ public void popTransaction() { this.operations.pop(); } - @Override + /* public void tracePreOpcode(MessageFrame frame) { - /* final Address target = Words.toAddress(frame.getStackItem(1)); if (!EC_PRECOMPILES.contains(target)) { return; } final MemorySpan callDataSource = hub.transients().op().callDataSegment(); - + TODO: where this check should be moved? if (target.equals(Address.ALTBN128_PAIRING) && (callDataSource.isEmpty() || callDataSource.length() % 192 != 0)) { return; @@ -94,8 +92,8 @@ public void tracePreOpcode(MessageFrame frame) { EcDataOperation.of( this.wcp, this.ext, hub.precompileId(), addressToPrecompileFlag(target), data); this.operations.add(ecDataOperation); - */ } + */ @Override public int lineCount() { @@ -118,7 +116,7 @@ public void commit(List buffers) { for (EcDataOperation op : sortedOperations) { // TODO: temporary hack, we should have only successful EcData Operations, will be fixed in PR - // #748 + // #748 if (op.successBit()) { stamp++; op.trace(trace, stamp, previousId); @@ -127,7 +125,7 @@ public void commit(List buffers) { } } - public void callEcdata( + public void callEcData( PrecompileScenarioFragment.PrecompileFlag precompileFlag, Bytes callData, Bytes returnData) { this.ecDataOperation = EcDataOperation.of( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index 86a5dbe9da..8ead41e0f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -58,7 +58,7 @@ public EllipticCurvePrecompileSubsection(Hub hub, CallSection callSection) { public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); - hub.ecData.callEcdata(flag(), callData(), returnData()); + hub.ecData.callEcData(flag(), callData(), returnData()); // sanity checks switch (flag()) { From a6e66e00f355ea6ce290dbc458c7d0918a0f1156 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 16 Aug 2024 08:17:59 +0530 Subject: [PATCH 375/461] fix: move the triggering of ecdata after the check that the call is successfull Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/ecdata/EcData.java | 33 ++++--------------- .../linea/zktracer/module/hub/Hub.java | 5 --- .../EllipticCurvePrecompileSubsection.java | 8 +++-- .../PrecompileSubsection.java | 4 +-- 4 files changed, 14 insertions(+), 36 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index ee81425896..80fa4d1353 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -26,7 +26,6 @@ import net.consensys.linea.zktracer.container.stacked.set.StackedSet; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.ext.Ext; -import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall; @@ -44,7 +43,6 @@ public class EcData implements Module { Set.of(Address.ECREC, Address.ALTBN128_ADD, Address.ALTBN128_MUL, Address.ALTBN128_PAIRING); @Getter private final StackedSet operations = new StackedSet<>(); - private final Hub hub; private final Wcp wcp; private final Ext ext; @@ -73,28 +71,6 @@ public void popTransaction() { this.operations.pop(); } - /* - public void tracePreOpcode(MessageFrame frame) { - final Address target = Words.toAddress(frame.getStackItem(1)); - if (!EC_PRECOMPILES.contains(target)) { - return; - } - final MemorySpan callDataSource = hub.transients().op().callDataSegment(); - TODO: where this check should be moved? - if (target.equals(Address.ALTBN128_PAIRING) - && (callDataSource.isEmpty() || callDataSource.length() % 192 != 0)) { - return; - } - - final Bytes data = hub.transients().op().callData(); - - this.ecDataOperation = - EcDataOperation.of( - this.wcp, this.ext, hub.precompileId(), addressToPrecompileFlag(target), data); - this.operations.add(ecDataOperation); - } - */ - @Override public int lineCount() { return this.operations.lineCount(); @@ -111,6 +87,7 @@ public void commit(List buffers) { int stamp = 0; long previousId = 0; + // TODO: operations should come in the right order now, no need to sort them. To test. List sortedOperations = this.operations.stream().sorted(Comparator.comparingLong(EcDataOperation::id)).toList(); @@ -126,10 +103,12 @@ public void commit(List buffers) { } public void callEcData( - PrecompileScenarioFragment.PrecompileFlag precompileFlag, Bytes callData, Bytes returnData) { + final int id, + final PrecompileScenarioFragment.PrecompileFlag precompileFlag, + final Bytes callData, + final Bytes returnData) { this.ecDataOperation = - EcDataOperation.of( - this.wcp, this.ext, hub.precompileId(), precompileFlag, callData, returnData); + EcDataOperation.of(this.wcp, this.ext, id, precompileFlag, callData, returnData); this.operations.add(ecDataOperation); switch (ecDataOperation.precompileFlag()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 0c86b93642..7e728499dd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -285,7 +285,6 @@ private List precompileLimitModules() { @Getter public final EcData ecData = new EcData( - this, wcp, ext, ecAddEffectiveCall, @@ -845,10 +844,6 @@ public int newChildContextNumber() { return 1 + this.stamp(); } - public int precompileId() { - return newChildContextNumber(); - } - public CallFrame currentFrame() { if (this.callStack().isEmpty()) { return CallFrame.EMPTY; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java index 8ead41e0f1..d40006f822 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/EllipticCurvePrecompileSubsection.java @@ -58,8 +58,6 @@ public EllipticCurvePrecompileSubsection(Hub hub, CallSection callSection) { public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { super.resolveAtContextReEntry(hub, callFrame); - hub.ecData.callEcData(flag(), callData(), returnData()); - // sanity checks switch (flag()) { case PRC_ECRECOVER -> { @@ -105,6 +103,12 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { default -> throw new IllegalArgumentException("Not an elliptic curve precompile"); } firstImcFragment.callMmu(firstMmuCall); + + hub.ecData.callEcData( + exoModuleOperationId(), + flag(), + callData(), + returnData()); // TODO @Lorenzo @Olivier : verify it's at the right position } final ImcFragment secondImcFragment = ImcFragment.empty(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index 7e053b9242..c088bc799d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -184,7 +184,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca } public int exoModuleOperationId() { - return this.callSection.hubStamp() + 1; + return callSection.hubStamp() + 1; } public int returnDataContextNumber() { @@ -196,6 +196,6 @@ public PrecompileScenarioFragment.PrecompileFlag flag() { } public void setScenario(PrecompileScenarioFragment.PrecompileScenario scenario) { - this.precompileScenarioFragment.scenario(scenario); + precompileScenarioFragment.scenario(scenario); } } From 54de55fe116678483728fa77c56934784bc28b80 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 16 Aug 2024 13:24:19 +0530 Subject: [PATCH 376/461] fix: delete ecdata from signals Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 29 ------------------- .../zktracer/module/hub/signals/Signals.java | 6 ---- 2 files changed, 35 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 7e728499dd..220070b36f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -171,9 +171,6 @@ public class Hub implements Module { /** stores all data related to failure states & module activation */ @Getter private final PlatformController pch = new PlatformController(this); - // TODO: should die - private boolean previousOperationWasCallToEcPrecompile; - @Override public String moduleKey() { return "HUB"; @@ -790,11 +787,6 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.defers.resolvePostExecution(this, frame, operationResult); - // TODO this should die - if (this.previousOperationWasCallToEcPrecompile) { - this.ecData.getEcDataOperation().returnData(frame.getReturnData()); - } - if (!this.currentFrame().opCode().isCall() && !this.currentFrame().opCode().isCreate()) { this.unlatchStack(frame); } @@ -905,11 +897,6 @@ void triggerModules(MessageFrame frame) { if (this.pch.signals().hashInfo()) { // TODO: this.hashInfo.tracePreOpcode(frame); } - if (this.pch - .signals() - .ecData()) { // TODO why do we have this ? Shouldn't it be triggered by a precompileLimits ? - this.ecData.tracePreOpcode(frame); - } if (this.pch.signals().blockhash()) { this.blockhash.tracePreOpcode(frame); } @@ -967,11 +954,6 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { void processStateExec(MessageFrame frame) { - if (previousOperationWasCallToEcPrecompile) { - this.ecData.getEcDataOperation().returnData(frame.getReturnData()); - previousOperationWasCallToEcPrecompile = false; - } - this.state.stamps().incrementHubStamp(); this.pch.setup(frame); @@ -984,17 +966,6 @@ void processStateExec(MessageFrame frame) { } if (this.currentFrame().stack().isOk()) { - // TODO: this is insufficient because it neglects: - // - exceptions other than stack exceptions e.g. - // * STATICX - // * MXPX - // * OOGX - // - it COULD (unlikely ?) produce issues with ABORTS - // - it COULD interfere with CALL's to precompiles that don't reach EC_DATA e.g. - // * ECRECOVER, ECADD, ECMUL, ECPAIRING with zero call data size parameter - if (this.pch.signals().ecData()) { - this.previousOperationWasCallToEcPrecompile = true; - } this.traceOpcode(frame); } else { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java index 1fd3d8bbdf..ab58fe0833 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/signals/Signals.java @@ -15,8 +15,6 @@ package net.consensys.linea.zktracer.module.hub.signals; -import static net.consensys.linea.zktracer.module.ecdata.EcData.EC_PRECOMPILES; - import java.util.Optional; import java.util.Set; @@ -64,7 +62,6 @@ public class Signals { @Getter private boolean trm; @Getter private boolean hashInfo; @Getter private boolean rlpAddr; - @Getter private boolean ecData; private final PlatformController platformController; @@ -86,7 +83,6 @@ public void reset() { this.trm = false; this.hashInfo = false; this.rlpAddr = false; - this.ecData = false; } public Signals snapshot() { @@ -108,7 +104,6 @@ public Signals snapshot() { r.trm = this.trm; r.hashInfo = this.hashInfo; r.rlpAddr = this.rlpAddr; - r.ecData = this.ecData; return r; } @@ -150,7 +145,6 @@ public void prepare(MessageFrame frame, PlatformController platformController, H .map(AccountState::hasCode) .orElse(false); - this.ecData = Exceptions.none(ex) && EC_PRECOMPILES.contains(target); this.exp = Exceptions.none(ex) && this.platformController.abortingConditions().none() From 3acb97889e2d5b8655d9e701bdd0a96f199dcc1a Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 16 Aug 2024 15:53:18 +0530 Subject: [PATCH 377/461] fix deployment status for CREATE's in RomLex Signed-off-by: Francois Bojarski --- .../zktracer/module/hub/section/CreateSection.java | 6 ++---- .../consensys/linea/zktracer/module/romlex/RomLex.java | 10 +++++++--- .../linea/zktracer/runtime/callstack/CallFrame.java | 6 +----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index f0a0925abe..d0c8a26d1c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -70,8 +70,6 @@ public class CreateSection extends TraceSection ContextReEntryDefer, PostTransactionDefer { - private int creatorContextId; - // Just before create private AccountSnapshot preOpcodeCreatorSnapshot; private AccountSnapshot preOpcodeCreateeSnapshot; @@ -200,7 +198,7 @@ public CreateSection(Hub hub) { } if (failedCreate || emptyInitCode) { - this.finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); + finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); if (failedCreate) { scenarioFragment.setScenario(CREATE_FAILURE_CONDITION_WONT_REVERT); @@ -318,7 +316,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca @Override public void resolvePostTransaction( Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { - this.addFragment(this.finalContextFragment); + addFragment(finalContextFragment); } private static short maxNumberOfLines(final short exceptions, final AbortingConditions abort) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index f57e5149c7..e69c56b20b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -77,6 +77,12 @@ public void popTransaction() { this.chunks.pop(); } + public int getCodeFragmentIndexByMetadata( + final Address address, final int deploymentNumber, final boolean depStatus) { + return getCodeFragmentIndexByMetadata( + ContractMetadata.make(address, deploymentNumber, depStatus)); + } + public int getCodeFragmentIndexByMetadata(final ContractMetadata metadata) { if (this.sortedChunks.isEmpty()) { throw new RuntimeException("Chunks have not been sorted yet"); @@ -240,10 +246,8 @@ public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { Preconditions.checkArgument(hub.opCode().isCreate()); final int depNumber = hub.transients().conflation().deploymentInfo().number(this.address); - final boolean depStatus = - hub.transients().conflation().deploymentInfo().isDeploying(this.address); final ContractMetadata contractMetadata = - ContractMetadata.make(this.address, depNumber, depStatus); + ContractMetadata.underDeployment(this.address, depNumber); final RomChunk chunk = new RomChunk(contractMetadata, true, false, this.byteCode); this.chunks.add(chunk); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java index 528a5022c2..091efef55f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/callstack/CallFrame.java @@ -38,7 +38,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.internal.Words; @Accessors(fluent = true) public class CallFrame { @@ -98,10 +97,7 @@ public boolean isMessageCall() { public int getCodeFragmentIndex(Hub hub) { return this == CallFrame.EMPTY || this.type() == CallFrameType.TRANSACTION_CALL_DATA_HOLDER ? 0 - : hub.getCfiByMetaData( - Words.toAddress(this.codeAddressAsEWord()), - this.codeDeploymentNumber(), - this.isDeployment()); + : hub.getCfiByMetaData(byteCodeAddress, codeDeploymentNumber, isDeployment); } @Getter @Setter private int pc; From 301d3231f62640367dcd3f452bb00c942963cd35 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 16 Aug 2024 17:59:13 +0530 Subject: [PATCH 378/461] fix(mmu/prprc/anyToRamWithPadding): need at row 3 results of rows 5 & 6 Signed-off-by: Francois Bojarski --- .../hub/section/copy/CallDataCopySection.java | 2 +- .../mmu/instructions/AnyToRamWithPadding.java | 73 +++++++++++-------- 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index e279431934..fed5c950e6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -71,7 +71,7 @@ public CallDataCopySection(Hub hub) { return; } - MmuCall mmuCall = MmuCall.callDataCopy(hub); + final MmuCall mmuCall = MmuCall.callDataCopy(hub); imcFragment.callMmu(mmuCall); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java index 6e759e1fb1..e22c74efac 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java @@ -114,7 +114,7 @@ public MmuData preProcess(MmuData mmuData, final CallStack callStack) { // Setting subCase in MmuData mmuData.mmuInstAnyToRamWithPaddingIsPurePadding(purePadding); - // PrProcessing depending on the subcase + // PreProcessing depending on the subcase if (purePadding) { purePaddingCasePreProcessing(); } else { @@ -140,10 +140,14 @@ public MmuData preProcess(MmuData mmuData, final CallStack callStack) { } private void someDataCasePreProcessing(final HubToMmuValues hubToMmuValues) { + // The result of the computation of row 5 & 6 are used at row 3 + final MmuEucCallRecord eucOpRow5 = eucCallMinSourceOffset(hubToMmuValues); + final MmuEucCallRecord eucOpRow6 = eucCallMaxSourceOffset(); + someDataRow3(hubToMmuValues); someDataRow4(); - someDataRow5(hubToMmuValues); - someDataRow6(); + someDataRow5(eucOpRow5); + someDataRow6(eucOpRow6); someDataRow7(); someDataRow8(); someDataRow9(); @@ -183,7 +187,7 @@ private void sharedRow1(final HubToMmuValues hubToMmuValues) { minTargetOffset = hubToMmuValues.targetOffset(); maxTargetOffset = (minTargetOffset + hubToMmuValues.size() - 1); final long dividend = minTargetOffset; - EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); + final EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); eucCallRecords.add( MmuEucCallRecord.builder() .dividend(dividend) @@ -275,6 +279,36 @@ private void purePaddingRow4() { onlyPaddingSize = (short) paddingSize; } + private MmuEucCallRecord eucCallMinSourceOffset(final HubToMmuValues hubToMmuValues) { + minSourceOffset = + (hubToMmuValues.sourceOffsetLo().longValueExact() + hubToMmuValues.referenceOffset()); + final long dividend = minSourceOffset; + final EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); + + minSourceLimbOffset = eucOp.quotient().toLong(); + minSourceByteOffset = (short) eucOp.remainder().toInt(); + + return MmuEucCallRecord.builder() + .dividend(dividend) + .divisor((short) LLARGE) + .quotient(eucOp.quotient().toLong()) + .remainder((short) eucOp.remainder().toInt()) + .build(); + } + + private MmuEucCallRecord eucCallMaxSourceOffset() { + final long dividend = minSourceOffset + transferSize - 1; + final EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); + maxSourceLimbOffset = eucOp.quotient().toLong(); + maxSourceByteOffset = (short) eucOp.remainder().toInt(); + return MmuEucCallRecord.builder() + .dividend(dividend) + .divisor((short) LLARGE) + .quotient(eucOp.quotient().toLong()) + .remainder((short) eucOp.remainder().toInt()) + .build(); + } + private void someDataRow3(final HubToMmuValues hubToMmuValues) { final Bytes wcpArg1 = longToBytes(hubToMmuValues.exoSum()); final boolean wcpResult = wcp.callISZERO(wcpArg1); @@ -300,20 +334,8 @@ private void someDataRow4() { eucCallRecords.add(MmuEucCallRecord.EMPTY_CALL); } - private void someDataRow5(final HubToMmuValues hubToMmuValues) { - minSourceOffset = - (hubToMmuValues.sourceOffsetLo().longValueExact() + hubToMmuValues.referenceOffset()); - final long dividend = minSourceOffset; - EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); - eucCallRecords.add( - MmuEucCallRecord.builder() - .dividend(dividend) - .divisor((short) LLARGE) - .quotient(eucOp.quotient().toLong()) - .remainder((short) eucOp.remainder().toInt()) - .build()); - minSourceLimbOffset = eucOp.quotient().toLong(); - minSourceByteOffset = (short) eucOp.remainder().toInt(); + private void someDataRow5(final MmuEucCallRecord eucOperation) { + eucCallRecords.add(eucOperation); final Bytes wcpArg1 = longToBytes(minTargetByteOffset); final Bytes wcpArg2 = longToBytes(minSourceByteOffset); @@ -323,19 +345,8 @@ private void someDataRow5(final HubToMmuValues hubToMmuValues) { aligned = wcpResult; } - private void someDataRow6() { - final long dividend = minSourceOffset + transferSize - 1; - EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); - eucCallRecords.add( - MmuEucCallRecord.builder() - .dividend(dividend) - .divisor((short) LLARGE) - .quotient(eucOp.quotient().toLong()) - .remainder((short) eucOp.remainder().toInt()) - .build()); - maxSourceLimbOffset = eucOp.quotient().toLong(); - maxSourceByteOffset = (short) eucOp.remainder().toInt(); - + private void someDataRow6(final MmuEucCallRecord eucOperation) { + eucCallRecords.add(eucOperation); wcpCallRecords.add(MmuWcpCallRecord.EMPTY_CALL); } From f2c86336644b44aba2935c1a705de73ebfb754f1 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 16 Aug 2024 23:17:36 +0530 Subject: [PATCH 379/461] fix(stp): trace all columns Signed-off-by: Francois Bojarski --- .../zktracer/module/stp/StpOperation.java | 42 +++--- .../linea/zktracer/module/stp/Trace.java | 139 +++++++----------- gradle/trace-files.gradle | 2 +- 3 files changed, 74 insertions(+), 109 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java index a962f11061..f3241a1cdd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/StpOperation.java @@ -92,10 +92,6 @@ private void traceCreate(Trace trace, int stamp) { .instruction(UnsignedByte.of(stpCall.opCode().byteValue())) .isCreate(isCreate()) .isCreate2(isCreate2()) - .isCall(false) - .isCallcode(false) - .isDelegatecall(false) - .isStaticcall(false) // .gasHi(Bytes.EMPTY) // redundant // .gasLo(Bytes.EMPTY) // redundant .valHi(stpCall.value().slice(0, 16)) @@ -103,11 +99,11 @@ private void traceCreate(Trace trace, int stamp) { // .exists(false) // redundant // .warm(false) // redundant .outOfGasException(stpCall.outOfGasException()) - .gasActual(Bytes.ofUnsignedLong(stpCall.gasActual())) - .gasMxp(Bytes.ofUnsignedLong(stpCall.memoryExpansionGas())) - .gasUpfront(Bytes.ofUnsignedLong(stpCall.upfrontGasCost())) - .gasOutOfPocket(Bytes.ofUnsignedLong(gasOopkt)) - .gasStipend(Bytes.ofUnsignedLong(stpCall.stipend())) + .gasActual(stpCall.gasActual()) + .gasMxp(stpCall.memoryExpansionGas()) + .gasUpfront(stpCall.upfrontGasCost()) + .gasOutOfPocket(gasOopkt) + .gasStipend(stpCall.stipend()) .arg1Hi(Bytes.EMPTY); switch (ct) { @@ -118,7 +114,7 @@ private void traceCreate(Trace trace, int stamp) { .resLo(Bytes.EMPTY) // we REQUIRE that the currently available gas is nonnegative .wcpFlag(true) .modFlag(false) - .validateRow(); + .fillAndValidateRow(); case 1 -> trace .arg1Lo(Bytes.ofUnsignedLong(stpCall.gasActual())) .arg2Lo(Bytes.ofUnsignedLong(stpCall.upfrontGasCost())) @@ -126,7 +122,7 @@ private void traceCreate(Trace trace, int stamp) { .resLo(Bytes.of(stpCall.outOfGasException() ? 1 : 0)) .wcpFlag(true) .modFlag(false) - .validateRow(); + .fillAndValidateRow(); case 2 -> trace .arg1Lo(Bytes.ofUnsignedLong(getGDiff())) .arg2Lo(Bytes.of(64)) @@ -134,7 +130,7 @@ private void traceCreate(Trace trace, int stamp) { .resLo(Bytes.ofUnsignedLong(getGDiffOver64())) .wcpFlag(false) .modFlag(true) - .validateRow(); + .fillAndValidateRow(); default -> throw new IllegalArgumentException("counter too big, should be <=" + ctMax); } } @@ -148,8 +144,6 @@ private void traceCall(Trace trace, int stamp) { .ct(UnsignedByte.of(ct)) .ctMax(UnsignedByte.of(ctMax)) .instruction(UnsignedByte.of(stpCall.opCode().byteValue())) - .isCreate(false) - .isCreate2(false) .isCall(isCall()) .isCallcode(isCallCode()) .isDelegatecall(isDelegateCall()) @@ -161,11 +155,11 @@ private void traceCall(Trace trace, int stamp) { .exists(stpCall.exists()) .warm(stpCall.warm()) .outOfGasException(stpCall.outOfGasException()) - .gasActual(Bytes.ofUnsignedLong(stpCall.gasActual())) - .gasMxp(Bytes.ofUnsignedLong(stpCall.memoryExpansionGas())) - .gasUpfront(Bytes.ofUnsignedLong(stpCall.upfrontGasCost())) - .gasOutOfPocket(Bytes.ofUnsignedLong(stpCall.gasPaidOutOfPocket())) - .gasStipend(Bytes.ofUnsignedLong(stpCall.stipend())); + .gasActual(stpCall.gasActual()) + .gasMxp(stpCall.memoryExpansionGas()) + .gasUpfront(stpCall.upfrontGasCost()) + .gasOutOfPocket(stpCall.gasPaidOutOfPocket()) + .gasStipend(stpCall.stipend()); switch (ct) { case 0 -> trace @@ -176,7 +170,7 @@ private void traceCall(Trace trace, int stamp) { .resLo(Bytes.EMPTY) // we REQUIRE that the currently available gas is nonnegative .wcpFlag(true) .modFlag(false) - .validateRow(); + .fillAndValidateRow(); case 1 -> trace .arg1Hi(stpCall.value().slice(0, 16)) .arg1Lo(stpCall.value().slice(16, 16)) @@ -185,7 +179,7 @@ private void traceCall(Trace trace, int stamp) { .resLo(Bytes.of(stpCall.value().isZero() ? 1 : 0)) .wcpFlag(stpCall.opCode().callCanTransferValue()) .modFlag(false) - .validateRow(); + .fillAndValidateRow(); case 2 -> trace .arg1Hi(Bytes.EMPTY) .arg1Lo(Bytes.ofUnsignedLong(stpCall.gasActual())) @@ -194,7 +188,7 @@ private void traceCall(Trace trace, int stamp) { .resLo(Bytes.of(stpCall.outOfGasException() ? 1 : 0)) .wcpFlag(true) .modFlag(false) - .validateRow(); + .fillAndValidateRow(); // the following rows are only filled in if no out of gas exception case 3 -> trace .arg1Hi(Bytes.EMPTY) @@ -204,7 +198,7 @@ private void traceCall(Trace trace, int stamp) { .resLo(Bytes.ofUnsignedLong(getGDiffOver64())) .wcpFlag(false) .modFlag(true) - .validateRow(); + .fillAndValidateRow(); case 4 -> trace .arg1Hi(stpCall.gas().slice(0, 16)) .arg1Lo(stpCall.gas().slice(16, 16)) @@ -221,7 +215,7 @@ private void traceCall(Trace trace, int stamp) { : 0)) .wcpFlag(true) .modFlag(false) - .validateRow(); + .fillAndValidateRow(); default -> throw new IllegalArgumentException("counter too big, should be <=" + ctMax); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Trace.java index f902e6dfd0..8a9c491a7e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/stp/Trace.java @@ -73,13 +73,13 @@ static List headers(int length) { new ColumnHeader("stp.CT_MAX", 1, length), new ColumnHeader("stp.EXISTS", 1, length), new ColumnHeader("stp.EXOGENOUS_MODULE_INSTRUCTION", 1, length), - new ColumnHeader("stp.GAS_ACTUAL", 32, length), + new ColumnHeader("stp.GAS_ACTUAL", 6, length), new ColumnHeader("stp.GAS_HI", 16, length), new ColumnHeader("stp.GAS_LO", 16, length), - new ColumnHeader("stp.GAS_MXP", 32, length), - new ColumnHeader("stp.GAS_OUT_OF_POCKET", 32, length), - new ColumnHeader("stp.GAS_STIPEND", 32, length), - new ColumnHeader("stp.GAS_UPFRONT", 32, length), + new ColumnHeader("stp.GAS_MXP", 6, length), + new ColumnHeader("stp.GAS_OUT_OF_POCKET", 6, length), + new ColumnHeader("stp.GAS_STIPEND", 6, length), + new ColumnHeader("stp.GAS_UPFRONT", 6, length), new ColumnHeader("stp.INSTRUCTION", 1, length), new ColumnHeader("stp.IS_CALL", 1, length), new ColumnHeader("stp.IS_CALLCODE", 1, length), @@ -260,28 +260,22 @@ public Trace exogenousModuleInstruction(final UnsignedByte b) { return this; } - public Trace gasActual(final Bytes b) { + public Trace gasActual(final long b) { if (filled.get(7)) { throw new IllegalStateException("stp.GAS_ACTUAL already set"); } else { filled.set(7); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 256) { - throw new IllegalArgumentException( - "gasActual has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { - gasActual.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasActual.put(bs.get(j)); + if (b >= 281474976710656L) { + throw new IllegalArgumentException("gasActual has invalid value (" + b + ")"); } + gasActual.put((byte) (b >> 40)); + gasActual.put((byte) (b >> 32)); + gasActual.put((byte) (b >> 24)); + gasActual.put((byte) (b >> 16)); + gasActual.put((byte) (b >> 8)); + gasActual.put((byte) b); return this; } @@ -336,105 +330,82 @@ public Trace gasLo(final Bytes b) { return this; } - public Trace gasMxp(final Bytes b) { + public Trace gasMxp(final long b) { if (filled.get(10)) { throw new IllegalStateException("stp.GAS_MXP already set"); } else { filled.set(10); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 256) { - throw new IllegalArgumentException("gasMxp has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { - gasMxp.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasMxp.put(bs.get(j)); + if (b >= 281474976710656L) { + throw new IllegalArgumentException("gasMxp has invalid value (" + b + ")"); } + gasMxp.put((byte) (b >> 40)); + gasMxp.put((byte) (b >> 32)); + gasMxp.put((byte) (b >> 24)); + gasMxp.put((byte) (b >> 16)); + gasMxp.put((byte) (b >> 8)); + gasMxp.put((byte) b); return this; } - public Trace gasOutOfPocket(final Bytes b) { + public Trace gasOutOfPocket(final long b) { if (filled.get(11)) { throw new IllegalStateException("stp.GAS_OUT_OF_POCKET already set"); } else { filled.set(11); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 256) { - throw new IllegalArgumentException( - "gasOutOfPocket has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { - gasOutOfPocket.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasOutOfPocket.put(bs.get(j)); + if (b >= 281474976710656L) { + throw new IllegalArgumentException("gasOutOfPocket has invalid value (" + b + ")"); } + gasOutOfPocket.put((byte) (b >> 40)); + gasOutOfPocket.put((byte) (b >> 32)); + gasOutOfPocket.put((byte) (b >> 24)); + gasOutOfPocket.put((byte) (b >> 16)); + gasOutOfPocket.put((byte) (b >> 8)); + gasOutOfPocket.put((byte) b); return this; } - public Trace gasStipend(final Bytes b) { + public Trace gasStipend(final long b) { if (filled.get(12)) { throw new IllegalStateException("stp.GAS_STIPEND already set"); } else { filled.set(12); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 256) { - throw new IllegalArgumentException( - "gasStipend has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { - gasStipend.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasStipend.put(bs.get(j)); + if (b >= 281474976710656L) { + throw new IllegalArgumentException("gasStipend has invalid value (" + b + ")"); } + gasStipend.put((byte) (b >> 40)); + gasStipend.put((byte) (b >> 32)); + gasStipend.put((byte) (b >> 24)); + gasStipend.put((byte) (b >> 16)); + gasStipend.put((byte) (b >> 8)); + gasStipend.put((byte) b); return this; } - public Trace gasUpfront(final Bytes b) { + public Trace gasUpfront(final long b) { if (filled.get(13)) { throw new IllegalStateException("stp.GAS_UPFRONT already set"); } else { filled.set(13); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 256) { - throw new IllegalArgumentException( - "gasUpfront has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { - gasUpfront.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasUpfront.put(bs.get(j)); + if (b >= 281474976710656L) { + throw new IllegalArgumentException("gasUpfront has invalid value (" + b + ")"); } + gasUpfront.put((byte) (b >> 40)); + gasUpfront.put((byte) (b >> 32)); + gasUpfront.put((byte) (b >> 24)); + gasUpfront.put((byte) (b >> 16)); + gasUpfront.put((byte) (b >> 8)); + gasUpfront.put((byte) b); return this; } @@ -816,7 +787,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(7)) { - gasActual.position(gasActual.position() + 32); + gasActual.position(gasActual.position() + 6); } if (!filled.get(8)) { @@ -828,19 +799,19 @@ public Trace fillAndValidateRow() { } if (!filled.get(10)) { - gasMxp.position(gasMxp.position() + 32); + gasMxp.position(gasMxp.position() + 6); } if (!filled.get(11)) { - gasOutOfPocket.position(gasOutOfPocket.position() + 32); + gasOutOfPocket.position(gasOutOfPocket.position() + 6); } if (!filled.get(12)) { - gasStipend.position(gasStipend.position() + 32); + gasStipend.position(gasStipend.position() + 6); } if (!filled.get(13)) { - gasUpfront.position(gasUpfront.position() + 32); + gasUpfront.position(gasUpfront.position() + 6); } if (!filled.get(14)) { diff --git a/gradle/trace-files.gradle b/gradle/trace-files.gradle index 49f7e47480..02e615a009 100644 --- a/gradle/trace-files.gradle +++ b/gradle/trace-files.gradle @@ -71,7 +71,7 @@ tasks.register('binreftable', TraceFilesTask) { ['bin', 'blockhash', 'euc', 'mmio', 'shf', 'wcp', 'rlptxn', 'rom', 'romlex', 'trm', 'stp', 'loginfo', 'logdata'].each {moduleName -> tasks.register(moduleName, TraceFilesTask) { group "Trace files generation" - dependsOn corsetExists + // dependsOn corsetExists module = moduleName files = ["${moduleName}/columns.lisp"] From 9d702479477a553ebecf7be016cd7b1f537f3315 Mon Sep 17 00:00:00 2001 From: FlorianHuc Date: Mon, 19 Aug 2024 11:34:18 +0200 Subject: [PATCH 380/461] initialize preOpcodeCreateeSnapshot before checking aborts as it's required --- .../linea/zktracer/module/hub/section/CreateSection.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index d0c8a26d1c..f91699df7f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -156,6 +156,9 @@ public CreateSection(Hub hub) { final Address creatorAddress = callFrame.accountAddress(); preOpcodeCreatorSnapshot = AccountSnapshot.canonical(hub, creatorAddress); + final Address createeAddress = getDeploymentAddress(frame); + preOpcodeCreateeSnapshot = AccountSnapshot.canonical(hub, createeAddress); + if (aborts.any()) { scenarioFragment.setScenario(CREATE_ABORT); this.finishAbortCreate(hub); @@ -168,10 +171,9 @@ public CreateSection(Hub hub) { hub.defers().scheduleForPostRollback(this, hub.currentFrame()); // in case of Rollback hub.defers().scheduleForPostTransaction(this); // when we add the last context row - final Address createeAddress = getDeploymentAddress(frame); rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createeAddress); - preOpcodeCreateeSnapshot = AccountSnapshot.canonical(hub, createeAddress); + final Optional deploymentAccount = Optional.ofNullable(frame.getWorldUpdater().get(createeAddress)); From 46c79fa7a6536b7d64fc3d1001e0c9d778832001 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 19 Aug 2024 16:53:11 +0530 Subject: [PATCH 381/461] fix: mix between CREATE and CREATE2 in stack rows, thank you Florian Signed-off-by: Francois Bojarski --- .../module/hub/section/CreateSection.java | 2 -- .../linea/zktracer/runtime/stack/Stack.java | 17 ++++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index f91699df7f..566801f2cf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -173,8 +173,6 @@ public CreateSection(Hub hub) { rlpAddrSubFragment = RlpAddrSubFragment.makeFragment(hub, createeAddress); - - final Optional deploymentAccount = Optional.ofNullable(frame.getWorldUpdater().get(createeAddress)); final boolean createdAddressHasNonZeroNonce = 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 a74a35eba9..4af532d495 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 @@ -324,17 +324,18 @@ private void call(MessageFrame frame, StackContext pending) { } private void create(MessageFrame frame, StackContext pending) { - Bytes val1 = getStack(frame, 1); - Bytes val2 = getStack(frame, 2); + final Bytes val1 = getStack(frame, 1); + final Bytes val2 = getStack(frame, 2); pending.addLine( new IndexedStackOperation( 1, StackOperation.pop(this.height - 1, val1, stackStampWithOffset(1))), new IndexedStackOperation( 2, StackOperation.pop(this.height - 2, val2, stackStampWithOffset(2)))); - if (this.currentOpcodeData.stackSettings().flag1()) { - Bytes val3 = getStack(frame, 3); - Bytes val4 = getStack(frame, 0); + // case CREATE2 + if (this.currentOpcodeData.stackSettings().flag2()) { + final Bytes val3 = getStack(frame, 3); + final Bytes val4 = getStack(frame, 0); pending.addArmingLine( new IndexedStackOperation( @@ -343,8 +344,10 @@ private void create(MessageFrame frame, StackContext pending) { 3, StackOperation.pop(this.height, val4, stackStampWithOffset(0))), new IndexedStackOperation( 4, StackOperation.push(this.height - 3, stackStampWithOffset(4)))); - } else { - Bytes val4 = getStack(frame, 0); + } else + // case CREATE + { + final Bytes val4 = getStack(frame, 0); pending.addArmingLine( new IndexedStackOperation( From fe53da9ad160851b9d1eee9444310b8daccfe499 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 19 Aug 2024 19:13:42 +0200 Subject: [PATCH 382/461] feat(oob): add MAX_NONCE business --- .../linea/zktracer/module/add/Trace.java | 164 ++++-- .../imc/oob/opcodes/CallDataLoadOobCall.java | 3 +- .../fragment/imc/oob/opcodes/CallOobCall.java | 3 +- .../imc/oob/opcodes/CreateOobCall.java | 4 +- .../imc/oob/opcodes/DeploymentOobCall.java | 3 +- .../fragment/imc/oob/opcodes/JumpOobCall.java | 3 +- .../imc/oob/opcodes/JumpiOobCall.java | 3 +- .../oob/opcodes/ReturnDataCopyOobCall.java | 3 +- .../imc/oob/opcodes/SstoreOobCall.java | 3 +- .../imc/oob/opcodes/XCallOobCall.java | 3 +- .../Blake2fCallDataSizeOobCall.java | 3 +- .../oob/precompiles/Blake2fParamsOobCall.java | 3 +- .../ModexpCallDataSizeOobCall.java | 3 +- .../oob/precompiles/ModexpExtractOobCall.java | 3 +- .../oob/precompiles/ModexpLeadOobCall.java | 3 +- .../oob/precompiles/ModexpPricingOobCall.java | 3 +- .../imc/oob/precompiles/ModexpXbsOobCall.java | 3 +- .../precompiles/PrecompileCommonOobCall.java | 3 +- .../linea/zktracer/module/oob/Oob.java | 3 +- .../zktracer/module/oob/OobOperation.java | 13 +- .../linea/zktracer/module/oob/Trace.java | 479 +++++++++--------- zkevm-constraints | 2 +- 22 files changed, 423 insertions(+), 290 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java index 191bd1c6a0..b1df4b1234 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java @@ -52,21 +52,21 @@ public class Trace { static List headers(int length) { return List.of( - new ColumnHeader("add.ACC_1", 32, length), - new ColumnHeader("add.ACC_2", 32, length), - new ColumnHeader("add.ARG_1_HI", 32, length), - new ColumnHeader("add.ARG_1_LO", 32, length), - new ColumnHeader("add.ARG_2_HI", 32, length), - new ColumnHeader("add.ARG_2_LO", 32, length), + new ColumnHeader("add.ACC_1", 16, length), + new ColumnHeader("add.ACC_2", 16, length), + new ColumnHeader("add.ARG_1_HI", 16, length), + new ColumnHeader("add.ARG_1_LO", 16, length), + new ColumnHeader("add.ARG_2_HI", 16, length), + new ColumnHeader("add.ARG_2_LO", 16, length), new ColumnHeader("add.BYTE_1", 1, length), new ColumnHeader("add.BYTE_2", 1, length), new ColumnHeader("add.CT", 1, length), new ColumnHeader("add.CT_MAX", 1, length), new ColumnHeader("add.INST", 1, length), new ColumnHeader("add.OVERFLOW", 1, length), - new ColumnHeader("add.RES_HI", 32, length), - new ColumnHeader("add.RES_LO", 32, length), - new ColumnHeader("add.STAMP", 8, length)); + new ColumnHeader("add.RES_HI", 16, length), + new ColumnHeader("add.RES_LO", 16, length), + new ColumnHeader("add.STAMP", 4, length)); } public Trace(List buffers) { @@ -102,11 +102,20 @@ public Trace acc1(final Bytes b) { filled.set(0); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { acc1.put((byte) 0); } - acc1.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + acc1.put(bs.get(j)); + } return this; } @@ -118,11 +127,20 @@ public Trace acc2(final Bytes b) { filled.set(1); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { acc2.put((byte) 0); } - acc2.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + acc2.put(bs.get(j)); + } return this; } @@ -134,11 +152,20 @@ public Trace arg1Hi(final Bytes b) { filled.set(2); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { arg1Hi.put((byte) 0); } - arg1Hi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + arg1Hi.put(bs.get(j)); + } return this; } @@ -150,11 +177,20 @@ public Trace arg1Lo(final Bytes b) { filled.set(3); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { arg1Lo.put((byte) 0); } - arg1Lo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + arg1Lo.put(bs.get(j)); + } return this; } @@ -166,11 +202,20 @@ public Trace arg2Hi(final Bytes b) { filled.set(4); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { arg2Hi.put((byte) 0); } - arg2Hi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + arg2Hi.put(bs.get(j)); + } return this; } @@ -182,11 +227,20 @@ public Trace arg2Lo(final Bytes b) { filled.set(5); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { arg2Lo.put((byte) 0); } - arg2Lo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + arg2Lo.put(bs.get(j)); + } return this; } @@ -270,11 +324,20 @@ public Trace resHi(final Bytes b) { filled.set(12); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { resHi.put((byte) 0); } - resHi.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + resHi.put(bs.get(j)); + } return this; } @@ -286,11 +349,20 @@ public Trace resLo(final Bytes b) { filled.set(13); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { resLo.put((byte) 0); } - resLo.put(b.toArrayUnsafe()); + // Write bytes + for (int j = 0; j < bs.size(); j++) { + resLo.put(bs.get(j)); + } return this; } @@ -302,7 +374,13 @@ public Trace stamp(final long b) { filled.set(14); } - stamp.putLong(b); + if (b >= 4294967296L) { + throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); + } + stamp.put((byte) (b >> 24)); + stamp.put((byte) (b >> 16)); + stamp.put((byte) (b >> 8)); + stamp.put((byte) b); return this; } @@ -376,27 +454,27 @@ public Trace validateRow() { public Trace fillAndValidateRow() { if (!filled.get(0)) { - acc1.position(acc1.position() + 32); + acc1.position(acc1.position() + 16); } if (!filled.get(1)) { - acc2.position(acc2.position() + 32); + acc2.position(acc2.position() + 16); } if (!filled.get(2)) { - arg1Hi.position(arg1Hi.position() + 32); + arg1Hi.position(arg1Hi.position() + 16); } if (!filled.get(3)) { - arg1Lo.position(arg1Lo.position() + 32); + arg1Lo.position(arg1Lo.position() + 16); } if (!filled.get(4)) { - arg2Hi.position(arg2Hi.position() + 32); + arg2Hi.position(arg2Hi.position() + 16); } if (!filled.get(5)) { - arg2Lo.position(arg2Lo.position() + 32); + arg2Lo.position(arg2Lo.position() + 16); } if (!filled.get(6)) { @@ -424,15 +502,15 @@ public Trace fillAndValidateRow() { } if (!filled.get(12)) { - resHi.position(resHi.position() + 32); + resHi.position(resHi.position() + 16); } if (!filled.get(13)) { - resLo.position(resLo.position() + 32); + resLo.position(resLo.position() + 16); } if (!filled.get(14)) { - stamp.position(stamp.position() + 8); + stamp.position(stamp.position() + 4); } filled.clear(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallDataLoadOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallDataLoadOobCall.java index a54178e248..3d3e3ae64d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallDataLoadOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallDataLoadOobCall.java @@ -57,7 +57,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(cds)) .data6(ZERO) .data7(booleanToBytes(cdlOutOfBounds)) - .data8(ZERO); + .data8(ZERO) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java index a3040695fe..e59f42f767 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CallOobCall.java @@ -58,7 +58,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(ZERO) .data6(bigIntegerToBytes(callStackDepth)) .data7(booleanToBytes(!value.isZero())) - .data8(booleanToBytes(abortingCondition)); + .data8(booleanToBytes(abortingCondition)) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java index 050b15a837..e2b19df28d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java @@ -37,6 +37,7 @@ public class CreateOobCall extends OobCall { BigInteger callStackDepth; boolean abortingCondition; boolean failureCondition; + BigInteger creatorNonce; public CreateOobCall() { super(OOB_INST_CREATE); @@ -61,7 +62,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(booleanToBytes(hasCode)) .data6(bigIntegerToBytes(callStackDepth)) .data7(booleanToBytes(abortingCondition)) - .data8(booleanToBytes(failureCondition)); + .data8(booleanToBytes(failureCondition)) + .data9(bigIntegerToBytes(creatorNonce)); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/DeploymentOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/DeploymentOobCall.java index 9f6de6da91..1c2812be9f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/DeploymentOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/DeploymentOobCall.java @@ -56,7 +56,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(ZERO) .data6(ZERO) .data7(booleanToBytes(maxCodeSizeException)) - .data8(ZERO); + .data8(ZERO) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpOobCall.java index 7c97833483..156c737895 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpOobCall.java @@ -58,7 +58,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(codeSize)) .data6(ZERO) .data7(booleanToBytes(jumpGuaranteedException)) - .data8(booleanToBytes(jumpMustBeAttempted)); + .data8(booleanToBytes(jumpMustBeAttempted)) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpiOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpiOobCall.java index 8f8f576dc7..1f9b493315 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpiOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/JumpiOobCall.java @@ -83,6 +83,7 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(codeSize)) .data6(booleanToBytes(jumpNotAttempted)) .data7(booleanToBytes(jumpGuanranteedException)) - .data8(booleanToBytes(jumpMustBeAttempted)); + .data8(booleanToBytes(jumpMustBeAttempted)) + .data9(ZERO); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/ReturnDataCopyOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/ReturnDataCopyOobCall.java index 94a080d16e..ef97032f23 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/ReturnDataCopyOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/ReturnDataCopyOobCall.java @@ -66,7 +66,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(rds)) .data6(ZERO) .data7(booleanToBytes(rdcx)) - .data8(ZERO); + .data8(ZERO) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/SstoreOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/SstoreOobCall.java index 6f4ae05bc9..31538f6e5b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/SstoreOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/SstoreOobCall.java @@ -47,7 +47,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(gas)) .data6(ZERO) .data7(booleanToBytes(sstorex)) - .data8(ZERO); + .data8(ZERO) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/XCallOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/XCallOobCall.java index af9d72b0cc..de7f76691f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/XCallOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/XCallOobCall.java @@ -57,7 +57,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(ZERO) .data6(ZERO) .data7(booleanToBytes(valueIsNonzero)) - .data8(booleanToBytes(valueIsZero)); + .data8(booleanToBytes(valueIsZero)) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fCallDataSizeOobCall.java index 56248df98a..bfc69b3e0d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fCallDataSizeOobCall.java @@ -49,7 +49,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(ZERO) .data6(ZERO) .data7(ZERO) - .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + .data8(booleanToBytes(returnAtCapacityNonZero)) // Set after the constructor + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fParamsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fParamsOobCall.java index 011a5631f3..6425c8e41c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fParamsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/Blake2fParamsOobCall.java @@ -52,7 +52,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(returnGas)) // Set after the constructor .data6(bigIntegerToBytes(blakeR)) .data7(bigIntegerToBytes(blakeF)) - .data8(ZERO); + .data8(ZERO) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpCallDataSizeOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpCallDataSizeOobCall.java index 5f4c90f0f7..de48b87384 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpCallDataSizeOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpCallDataSizeOobCall.java @@ -50,7 +50,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(booleanToBytes(extractMbs)) .data6(ZERO) .data7(ZERO) - .data8(ZERO); + .data8(ZERO) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpExtractOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpExtractOobCall.java index 5190344670..b7de04f496 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpExtractOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpExtractOobCall.java @@ -54,7 +54,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(mbs)) .data6(booleanToBytes(extractBase)) .data7(booleanToBytes(extractExponent)) - .data8(booleanToBytes(extractModulus)); + .data8(booleanToBytes(extractModulus)) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpLeadOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpLeadOobCall.java index 9d50e5eb49..01908583de 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpLeadOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpLeadOobCall.java @@ -55,7 +55,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(ZERO) .data6(Bytes.of(cdsCutoff)) .data7(Bytes.of(ebsCutoff)) - .data8(Bytes.of(subEbs32)); + .data8(Bytes.of(subEbs32)) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpPricingOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpPricingOobCall.java index 7ace069354..afbb2c2252 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpPricingOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpPricingOobCall.java @@ -55,7 +55,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(returnGas)) .data6(bigIntegerToBytes(exponentLog)) .data7(Bytes.of(maxMbsBbs)) - .data8(booleanToBytes(returnAtCapacityNonZero)); + .data8(booleanToBytes(returnAtCapacityNonZero)) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsOobCall.java index 8fcc1c3357..7e7f3df324 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/ModexpXbsOobCall.java @@ -55,7 +55,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(ZERO) .data6(ZERO) .data7(bigIntegerToBytes(maxXbsYbs)) - .data8(booleanToBytes(xbsNonZero)); + .data8(booleanToBytes(xbsNonZero)) + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java index aed83feea3..a4890f3cbf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/precompiles/PrecompileCommonOobCall.java @@ -63,7 +63,8 @@ public net.consensys.linea.zktracer.module.oob.Trace trace( .data5(bigIntegerToBytes(returnGas)) // Set after the constructor .data6(booleanToBytes(getExtractCallData())) // Derived from other parameters .data7(booleanToBytes(getCallDataIsEmpty())) // Derived from other parameters - .data8(booleanToBytes(returnAtCapacityNonZero)); // Set after the constructor + .data8(booleanToBytes(returnAtCapacityNonZero)) // Set after the constructor + .data9(ZERO); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index 5da482cc11..e472e95495 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -18,7 +18,6 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.List; @@ -106,7 +105,7 @@ final void traceChunk(final OobOperation oobOperation, int stamp, Trace trace) { .stamp(stamp) .ct((short) ct) .ctMax((short) oobOperation.ctMax()) - .oobInst(bigIntegerToBytes(BigInteger.valueOf(oobInstruction.getValue()))) + .oobInst(oobInstruction.getValue()) .isJump(oobInstruction == OOB_INST_JUMP) .isJumpi(oobInstruction == OOB_INST_JUMPI) .isRdc(oobInstruction == OOB_INST_RDC) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 5b0734d9fc..1d12664781 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -278,6 +278,7 @@ private void populateColumnsForEvmInstruction(MessageFrame frame) { createOobCall.setNonce(BigInteger.valueOf(nonce)); createOobCall.setHasCode(hasCode); createOobCall.setCallStackDepth(BigInteger.valueOf(frame.getDepth())); + createOobCall.setCreatorNonce(BigInteger.valueOf(creatorAccount.getNonce())); setCreate(createOobCall); } case OOB_INST_SSTORE -> { @@ -801,8 +802,18 @@ private void setCreate(CreateOobCall createOobCall) { // row i + 2 final boolean nonzeroNonce = !callToISZERO(2, BigInteger.ZERO, createOobCall.getNonce()); + // row i + 3 + final boolean creatorNonceAbort = + !callToLT( + 3, + BigInteger.ZERO, + createOobCall.getCreatorNonce(), + BigInteger.ZERO, + (BigInteger.valueOf(2).pow(64)).subtract(BigInteger.valueOf(1))); // TODO: use constant + // Set aborting condition - createOobCall.setAbortingCondition(insufficientBalanceAbort || callStackDepthAbort); + createOobCall.setAbortingCondition( + insufficientBalanceAbort || callStackDepthAbort || creatorNonceAbort); // Set failureCondition createOobCall.setFailureCondition( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Trace.java index 89a912c747..b489183943 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Trace.java @@ -34,7 +34,7 @@ public class Trace { public static final int CT_MAX_BLAKE2F_PARAMS = 0x1; public static final int CT_MAX_CALL = 0x2; public static final int CT_MAX_CDL = 0x0; - public static final int CT_MAX_CREATE = 0x2; + public static final int CT_MAX_CREATE = 0x3; public static final int CT_MAX_DEPLOYMENT = 0x0; public static final int CT_MAX_ECADD = 0x2; public static final int CT_MAX_ECMUL = 0x2; @@ -69,6 +69,7 @@ public class Trace { private final MappedByteBuffer data6; private final MappedByteBuffer data7; private final MappedByteBuffer data8; + private final MappedByteBuffer data9; private final MappedByteBuffer isBlake2FCds; private final MappedByteBuffer isBlake2FParams; private final MappedByteBuffer isCall; @@ -108,14 +109,15 @@ static List headers(int length) { new ColumnHeader("oob.ADD_FLAG", 1, length), new ColumnHeader("oob.CT", 1, length), new ColumnHeader("oob.CT_MAX", 1, length), - new ColumnHeader("oob.DATA_1", 32, length), - new ColumnHeader("oob.DATA_2", 32, length), - new ColumnHeader("oob.DATA_3", 32, length), - new ColumnHeader("oob.DATA_4", 32, length), - new ColumnHeader("oob.DATA_5", 32, length), - new ColumnHeader("oob.DATA_6", 32, length), - new ColumnHeader("oob.DATA_7", 32, length), - new ColumnHeader("oob.DATA_8", 32, length), + new ColumnHeader("oob.DATA_1", 16, length), + new ColumnHeader("oob.DATA_2", 16, length), + new ColumnHeader("oob.DATA_3", 16, length), + new ColumnHeader("oob.DATA_4", 16, length), + new ColumnHeader("oob.DATA_5", 16, length), + new ColumnHeader("oob.DATA_6", 16, length), + new ColumnHeader("oob.DATA_7", 16, length), + new ColumnHeader("oob.DATA_8", 16, length), + new ColumnHeader("oob.DATA_9", 16, length), new ColumnHeader("oob.IS_BLAKE2F_CDS", 1, length), new ColumnHeader("oob.IS_BLAKE2F_PARAMS", 1, length), new ColumnHeader("oob.IS_CALL", 1, length), @@ -140,13 +142,13 @@ static List headers(int length) { new ColumnHeader("oob.IS_SSTORE", 1, length), new ColumnHeader("oob.IS_XCALL", 1, length), new ColumnHeader("oob.MOD_FLAG", 1, length), - new ColumnHeader("oob.OOB_INST", 32, length), - new ColumnHeader("oob.OUTGOING_DATA_1", 32, length), - new ColumnHeader("oob.OUTGOING_DATA_2", 32, length), - new ColumnHeader("oob.OUTGOING_DATA_3", 32, length), - new ColumnHeader("oob.OUTGOING_DATA_4", 32, length), + new ColumnHeader("oob.OOB_INST", 2, length), + new ColumnHeader("oob.OUTGOING_DATA_1", 16, length), + new ColumnHeader("oob.OUTGOING_DATA_2", 16, length), + new ColumnHeader("oob.OUTGOING_DATA_3", 16, length), + new ColumnHeader("oob.OUTGOING_DATA_4", 16, length), new ColumnHeader("oob.OUTGOING_INST", 1, length), - new ColumnHeader("oob.OUTGOING_RES_LO", 32, length), + new ColumnHeader("oob.OUTGOING_RES_LO", 16, length), new ColumnHeader("oob.STAMP", 4, length), new ColumnHeader("oob.WCP_FLAG", 1, length)); } @@ -163,39 +165,40 @@ public Trace(List buffers) { this.data6 = buffers.get(8); this.data7 = buffers.get(9); this.data8 = buffers.get(10); - this.isBlake2FCds = buffers.get(11); - this.isBlake2FParams = buffers.get(12); - this.isCall = buffers.get(13); - this.isCdl = buffers.get(14); - this.isCreate = buffers.get(15); - this.isDeployment = buffers.get(16); - this.isEcadd = buffers.get(17); - this.isEcmul = buffers.get(18); - this.isEcpairing = buffers.get(19); - this.isEcrecover = buffers.get(20); - this.isIdentity = buffers.get(21); - this.isJump = buffers.get(22); - this.isJumpi = buffers.get(23); - this.isModexpCds = buffers.get(24); - this.isModexpExtract = buffers.get(25); - this.isModexpLead = buffers.get(26); - this.isModexpPricing = buffers.get(27); - this.isModexpXbs = buffers.get(28); - this.isRdc = buffers.get(29); - this.isRipemd = buffers.get(30); - this.isSha2 = buffers.get(31); - this.isSstore = buffers.get(32); - this.isXcall = buffers.get(33); - this.modFlag = buffers.get(34); - this.oobInst = buffers.get(35); - this.outgoingData1 = buffers.get(36); - this.outgoingData2 = buffers.get(37); - this.outgoingData3 = buffers.get(38); - this.outgoingData4 = buffers.get(39); - this.outgoingInst = buffers.get(40); - this.outgoingResLo = buffers.get(41); - this.stamp = buffers.get(42); - this.wcpFlag = buffers.get(43); + this.data9 = buffers.get(11); + this.isBlake2FCds = buffers.get(12); + this.isBlake2FParams = buffers.get(13); + this.isCall = buffers.get(14); + this.isCdl = buffers.get(15); + this.isCreate = buffers.get(16); + this.isDeployment = buffers.get(17); + this.isEcadd = buffers.get(18); + this.isEcmul = buffers.get(19); + this.isEcpairing = buffers.get(20); + this.isEcrecover = buffers.get(21); + this.isIdentity = buffers.get(22); + this.isJump = buffers.get(23); + this.isJumpi = buffers.get(24); + this.isModexpCds = buffers.get(25); + this.isModexpExtract = buffers.get(26); + this.isModexpLead = buffers.get(27); + this.isModexpPricing = buffers.get(28); + this.isModexpXbs = buffers.get(29); + this.isRdc = buffers.get(30); + this.isRipemd = buffers.get(31); + this.isSha2 = buffers.get(32); + this.isSstore = buffers.get(33); + this.isXcall = buffers.get(34); + this.modFlag = buffers.get(35); + this.oobInst = buffers.get(36); + this.outgoingData1 = buffers.get(37); + this.outgoingData2 = buffers.get(38); + this.outgoingData3 = buffers.get(39); + this.outgoingData4 = buffers.get(40); + this.outgoingInst = buffers.get(41); + this.outgoingResLo = buffers.get(42); + this.stamp = buffers.get(43); + this.wcpFlag = buffers.get(44); } public int size() { @@ -258,11 +261,11 @@ public Trace data1(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data1.put((byte) 0); } // Write bytes @@ -283,11 +286,11 @@ public Trace data2(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data2.put((byte) 0); } // Write bytes @@ -308,11 +311,11 @@ public Trace data3(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data3 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data3.put((byte) 0); } // Write bytes @@ -333,11 +336,11 @@ public Trace data4(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data4 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data4.put((byte) 0); } // Write bytes @@ -358,11 +361,11 @@ public Trace data5(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data5 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data5.put((byte) 0); } // Write bytes @@ -383,11 +386,11 @@ public Trace data6(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data6 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data6.put((byte) 0); } // Write bytes @@ -408,11 +411,11 @@ public Trace data7(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data7 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data7.put((byte) 0); } // Write bytes @@ -433,11 +436,11 @@ public Trace data8(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException("data8 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { data8.put((byte) 0); } // Write bytes @@ -448,23 +451,48 @@ public Trace data8(final Bytes b) { return this; } - public Trace isBlake2FCds(final Boolean b) { + public Trace data9(final Bytes b) { if (filled.get(11)) { - throw new IllegalStateException("oob.IS_BLAKE2F_CDS already set"); + throw new IllegalStateException("oob.DATA_9 already set"); } else { filled.set(11); } + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("data9 has invalid width (" + bs.bitLength() + "bits)"); + } + // Write padding (if necessary) + for (int i = bs.size(); i < 16; i++) { + data9.put((byte) 0); + } + // Write bytes + for (int j = 0; j < bs.size(); j++) { + data9.put(bs.get(j)); + } + + return this; + } + + public Trace isBlake2FCds(final Boolean b) { + if (filled.get(12)) { + throw new IllegalStateException("oob.IS_BLAKE2F_CDS already set"); + } else { + filled.set(12); + } + isBlake2FCds.put((byte) (b ? 1 : 0)); return this; } public Trace isBlake2FParams(final Boolean b) { - if (filled.get(12)) { + if (filled.get(13)) { throw new IllegalStateException("oob.IS_BLAKE2F_PARAMS already set"); } else { - filled.set(12); + filled.set(13); } isBlake2FParams.put((byte) (b ? 1 : 0)); @@ -473,10 +501,10 @@ public Trace isBlake2FParams(final Boolean b) { } public Trace isCall(final Boolean b) { - if (filled.get(13)) { + if (filled.get(14)) { throw new IllegalStateException("oob.IS_CALL already set"); } else { - filled.set(13); + filled.set(14); } isCall.put((byte) (b ? 1 : 0)); @@ -485,10 +513,10 @@ public Trace isCall(final Boolean b) { } public Trace isCdl(final Boolean b) { - if (filled.get(14)) { + if (filled.get(15)) { throw new IllegalStateException("oob.IS_CDL already set"); } else { - filled.set(14); + filled.set(15); } isCdl.put((byte) (b ? 1 : 0)); @@ -497,10 +525,10 @@ public Trace isCdl(final Boolean b) { } public Trace isCreate(final Boolean b) { - if (filled.get(15)) { + if (filled.get(16)) { throw new IllegalStateException("oob.IS_CREATE already set"); } else { - filled.set(15); + filled.set(16); } isCreate.put((byte) (b ? 1 : 0)); @@ -509,10 +537,10 @@ public Trace isCreate(final Boolean b) { } public Trace isDeployment(final Boolean b) { - if (filled.get(16)) { + if (filled.get(17)) { throw new IllegalStateException("oob.IS_DEPLOYMENT already set"); } else { - filled.set(16); + filled.set(17); } isDeployment.put((byte) (b ? 1 : 0)); @@ -521,10 +549,10 @@ public Trace isDeployment(final Boolean b) { } public Trace isEcadd(final Boolean b) { - if (filled.get(17)) { + if (filled.get(18)) { throw new IllegalStateException("oob.IS_ECADD already set"); } else { - filled.set(17); + filled.set(18); } isEcadd.put((byte) (b ? 1 : 0)); @@ -533,10 +561,10 @@ public Trace isEcadd(final Boolean b) { } public Trace isEcmul(final Boolean b) { - if (filled.get(18)) { + if (filled.get(19)) { throw new IllegalStateException("oob.IS_ECMUL already set"); } else { - filled.set(18); + filled.set(19); } isEcmul.put((byte) (b ? 1 : 0)); @@ -545,10 +573,10 @@ public Trace isEcmul(final Boolean b) { } public Trace isEcpairing(final Boolean b) { - if (filled.get(19)) { + if (filled.get(20)) { throw new IllegalStateException("oob.IS_ECPAIRING already set"); } else { - filled.set(19); + filled.set(20); } isEcpairing.put((byte) (b ? 1 : 0)); @@ -557,10 +585,10 @@ public Trace isEcpairing(final Boolean b) { } public Trace isEcrecover(final Boolean b) { - if (filled.get(20)) { + if (filled.get(21)) { throw new IllegalStateException("oob.IS_ECRECOVER already set"); } else { - filled.set(20); + filled.set(21); } isEcrecover.put((byte) (b ? 1 : 0)); @@ -569,10 +597,10 @@ public Trace isEcrecover(final Boolean b) { } public Trace isIdentity(final Boolean b) { - if (filled.get(21)) { + if (filled.get(22)) { throw new IllegalStateException("oob.IS_IDENTITY already set"); } else { - filled.set(21); + filled.set(22); } isIdentity.put((byte) (b ? 1 : 0)); @@ -581,10 +609,10 @@ public Trace isIdentity(final Boolean b) { } public Trace isJump(final Boolean b) { - if (filled.get(22)) { + if (filled.get(23)) { throw new IllegalStateException("oob.IS_JUMP already set"); } else { - filled.set(22); + filled.set(23); } isJump.put((byte) (b ? 1 : 0)); @@ -593,10 +621,10 @@ public Trace isJump(final Boolean b) { } public Trace isJumpi(final Boolean b) { - if (filled.get(23)) { + if (filled.get(24)) { throw new IllegalStateException("oob.IS_JUMPI already set"); } else { - filled.set(23); + filled.set(24); } isJumpi.put((byte) (b ? 1 : 0)); @@ -605,10 +633,10 @@ public Trace isJumpi(final Boolean b) { } public Trace isModexpCds(final Boolean b) { - if (filled.get(24)) { + if (filled.get(25)) { throw new IllegalStateException("oob.IS_MODEXP_CDS already set"); } else { - filled.set(24); + filled.set(25); } isModexpCds.put((byte) (b ? 1 : 0)); @@ -617,10 +645,10 @@ public Trace isModexpCds(final Boolean b) { } public Trace isModexpExtract(final Boolean b) { - if (filled.get(25)) { + if (filled.get(26)) { throw new IllegalStateException("oob.IS_MODEXP_EXTRACT already set"); } else { - filled.set(25); + filled.set(26); } isModexpExtract.put((byte) (b ? 1 : 0)); @@ -629,10 +657,10 @@ public Trace isModexpExtract(final Boolean b) { } public Trace isModexpLead(final Boolean b) { - if (filled.get(26)) { + if (filled.get(27)) { throw new IllegalStateException("oob.IS_MODEXP_LEAD already set"); } else { - filled.set(26); + filled.set(27); } isModexpLead.put((byte) (b ? 1 : 0)); @@ -641,10 +669,10 @@ public Trace isModexpLead(final Boolean b) { } public Trace isModexpPricing(final Boolean b) { - if (filled.get(27)) { + if (filled.get(28)) { throw new IllegalStateException("oob.IS_MODEXP_PRICING already set"); } else { - filled.set(27); + filled.set(28); } isModexpPricing.put((byte) (b ? 1 : 0)); @@ -653,10 +681,10 @@ public Trace isModexpPricing(final Boolean b) { } public Trace isModexpXbs(final Boolean b) { - if (filled.get(28)) { + if (filled.get(29)) { throw new IllegalStateException("oob.IS_MODEXP_XBS already set"); } else { - filled.set(28); + filled.set(29); } isModexpXbs.put((byte) (b ? 1 : 0)); @@ -665,10 +693,10 @@ public Trace isModexpXbs(final Boolean b) { } public Trace isRdc(final Boolean b) { - if (filled.get(29)) { + if (filled.get(30)) { throw new IllegalStateException("oob.IS_RDC already set"); } else { - filled.set(29); + filled.set(30); } isRdc.put((byte) (b ? 1 : 0)); @@ -677,10 +705,10 @@ public Trace isRdc(final Boolean b) { } public Trace isRipemd(final Boolean b) { - if (filled.get(30)) { + if (filled.get(31)) { throw new IllegalStateException("oob.IS_RIPEMD already set"); } else { - filled.set(30); + filled.set(31); } isRipemd.put((byte) (b ? 1 : 0)); @@ -689,10 +717,10 @@ public Trace isRipemd(final Boolean b) { } public Trace isSha2(final Boolean b) { - if (filled.get(31)) { + if (filled.get(32)) { throw new IllegalStateException("oob.IS_SHA2 already set"); } else { - filled.set(31); + filled.set(32); } isSha2.put((byte) (b ? 1 : 0)); @@ -701,10 +729,10 @@ public Trace isSha2(final Boolean b) { } public Trace isSstore(final Boolean b) { - if (filled.get(32)) { + if (filled.get(33)) { throw new IllegalStateException("oob.IS_SSTORE already set"); } else { - filled.set(32); + filled.set(33); } isSstore.put((byte) (b ? 1 : 0)); @@ -713,10 +741,10 @@ public Trace isSstore(final Boolean b) { } public Trace isXcall(final Boolean b) { - if (filled.get(33)) { + if (filled.get(34)) { throw new IllegalStateException("oob.IS_XCALL already set"); } else { - filled.set(33); + filled.set(34); } isXcall.put((byte) (b ? 1 : 0)); @@ -725,10 +753,10 @@ public Trace isXcall(final Boolean b) { } public Trace modFlag(final Boolean b) { - if (filled.get(34)) { + if (filled.get(35)) { throw new IllegalStateException("oob.MOD_FLAG already set"); } else { - filled.set(34); + filled.set(35); } modFlag.put((byte) (b ? 1 : 0)); @@ -736,47 +764,38 @@ public Trace modFlag(final Boolean b) { return this; } - public Trace oobInst(final Bytes b) { - if (filled.get(35)) { + public Trace oobInst(final long b) { + if (filled.get(36)) { throw new IllegalStateException("oob.OOB_INST already set"); } else { - filled.set(35); + filled.set(36); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 256) { - throw new IllegalArgumentException("oobInst has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { - oobInst.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobInst.put(bs.get(j)); + if (b >= 65536L) { + throw new IllegalArgumentException("oobInst has invalid value (" + b + ")"); } + oobInst.put((byte) (b >> 8)); + oobInst.put((byte) b); return this; } public Trace outgoingData1(final Bytes b) { - if (filled.get(36)) { + if (filled.get(37)) { throw new IllegalStateException("oob.OUTGOING_DATA_1 already set"); } else { - filled.set(36); + filled.set(37); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException( "outgoingData1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { outgoingData1.put((byte) 0); } // Write bytes @@ -788,21 +807,21 @@ public Trace outgoingData1(final Bytes b) { } public Trace outgoingData2(final Bytes b) { - if (filled.get(37)) { + if (filled.get(38)) { throw new IllegalStateException("oob.OUTGOING_DATA_2 already set"); } else { - filled.set(37); + filled.set(38); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException( "outgoingData2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { outgoingData2.put((byte) 0); } // Write bytes @@ -814,21 +833,21 @@ public Trace outgoingData2(final Bytes b) { } public Trace outgoingData3(final Bytes b) { - if (filled.get(38)) { + if (filled.get(39)) { throw new IllegalStateException("oob.OUTGOING_DATA_3 already set"); } else { - filled.set(38); + filled.set(39); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException( "outgoingData3 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { outgoingData3.put((byte) 0); } // Write bytes @@ -840,21 +859,21 @@ public Trace outgoingData3(final Bytes b) { } public Trace outgoingData4(final Bytes b) { - if (filled.get(39)) { + if (filled.get(40)) { throw new IllegalStateException("oob.OUTGOING_DATA_4 already set"); } else { - filled.set(39); + filled.set(40); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException( "outgoingData4 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { outgoingData4.put((byte) 0); } // Write bytes @@ -866,10 +885,10 @@ public Trace outgoingData4(final Bytes b) { } public Trace outgoingInst(final UnsignedByte b) { - if (filled.get(40)) { + if (filled.get(41)) { throw new IllegalStateException("oob.OUTGOING_INST already set"); } else { - filled.set(40); + filled.set(41); } outgoingInst.put(b.toByte()); @@ -878,21 +897,21 @@ public Trace outgoingInst(final UnsignedByte b) { } public Trace outgoingResLo(final Bytes b) { - if (filled.get(41)) { + if (filled.get(42)) { throw new IllegalStateException("oob.OUTGOING_RES_LO already set"); } else { - filled.set(41); + filled.set(42); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 256) { + if (bs.bitLength() > 128) { throw new IllegalArgumentException( "outgoingResLo has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { + for (int i = bs.size(); i < 16; i++) { outgoingResLo.put((byte) 0); } // Write bytes @@ -904,10 +923,10 @@ public Trace outgoingResLo(final Bytes b) { } public Trace stamp(final long b) { - if (filled.get(42)) { + if (filled.get(43)) { throw new IllegalStateException("oob.STAMP already set"); } else { - filled.set(42); + filled.set(43); } if (b >= 4294967296L) { @@ -922,10 +941,10 @@ public Trace stamp(final long b) { } public Trace wcpFlag(final Boolean b) { - if (filled.get(43)) { + if (filled.get(44)) { throw new IllegalStateException("oob.WCP_FLAG already set"); } else { - filled.set(43); + filled.set(44); } wcpFlag.put((byte) (b ? 1 : 0)); @@ -979,134 +998,138 @@ public Trace validateRow() { } if (!filled.get(11)) { - throw new IllegalStateException("oob.IS_BLAKE2F_CDS has not been filled"); + throw new IllegalStateException("oob.DATA_9 has not been filled"); } if (!filled.get(12)) { - throw new IllegalStateException("oob.IS_BLAKE2F_PARAMS has not been filled"); + throw new IllegalStateException("oob.IS_BLAKE2F_CDS has not been filled"); } if (!filled.get(13)) { - throw new IllegalStateException("oob.IS_CALL has not been filled"); + throw new IllegalStateException("oob.IS_BLAKE2F_PARAMS has not been filled"); } if (!filled.get(14)) { - throw new IllegalStateException("oob.IS_CDL has not been filled"); + throw new IllegalStateException("oob.IS_CALL has not been filled"); } if (!filled.get(15)) { - throw new IllegalStateException("oob.IS_CREATE has not been filled"); + throw new IllegalStateException("oob.IS_CDL has not been filled"); } if (!filled.get(16)) { - throw new IllegalStateException("oob.IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException("oob.IS_CREATE has not been filled"); } if (!filled.get(17)) { - throw new IllegalStateException("oob.IS_ECADD has not been filled"); + throw new IllegalStateException("oob.IS_DEPLOYMENT has not been filled"); } if (!filled.get(18)) { - throw new IllegalStateException("oob.IS_ECMUL has not been filled"); + throw new IllegalStateException("oob.IS_ECADD has not been filled"); } if (!filled.get(19)) { - throw new IllegalStateException("oob.IS_ECPAIRING has not been filled"); + throw new IllegalStateException("oob.IS_ECMUL has not been filled"); } if (!filled.get(20)) { - throw new IllegalStateException("oob.IS_ECRECOVER has not been filled"); + throw new IllegalStateException("oob.IS_ECPAIRING has not been filled"); } if (!filled.get(21)) { - throw new IllegalStateException("oob.IS_IDENTITY has not been filled"); + throw new IllegalStateException("oob.IS_ECRECOVER has not been filled"); } if (!filled.get(22)) { - throw new IllegalStateException("oob.IS_JUMP has not been filled"); + throw new IllegalStateException("oob.IS_IDENTITY has not been filled"); } if (!filled.get(23)) { - throw new IllegalStateException("oob.IS_JUMPI has not been filled"); + throw new IllegalStateException("oob.IS_JUMP has not been filled"); } if (!filled.get(24)) { - throw new IllegalStateException("oob.IS_MODEXP_CDS has not been filled"); + throw new IllegalStateException("oob.IS_JUMPI has not been filled"); } if (!filled.get(25)) { - throw new IllegalStateException("oob.IS_MODEXP_EXTRACT has not been filled"); + throw new IllegalStateException("oob.IS_MODEXP_CDS has not been filled"); } if (!filled.get(26)) { - throw new IllegalStateException("oob.IS_MODEXP_LEAD has not been filled"); + throw new IllegalStateException("oob.IS_MODEXP_EXTRACT has not been filled"); } if (!filled.get(27)) { - throw new IllegalStateException("oob.IS_MODEXP_PRICING has not been filled"); + throw new IllegalStateException("oob.IS_MODEXP_LEAD has not been filled"); } if (!filled.get(28)) { - throw new IllegalStateException("oob.IS_MODEXP_XBS has not been filled"); + throw new IllegalStateException("oob.IS_MODEXP_PRICING has not been filled"); } if (!filled.get(29)) { - throw new IllegalStateException("oob.IS_RDC has not been filled"); + throw new IllegalStateException("oob.IS_MODEXP_XBS has not been filled"); } if (!filled.get(30)) { - throw new IllegalStateException("oob.IS_RIPEMD has not been filled"); + throw new IllegalStateException("oob.IS_RDC has not been filled"); } if (!filled.get(31)) { - throw new IllegalStateException("oob.IS_SHA2 has not been filled"); + throw new IllegalStateException("oob.IS_RIPEMD has not been filled"); } if (!filled.get(32)) { - throw new IllegalStateException("oob.IS_SSTORE has not been filled"); + throw new IllegalStateException("oob.IS_SHA2 has not been filled"); } if (!filled.get(33)) { - throw new IllegalStateException("oob.IS_XCALL has not been filled"); + throw new IllegalStateException("oob.IS_SSTORE has not been filled"); } if (!filled.get(34)) { - throw new IllegalStateException("oob.MOD_FLAG has not been filled"); + throw new IllegalStateException("oob.IS_XCALL has not been filled"); } if (!filled.get(35)) { - throw new IllegalStateException("oob.OOB_INST has not been filled"); + throw new IllegalStateException("oob.MOD_FLAG has not been filled"); } if (!filled.get(36)) { - throw new IllegalStateException("oob.OUTGOING_DATA_1 has not been filled"); + throw new IllegalStateException("oob.OOB_INST has not been filled"); } if (!filled.get(37)) { - throw new IllegalStateException("oob.OUTGOING_DATA_2 has not been filled"); + throw new IllegalStateException("oob.OUTGOING_DATA_1 has not been filled"); } if (!filled.get(38)) { - throw new IllegalStateException("oob.OUTGOING_DATA_3 has not been filled"); + throw new IllegalStateException("oob.OUTGOING_DATA_2 has not been filled"); } if (!filled.get(39)) { - throw new IllegalStateException("oob.OUTGOING_DATA_4 has not been filled"); + throw new IllegalStateException("oob.OUTGOING_DATA_3 has not been filled"); } if (!filled.get(40)) { - throw new IllegalStateException("oob.OUTGOING_INST has not been filled"); + throw new IllegalStateException("oob.OUTGOING_DATA_4 has not been filled"); } if (!filled.get(41)) { - throw new IllegalStateException("oob.OUTGOING_RES_LO has not been filled"); + throw new IllegalStateException("oob.OUTGOING_INST has not been filled"); } if (!filled.get(42)) { - throw new IllegalStateException("oob.STAMP has not been filled"); + throw new IllegalStateException("oob.OUTGOING_RES_LO has not been filled"); } if (!filled.get(43)) { + throw new IllegalStateException("oob.STAMP has not been filled"); + } + + if (!filled.get(44)) { throw new IllegalStateException("oob.WCP_FLAG has not been filled"); } @@ -1130,166 +1153,170 @@ public Trace fillAndValidateRow() { } if (!filled.get(3)) { - data1.position(data1.position() + 32); + data1.position(data1.position() + 16); } if (!filled.get(4)) { - data2.position(data2.position() + 32); + data2.position(data2.position() + 16); } if (!filled.get(5)) { - data3.position(data3.position() + 32); + data3.position(data3.position() + 16); } if (!filled.get(6)) { - data4.position(data4.position() + 32); + data4.position(data4.position() + 16); } if (!filled.get(7)) { - data5.position(data5.position() + 32); + data5.position(data5.position() + 16); } if (!filled.get(8)) { - data6.position(data6.position() + 32); + data6.position(data6.position() + 16); } if (!filled.get(9)) { - data7.position(data7.position() + 32); + data7.position(data7.position() + 16); } if (!filled.get(10)) { - data8.position(data8.position() + 32); + data8.position(data8.position() + 16); } if (!filled.get(11)) { - isBlake2FCds.position(isBlake2FCds.position() + 1); + data9.position(data9.position() + 16); } if (!filled.get(12)) { - isBlake2FParams.position(isBlake2FParams.position() + 1); + isBlake2FCds.position(isBlake2FCds.position() + 1); } if (!filled.get(13)) { - isCall.position(isCall.position() + 1); + isBlake2FParams.position(isBlake2FParams.position() + 1); } if (!filled.get(14)) { - isCdl.position(isCdl.position() + 1); + isCall.position(isCall.position() + 1); } if (!filled.get(15)) { - isCreate.position(isCreate.position() + 1); + isCdl.position(isCdl.position() + 1); } if (!filled.get(16)) { - isDeployment.position(isDeployment.position() + 1); + isCreate.position(isCreate.position() + 1); } if (!filled.get(17)) { - isEcadd.position(isEcadd.position() + 1); + isDeployment.position(isDeployment.position() + 1); } if (!filled.get(18)) { - isEcmul.position(isEcmul.position() + 1); + isEcadd.position(isEcadd.position() + 1); } if (!filled.get(19)) { - isEcpairing.position(isEcpairing.position() + 1); + isEcmul.position(isEcmul.position() + 1); } if (!filled.get(20)) { - isEcrecover.position(isEcrecover.position() + 1); + isEcpairing.position(isEcpairing.position() + 1); } if (!filled.get(21)) { - isIdentity.position(isIdentity.position() + 1); + isEcrecover.position(isEcrecover.position() + 1); } if (!filled.get(22)) { - isJump.position(isJump.position() + 1); + isIdentity.position(isIdentity.position() + 1); } if (!filled.get(23)) { - isJumpi.position(isJumpi.position() + 1); + isJump.position(isJump.position() + 1); } if (!filled.get(24)) { - isModexpCds.position(isModexpCds.position() + 1); + isJumpi.position(isJumpi.position() + 1); } if (!filled.get(25)) { - isModexpExtract.position(isModexpExtract.position() + 1); + isModexpCds.position(isModexpCds.position() + 1); } if (!filled.get(26)) { - isModexpLead.position(isModexpLead.position() + 1); + isModexpExtract.position(isModexpExtract.position() + 1); } if (!filled.get(27)) { - isModexpPricing.position(isModexpPricing.position() + 1); + isModexpLead.position(isModexpLead.position() + 1); } if (!filled.get(28)) { - isModexpXbs.position(isModexpXbs.position() + 1); + isModexpPricing.position(isModexpPricing.position() + 1); } if (!filled.get(29)) { - isRdc.position(isRdc.position() + 1); + isModexpXbs.position(isModexpXbs.position() + 1); } if (!filled.get(30)) { - isRipemd.position(isRipemd.position() + 1); + isRdc.position(isRdc.position() + 1); } if (!filled.get(31)) { - isSha2.position(isSha2.position() + 1); + isRipemd.position(isRipemd.position() + 1); } if (!filled.get(32)) { - isSstore.position(isSstore.position() + 1); + isSha2.position(isSha2.position() + 1); } if (!filled.get(33)) { - isXcall.position(isXcall.position() + 1); + isSstore.position(isSstore.position() + 1); } if (!filled.get(34)) { - modFlag.position(modFlag.position() + 1); + isXcall.position(isXcall.position() + 1); } if (!filled.get(35)) { - oobInst.position(oobInst.position() + 32); + modFlag.position(modFlag.position() + 1); } if (!filled.get(36)) { - outgoingData1.position(outgoingData1.position() + 32); + oobInst.position(oobInst.position() + 2); } if (!filled.get(37)) { - outgoingData2.position(outgoingData2.position() + 32); + outgoingData1.position(outgoingData1.position() + 16); } if (!filled.get(38)) { - outgoingData3.position(outgoingData3.position() + 32); + outgoingData2.position(outgoingData2.position() + 16); } if (!filled.get(39)) { - outgoingData4.position(outgoingData4.position() + 32); + outgoingData3.position(outgoingData3.position() + 16); } if (!filled.get(40)) { - outgoingInst.position(outgoingInst.position() + 1); + outgoingData4.position(outgoingData4.position() + 16); } if (!filled.get(41)) { - outgoingResLo.position(outgoingResLo.position() + 32); + outgoingInst.position(outgoingInst.position() + 1); } if (!filled.get(42)) { - stamp.position(stamp.position() + 4); + outgoingResLo.position(outgoingResLo.position() + 16); } if (!filled.get(43)) { + stamp.position(stamp.position() + 4); + } + + if (!filled.get(44)) { wcpFlag.position(wcpFlag.position() + 1); } diff --git a/zkevm-constraints b/zkevm-constraints index 5014f30b63..89cc224cc6 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 5014f30b6305d9da6d2b53a26cea574a86ee6d5b +Subproject commit 89cc224cc6f88377e2497e8fe82e990e22b154ac From e25b2aba0e557ba7d937d6cd02e5be3a9d55afe6 Mon Sep 17 00:00:00 2001 From: FlorianHuc Date: Tue, 20 Aug 2024 06:52:40 +0200 Subject: [PATCH 383/461] fix toy account storage check. --- .../src/main/java/net/consensys/linea/testing/ToyAccount.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java index 8ab6fe8646..fa4f240315 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java @@ -71,7 +71,7 @@ public Address getAddress() { @Override public boolean isStorageEmpty() { - return false; + return this.storage.isEmpty(); } @Override From 08c9f10c680c0c731f1924b8f856e80f9a4daf51 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 20 Aug 2024 12:14:51 +0530 Subject: [PATCH 384/461] fix(mmu): any to ram with padding constraints (and tracing) fixes Signed-off-by: Francois Bojarski --- .../zktracer/module/mmu/instructions/AnyToRamWithPadding.java | 4 ++-- zkevm-constraints | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java index e22c74efac..fd4f539bea 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/AnyToRamWithPadding.java @@ -261,8 +261,8 @@ private void purePaddingRow4() { wcpCallRecords.add( MmuWcpCallRecord.instIsZeroBuilder().arg1Lo(wcpArg1).result(wcpResult).build()); - final long dividend = maxTargetOffset + 1; - EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); + final long dividend = maxTargetByteOffset + 1; + final EucOperation eucOp = euc.callEUC(longToBytes(dividend), Bytes.of(LLARGE)); eucCallRecords.add( MmuEucCallRecord.builder() .dividend(dividend) diff --git a/zkevm-constraints b/zkevm-constraints index 89cc224cc6..7dfe31be50 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 89cc224cc6f88377e2497e8fe82e990e22b154ac +Subproject commit 7dfe31be505c6852195caaf140bcf886b7b84c62 From ad8980a7ced7db9c37f21776eafd090dff1cc8d7 Mon Sep 17 00:00:00 2001 From: FlorianHuc Date: Tue, 20 Aug 2024 09:58:02 +0200 Subject: [PATCH 385/461] revert toy account storage check. --- .../src/main/java/net/consensys/linea/testing/ToyAccount.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java index fa4f240315..1e6d164f8b 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java @@ -71,7 +71,7 @@ public Address getAddress() { @Override public boolean isStorageEmpty() { - return this.storage.isEmpty(); + return false;//TODO fix NPE triggered by setting it to this.storage.isEmpty(); } @Override From 61c44794c25f2cd4849a10d93fdab7d7174bee04 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 20 Aug 2024 13:28:14 +0530 Subject: [PATCH 386/461] fix(modexp sub section): call OOB at preOpcode, not contextReEntry Signed-off-by: Francois Bojarski --- .../precompileSubsection/BlakeSubsection.java | 24 ++++++++++--------- .../ModexpSubsection.java | 12 +++++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java index a280d303f8..fd072b9b41 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java @@ -48,13 +48,13 @@ public BlakeSubsection(Hub hub, CallSection callSection) { return; } - Bytes blakeR = callData.slice(0, 4); - Bytes blakeF = callData.slice(212, 1); + final Bytes blakeR = callData.slice(0, 4); + final Bytes blakeF = callData.slice(212, 1); { - boolean wellFormedF = blakeF.get(0) == 0 || blakeF.get(0) == 1; - long rounds = blakeR.toLong(); - boolean sufficientGas = calleeGas >= rounds; + final boolean wellFormedF = blakeF.get(0) == 0 || blakeF.get(0) == 1; + final long rounds = blakeR.toLong(); + final boolean sufficientGas = calleeGas >= rounds; blakeSuccess = wellFormedF && sufficientGas; } @@ -62,7 +62,7 @@ public BlakeSubsection(Hub hub, CallSection callSection) { this.setScenario(PRC_FAILURE_KNOWN_TO_RAM); } - MmuCall blakeParameterExtractionMmuCall = + final MmuCall blakeParameterExtractionMmuCall = MmuCall.parameterExtractionForBlake(hub, this, blakeSuccess, blakeR, blakeF); firstImcFragment.callMmu(blakeParameterExtractionMmuCall); @@ -89,22 +89,24 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { } // finish 2nd MISC row - MmuCall callDataExtractionforBlake = MmuCall.callDataExtractionforBlake(hub, this); + final MmuCall callDataExtractionforBlake = MmuCall.callDataExtractionforBlake(hub, this); secondImcFragment.callMmu(callDataExtractionforBlake); // 3rd MISC row - ImcFragment thirdImcFragment = ImcFragment.empty(hub); + final ImcFragment thirdImcFragment = ImcFragment.empty(hub); fragments.add(thirdImcFragment); - MmuCall returnDataFullTransferForBlake = MmuCall.fullReturnDataTransferForBlake(hub, this); + final MmuCall returnDataFullTransferForBlake = + MmuCall.fullReturnDataTransferForBlake(hub, this); thirdImcFragment.callMmu(returnDataFullTransferForBlake); // 3rd MISC row - ImcFragment fourthImcFragment = ImcFragment.empty(hub); + final ImcFragment fourthImcFragment = ImcFragment.empty(hub); fragments.add(fourthImcFragment); if (!this.parentReturnDataTarget.isEmpty()) { - MmuCall partialReturnDataCopyForBlake = MmuCall.partialCopyOfReturnDataforBlake(hub, this); + final MmuCall partialReturnDataCopyForBlake = + MmuCall.partialCopyOfReturnDataforBlake(hub, this); fourthImcFragment.callMmu(partialReturnDataCopyForBlake); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index c3b96313f9..2dc6bd0593 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -35,6 +35,7 @@ import com.google.common.base.Preconditions; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpCallDataSizeOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpExtractOobCall; @@ -49,6 +50,7 @@ public class ModexpSubsection extends PrecompileSubsection { private final ModExpMetadata modExpMetadata; private ModexpPricingOobCall sixthOobCall; + private ModexpExtractOobCall seventhOobCall; public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); @@ -110,14 +112,19 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { if (modExpMetadata.loadRawLeadingWord()) { final MmuCall mmuCall = forModexpLoadLead(hub, this, modExpMetadata); fifthImcFragment.callMmu(mmuCall); - // final ExpCall expCall = new ModexpLogExpCall(); // TODO: to do - // fifthImcFragment.callExp(expCall); + final ExpCall expCall = null; // TODO: to do new ModexpLogExpCall() ... @Lorenzo; + fifthImcFragment.callExp(expCall); } final ImcFragment sixthImcFragment = ImcFragment.empty(hub); fragments().add(sixthImcFragment); sixthOobCall = new ModexpPricingOobCall(); sixthImcFragment.callOob(sixthOobCall); + + // We need to trigger the OOB before CALL's execution + if (sixthOobCall.isRamSuccess()) { + seventhOobCall = new ModexpExtractOobCall(); + } } @Override @@ -137,7 +144,6 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { final ImcFragment seventhImcFragment = ImcFragment.empty(hub); fragments().add(seventhImcFragment); - final ModexpExtractOobCall seventhOobCall = new ModexpExtractOobCall(); seventhImcFragment.callOob(seventhOobCall); if (modExpMetadata.extractModulus()) { final MmuCall mmuCall = forModexpExtractBase(hub, this, modExpMetadata); From 7937b5a308da62ce4baf9acfc110017c68bd2f1d Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 20 Aug 2024 13:37:38 +0530 Subject: [PATCH 387/461] fix: it's adding the oob call to the imc fragment that triggers OOB Signed-off-by: Francois Bojarski --- .../call/precompileSubsection/ModexpSubsection.java | 8 ++++---- .../main/java/net/consensys/linea/testing/ToyAccount.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 2dc6bd0593..ad8b86ff2d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -50,7 +50,7 @@ public class ModexpSubsection extends PrecompileSubsection { private final ModExpMetadata modExpMetadata; private ModexpPricingOobCall sixthOobCall; - private ModexpExtractOobCall seventhOobCall; + private ImcFragment seventhImcFragment; public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); @@ -123,7 +123,9 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { // We need to trigger the OOB before CALL's execution if (sixthOobCall.isRamSuccess()) { - seventhOobCall = new ModexpExtractOobCall(); + seventhImcFragment = ImcFragment.empty(hub); + final ModexpExtractOobCall seventhOobCall = new ModexpExtractOobCall(); + seventhImcFragment.callOob(seventhOobCall); } } @@ -142,9 +144,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { modExpMetadata.rawResult(returnData); hub.blakeModexpData().callModexp(modExpMetadata, this.exoModuleOperationId()); - final ImcFragment seventhImcFragment = ImcFragment.empty(hub); fragments().add(seventhImcFragment); - seventhImcFragment.callOob(seventhOobCall); if (modExpMetadata.extractModulus()) { final MmuCall mmuCall = forModexpExtractBase(hub, this, modExpMetadata); seventhImcFragment.callMmu(mmuCall); diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java index 1e6d164f8b..8ede8a815f 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java @@ -71,7 +71,7 @@ public Address getAddress() { @Override public boolean isStorageEmpty() { - return false;//TODO fix NPE triggered by setting it to this.storage.isEmpty(); + return false; // TODO fix NPE triggered by setting it to this.storage.isEmpty(); } @Override From 68ba4ca978a828063fabaec234700e8b167193f2 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 20 Aug 2024 15:27:23 +0530 Subject: [PATCH 388/461] fix keccak calling twice SHAKIRA + no need to reorder SHAKIRA op Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 4 +- .../module/hub/section/KeccakSection.java | 1 - .../module/shakiradata/ShakiraData.java | 48 ++++++------------- .../shakiradata/ShakiraDataComparator.java | 25 ---------- .../shakiradata/ShakiraDataOperation.java | 1 + zkevm-constraints | 2 +- 6 files changed, 18 insertions(+), 63 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataComparator.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 220070b36f..8863a73a59 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -740,8 +740,8 @@ public void tracePreExecution(final MessageFrame frame) { public void tracePostExecution(MessageFrame frame, Operation.OperationResult operationResult) { Preconditions.checkArgument( - this.state().processingPhase != TX_SKIP, - "There can't be any execution if the HUB is in the a skip phase"); + this.state().processingPhase == TX_EXEC, + "There can't be any execution if the HUB is not in execution phase"); final long gasCost = operationResult.getGasCost(); final TraceSection currentSection = this.state.currentTxTrace().currentSection(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index ecfa3d6b1f..eda52361d9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -49,7 +49,6 @@ public KeccakSection(Hub hub) { triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions()); if (triggerMmu) { - hub.defers().scheduleForPostExecution(this); final MmuCall mmuCall = MmuCall.sha3(hub); imcFragment.callMmu(mmuCall); hashInput = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java index 8b4f52fdc0..a94d68cb01 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraData.java @@ -18,32 +18,28 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import java.nio.MappedByteBuffer; -import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.container.stacked.set.StackedSet; +import net.consensys.linea.zktracer.container.stacked.list.StackedList; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.limits.Keccak; import net.consensys.linea.zktracer.module.limits.precompiles.RipemdBlocks; import net.consensys.linea.zktracer.module.limits.precompiles.Sha256Blocks; import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor public class ShakiraData implements Module { private final Wcp wcp; - private final StackedSet operations = new StackedSet<>(); - private final List sortedOperations = new ArrayList<>(); - private int numberOfOperationsAtStartTx = 0; - private final ShakiraDataComparator comparator = new ShakiraDataComparator(); + private final StackedList operations = new StackedList<>(); private final Sha256Blocks sha256Blocks; private final Keccak keccak; private final RipemdBlocks ripemdBlocks; + private long previousID = 0; + @Override public String moduleKey() { return "SHAKIRA_DATA"; @@ -51,18 +47,17 @@ public String moduleKey() { @Override public void enterTransaction() { - this.operations.enter(); + operations.enter(); } @Override public void popTransaction() { - this.sortedOperations.removeAll(this.operations.sets.getLast()); - this.operations.pop(); + operations.pop(); } @Override public int lineCount() { - return this.operations.lineCount() + return operations.lineCount() + 1; /*because the lookup HUB -> SHAKIRA requires at least two padding rows. TODO: shouldn't it be done by Corset via the spilling ? */ } @@ -72,9 +67,12 @@ public List columnsHeaders() { } public void call(final ShakiraDataOperation operation) { - this.operations.add(operation); - this.wcp.callGT(operation.lastNBytes(), 0); - this.wcp.callLEQ(operation.lastNBytes(), LLARGE); + operations.add(operation); + + wcp.callLT(previousID, operation.ID()); + previousID = operation.ID(); + wcp.callGT(operation.lastNBytes(), 0); + wcp.callLEQ(operation.lastNBytes(), LLARGE); switch (operation.hashType()) { case SHA256 -> sha256Blocks.addPrecompileLimit(operation.inputSize()); @@ -84,24 +82,6 @@ public void call(final ShakiraDataOperation operation) { } } - @Override - public void traceStartTx(WorldView worldView, TransactionProcessingMetadata tx) { - this.numberOfOperationsAtStartTx = operations.size(); - } - - @Override - public void traceEndTx(TransactionProcessingMetadata tx) { - final List newOperations = - new ArrayList<>(this.operations.sets.getLast()); - newOperations.sort(comparator); - this.sortedOperations.addAll(newOperations); - final int numberOfOperationsAtEndTx = sortedOperations.size(); - for (int i = numberOfOperationsAtStartTx; i < numberOfOperationsAtEndTx; i++) { - final long previousID = i == 0 ? 0 : sortedOperations.get(i - 1).ID(); - this.wcp.callLT(previousID, sortedOperations.get(i).ID()); - } - } - @Override public void commit(List buffers) { final Trace trace = new Trace(buffers); @@ -110,7 +90,7 @@ public void commit(List buffers) { trace.fillAndValidateRow(); int stamp = 0; - for (ShakiraDataOperation operation : sortedOperations) { + for (ShakiraDataOperation operation : operations) { stamp++; operation.trace(trace, stamp); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataComparator.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataComparator.java deleted file mode 100644 index 5a515185b9..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataComparator.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.shakiradata; - -import java.util.Comparator; - -class ShakiraDataComparator implements Comparator { - @Override - public int compare(ShakiraDataOperation o1, ShakiraDataOperation o2) { - return (int) (o1.ID() - o2.ID()); - } -} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java index e57489ad14..aaa172da0d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java @@ -173,6 +173,7 @@ private void traceResult(Trace trace, final int stamp) { } } + // TODO: this should die, we should use teh result from BESU private Bytes computeResult() { return switch (hashType) { case SHA256 -> Hash.sha256(hashInput); diff --git a/zkevm-constraints b/zkevm-constraints index 7dfe31be50..11438efcd6 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 7dfe31be505c6852195caaf140bcf886b7b84c62 +Subproject commit 11438efcd688cced4f0904eefc8c402b22d2f02e From ec82e4752b44f707c7690395cc1b1cfb29b4b417 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 20 Aug 2024 16:03:55 +0530 Subject: [PATCH 389/461] fix(blake): trigger blakeModexp for Blake2f Signed-off-by: Francois Bojarski --- .../blake2fmodexpdata/BlakeComponents.java | 2 +- .../blake2fmodexpdata/BlakeModexpData.java | 51 +++++++------------ .../BlakeModexpDataOperation.java | 4 +- .../precompileSubsection/BlakeSubsection.java | 6 +++ 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeComponents.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeComponents.java index 27ca817d90..c438109761 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeComponents.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeComponents.java @@ -17,4 +17,4 @@ import org.apache.tuweni.bytes.Bytes; -public record BlakeComponents(Bytes data, Bytes r, Bytes f) {} +public record BlakeComponents(Bytes data, Bytes r, Bytes f, Bytes result) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java index 391ac84cf2..7841518537 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java @@ -23,22 +23,18 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_RESULT; import java.nio.MappedByteBuffer; -import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import lombok.RequiredArgsConstructor; import net.consensys.linea.zktracer.ColumnHeader; -import net.consensys.linea.zktracer.container.stacked.set.StackedSet; +import net.consensys.linea.zktracer.container.stacked.list.StackedList; import net.consensys.linea.zktracer.module.Module; import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds; import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall; import net.consensys.linea.zktracer.module.wcp.Wcp; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.worldstate.WorldView; @RequiredArgsConstructor public class BlakeModexpData implements Module { @@ -46,9 +42,9 @@ public class BlakeModexpData implements Module { private final ModexpEffectiveCall modexpEffectiveCall; private final BlakeEffectiveCall blakeEffectiveCall; private final BlakeRounds blakeRounds; - private final StackedSet operations = new StackedSet<>(); - private final List sortedOperations = new ArrayList<>(); - private int numberOfOperationsAtStartTx = 0; + + private final StackedList operations = new StackedList<>(); + private long previousID = 0; @Override public String moduleKey() { @@ -60,29 +56,8 @@ public void enterTransaction() { this.operations.enter(); } - @Override - public void traceEndTx(TransactionProcessingMetadata tx) { - final List newOperations = - new ArrayList<>(this.operations.sets.getLast()) - .stream().sorted(Comparator.comparingLong(BlakeModexpDataOperation::id)).toList(); - - this.sortedOperations.addAll(newOperations); - final int numberOfOperationsAtEndTx = sortedOperations.size(); - for (int i = numberOfOperationsAtStartTx; i < numberOfOperationsAtEndTx; i++) { - final long previousID = i == 0 ? 0 : sortedOperations.get(i - 1).id(); - this.wcp.callLT(previousID, sortedOperations.get(i).id()); - } - } - - @Override - public void traceStartTx( - WorldView world, TransactionProcessingMetadata transactionProcessingMetadata) { - this.numberOfOperationsAtStartTx = operations.size(); - } - @Override public void popTransaction() { - this.sortedOperations.removeAll(this.operations.sets.getLast()); this.operations.pop(); } @@ -96,27 +71,35 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - public void callModexp(final ModExpMetadata modexpMetaData, final int id) { - operations.add(new BlakeModexpDataOperation(modexpMetaData, id)); + public void callModexp(final ModExpMetadata modexpMetaData, final int operationID) { + operations.add(new BlakeModexpDataOperation(modexpMetaData, operationID)); modexpEffectiveCall.addPrecompileLimit(1); + callWcpForIdCheck(operationID); } - public void callBlake(final BlakeComponents blakeComponents) { - operations.add(new BlakeModexpDataOperation(blakeComponents)); + public void callBlake(final BlakeComponents blakeComponents, final int operationID) { + operations.add(new BlakeModexpDataOperation(blakeComponents, operationID)); blakeEffectiveCall.addPrecompileLimit(1); blakeRounds.addPrecompileLimit(blakeComponents.r().toInt()); + callWcpForIdCheck(operationID); + } + + private void callWcpForIdCheck(final int operationID) { + wcp.callLT(previousID, operationID); + previousID = operationID; } @Override public void commit(List buffers) { Trace trace = new Trace(buffers); int stamp = 0; - for (BlakeModexpDataOperation o : this.sortedOperations) { + for (BlakeModexpDataOperation o : operations) { stamp++; o.trace(trace, stamp); } } + // TODO: this should die, the MMU just have to read in MmuCall public Bytes getInputDataByIdAndPhase(final int id, final int phase) { final BlakeModexpDataOperation op = getOperationById(id); return switch (phase) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java index e16ddd7d5c..8ff52d6729 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java @@ -67,8 +67,8 @@ public BlakeModexpDataOperation(final ModExpMetadata modexpMetaData, final int i this.blake2fComponents = Optional.empty(); } - public BlakeModexpDataOperation(final BlakeComponents blakeComponents) { - this.id = 0; // TODO + public BlakeModexpDataOperation(final BlakeComponents blakeComponents, final int id) { + this.id = id; this.modexpMetaData = Optional.empty(); this.blake2fComponents = Optional.of(blakeComponents); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java index fd072b9b41..2ec0f52313 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java @@ -19,6 +19,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_RAM; +import net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeComponents; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; @@ -109,6 +110,11 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { MmuCall.partialCopyOfReturnDataforBlake(hub, this); fourthImcFragment.callMmu(partialReturnDataCopyForBlake); } + + // TODO: make it smarter + final BlakeComponents blake2f = + new BlakeComponents(callData, callData.slice(0, 4), callData.slice(212, 1), returnData); + hub.blakeModexpData().callBlake(blake2f, this.exoModuleOperationId()); } @Override From 172e8b927d8c3c9271f041b359d967692fe82f5a Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 20 Aug 2024 13:51:46 +0200 Subject: [PATCH 390/461] fix(selfdestruct): ensure contracts are compatible with London EVM --- .../instructionprocessing/ContractModifyingStorageTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index 6aa995b61a..1b39d82986 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -57,6 +57,8 @@ public class ContractModifyingStorageTest { - The same contract can have a function doing the same stuff. */ + // NOTE: 0.8.0+commit.c7dfd78e compiler version is used and Remix VM (London) as environment to + // compile and deploy the contracts below @Test void contractModifyingStorageInConstructorTest() { // Deploy @@ -71,7 +73,6 @@ void contractModifyingStorageInConstructorTest() { System.out.println("User address: " + userAddress); // Deployment transaction - // NOTE: 3050 in the beginning has been added manually Transaction tx = ToyTransaction.builder() .sender(userAccount) From 837c4ee84d09b81e8b717c787a977889846f5f2c Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Tue, 20 Aug 2024 13:54:08 +0200 Subject: [PATCH 391/461] fix(selfdestruct): update bytecode for tests --- .../instructionprocessing/ContractModifyingStorageTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index 1b39d82986..7a2eaaefb8 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -81,7 +81,7 @@ void contractModifyingStorageInConstructorTest() { .gasLimit(0xffffffL) // 0xffffffffL .payload( Bytes.fromHexString( - "0x3050608060405234801561000f575f80fd5b505f8081905550600180819055506002808190555060038081905550600a5f546100399190610109565b5f81905550600b60015461004d9190610109565b600181905550600c6002546100629190610109565b600281905550600d6003546100779190610109565b6003819055505f805461008a919061013c565b5f81905550601460015461009e919061013c565b60018190555060156002546100b3919061013c565b60028190555060156003546100c8919061013c565b60038190555061017d565b5f819050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f610113826100d3565b915061011e836100d3565b9250828201905080821115610136576101356100dc565b5b92915050565b5f610146826100d3565b9150610151836100d3565b925082820261015f816100d3565b91508282048414831517610176576101756100dc565b5b5092915050565b61012a8061018a5f395ff3fe6080604052348015600e575f80fd5b50600436106044575f3560e01c8063501e82121460485780636cc014de146062578063a314150f14607c578063a5d666a9146096575b5f80fd5b604e60b0565b6040516059919060dd565b60405180910390f35b606860b5565b6040516073919060dd565b60405180910390f35b608260bb565b604051608d919060dd565b60405180910390f35b609c60c1565b60405160a7919060dd565b60405180910390f35b5f5481565b60015481565b60025481565b60035481565b5f819050919050565b60d78160c7565b82525050565b5f60208201905060ee5f83018460d0565b9291505056fea26469706673582212203b939ad06f3d7d92a207fb36abc74231e00c81272ebf0645d4d40e917fc5e43b64736f6c634300081a0033")) + "0x608060405234801561001057600080fd5b5060008081905550600180819055506002808190555060038081905550600a60005461003c91906100d9565b600081905550600b60015461005191906100d9565b600181905550600c60025461006691906100d9565b600281905550600d60035461007b91906100d9565b6003819055506000805461008f919061012f565b60008190555060146001546100a4919061012f565b60018190555060156002546100b9919061012f565b60028190555060156003546100ce919061012f565b6003819055506101c2565b60006100e482610189565b91506100ef83610189565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561012457610123610193565b5b828201905092915050565b600061013a82610189565b915061014583610189565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561017e5761017d610193565b5b828202905092915050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b610131806101d16000396000f3fe6080604052348015600f57600080fd5b506004361060465760003560e01c8063501e821214604b5780636cc014de146065578063a314150f14607f578063a5d666a9146099575b600080fd5b605160b3565b604051605c919060d8565b60405180910390f35b606b60b9565b6040516076919060d8565b60405180910390f35b608560bf565b6040516090919060d8565b60405180910390f35b609f60c5565b60405160aa919060d8565b60405180910390f35b60005481565b60015481565b60025481565b60035481565b60d28160f1565b82525050565b600060208201905060eb600083018460cb565b92915050565b600081905091905056fea2646970667358221220cebaf0c22dd1be33c20b916dce0c167bffc36711ff2f805c6d8667fe803601f464736f6c63430008000033")) .build(); Address deployedAddress = AddressUtils.effectiveToAddress(tx); @@ -118,7 +118,7 @@ void contractModifyingStorageInFunctionTest() { .sender(userAccount) .payload( Bytes.fromHexString( - "0x6080604052348015600e575f80fd5b506102ba8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610055575f3560e01c8063501e8212146100595780636cc014de14610077578063a314150f14610095578063a5d666a9146100b3578063e8af2fa5146100d1575b5f80fd5b6100616100db565b60405161006e91906101ca565b60405180910390f35b61007f6100e0565b60405161008c91906101ca565b60405180910390f35b61009d6100e6565b6040516100aa91906101ca565b60405180910390f35b6100bb6100ec565b6040516100c891906101ca565b60405180910390f35b6100d96100f2565b005b5f5481565b60015481565b60025481565b60035481565b5f8081905550600180819055506002808190555060038081905550600a5f5461011b9190610210565b5f81905550600b60015461012f9190610210565b600181905550600c6002546101449190610210565b600281905550600d6003546101599190610210565b6003819055505f805461016c9190610243565b5f8190555060146001546101809190610243565b60018190555060156002546101959190610243565b60028190555060156003546101aa9190610243565b600381905550565b5f819050919050565b6101c4816101b2565b82525050565b5f6020820190506101dd5f8301846101bb565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61021a826101b2565b9150610225836101b2565b925082820190508082111561023d5761023c6101e3565b5b92915050565b5f61024d826101b2565b9150610258836101b2565b9250828202610266816101b2565b9150828204841483151761027d5761027c6101e3565b5b509291505056fea2646970667358221220b40040e95e9f0674ff5c258759b2ac4564a8cf968f9d59477114688f3eff824364736f6c634300081a0033")) + "0x608060405234801561001057600080fd5b50610304806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c8063501e82121461005c5780636cc014de1461007a578063a314150f14610098578063a5d666a9146100b6578063e8af2fa5146100d4575b600080fd5b6100646100de565b60405161007191906101ca565b60405180910390f35b6100826100e4565b60405161008f91906101ca565b60405180910390f35b6100a06100ea565b6040516100ad91906101ca565b60405180910390f35b6100be6100f0565b6040516100cb91906101ca565b60405180910390f35b6100dc6100f6565b005b60005481565b60015481565b60025481565b60035481565b60008081905550600180819055506002808190555060038081905550600a60005461012191906101e5565b600081905550600b60015461013691906101e5565b600181905550600c60025461014b91906101e5565b600281905550600d60035461016091906101e5565b60038190555060008054610174919061023b565b6000819055506014600154610189919061023b565b600181905550601560025461019e919061023b565b60028190555060156003546101b3919061023b565b600381905550565b6101c481610295565b82525050565b60006020820190506101df60008301846101bb565b92915050565b60006101f082610295565b91506101fb83610295565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156102305761022f61029f565b5b828201905092915050565b600061024682610295565b915061025183610295565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561028a5761028961029f565b5b828202905092915050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fdfea26469706673582212200d443753b26ea215c94e8fd1b03e4d389ebc740d96823003d127316393455da664736f6c63430008000033")) .transactionType(TransactionType.FRONTIER) .gasLimit(0xffffffffL) .value(Wei.ZERO) From 9d998b74f1e914477e7761dc8b83849188efb13e Mon Sep 17 00:00:00 2001 From: FlorianHuc Date: Tue, 20 Aug 2024 14:49:01 +0200 Subject: [PATCH 392/461] use a more realistic gas price. --- .../linea/zktracer/module/rlpaddr/TestRlpAddress.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index 991a429bfa..dd1ddf1f42 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -64,6 +64,7 @@ void randDeployment() { .keyPair(keyPair) .transactionType(TransactionType.FRONTIER) .gasLimit(rnd.nextLong(21000, 0xffffL)) + .gasPrice(Wei.of(10L)) .payload(initCode) .build(); @@ -85,7 +86,7 @@ void create() { final ToyAccount senderAccount = ToyAccount.builder() - .balance(Wei.of(100000000)) + .balance(Wei.fromEth(1000)) .nonce(randLong()) .address(senderAddress) .build(); @@ -94,7 +95,7 @@ void create() { final Address contractAddress = Address.fromHexString("0x000bad000000b077000"); final ToyAccount contractAccount = ToyAccount.builder() - .balance(Wei.of(10000000)) + .balance(Wei.fromEth(1000)) .nonce(10) .address(contractAddress) .code( From 1cf89d2c45875a462f5ad535709a36b20dce3013 Mon Sep 17 00:00:00 2001 From: FlorianHuc Date: Tue, 20 Aug 2024 17:08:54 +0200 Subject: [PATCH 393/461] use a more realistic gas limit. --- .../net/consensys/linea/zktracer/module/oob/OobCallTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java index 40b0f32208..e6cb0a7344 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java @@ -94,7 +94,7 @@ void testRecursiveCalls1025() { void TestRecursiveCallsWithBytecode() { BytecodeRunner bytecodeRunner = BytecodeRunner.of(Bytes.fromHexString("60006000600060006000305af1")); - bytecodeRunner.run(Wei.fromEth(400), 0xfffffffffffL); + bytecodeRunner.run(Wei.fromEth(400), 0xFFFFFFFFL); Hub hub = bytecodeRunner.getHub(); From 032a3ee05618f6677d01f2c3b10ff4b43f4f1687 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 10:44:08 +0530 Subject: [PATCH 394/461] fix recipient account in init phase for deployement tx Signed-off-by: Francois Bojarski --- .../hub/fragment/account/AccountFragment.java | 41 +++++++++---------- .../hub/section/TxInitializationSection.java | 27 ++++++++---- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index c289aa8ad2..f9e80a81c9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -98,13 +98,13 @@ public AccountFragment( DomSubStampsSubFragment domSubStampsSubFragment) { Preconditions.checkArgument(oldState.address().equals(newState.address())); - this.transactionProcessingMetadata = hub.txStack().current(); - this.hubStamp = hub.stamp(); + transactionProcessingMetadata = hub.txStack().current(); + hubStamp = hub.stamp(); this.oldState = oldState; this.newState = newState; - this.deploymentNumber = newState.deploymentNumber(); - this.isDeployment = newState.deploymentStatus(); + deploymentNumber = newState.deploymentNumber(); + isDeployment = newState.deploymentStatus(); this.addressToTrim = addressToTrim; this.domSubStampsSubFragment = domSubStampsSubFragment; @@ -122,9 +122,9 @@ public Trace trace(Trace trace) { final EWord eCodeHashNew = EWord.of(newState.code().getCodeHash()); // tracing - this.domSubStampsSubFragment.trace(trace); + domSubStampsSubFragment.trace(trace); if (rlpAddrSubFragment != null) { - this.rlpAddrSubFragment.trace(trace); + rlpAddrSubFragment.trace(trace); } return trace @@ -143,7 +143,7 @@ public Trace trace(Trace trace) { .pAccountCodeHashLoNew(eCodeHashNew.lo()) .pAccountHasCode(oldState.code().getCodeHash() != Hash.EMPTY) .pAccountHasCodeNew(newState.code().getCodeHash() != Hash.EMPTY) - .pAccountCodeFragmentIndex(this.codeFragmentIndex) + .pAccountCodeFragmentIndex(codeFragmentIndex) .pAccountRomlexFlag(requiresRomlex) .pAccountExists( oldState.nonce() > 0 @@ -163,8 +163,8 @@ public Trace trace(Trace trace) { .pAccountDeploymentStatusNew(newState.deploymentStatus()) .pAccountDeploymentNumberInfty(deploymentNumberInfinity) .pAccountDeploymentStatusInfty(existsInfinity) - .pAccountTrmFlag(this.addressToTrim.isPresent()) - .pAccountTrmRawAddressHi(this.addressToTrim.map(a -> EWord.of(a).hi()).orElse(Bytes.EMPTY)) + .pAccountTrmFlag(addressToTrim.isPresent()) + .pAccountTrmRawAddressHi(addressToTrim.map(a -> EWord.of(a).hi()).orElse(Bytes.EMPTY)) .pAccountIsPrecompile(isPrecompile(oldState.address())); } @@ -175,28 +175,27 @@ public void resolvePostTransaction( transactionProcessingMetadata.getEffectiveSelfDestructMap(); final TransactionProcessingMetadata.EphemeralAccount ephemeralAccount = new TransactionProcessingMetadata.EphemeralAccount( - this.oldState.address(), this.oldState.deploymentNumber()); + oldState.address(), oldState.deploymentNumber()); if (effectiveSelfDestructMap.containsKey(ephemeralAccount)) { final int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); - this.markedForSelfDestruct = this.hubStamp < selfDestructTime; - this.markedForSelfDestructNew = this.hubStamp >= selfDestructTime; + markedForSelfDestruct = hubStamp < selfDestructTime; + markedForSelfDestructNew = hubStamp >= selfDestructTime; } else { - this.markedForSelfDestruct = false; - this.markedForSelfDestructNew = false; + markedForSelfDestruct = false; + markedForSelfDestructNew = false; } } @Override public void resolvePostConflation(Hub hub, WorldView world) { - this.deploymentNumberInfinity = - hub.transients().conflation().deploymentInfo().number(this.oldState.address()); - this.existsInfinity = world.get(this.oldState.address()) != null; - this.codeFragmentIndex = - this.requiresRomlex + deploymentNumberInfinity = + hub.transients().conflation().deploymentInfo().number(oldState.address()); + existsInfinity = world.get(oldState.address()) != null; + codeFragmentIndex = + requiresRomlex ? hub.romLex() .getCodeFragmentIndexByMetadata( - ContractMetadata.make( - this.oldState.address(), this.deploymentNumber, this.isDeployment)) + ContractMetadata.make(oldState.address(), deploymentNumber, isDeployment)) : 0; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index f584b066c7..b8fd8bfe29 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -67,14 +67,25 @@ public TxInitializationSection(Hub hub, WorldView world) { final Account recipientAccount = world.get(toAddress); - final AccountSnapshot recipientBeforeValueTransfer = - isSelfCredit - ? senderAfterPayingForTransaction - : AccountSnapshot.fromAccount( - recipientAccount, - tx.isReceiverPreWarmed(), - deploymentInfo.number(toAddress), - deploymentInfo.isDeploying(toAddress)); + AccountSnapshot recipientBeforeValueTransfer; + + if (recipientAccount != null) { + recipientBeforeValueTransfer = + isSelfCredit + ? senderAfterPayingForTransaction + : AccountSnapshot.fromAccount( + recipientAccount, + tx.isReceiverPreWarmed(), + deploymentInfo.number(toAddress), + deploymentInfo.isDeploying(toAddress)); + } else { + recipientBeforeValueTransfer = + AccountSnapshot.fromAddress( + toAddress, + tx.isReceiverPreWarmed(), + deploymentInfo.number(toAddress), + deploymentInfo.isDeploying(toAddress)); + } if (isDeployment) { deploymentInfo.deploy(toAddress); From f4a9fe0038d857061c9172bcf1332212df9d0fb6 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 11:24:05 +0530 Subject: [PATCH 395/461] test: more gas available Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/rlpaddr/TestRlpAddress.java | 4 ++-- .../linea/zktracer/module/rlpcommon/RlpRandEdgeCase.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index dd1ddf1f42..a5e102d81e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -63,7 +63,7 @@ void randDeployment() { .sender(senderAccount) .keyPair(keyPair) .transactionType(TransactionType.FRONTIER) - .gasLimit(rnd.nextLong(21000, 0xffffL)) + .gasLimit(1000000L) .gasPrice(Wei.of(10L)) .payload(initCode) .build(); @@ -135,7 +135,7 @@ void create() { .to(contractAccount) .keyPair(keyPair) .transactionType(TransactionType.FRONTIER) - .gasLimit(rnd.nextLong(21000, 0xffffL)) + .gasLimit(1000000L) .payload(initCodeReturnContractCode) .build(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpcommon/RlpRandEdgeCase.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpcommon/RlpRandEdgeCase.java index 8e0dbeb817..23c4f697d1 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpcommon/RlpRandEdgeCase.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpcommon/RlpRandEdgeCase.java @@ -61,7 +61,7 @@ public static Long randLong() { case 0 -> 0L; case 1 -> RAND.nextLong(1, 128); case 2 -> RAND.nextLong(128, 256); - case 3 -> RAND.nextLong(256, 0xfffffffffffffffL); + case 3 -> RAND.nextLong(256, 0xfffffffffffffffL - 2); default -> throw new IllegalStateException("Unexpected value: " + selector); }; } From 26a4240cf9fe744735dae44974639ab23477449d Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 11:40:58 +0530 Subject: [PATCH 396/461] fix ras Signed-off-by: Francois Bojarski --- .../module/hub/section/copy/ExtCodeCopySection.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index bdca9c4a3a..cb25e20379 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -54,7 +54,7 @@ public ExtCodeCopySection(Hub hub) { final MessageFrame frame = hub.messageFrame(); rawAddress = frame.getStackItem(0); - address = Address.extract((Bytes32) rawAddress); + address = Address.extract(Bytes32.leftPad(rawAddress)); incomingDeploymentNumber = hub.transients().conflation().deploymentInfo().number(address); incomingDeploymentStatus = hub.transients().conflation().deploymentInfo().isDeploying(address); incomingWarmth = frame.isAddressWarm(address); @@ -78,9 +78,9 @@ public ExtCodeCopySection(Hub hub) { return; } - final Account foreignAccount = frame.getWorldUpdater().get(this.address); + final Account foreignAccount = frame.getWorldUpdater().get(address); - this.accountBefore = AccountSnapshot.canonical(hub, address); + accountBefore = AccountSnapshot.canonical(hub, address); final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); @@ -102,7 +102,7 @@ public ExtCodeCopySection(Hub hub) { final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; if (triggerMmu) { - MmuCall mmuCall = MmuCall.extCodeCopy(hub); + final MmuCall mmuCall = MmuCall.extCodeCopy(hub); imcFragment.callMmu(mmuCall); } @@ -110,7 +110,7 @@ public ExtCodeCopySection(Hub hub) { // in particular: write tests for that scenario final boolean triggerCfi = triggerMmu && foreignAccount.hasCode(); - this.accountAfter = + accountAfter = AccountSnapshot.fromAccount( foreignAccount, true, incomingDeploymentNumber, incomingDeploymentStatus); @@ -130,7 +130,7 @@ public ExtCodeCopySection(Hub hub) { @Override public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) { - AccountSnapshot accountPostRollback = AccountSnapshot.canonical(hub, address); + final AccountSnapshot accountPostRollback = AccountSnapshot.canonical(hub, address); final DomSubStampsSubFragment undoingDomSubStamps = DomSubStampsSubFragment.revertWithCurrentDomSubStamps( From 3ae2f9851289f565da5b4bcd57dba4e4a94b246a Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 12:12:01 +0530 Subject: [PATCH 397/461] fix extcodecopying empty account Signed-off-by: Francois Bojarski --- .../module/hub/section/copy/ExtCodeCopySection.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index cb25e20379..86ff2bb90a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -80,7 +80,11 @@ public ExtCodeCopySection(Hub hub) { final Account foreignAccount = frame.getWorldUpdater().get(address); - accountBefore = AccountSnapshot.canonical(hub, address); + accountBefore = + foreignAccount != null + ? AccountSnapshot.canonical(hub, address) + : AccountSnapshot.fromAddress( + address, incomingWarmth, incomingDeploymentNumber, incomingDeploymentStatus); final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); @@ -108,11 +112,10 @@ public ExtCodeCopySection(Hub hub) { // TODO: make sure that hasCode returns false during deployments // in particular: write tests for that scenario - final boolean triggerCfi = triggerMmu && foreignAccount.hasCode(); + final boolean foreignAccountHasCode = foreignAccount != null && foreignAccount.hasCode(); + final boolean triggerCfi = triggerMmu && foreignAccountHasCode; - accountAfter = - AccountSnapshot.fromAccount( - foreignAccount, true, incomingDeploymentNumber, incomingDeploymentStatus); + accountAfter = accountBefore.turnOnWarmth(); final AccountFragment accountDoingFragment = hub.factories() From dc6aae7ddc411ea3c7056be2fa36a4df56cc2d9e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 13:44:43 +0530 Subject: [PATCH 398/461] clean: delete duplicate when creating section Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 28 +-- .../module/hub/section/AccountSection.java | 1 - .../hub/section/CallDataLoadSection.java | 1 - .../module/hub/section/ContextSection.java | 1 - .../module/hub/section/CreateSection.java | 1 - .../module/hub/section/ExpSection.java | 1 - .../module/hub/section/JumpSection.java | 17 +- .../module/hub/section/KeccakSection.java | 1 - .../module/hub/section/SloadSection.java | 1 - .../module/hub/section/SstoreSection.java | 2 - .../module/hub/section/StackOnlySection.java | 1 - .../module/hub/section/StackRamSection.java | 1 - .../module/hub/section/TraceSection.java | 2 + .../hub/section/TransactionSection.java | 1 - .../hub/section/TxFinalizationSection.java | 188 +++++++++--------- .../hub/section/TxInitializationSection.java | 41 ++-- .../hub/section/TxPreWarmingMacroSection.java | 21 +- ...ctionDefers.java => TxSkippedSection.java} | 77 ++++--- .../module/hub/section/call/CallSection.java | 2 +- .../hub/section/copy/CallDataCopySection.java | 11 +- .../hub/section/copy/CodeCopySection.java | 1 - .../hub/section/copy/ExtCodeCopySection.java | 1 - .../section/copy/ReturnDataCopySection.java | 1 - .../hub/section/halt/ReturnSection.java | 1 - .../hub/section/halt/RevertSection.java | 1 - .../hub/section/halt/SelfdestructSection.java | 1 - .../module/hub/section/halt/StopSection.java | 1 - 27 files changed, 179 insertions(+), 227 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/{TxSkippedSectionDefers.java => TxSkippedSection.java} (71%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 8863a73a59..409d89089c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -17,10 +17,10 @@ import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINL; +import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM; import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT; -import static net.consensys.linea.zktracer.opcode.InstructionFamily.CALL; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import java.nio.MappedByteBuffer; @@ -66,7 +66,7 @@ import net.consensys.linea.zktracer.module.hub.section.TxFinalizationSection; import net.consensys.linea.zktracer.module.hub.section.TxInitializationSection; import net.consensys.linea.zktracer.module.hub.section.TxPreWarmingMacroSection; -import net.consensys.linea.zktracer.module.hub.section.TxSkippedSectionDefers; +import net.consensys.linea.zktracer.module.hub.section.TxSkippedSection; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.module.hub.section.copy.CallDataCopySection; import net.consensys.linea.zktracer.module.hub.section.copy.CodeCopySection; @@ -489,23 +489,23 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo } public void traceStartTransaction(final WorldView world, final Transaction tx) { - this.pch.reset(); - this.state.enter(); - this.txStack.enterTransaction(world, tx, transients.block()); + pch.reset(); + state.enter(); + txStack.enterTransaction(world, tx, transients.block()); this.enterTransaction(); - if (!this.txStack.current().requiresEvmExecution()) { - this.state.setProcessingPhase(TX_SKIP); - this.state.stamps().incrementHubStamp(); - this.defers.scheduleForPostTransaction( - new TxSkippedSectionDefers(world, this.txStack.current(), this.transients)); + if (!txStack.current().requiresEvmExecution()) { + state.setProcessingPhase(TX_SKIP); + state.stamps().incrementHubStamp(); + defers.scheduleForPostTransaction( + new TxSkippedSection(this, world, this.txStack.current(), this.transients)); } else { - if (this.txStack.current().requiresPrewarming()) { - this.state.setProcessingPhase(TX_WARM); + if (txStack.current().requiresPrewarming()) { + state.setProcessingPhase(TX_WARM); new TxPreWarmingMacroSection(world, this); } - + state.setProcessingPhase(TX_INIT); new TxInitializationSection(this, world); } @@ -515,7 +515,7 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { * 2. should be the father of all root contexts * 3. should have the current root context as its lastCallee() */ - this.callStack.getById(0).universalParentReturnDataContextNumber(this.stamp() + 1); + callStack.getById(0).universalParentReturnDataContextNumber(this.stamp() + 1); for (Module m : this.modules) { m.traceStartTx(world, this.txStack().current()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java index 13b73dca4b..28fe486e4d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/AccountSection.java @@ -39,7 +39,6 @@ public class AccountSection extends TraceSection implements PostRollbackDefer { public AccountSection(Hub hub) { super(hub, maxNumberOfRows(hub)); - hub.addTraceSection(this); this.addStack(hub); final short exceptions = hub.pch().exceptions(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index b921bcb7f2..e8d0ed66ee 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -46,7 +46,6 @@ public class CallDataLoadSection extends TraceSection { public CallDataLoadSection(Hub hub) { super(hub, (short) (hub.opCode().equals(OpCode.CALLDATALOAD) ? 4 : 3)); - hub.addTraceSection(this); this.addStack(hub); this.exception = hub.pch().exceptions(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java index 2821704393..98ec40f1fb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ContextSection.java @@ -21,7 +21,6 @@ public class ContextSection extends TraceSection { public ContextSection(Hub hub) { super(hub, (short) 3); - hub.addTraceSection(this); ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); this.addStackAndFragments(hub, currentContext); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java index 566801f2cf..700c8828a3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CreateSection.java @@ -95,7 +95,6 @@ public CreateSection(Hub hub) { super(hub, maxNumberOfLines(hub.pch().exceptions(), hub.pch().abortingConditions())); final short exceptions = hub.pch().exceptions(); - hub.addTraceSection(this); this.addStack(hub); // row i+ 0 diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java index deeb6cef19..456cbd78ca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/ExpSection.java @@ -26,7 +26,6 @@ public ExpSection(Hub hub) { // 1 + 1 (stack, misc) // 1 + 1 + 1 (stack, misc, context) super(hub, Exceptions.none(hub.pch().exceptions()) ? (short) 3 : (short) 2); - hub.addTraceSection(this); final ExpCall expCall = new ExplogExpCall(); final ImcFragment miscFragment = ImcFragment.empty(hub).callExp(expCall); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java index b08217f89e..a5cc75a8df 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/JumpSection.java @@ -37,11 +37,6 @@ public JumpSection(Hub hub) { // 5 = 1 + 4 // There are up to 4 NSR's super(hub, (short) 5); - this.populateSection(hub); - hub.addTraceSection(this); - } - - public void populateSection(Hub hub) { this.addStackAndFragments(hub); @@ -51,22 +46,22 @@ public void populateSection(Hub hub) { // CONTEXT fragment /////////////////// - ContextFragment contextRowCurrentContext = ContextFragment.readCurrentContextData(hub); + final ContextFragment contextRowCurrentContext = ContextFragment.readCurrentContextData(hub); // ACCOUNT fragment /////////////////// - Address codeAddress = hub.messageFrame().getContractAddress(); + final Address codeAddress = hub.messageFrame().getContractAddress(); - DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); + final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); final int deploymentNumber = deploymentInfo.number(codeAddress); final boolean deploymentStatus = deploymentInfo.isDeploying(codeAddress); final boolean warmth = hub.messageFrame().isAddressWarm(codeAddress); Preconditions.checkArgument(warmth); - AccountSnapshot codeAccount = canonical(hub, codeAddress); + final AccountSnapshot codeAccount = canonical(hub, codeAddress); - AccountFragment accountRowCodeAccount = + final AccountFragment accountRowCodeAccount = hub.factories() .accountFragment() .make( @@ -76,7 +71,7 @@ public void populateSection(Hub hub) { // MISCELLANEOUS fragment ///////////////////////// - ImcFragment miscellaneousRow = ImcFragment.empty(hub); + final ImcFragment miscellaneousRow = ImcFragment.empty(hub); boolean mustAttemptJump = false; switch (hub.opCode()) { case OpCode.JUMP -> { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index eda52361d9..d0ce948f11 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -36,7 +36,6 @@ public class KeccakSection extends TraceSection implements PostOpcodeDefer { public KeccakSection(Hub hub) { super(hub, (short) 3); - hub.addTraceSection(this); hub.defers().scheduleForPostExecution(this); final ImcFragment imcFragment = ImcFragment.empty(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 0cfca1fa74..26ee99863a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -61,7 +61,6 @@ public SloadSection(Hub hub, WorldView world) { this.valueCurrent = EWord.of(world.get(address).getStorageValue(UInt256.fromBytes(storageKey))); this.exceptions = hub.pch().exceptions(); - hub.addTraceSection(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); // NOTE: SLOAD can only trigger diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 911e39330b..48b7852f13 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -63,8 +63,6 @@ public SstoreSection(Hub hub, WorldView world) { this.valueNext = EWord.of(hub.messageFrame().getStackItem(1)); final short exceptions = hub.pch().exceptions(); - hub.addTraceSection(this); - final boolean staticContextException = Exceptions.staticFault(exceptions); final boolean sstoreException = Exceptions.outOfSStore(exceptions); 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 70d1c61b58..07ceedaa87 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 @@ -20,7 +20,6 @@ public class StackOnlySection extends TraceSection { public StackOnlySection(Hub hub) { super(hub, (short) (hub.opCode().getData().stackSettings().twoLineInstruction() ? 2 : 1)); - hub.addTraceSection(this); this.addStack(hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java index a416c1a44d..d4d25a3a5f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackRamSection.java @@ -40,7 +40,6 @@ public class StackRamSection extends TraceSection { public StackRamSection(Hub hub) { super(hub, (short) 3); - hub.addTraceSection(this); this.addStack(hub); final OpCode instruction = hub.opCode(); 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 fd39e89623..c49791e7fa 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 @@ -63,6 +63,7 @@ public TraceSection(Hub hub) { this.fragments = new ArrayList<>( 22); // 22 is the maximum number of lines in a section (Successful reverted Modexp) + hub.addTraceSection(this); } /** Default creator specifying the max number of rows the section can contain. */ @@ -70,6 +71,7 @@ public TraceSection(final Hub hub, final short maxNumberOfLines) { this.hub = hub; this.commonValues = new CommonFragmentValues(hub); this.fragments = new ArrayList<>(maxNumberOfLines); + hub.addTraceSection(this); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java index f66d1f4098..2f8c7dc515 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TransactionSection.java @@ -25,7 +25,6 @@ public TransactionSection(Hub hub) { // 2 = 1 + 1 (stack, transaction) // 3 = 1 + 1 + 1 (stack, transaction, context) super(hub, Exceptions.none(hub.pch().exceptions()) ? (short) 2 : (short) 3); - hub.addTraceSection(this); this.addStackAndFragments(hub, TransactionFragment.prepare(hub.txStack().current())); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java index 85e9b4141c..aa96bb21f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxFinalizationSection.java @@ -20,7 +20,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -29,7 +28,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.worldstate.WorldView; -public class TxFinalizationSection implements PostTransactionDefer { +public class TxFinalizationSection extends TraceSection implements PostTransactionDefer { private final TransactionProcessingMetadata txMetadata; private final AccountSnapshot fromAccountBeforeTxFinalization; private final AccountSnapshot toAccountBeforeTxFinalization; @@ -39,6 +38,7 @@ public class TxFinalizationSection implements PostTransactionDefer { private @Setter AccountSnapshot minerAccountAfterTxFinalization; public TxFinalizationSection(Hub hub, WorldView world) { + super(hub, (short) 4); this.txMetadata = hub.txStack().current(); final DeploymentInfo depInfo = hub.transients().conflation().deploymentInfo(); @@ -105,102 +105,105 @@ public void resolvePostTransaction( private void successfulFinalization(Hub hub) { if (!senderIsMiner()) { - hub.addTraceSection( - new FinalizationSection( - hub, - hub.factories() - .accountFragment() - .make( - this.fromAccountBeforeTxFinalization, - this.fromAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), - hub.factories() - .accountFragment() - .make( - this.minerAccountBeforeTxFinalization, - this.minerAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), - TransactionFragment.prepare(hub.txStack().current()))); + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0))); + + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.minerAccountBeforeTxFinalization, + this.minerAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1))); + this.addFragment(TransactionFragment.prepare(hub.txStack().current())); } else { // TODO: verify it works - hub.addTraceSection( - new FinalizationSection( - hub, - hub.factories() - .accountFragment() - .make( - this.fromAccountBeforeTxFinalization, - this.fromAccountBeforeTxFinalization.incrementBalance( - txMetadata.getGasRefundInWei()), - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), - hub.factories() - .accountFragment() - .make( - this.fromAccountBeforeTxFinalization, - this.minerAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), - TransactionFragment.prepare(hub.txStack().current()))); + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountBeforeTxFinalization.incrementBalance( + txMetadata.getGasRefundInWei()), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0))); + + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.minerAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1))); + this.addFragment(TransactionFragment.prepare(hub.txStack().current())); } } private void unsuccessfulFinalization(Hub hub) { if (noAccountCollision()) { - hub.addTraceSection( - new FinalizationSection( - hub, - hub.factories() - .accountFragment() - .make( - this.fromAccountBeforeTxFinalization, - this.fromAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), - hub.factories() - .accountFragment() - .make( - this.toAccountBeforeTxFinalization, - this.toAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), - hub.factories() - .accountFragment() - .make( - this.minerAccountBeforeTxFinalization, - this.minerAccountAfterTxFinalization, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2)), - TransactionFragment.prepare(hub.txStack().current()))); + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0))); + + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.toAccountBeforeTxFinalization, + this.toAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1))); + + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.minerAccountBeforeTxFinalization, + this.minerAccountAfterTxFinalization, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2))); + this.addFragment(TransactionFragment.prepare(hub.txStack().current())); } else { // TODO: test this - hub.addTraceSection( - new FinalizationSection( - hub, - hub.factories() - .accountFragment() - .make( - this.fromAccountBeforeTxFinalization, - this.fromAccountBeforeTxFinalization - .incrementBalance((Wei) txMetadata.getBesuTransaction().getValue()) - .incrementBalance(txMetadata.getGasRefundInWei()), - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), - hub.factories() - .accountFragment() - .make( - senderIsTo() - ? this.fromAccountBeforeTxFinalization - : this.toAccountBeforeTxFinalization, - senderIsTo() - ? this.fromAccountBeforeTxFinalization.decrementBalance( - (Wei) txMetadata.getBesuTransaction().getValue()) - : this.toAccountBeforeTxFinalization.decrementBalance( - (Wei) txMetadata.getBesuTransaction().getValue()), - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), - hub.factories() - .accountFragment() - .make( - this.minerAccountAfterTxFinalization.decrementBalance( - txMetadata.getMinerReward()), - this.minerAccountAfterTxFinalization.incrementBalance( - txMetadata.getMinerReward()), - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2)), - TransactionFragment.prepare(hub.txStack().current()))); + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.fromAccountBeforeTxFinalization, + this.fromAccountBeforeTxFinalization + .incrementBalance((Wei) txMetadata.getBesuTransaction().getValue()) + .incrementBalance(txMetadata.getGasRefundInWei()), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0))); + this.addFragment( + hub.factories() + .accountFragment() + .make( + senderIsTo() + ? this.fromAccountBeforeTxFinalization + : this.toAccountBeforeTxFinalization, + senderIsTo() + ? this.fromAccountBeforeTxFinalization.decrementBalance( + (Wei) txMetadata.getBesuTransaction().getValue()) + : this.toAccountBeforeTxFinalization.decrementBalance( + (Wei) txMetadata.getBesuTransaction().getValue()), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1))); + + this.addFragment( + hub.factories() + .accountFragment() + .make( + this.minerAccountAfterTxFinalization.decrementBalance( + txMetadata.getMinerReward()), + this.minerAccountAfterTxFinalization.incrementBalance( + txMetadata.getMinerReward()), + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2))); + this.addFragment(TransactionFragment.prepare(hub.txStack().current())); } } @@ -225,11 +228,4 @@ private boolean toIsMiner() { private boolean noAccountCollision() { return !senderIsMiner() && !senderIsTo() && !toIsMiner(); } - - public class FinalizationSection extends TraceSection { - public FinalizationSection(Hub hub, TraceFragment... fragments) { - super(hub, (short) (txMetadata.statusCode() ? 3 : 4)); - this.addFragments(fragments); - } - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index b8fd8bfe29..ba3416dc2c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -22,7 +22,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; @@ -35,8 +34,9 @@ import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.worldstate.WorldView; -public class TxInitializationSection { +public class TxInitializationSection extends TraceSection { public TxInitializationSection(Hub hub, WorldView world) { + super(hub, (short) 5); hub.state.setProcessingPhase(TX_INIT); hub.state.stamps().incrementHubStamp(); @@ -106,31 +106,20 @@ public TxInitializationSection(Hub hub, WorldView world) { final AccountFragment.AccountFragmentFactory accountFragmentFactory = hub.factories().accountFragment(); - hub.addTraceSection( - new InitializationSection( - hub, - accountFragmentFactory.make( - senderBeforePayingForTransaction, - senderAfterPayingForTransaction, - senderDomSubStamps), - accountFragmentFactory - .makeWithTrm( - recipientBeforeValueTransfer, - recipientAfterValueTransfer, - toAddress, - recipientDomSubStamps) - .requiresRomlex(true), - ImcFragment.forTxInit(hub), - ContextFragment.initializeNewExecutionContext(hub), - txFragment)); + this.addFragment( + accountFragmentFactory.make( + senderBeforePayingForTransaction, senderAfterPayingForTransaction, senderDomSubStamps)); + this.addFragment( + accountFragmentFactory + .makeWithTrm( + recipientBeforeValueTransfer, + recipientAfterValueTransfer, + toAddress, + recipientDomSubStamps) + .requiresRomlex(true)); + this.addFragments( + ImcFragment.forTxInit(hub), ContextFragment.initializeNewExecutionContext(hub), txFragment); hub.state.setProcessingPhase(TX_EXEC); } - - public static class InitializationSection extends TraceSection { - public InitializationSection(Hub hub, TraceFragment... fragments) { - super(hub, (short) 5); - this.addFragments(fragments); - } - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 6d55eadfd7..9b511f3f6d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -82,16 +82,15 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { new DomSubStampsSubFragment( DomSubStampsSubFragment.DomSubType.STANDARD, hub.stamp(), 0, 0, 0, 0, 0); - hub.addTraceSection( - new TxPrewarmingSection( - hub, - hub.factories() - .accountFragment() - .makeWithTrm( - preWarmingAccountSnapshot, - postWarmingAccountSnapshot, - address, - domSubStampsSubFragment))); + new TxPrewarmingSection( + hub, + hub.factories() + .accountFragment() + .makeWithTrm( + preWarmingAccountSnapshot, + postWarmingAccountSnapshot, + address, + domSubStampsSubFragment)); seenAddresses.add(address); @@ -122,7 +121,7 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size()); - hub.addTraceSection(new TxPrewarmingSection(hub, storageFragment)); + new TxPrewarmingSection(hub, storageFragment); hub.state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, storageFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java similarity index 71% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java index a4ba2fa4a9..c83665fb07 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSectionDefers.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java @@ -21,7 +21,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.TransactionFragment; import net.consensys.linea.zktracer.module.hub.transients.Transients; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -34,19 +33,20 @@ * later, through a {@link PostTransactionDefer}, to generate the trace chunks required for the * proving of a pure transaction. */ -public class TxSkippedSectionDefers implements PostTransactionDefer { +public class TxSkippedSection extends TraceSection implements PostTransactionDefer { final TransactionProcessingMetadata txMetadata; final AccountSnapshot oldFromAccount; final AccountSnapshot oldToAccount; final AccountSnapshot oldMinerAccount; - public TxSkippedSectionDefers( - WorldView world, TransactionProcessingMetadata txMetadata, Transients transients) { + public TxSkippedSection( + Hub hub, WorldView world, TransactionProcessingMetadata txMetadata, Transients transients) { + super(hub, (short) 4); this.txMetadata = txMetadata; // From account information final Address fromAddress = txMetadata.getBesuTransaction().getSender(); - this.oldFromAccount = + oldFromAccount = AccountSnapshot.fromAccount( world.get(fromAddress), isPrecompile(fromAddress), @@ -58,7 +58,7 @@ public TxSkippedSectionDefers( if (txMetadata.isDeployment()) { transients.conflation().deploymentInfo().deploy(toAddress); } - this.oldToAccount = + oldToAccount = AccountSnapshot.fromAccount( world.get(toAddress), isPrecompile(toAddress), @@ -67,7 +67,7 @@ public TxSkippedSectionDefers( // Miner account information final Address minerAddress = txMetadata.getCoinbase(); - this.oldMinerAccount = + oldMinerAccount = AccountSnapshot.fromAccount( world.get(minerAddress), isPrecompile(minerAddress), @@ -104,41 +104,34 @@ public void resolvePostTransaction( hub.transients().conflation().deploymentInfo().number(minerAddress), false); - // Append the final chunk to the hub chunks - hub.addTraceSection( - new TxSkippedSection( - hub, - // 3 lines -- account changes - // From - hub.factories() - .accountFragment() - .make( - oldFromAccount, - newFromAccount, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0)), - // To - hub.factories() - .accountFragment() - .make( - oldToAccount, - newToAccount, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1)), - // Miner - hub.factories() - .accountFragment() - .make( - oldMinerAccount, - newMinerAccount, - DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2)), - - // 1 line -- transaction data - TransactionFragment.prepare(hub.txStack().current()))); - } + // From + this.addFragment( + hub.factories() + .accountFragment() + .make( + oldFromAccount, + newFromAccount, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0))); - public static class TxSkippedSection extends TraceSection { - public TxSkippedSection(Hub hub, TraceFragment... fragments) { - super(hub, (short) 4); - this.addFragments(fragments); - } + // To + this.addFragment( + hub.factories() + .accountFragment() + .make( + oldToAccount, + newToAccount, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 1))); + + // Miner + this.addFragment( + hub.factories() + .accountFragment() + .make( + oldMinerAccount, + newMinerAccount, + DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 2))); + + // Transaction data + this.addFragment(TransactionFragment.prepare(hub.txStack().current())); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 17056e0001..8d85ac19c4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -115,7 +115,7 @@ public class CallSection extends TraceSection public CallSection(Hub hub) { super(hub, maxNumberOfLines(hub)); - hub.addTraceSection(this); + final short exceptions = hub.pch().exceptions(); // row i + 1 diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java index fed5c950e6..9305968782 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CallDataCopySection.java @@ -31,7 +31,6 @@ public class CallDataCopySection extends TraceSection { public CallDataCopySection(Hub hub) { // 3 = 1 + 2 super(hub, maxNumberOfRows(hub)); - hub.addTraceSection(this); final ImcFragment imcFragment = ImcFragment.empty(hub); this.addStack(hub); @@ -47,7 +46,7 @@ public CallDataCopySection(Hub hub) { // - outOfGasException OOGX //////////////////////////////////// - short exceptions = hub.pch().exceptions(); + final short exceptions = hub.pch().exceptions(); Preconditions.checkArgument(mxpCall.mxpx == Exceptions.memoryExpansionException(exceptions)); // The MXPX case @@ -67,12 +66,10 @@ public CallDataCopySection(Hub hub) { final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; - if (!triggerMmu) { - return; + if (triggerMmu) { + final MmuCall mmuCall = MmuCall.callDataCopy(hub); + imcFragment.callMmu(mmuCall); } - - final MmuCall mmuCall = MmuCall.callDataCopy(hub); - imcFragment.callMmu(mmuCall); } private static short maxNumberOfRows(Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index a498038cb4..c6e7623415 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -34,7 +34,6 @@ public class CodeCopySection extends TraceSection { public CodeCopySection(Hub hub) { super(hub, maxNumberOfRows(hub)); - hub.addTraceSection(this); // Miscellaneous row final ImcFragment imcFragment = ImcFragment.empty(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index 86ff2bb90a..e698ae5a98 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -50,7 +50,6 @@ public class ExtCodeCopySection extends TraceSection implements PostRollbackDefe public ExtCodeCopySection(Hub hub) { // 4 = 1 + 3 super(hub, maxNumberOfRows(hub)); - hub.addTraceSection(this); final MessageFrame frame = hub.messageFrame(); rawAddress = frame.getStackItem(0); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 77201f8777..9568c60e29 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -31,7 +31,6 @@ public class ReturnDataCopySection extends TraceSection { public ReturnDataCopySection(Hub hub) { super(hub, maxNumberOfRows(hub)); - hub.addTraceSection(this); final ContextFragment currentContext = ContextFragment.readCurrentContextData(hub); final ImcFragment imcFragment = ImcFragment.empty(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 0a18d734cb..1ea023e1da 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -64,7 +64,6 @@ public class ReturnSection extends TraceSection public ReturnSection(Hub hub) { super(hub, maxNumberOfRows(hub)); - hub.addTraceSection(this); final CallFrame currentFrame = hub.currentFrame(); returnFromMessageCall = currentFrame.isMessageCall(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java index 3d086e4f12..94e8e213c8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/RevertSection.java @@ -31,7 +31,6 @@ public class RevertSection extends TraceSection { public RevertSection(Hub hub) { // up to 4 = 1 + 3 rows super(hub, (short) 4); - hub.addTraceSection(this); short exceptions = hub.pch().exceptions(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 5792fdd75d..71c44f40f1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -67,7 +67,6 @@ public class SelfdestructSection extends TraceSection public SelfdestructSection(Hub hub) { // up to 8 = 1 + 7 rows super(hub, (short) 8); - hub.addTraceSection(this); // Init this.id = hub.currentFrame().id(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java index fbcc05b07e..d4b6aeca87 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/StopSection.java @@ -47,7 +47,6 @@ public StopSection(Hub hub) { // 3 = 1 + max_NON_STACK_ROWS in message call case // 5 = 1 + max_NON_STACK_ROWS in deployment case super(hub, hub.callStack().current().isMessageCall() ? (short) 3 : (short) 5); - hub.addTraceSection(this); hub.defers().scheduleForPostTransaction(this); // always hubStamp = hub.stamp(); From 40b88e5789dd53ed57bbca3faf6e9a5e57075783 Mon Sep 17 00:00:00 2001 From: FlorianHuc Date: Wed, 21 Aug 2024 11:37:42 +0200 Subject: [PATCH 399/461] Fix NPE + class cast exception --- .../net/consensys/linea/zktracer/module/oob/OobCallTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java index e6cb0a7344..6b422db685 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java @@ -211,7 +211,7 @@ private void testRecursiveCalls(EWord iterations, int numberOfOnesInOobEvent1) { .to(contractCallerAccount) .payload(Bytes.fromHexString("0x63acac8e" + iterations.toString().substring(2))) .transactionType(TransactionType.FRONTIER) - .gasLimit(0xffffffffffL) + .gasLimit(0xFFFFFFFFL) .value(Wei.ZERO) .keyPair(keyPair) .build(); From 92510c4e8e034edebcd524f4be9bc36aa4e4a240 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 15:57:20 +0530 Subject: [PATCH 400/461] ugly fix for root callDataCopy in a root context with empty payload Signed-off-by: Francois Bojarski --- .../module/hub/fragment/imc/mmu/MmuCall.java | 18 ++++++++++++++++-- .../hub/section/CallDataLoadSection.java | 5 ++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 525cda4b2e..486da23a0d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -197,11 +197,25 @@ public static MmuCall callDataCopy(final Hub hub) { final MemorySpan callDataSegment = hub.currentFrame().callDataInfo().memorySpan(); final int callDataContextNumber = callDataContextNumber(hub); - final CallFrame callFrame = hub.callStack().getByContextNumber(callDataContextNumber); + + /* TODO: we have a disjonction isRoot / isNotRoot we have to kill. We have it in the special case + - root context + - payload empty + + In this case, we haven't created a fictious context with the callData and thus hub.callStack().getByContextNumber(callDataContextNumber); + is not working. This is not normal. + * */ + final boolean isRoot = hub.currentFrame().isRoot(); + final CallFrame callFrame = + isRoot ? null : hub.callStack().getByContextNumber(callDataContextNumber); return new MmuCall(hub, MMU_INST_ANY_TO_RAM_WITH_PADDING) .sourceId(callDataContextNumber) - .sourceRamBytes(Optional.of(callFrame.callDataInfo().data())) + .sourceRamBytes( + Optional.of( + isRoot + ? hub.txStack().current().getBesuTransaction().getPayload() + : callFrame.callDataInfo().data())) .targetId(hub.currentFrame().contextNumber()) .targetRamBytes( Optional.of( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index e8d0ed66ee..6c23851a64 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -26,7 +26,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; -import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes.CallDataLoadOobCall; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; @@ -58,12 +57,12 @@ public CallDataLoadSection(Hub hub) { final ImcFragment imcFragment = ImcFragment.empty(hub); - final OobCall oobCall = new CallDataLoadOobCall(); + final CallDataLoadOobCall oobCall = new CallDataLoadOobCall(); imcFragment.callOob(oobCall); if (Exceptions.none(exception)) { - if (!(Words.clampedToLong(sourceOffset) >= callDataSize)) { + if (oobCall.isCdlOutOfBounds()) { final EWord read = EWord.of( From 2de7a1db97cd2f825fa9e6ce16914f788365e379 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 16:41:38 +0530 Subject: [PATCH 401/461] fix: create fictious CN even for empty call data Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 3 +-- .../module/hub/fragment/imc/mmu/MmuCall.java | 18 ++---------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 409d89089c..5b59ed05d4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -565,8 +565,7 @@ public void traceContextEnter(MessageFrame frame) { final Address toAddress = effectiveToAddress(currentTx.getBesuTransaction()); final boolean isDeployment = this.transients.tx().getBesuTransaction().getTo().isEmpty(); - final boolean shouldCopyTxCallData = - !isDeployment && !frame.getInputData().isEmpty() && currentTx.requiresEvmExecution(); + final boolean shouldCopyTxCallData = !isDeployment && currentTx.requiresEvmExecution(); // TODO simplify this, the same bedRock context ( = root context ??) seems to be // generated in // both case diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 486da23a0d..525cda4b2e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -197,25 +197,11 @@ public static MmuCall callDataCopy(final Hub hub) { final MemorySpan callDataSegment = hub.currentFrame().callDataInfo().memorySpan(); final int callDataContextNumber = callDataContextNumber(hub); - - /* TODO: we have a disjonction isRoot / isNotRoot we have to kill. We have it in the special case - - root context - - payload empty - - In this case, we haven't created a fictious context with the callData and thus hub.callStack().getByContextNumber(callDataContextNumber); - is not working. This is not normal. - * */ - final boolean isRoot = hub.currentFrame().isRoot(); - final CallFrame callFrame = - isRoot ? null : hub.callStack().getByContextNumber(callDataContextNumber); + final CallFrame callFrame = hub.callStack().getByContextNumber(callDataContextNumber); return new MmuCall(hub, MMU_INST_ANY_TO_RAM_WITH_PADDING) .sourceId(callDataContextNumber) - .sourceRamBytes( - Optional.of( - isRoot - ? hub.txStack().current().getBesuTransaction().getPayload() - : callFrame.callDataInfo().data())) + .sourceRamBytes(Optional.of(callFrame.callDataInfo().data())) .targetId(hub.currentFrame().contextNumber()) .targetRamBytes( Optional.of( From bfa5cf24d4e48a3114906c5c0438efb1bc2b1a8b Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 17:37:24 +0530 Subject: [PATCH 402/461] fix getting CFI for empty extCodeCopy Signed-off-by: Francois Bojarski --- .../fragment/imc/mmu/opcode/ExtCodeCopy.java | 31 ++++++++++--------- .../zktracer/module/mmu/ExoSumDecoder.java | 2 +- .../zktracer/module/mmu/MmuOperation.java | 5 +-- .../linea/zktracer/module/romlex/RomLex.java | 4 --- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java index 8aed2ae4e4..067094aadc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java @@ -20,23 +20,27 @@ import java.util.Optional; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.defer.PostConflationDefer; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.evm.worldstate.WorldView; /** * A specialization of {@link MmuCall} that addresses the fact that the MMU requires access to the * sorted Code Fragment Index of the copied bytecode, which is only available post-conflation. */ -public class ExtCodeCopy extends MmuCall { +public class ExtCodeCopy extends MmuCall implements PostConflationDefer { private final Hub hub; private final ContractMetadata contract; public ExtCodeCopy(final Hub hub) { super(hub, MMU_INST_ANY_TO_RAM_WITH_PADDING); this.hub = hub; + hub.defers().scheduleForPostConflation(this); + final Address sourceAddress = Words.toAddress(hub.messageFrame().getStackItem(0)); this.contract = ContractMetadata.make( @@ -56,22 +60,21 @@ public ExtCodeCopy(final Hub hub) { .setRom(); } - @Override - public int sourceId() { - try { - return this.hub.romLex().getCodeFragmentIndexByMetadata(this.contract); - } catch (Exception ignored) { - // Triggered if the external bytecode is empty, and thus absent from the ROMLex. - return 0; - } - } - @Override public long referenceSize() { - return this.hub - .romLex() - .getChunkByMetadata(this.contract) + return hub.romLex() + .getChunkByMetadata(contract) .map(chunk -> chunk.byteCode().size()) .orElse(0); } + + @Override + public void resolvePostConflation(Hub hub, WorldView world) { + try { + sourceId(hub.romLex().getCodeFragmentIndexByMetadata(contract)); + } catch (Exception ignored) { + // Can be 0 in case the ext account is empty. In this case, no associated CFI + sourceId(0); + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ExoSumDecoder.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ExoSumDecoder.java index 98145c34a0..b4beae7630 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ExoSumDecoder.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/ExoSumDecoder.java @@ -56,7 +56,7 @@ public Bytes getExoBytes(final HubToMmuValues hubToMmuValues, final int exoId) { exoIsTxcd = hubToMmuValues.exoIsTxcd(); if (exoIsRom) { - return this.romLex.sortedChunks().get(exoId - 1).byteCode().copy(); + return exoId == 0 ? Bytes.EMPTY : romLex.sortedChunks().get(exoId - 1).byteCode().copy(); } if (exoIsTxcd) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java index 9689045a21..160786d120 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java @@ -151,10 +151,7 @@ public void setExoBytes(ExoSumDecoder exoSumDecoder) { if (exoSum != 0) { mmuData.exoSumDecoder(exoSumDecoder); final int exoId = - (int) - (mmuData.exoLimbIsSource() - ? this.mmuData.hubToMmuValues().sourceId() - : this.mmuData.hubToMmuValues().targetId()); + mmuData.exoLimbIsSource() ? mmuData.mmuCall().sourceId() : mmuData.mmuCall().targetId(); mmuData.exoBytes(exoSumDecoder.getExoBytes(mmuData.hubToMmuValues(), exoId)); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index e69c56b20b..41cc0cf606 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -102,10 +102,6 @@ public int getCodeFragmentIndexByMetadata(final ContractMetadata metadata) { } public Optional getChunkByMetadata(final ContractMetadata metadata) { - if (this.sortedChunks.isEmpty()) { - throw new RuntimeException("Chunks have not been sorted yet"); - } - for (RomChunk c : this.chunks) { if (c.metadata().equals(metadata)) { return Optional.of(c); From b3ce0ac5e0175bce25345ba0d4708ba36d48db7e Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 21 Aug 2024 15:10:07 +0200 Subject: [PATCH 403/461] fix(oob): debug basicModexpTest --- .../consensys/linea/zktracer/module/oob/OobOperation.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 1d12664781..0a409f9c1b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -948,12 +948,12 @@ private void setModexpCds(ModexpCallDataSizeOobCall prcModexpCdsCall) { // row i + 1 final boolean extractEbs = callToLT( - 1, BigInteger.ZERO, prcModexpCdsCall.getCds(), BigInteger.ZERO, BigInteger.valueOf(32)); + 1, BigInteger.ZERO, BigInteger.valueOf(32), BigInteger.ZERO, prcModexpCdsCall.getCds()); // row i + 2 final boolean extractMbs = callToLT( - 2, BigInteger.ZERO, prcModexpCdsCall.getCds(), BigInteger.ZERO, BigInteger.valueOf(64)); + 2, BigInteger.ZERO, BigInteger.valueOf(64), BigInteger.ZERO, prcModexpCdsCall.getCds()); // Set extractBbs prcModexpCdsCall.setExtractBbs(extractBbs); @@ -1034,6 +1034,8 @@ private void setModexpLead(ModexpLeadOobCall prcModexpLeadOobCall) { BigInteger.valueOf(32)); } else { noCall(3); + // TODO: this is not explicitly indicated in the specs, but otherwise we have not + // initialized values when filling the trace } // Set loadLead From 6f1c3bfe303c2373bc4566324bab1f581482d20f Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 21 Aug 2024 15:16:34 +0200 Subject: [PATCH 404/461] docs(oob): remove TODO --- .../net/consensys/linea/zktracer/module/oob/OobOperation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 0a409f9c1b..bb2a83641e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -1034,8 +1034,8 @@ private void setModexpLead(ModexpLeadOobCall prcModexpLeadOobCall) { BigInteger.valueOf(32)); } else { noCall(3); - // TODO: this is not explicitly indicated in the specs, but otherwise we have not - // initialized values when filling the trace + // This is not explicitly indicated in the specs, but otherwise we have not + // initialized values when filling the trace } // Set loadLead From f82042dba37a534e1b70215403445387034d9153 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Wed, 21 Aug 2024 16:41:52 +0200 Subject: [PATCH 405/461] docs(oob): modexp lead --- .../net/consensys/linea/zktracer/module/oob/OobOperation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index bb2a83641e..6c7714a089 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -1034,8 +1034,8 @@ private void setModexpLead(ModexpLeadOobCall prcModexpLeadOobCall) { BigInteger.valueOf(32)); } else { noCall(3); - // This is not explicitly indicated in the specs, but otherwise we have not - // initialized values when filling the trace + // Note: this noCall is not explicitly indicated in the specs since not necessary + // Here it is done only to initialize the corresponding array elements to fill the trace } // Set loadLead From 33820ccf273152571fc877623be809fccd788cd3 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Wed, 21 Aug 2024 21:06:00 +0530 Subject: [PATCH 406/461] fix identity prc mmuCall Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 525cda4b2e..f1924f627f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -439,8 +439,8 @@ public static MmuCall forIdentityExtractCallData( .targetId(precompileSubsection.exoModuleOperationId()) .targetRamBytes(Optional.of(Bytes.EMPTY)) .sourceOffset(EWord.of(precompileSubsection.callDataMemorySpan.offset())) - .targetOffset(EWord.ZERO) - .size(precompileSubsection.callDataMemorySpan.length()); + .size(precompileSubsection.callDataMemorySpan.length()) + .referenceSize(precompileSubsection.callDataMemorySpan.length()); } public static MmuCall forIdentityReturnData( From c1f401d3e905dc5e0437420741a34ee1f714f9bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 21 Aug 2024 22:02:30 +0200 Subject: [PATCH 407/461] fix(ModexpMetadata): rawLeadingWord fix --- .../hub/precompiles/ModExpMetadata.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java index b07a9f79e9..ce5eacede7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java @@ -18,6 +18,7 @@ import static net.consensys.linea.zktracer.module.txndata.Trace.WORD_SIZE; import static net.consensys.linea.zktracer.types.Utils.rightPadTo; +import com.google.common.base.Preconditions; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -109,9 +110,22 @@ public boolean loadRawLeadingWord() { public EWord rawLeadingWord() { - return loadRawLeadingWord() - ? EWord.of(callData.slice(BASE_MIN_OFFSET + bbsInt(), WORD_SIZE)) - : EWord.ZERO; + if (!loadRawLeadingWord()) return EWord.ZERO; + + int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); + if (exponentOffsetInCallData + WORD_SIZE <= callData.size()) + return EWord.of(callData.slice(BASE_MIN_OFFSET + bbsInt(), WORD_SIZE)); + + int nExponentBytesInCallData = callData.size() - exponentOffsetInCallData; + Preconditions.checkArgument( + nExponentBytesInCallData > 0 + && nExponentBytesInCallData < WORD_SIZE); + StringBuilder callDataHexString = new StringBuilder(callData.slice(exponentOffsetInCallData, nExponentBytesInCallData).toHexString()); + for (int i = 0; i < nExponentBytesInCallData; i++) { + callDataHexString.append("00"); + } + Preconditions.checkArgument(callDataHexString.length() == WORD_SIZE); + return (EWord) Bytes.fromHexString(callDataHexString); } public boolean extractModulus() { From 44b467d6405ffc79bd7efa7b05397ff8f937fce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 21 Aug 2024 22:15:24 +0200 Subject: [PATCH 408/461] fix: fixed right zero padding + renaming to "ModexpMetaData" --- .../blake2fmodexpdata/BlakeModexpData.java | 4 ++-- .../BlakeModexpDataOperation.java | 6 ++--- .../zktracer/module/exp/ExpOperation.java | 4 ++-- .../module/hub/fragment/imc/mmu/MmuCall.java | 22 +++++++++---------- ...odExpMetadata.java => ModexpMetadata.java} | 10 ++++----- .../ModexpSubsection.java | 6 ++--- 6 files changed, 26 insertions(+), 26 deletions(-) rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/{ModExpMetadata.java => ModexpMetadata.java} (94%) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java index 7841518537..49f491e889 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java @@ -29,7 +29,7 @@ import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.stacked.list.StackedList; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; +import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds; import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall; @@ -71,7 +71,7 @@ public List columnsHeaders() { return Trace.headers(this.lineCount()); } - public void callModexp(final ModExpMetadata modexpMetaData, final int operationID) { + public void callModexp(final ModexpMetadata modexpMetaData, final int operationID) { operations.add(new BlakeModexpDataOperation(modexpMetaData, operationID)); modexpEffectiveCall.addPrecompileLimit(1); callWcpForIdCheck(operationID); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java index 8ff52d6729..ec6fc185ac 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java @@ -40,7 +40,7 @@ import lombok.Getter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; -import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; +import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.types.UnsignedByte; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.Hash; @@ -58,10 +58,10 @@ public class BlakeModexpDataOperation extends ModuleOperation { @Getter public final long id; - public final Optional modexpMetaData; + public final Optional modexpMetaData; public final Optional blake2fComponents; - public BlakeModexpDataOperation(final ModExpMetadata modexpMetaData, final int id) { + public BlakeModexpDataOperation(final ModexpMetadata modexpMetaData, final int id) { this.id = id; this.modexpMetaData = Optional.of(modexpMetaData); this.blake2fComponents = Optional.empty(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index 9d3be8bdaf..b3213a224d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -42,7 +42,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExplogExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ModexpLogExpCall; -import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; +import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.types.EWord; @@ -102,7 +102,7 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { // Extract inputs PrecompileInvocation precompileInvocation = modexplogExpCall.getP(); - ModExpMetadata modexpMetadata = (ModExpMetadata) precompileInvocation.metadata(); + ModexpMetadata modexpMetadata = (ModexpMetadata) precompileInvocation.metadata(); final int bbsInt = modexpMetadata.bbs().toUnsignedBigInteger().intValueExact(); final int ebsInt = modexpMetadata.ebs().toUnsignedBigInteger().intValueExact(); Preconditions.checkArgument( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index f1924f627f..52d83bcf3f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -78,7 +78,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ExtCodeCopy; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode.ReturnFromDeployment; import net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment; -import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; +import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.EllipticCurvePrecompileSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection; import net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.PrecompileSubsection; @@ -620,7 +620,7 @@ public static MmuCall partialCopyOfReturnDataforBlake( } public static MmuCall forModexpExtractBbs( - final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + final Hub hub, final ModexpSubsection precompileSubsection, final ModexpMetadata metaData) { return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) .sourceId(hub.currentFrame().contextNumber()) .referenceOffset(precompileSubsection.callDataMemorySpan.offset()) @@ -630,7 +630,7 @@ public static MmuCall forModexpExtractBbs( } public static MmuCall forModexpExtractEbs( - final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + final Hub hub, final ModexpSubsection precompileSubsection, final ModexpMetadata metaData) { return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) .sourceId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(32)) @@ -641,7 +641,7 @@ public static MmuCall forModexpExtractEbs( } public static MmuCall forModexpExtractMbs( - final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + final Hub hub, final ModexpSubsection precompileSubsection, final ModexpMetadata metaData) { return new MmuCall(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION) .sourceId(hub.currentFrame().contextNumber()) .sourceOffset(EWord.of(64)) @@ -652,7 +652,7 @@ public static MmuCall forModexpExtractMbs( } public static MmuCall forModexpLoadLead( - final Hub hub, final ModexpSubsection precompileSubsection, final ModExpMetadata metaData) { + final Hub hub, final ModexpSubsection precompileSubsection, final ModexpMetadata metaData) { return new MmuCall(hub, MMU_INST_MLOAD) .sourceId(hub.currentFrame().contextNumber()) .sourceOffset( @@ -663,7 +663,7 @@ public static MmuCall forModexpLoadLead( } public static MmuCall forModexpExtractBase( - final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + final Hub hub, final ModexpSubsection modexpSubsection, final ModexpMetadata modExpMetadata) { if (modExpMetadata.extractBase()) { return new MmuCall(hub, MMU_INST_MODEXP_DATA) .sourceId(modexpSubsection.callSection.hubStamp()) @@ -685,7 +685,7 @@ public static MmuCall forModexpExtractBase( } public static MmuCall forModexpExtractExponent( - final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + final Hub hub, final ModexpSubsection modexpSubsection, final ModexpMetadata modExpMetadata) { if (modExpMetadata.extractExponent()) { return new MmuCall(hub, MMU_INST_MODEXP_DATA) .sourceId(modexpSubsection.callSection.hubStamp()) @@ -707,7 +707,7 @@ public static MmuCall forModexpExtractExponent( } public static MmuCall forModexpExtractModulus( - final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + final Hub hub, final ModexpSubsection modexpSubsection, final ModexpMetadata modExpMetadata) { return new MmuCall(hub, MMU_INST_MODEXP_DATA) .sourceId(modexpSubsection.callSection.hubStamp()) .sourceRamBytes(Optional.of(modexpSubsection.callerMemorySnapshot)) @@ -722,7 +722,7 @@ public static MmuCall forModexpExtractModulus( } public static MmuCall forModexpFullResultCopy( - final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + final Hub hub, final ModexpSubsection modexpSubsection, final ModexpMetadata modExpMetadata) { return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS) .sourceId(modexpSubsection.exoModuleOperationId()) .exoBytes(Optional.of(modexpSubsection.returnData())) @@ -734,7 +734,7 @@ public static MmuCall forModexpFullResultCopy( } public static MmuCall forModexpPartialResultCopy( - final Hub hub, final ModexpSubsection modexpSubsection, final ModExpMetadata modExpMetadata) { + final Hub hub, final ModexpSubsection modexpSubsection, final ModexpMetadata modExpMetadata) { return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING) .sourceId(modexpSubsection.exoModuleOperationId()) .sourceRamBytes(Optional.of(modexpSubsection.returnData())) @@ -782,4 +782,4 @@ public void resolvePostTransaction( hub.mmu().call(this, hub.callStack()); } } -} +} \ No newline at end of file diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java similarity index 94% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java index ce5eacede7..42816eaedc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModExpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java @@ -28,7 +28,7 @@ @Getter @Accessors(fluent = true) -public class ModExpMetadata { +public class ModexpMetadata { static final int EBS_MIN_OFFSET = 32; static final int MBS_MIN_OFFSET = 64; static final int BASE_MIN_OFFSET = 96; @@ -36,7 +36,7 @@ public class ModExpMetadata { private final Bytes callData; @Setter private Bytes rawResult; - public ModExpMetadata(final Bytes callData) { + public ModexpMetadata(final Bytes callData) { this.callData = callData; } @@ -121,11 +121,11 @@ public EWord rawLeadingWord() { nExponentBytesInCallData > 0 && nExponentBytesInCallData < WORD_SIZE); StringBuilder callDataHexString = new StringBuilder(callData.slice(exponentOffsetInCallData, nExponentBytesInCallData).toHexString()); - for (int i = 0; i < nExponentBytesInCallData; i++) { + for (int i = nExponentBytesInCallData; i < WORD_SIZE; i++) { callDataHexString.append("00"); } - Preconditions.checkArgument(callDataHexString.length() == WORD_SIZE); - return (EWord) Bytes.fromHexString(callDataHexString); + Preconditions.checkArgument(callDataHexString.length() == 2 + 2 * WORD_SIZE); // "0x" + 2 characters per byte + return EWord.of(Bytes.fromHexString(callDataHexString)); } public boolean extractModulus() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index ad8b86ff2d..81be95aaa6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -42,20 +42,20 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpLeadOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpPricingOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpXbsOobCall; -import net.consensys.linea.zktracer.module.hub.precompiles.ModExpMetadata; +import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; public class ModexpSubsection extends PrecompileSubsection { - private final ModExpMetadata modExpMetadata; + private final ModexpMetadata modExpMetadata; private ModexpPricingOobCall sixthOobCall; private ImcFragment seventhImcFragment; public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); - modExpMetadata = new ModExpMetadata(callData); + modExpMetadata = new ModexpMetadata(callData); if (modExpMetadata .bbs() .toUnsignedBigInteger() From 8e2f104f8eee2f726ec759ff12c0e5874c9eacea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 21 Aug 2024 22:33:04 +0200 Subject: [PATCH 409/461] fix(testModexpLogSingleCase): made test pass removed PrecompileInvocation from ModexpLogExpCall class --- .../consensys/linea/zktracer/module/exp/ExpOperation.java | 7 +++---- .../module/hub/fragment/imc/exp/ModexpLogExpCall.java | 3 ++- .../call/precompileSubsection/ModexpSubsection.java | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index b3213a224d..dd69fadfda 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -101,15 +101,14 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { ModexpLogExpCall modexplogExpCall = (ModexpLogExpCall) expCall; // Extract inputs - PrecompileInvocation precompileInvocation = modexplogExpCall.getP(); - ModexpMetadata modexpMetadata = (ModexpMetadata) precompileInvocation.metadata(); + ModexpMetadata modexpMetadata = modexplogExpCall.getModexpMetadata(); final int bbsInt = modexpMetadata.bbs().toUnsignedBigInteger().intValueExact(); final int ebsInt = modexpMetadata.ebs().toUnsignedBigInteger().intValueExact(); Preconditions.checkArgument( - precompileInvocation.callDataSource().length() - 96 - bbsInt >= 0); + modexpMetadata.callData().size() - 96 - bbsInt >= 0); EWord rawLead = modexpMetadata.rawLeadingWord(); int cdsCutoff = - Math.min((int) (precompileInvocation.callDataSource().length() - 96 - bbsInt), 32); + Math.min(modexpMetadata.callData().size() - 96 - bbsInt, 32); int ebsCutoff = Math.min(ebsInt, 32); BigInteger leadLog = BigInteger.valueOf(LeadLogTrimLead.fromArgs(rawLead, cdsCutoff, ebsCutoff).leadLog()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java index b9b2139482..e1b1d19801 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java @@ -24,6 +24,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; +import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; @@ -32,7 +33,7 @@ @Getter @RequiredArgsConstructor public class ModexpLogExpCall implements ExpCall { - final PrecompileInvocation p; + final ModexpMetadata modexpMetadata; EWord rawLeadingWord; int cdsCutoff; int ebsCutoff; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 81be95aaa6..90906b6a76 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -36,6 +36,7 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment; import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExpCall; +import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ModexpLogExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpCallDataSizeOobCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.ModexpExtractOobCall; @@ -112,8 +113,8 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { if (modExpMetadata.loadRawLeadingWord()) { final MmuCall mmuCall = forModexpLoadLead(hub, this, modExpMetadata); fifthImcFragment.callMmu(mmuCall); - final ExpCall expCall = null; // TODO: to do new ModexpLogExpCall() ... @Lorenzo; - fifthImcFragment.callExp(expCall); + final ExpCall modexpLogCallToExp = new ModexpLogExpCall(modExpMetadata); + fifthImcFragment.callExp(modexpLogCallToExp); } final ImcFragment sixthImcFragment = ImcFragment.empty(hub); From 6ab6e8d80dc0d2f363d339f222bd5edd25d0367f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 21 Aug 2024 23:32:50 +0200 Subject: [PATCH 410/461] fix: get "testMxpRandomAdvanced" working again --- .../module/hub/fragment/account/RlpAddrSubFragment.java | 2 +- .../zktracer/module/hub/transients/OperationAncillaries.java | 5 +++++ .../net/consensys/linea/zktracer/types/AddressUtils.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java index bf875969c1..70d86209f5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/RlpAddrSubFragment.java @@ -42,7 +42,7 @@ public static RlpAddrSubFragment makeFragment(Hub hub, Address deploymentAddress switch (currentOpCode) { case CREATE2 -> { final Bytes32 salt = Bytes32.leftPad(hub.currentFrame().frame().getStackItem(3)); - final Bytes initCode = OperationAncillaries.callData(hub.currentFrame().frame()); + final Bytes initCode = OperationAncillaries.initCode(hub.currentFrame().frame()); final Bytes32 hash = Hash.keccak256(initCode); // TODO: could be done better, we compute the HASH two times return new RlpAddrSubFragment((short) 2, deploymentAddress, salt, hash); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java index e0087a3493..6b90b70ac1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/OperationAncillaries.java @@ -149,6 +149,11 @@ public static Bytes callData(final MessageFrame frame) { return maybeShadowReadMemory(callDataSegment, frame); } + public static Bytes initCode(final MessageFrame frame) { + final MemorySpan initCodeSegment = initCodeSegment(frame); + return maybeShadowReadMemory(initCodeSegment, frame); + } + /** * Returns the RAM segment offered by the caller for the return data if the current operation is a * call, throws otherwise. diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java index 5649aac6f0..7da734c296 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/AddressUtils.java @@ -108,7 +108,7 @@ public static Bytes32 getCreate2RawAddress( public static Address getCreate2Address(final MessageFrame frame) { final Address sender = frame.getRecipientAddress(); final Bytes32 salt = Bytes32.leftPad(frame.getStackItem(3)); - final Bytes initCode = OperationAncillaries.callData(frame); + final Bytes initCode = OperationAncillaries.initCode(frame); final Bytes32 hash = Hash.keccak256(initCode); return Address.extract(getCreate2RawAddress(sender, salt, hash)); } From e7685c2889d70b643861f72490c8d31cfac51197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 22 Aug 2024 00:55:18 +0200 Subject: [PATCH 411/461] fix(testSeveralKeccaks): test passes now --- .../linea/zktracer/module/hub/section/KeccakSection.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index d0ce948f11..e81822a979 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -50,10 +50,12 @@ public KeccakSection(Hub hub) { if (triggerMmu) { final MmuCall mmuCall = MmuCall.sha3(hub); imcFragment.callMmu(mmuCall); + long offset = hub.messageFrame().getStackItem(0).toLong(); + long size = hub.messageFrame().getStackItem(1).toLong(); hashInput = hub.currentFrame() .frame() - .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()); + .shadowReadMemory(offset, size); } } From 2b379a9f862061bced790da889b967e35933bd4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 22 Aug 2024 02:13:21 +0200 Subject: [PATCH 412/461] feat: new "is the beef dead yet ?" tests for KECCAK --- .../zktracer/module/mxp/SeveralKeccaks.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java index d9e05239fd..3fb39e6d16 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java @@ -26,19 +26,58 @@ public void testMul() { .run(); } + /** + * For readability we write __ instead of 00 + */ + @Test + void TestIsTheBeefDeadYet() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push("deadbeef") // 4 bytes + .push(28 * 8) + .op(OpCode.SHL) // stack = [ 0x DE AD BE EF __ ... __] + .op(OpCode.DUP1) // stack = [ 0x DE AD BE EF __ ... __, 0x DE AD BE EF __ ... __] + .push(1) + .op(OpCode.MSTORE) // memory looks like so 0x __ DE AD BE EF __ __ __ ... + .push(6) + .op(OpCode.MSTORE) // memory looks like so 0x __ DE AD BE EF __ DE AD BE EF __ __ __ ... + .push(4) .push(1) .op(OpCode.SHA3) // KEC(0xDEADBEEF) + .push(5) .push(0) .op(OpCode.SHA3) // KEC(0x00DEADBEEF) + .push(6) .push(0) .op(OpCode.SHA3) // KEC(0x00DEADBEEF00) + .push(5) .push(1) .op(OpCode.SHA3) // KEC(0xDEADBEEF00) + .push(4) .push(6) .op(OpCode.SHA3) // KEC(0xDEADBEEF) + .push(5) .push(6) .op(OpCode.SHA3) // KEC(0xDEADBEEF00) + .push(6) .push(5) .op(OpCode.SHA3) // KEC(0x00DEADBEEF00) + .push(5) .push(5) .op(OpCode.SHA3) // KEC(0x00DEADBEEF) + .compile()) + .run(); + } + @Test void testSeveralKeccaks() { BytecodeRunner.of( BytecodeCompiler.newProgram() .push(0) .push(0) + .op(OpCode.SHA3) // empty hash, no memory expansion + .op(OpCode.POP) + .push(0) + .push(31) + .op(OpCode.SHA3) // empty hash, no memory expansion + .op(OpCode.POP) + .push(64) + .push(13) + .op(OpCode.SHA3) + .op(OpCode.POP) + .push(0) + .push(49) .op(OpCode.SHA3) .op(OpCode.POP) .push(64) .push(13) .op(OpCode.SHA3) .op(OpCode.POP) - .push(11) + .push(37) .push(75) .op(OpCode.SHA3) .op(OpCode.POP) From 1b5489df7b353775541c90ca2faeb2ec6df2bc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 22 Aug 2024 02:46:47 +0200 Subject: [PATCH 413/461] fix(rawLeadingWord): simplified the rawLeadingWord() method --- .../hub/precompiles/ModexpMetadata.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java index 42816eaedc..458109243e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java @@ -24,6 +24,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.evm.internal.Words; @Getter @@ -110,22 +111,18 @@ public boolean loadRawLeadingWord() { public EWord rawLeadingWord() { - if (!loadRawLeadingWord()) return EWord.ZERO; + if (!loadRawLeadingWord()) { + return EWord.ZERO; + } int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); - if (exponentOffsetInCallData + WORD_SIZE <= callData.size()) - return EWord.of(callData.slice(BASE_MIN_OFFSET + bbsInt(), WORD_SIZE)); - - int nExponentBytesInCallData = callData.size() - exponentOffsetInCallData; - Preconditions.checkArgument( - nExponentBytesInCallData > 0 - && nExponentBytesInCallData < WORD_SIZE); - StringBuilder callDataHexString = new StringBuilder(callData.slice(exponentOffsetInCallData, nExponentBytesInCallData).toHexString()); - for (int i = nExponentBytesInCallData; i < WORD_SIZE; i++) { - callDataHexString.append("00"); - } - Preconditions.checkArgument(callDataHexString.length() == 2 + 2 * WORD_SIZE); // "0x" + 2 characters per byte - return EWord.of(Bytes.fromHexString(callDataHexString)); + int numberOfBytesToGrabFromCallData = + (exponentOffsetInCallData + WORD_SIZE <= callData.size()) + ? WORD_SIZE + : callData.size() - exponentOffsetInCallData; + Preconditions.checkArgument(0 < numberOfBytesToGrabFromCallData); + + return EWord.of(Bytes32.rightPad(callData.slice(BASE_MIN_OFFSET + bbsInt(), numberOfBytesToGrabFromCallData))); } public boolean extractModulus() { From 350d6b01b49822762d784a7a48ba19784d3e1cea Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 22 Aug 2024 09:51:44 +0530 Subject: [PATCH 414/461] spotless + manually update shakira Trace.java + constraint update Signed-off-by: Francois Bojarski --- .../zktracer/module/exp/ExpOperation.java | 7 +--- .../fragment/imc/exp/ModexpLogExpCall.java | 1 - .../module/hub/fragment/imc/mmu/MmuCall.java | 2 +- .../hub/precompiles/ModexpMetadata.java | 10 +++-- .../module/hub/section/KeccakSection.java | 5 +-- .../shakiradata/ShakiraDataOperation.java | 4 +- .../zktracer/module/shakiradata/Trace.java | 20 +++++----- .../zktracer/module/mxp/SeveralKeccaks.java | 39 +++++++++++++------ zkevm-constraints | 2 +- 9 files changed, 50 insertions(+), 40 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java index dd69fadfda..50b2d84318 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/exp/ExpOperation.java @@ -43,7 +43,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ExplogExpCall; import net.consensys.linea.zktracer.module.hub.fragment.imc.exp.ModexpLogExpCall; import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.module.wcp.Wcp; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.UnsignedByte; @@ -104,11 +103,9 @@ public ExpOperation(ExpCall expCall, Wcp wcp, Hub hub) { ModexpMetadata modexpMetadata = modexplogExpCall.getModexpMetadata(); final int bbsInt = modexpMetadata.bbs().toUnsignedBigInteger().intValueExact(); final int ebsInt = modexpMetadata.ebs().toUnsignedBigInteger().intValueExact(); - Preconditions.checkArgument( - modexpMetadata.callData().size() - 96 - bbsInt >= 0); + Preconditions.checkArgument(modexpMetadata.callData().size() - 96 - bbsInt >= 0); EWord rawLead = modexpMetadata.rawLeadingWord(); - int cdsCutoff = - Math.min(modexpMetadata.callData().size() - 96 - bbsInt, 32); + int cdsCutoff = Math.min(modexpMetadata.callData().size() - 96 - bbsInt, 32); int ebsCutoff = Math.min(ebsInt, 32); BigInteger leadLog = BigInteger.valueOf(LeadLogTrimLead.fromArgs(rawLead, cdsCutoff, ebsCutoff).leadLog()); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java index e1b1d19801..764f9dd558 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/exp/ModexpLogExpCall.java @@ -25,7 +25,6 @@ import lombok.Setter; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; -import net.consensys.linea.zktracer.module.hub.precompiles.PrecompileInvocation; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 52d83bcf3f..b0d3995374 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -782,4 +782,4 @@ public void resolvePostTransaction( hub.mmu().call(this, hub.callStack()); } } -} \ No newline at end of file +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java index 458109243e..7088949066 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java @@ -117,12 +117,14 @@ public EWord rawLeadingWord() { int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); int numberOfBytesToGrabFromCallData = - (exponentOffsetInCallData + WORD_SIZE <= callData.size()) - ? WORD_SIZE - : callData.size() - exponentOffsetInCallData; + (exponentOffsetInCallData + WORD_SIZE <= callData.size()) + ? WORD_SIZE + : callData.size() - exponentOffsetInCallData; Preconditions.checkArgument(0 < numberOfBytesToGrabFromCallData); - return EWord.of(Bytes32.rightPad(callData.slice(BASE_MIN_OFFSET + bbsInt(), numberOfBytesToGrabFromCallData))); + return EWord.of( + Bytes32.rightPad( + callData.slice(BASE_MIN_OFFSET + bbsInt(), numberOfBytesToGrabFromCallData))); } public boolean extractModulus() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index e81822a979..88627ef7b0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -52,10 +52,7 @@ public KeccakSection(Hub hub) { imcFragment.callMmu(mmuCall); long offset = hub.messageFrame().getStackItem(0).toLong(); long size = hub.messageFrame().getStackItem(1).toLong(); - hashInput = - hub.currentFrame() - .frame() - .shadowReadMemory(offset, size); + hashInput = hub.currentFrame().frame().shadowReadMemory(offset, size); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java index aaa172da0d..e890edc444 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/ShakiraDataOperation.java @@ -102,7 +102,7 @@ private void traceData(Trace trace, final int stamp) { for (int ct = 0; ct <= indexMaxData; ct++) { final boolean lastDataRow = ct == indexMaxData; trace - .ripshaStamp(stamp) + .shakiraStamp(stamp) .id(ID) .phase(phase) .index(ct) @@ -140,7 +140,7 @@ private void traceResult(Trace trace, final int stamp) { for (int ct = 0; ct <= INDEX_MAX_RESULT; ct++) { trace - .ripshaStamp(stamp) + .shakiraStamp(stamp) .id(ID) .phase(phase) .index(ct) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/Trace.java index a9f354a822..47d86ae90d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/shakiradata/Trace.java @@ -48,7 +48,7 @@ public class Trace { private final MappedByteBuffer nBytes; private final MappedByteBuffer nBytesAcc; private final MappedByteBuffer phase; - private final MappedByteBuffer ripshaStamp; + private final MappedByteBuffer shakiraStamp; private final MappedByteBuffer selectorKeccakResHi; private final MappedByteBuffer selectorRipemdResHi; private final MappedByteBuffer selectorSha2ResHi; @@ -69,7 +69,7 @@ static List headers(int length) { new ColumnHeader("shakiradata.nBYTES", 1, length), new ColumnHeader("shakiradata.nBYTES_ACC", 4, length), new ColumnHeader("shakiradata.PHASE", 1, length), - new ColumnHeader("shakiradata.RIPSHA_STAMP", 4, length), + new ColumnHeader("shakiradata.SHAKIRA_STAMP", 4, length), new ColumnHeader("shakiradata.SELECTOR_KECCAK_RES_HI", 1, length), new ColumnHeader("shakiradata.SELECTOR_RIPEMD_RES_HI", 1, length), new ColumnHeader("shakiradata.SELECTOR_SHA2_RES_HI", 1, length), @@ -90,7 +90,7 @@ public Trace(List buffers) { this.nBytes = buffers.get(10); this.nBytesAcc = buffers.get(11); this.phase = buffers.get(12); - this.ripshaStamp = buffers.get(13); + this.shakiraStamp = buffers.get(13); this.selectorKeccakResHi = buffers.get(14); this.selectorRipemdResHi = buffers.get(15); this.selectorSha2ResHi = buffers.get(16); @@ -301,7 +301,7 @@ public Trace phase(final UnsignedByte b) { return this; } - public Trace ripshaStamp(final long b) { + public Trace shakiraStamp(final long b) { if (filled.get(11)) { throw new IllegalStateException("shakiradata.RIPSHA_STAMP already set"); } else { @@ -309,12 +309,12 @@ public Trace ripshaStamp(final long b) { } if (b >= 4294967296L) { - throw new IllegalArgumentException("ripshaStamp has invalid value (" + b + ")"); + throw new IllegalArgumentException("shakiraStamp has invalid value (" + b + ")"); } - ripshaStamp.put((byte) (b >> 24)); - ripshaStamp.put((byte) (b >> 16)); - ripshaStamp.put((byte) (b >> 8)); - ripshaStamp.put((byte) b); + shakiraStamp.put((byte) (b >> 24)); + shakiraStamp.put((byte) (b >> 16)); + shakiraStamp.put((byte) (b >> 8)); + shakiraStamp.put((byte) b); return this; } @@ -506,7 +506,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(11)) { - ripshaStamp.position(ripshaStamp.position() + 4); + shakiraStamp.position(shakiraStamp.position() + 4); } if (!filled.get(12)) { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java index 3fb39e6d16..a0284527f2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/SeveralKeccaks.java @@ -26,9 +26,7 @@ public void testMul() { .run(); } - /** - * For readability we write __ instead of 00 - */ + /** For readability we write __ instead of 00 */ @Test void TestIsTheBeefDeadYet() { BytecodeRunner.of( @@ -40,15 +38,32 @@ void TestIsTheBeefDeadYet() { .push(1) .op(OpCode.MSTORE) // memory looks like so 0x __ DE AD BE EF __ __ __ ... .push(6) - .op(OpCode.MSTORE) // memory looks like so 0x __ DE AD BE EF __ DE AD BE EF __ __ __ ... - .push(4) .push(1) .op(OpCode.SHA3) // KEC(0xDEADBEEF) - .push(5) .push(0) .op(OpCode.SHA3) // KEC(0x00DEADBEEF) - .push(6) .push(0) .op(OpCode.SHA3) // KEC(0x00DEADBEEF00) - .push(5) .push(1) .op(OpCode.SHA3) // KEC(0xDEADBEEF00) - .push(4) .push(6) .op(OpCode.SHA3) // KEC(0xDEADBEEF) - .push(5) .push(6) .op(OpCode.SHA3) // KEC(0xDEADBEEF00) - .push(6) .push(5) .op(OpCode.SHA3) // KEC(0x00DEADBEEF00) - .push(5) .push(5) .op(OpCode.SHA3) // KEC(0x00DEADBEEF) + .op(OpCode.MSTORE) // memory looks like so 0x __ DE AD BE EF __ DE AD BE EF __ __ __ + // ... + .push(4) + .push(1) + .op(OpCode.SHA3) // KEC(0xDEADBEEF) + .push(5) + .push(0) + .op(OpCode.SHA3) // KEC(0x00DEADBEEF) + .push(6) + .push(0) + .op(OpCode.SHA3) // KEC(0x00DEADBEEF00) + .push(5) + .push(1) + .op(OpCode.SHA3) // KEC(0xDEADBEEF00) + .push(4) + .push(6) + .op(OpCode.SHA3) // KEC(0xDEADBEEF) + .push(5) + .push(6) + .op(OpCode.SHA3) // KEC(0xDEADBEEF00) + .push(6) + .push(5) + .op(OpCode.SHA3) // KEC(0x00DEADBEEF00) + .push(5) + .push(5) + .op(OpCode.SHA3) // KEC(0x00DEADBEEF) .compile()) .run(); } diff --git a/zkevm-constraints b/zkevm-constraints index 11438efcd6..7c19b5a63f 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 11438efcd688cced4f0904eefc8c402b22d2f02e +Subproject commit 7c19b5a63f9f66a509312eaeb337bdb6d6360b18 From 8b6009eb8cf4bf6f0d5f83a67631cf34b01365cf Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 22 Aug 2024 09:55:01 +0530 Subject: [PATCH 415/461] constraint update Signed-off-by: Francois Bojarski --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index 7c19b5a63f..715ded201f 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 7c19b5a63f9f66a509312eaeb337bdb6d6360b18 +Subproject commit 715ded201fc8c66838a3fedbdf2246371a1af51a From c6d8ef46ddbfabe880f8ff94993dd0543e9dbcd9 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 22 Aug 2024 10:22:35 +0530 Subject: [PATCH 416/461] fix converting stack item to long Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/section/KeccakSection.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java index 88627ef7b0..91083972d7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/KeccakSection.java @@ -27,6 +27,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; import org.hyperledger.besu.evm.operation.Operation; public class KeccakSection extends TraceSection implements PostOpcodeDefer { @@ -50,8 +51,8 @@ public KeccakSection(Hub hub) { if (triggerMmu) { final MmuCall mmuCall = MmuCall.sha3(hub); imcFragment.callMmu(mmuCall); - long offset = hub.messageFrame().getStackItem(0).toLong(); - long size = hub.messageFrame().getStackItem(1).toLong(); + final long offset = Words.clampedToLong(hub.messageFrame().getStackItem(0)); + final long size = Words.clampedToLong(hub.messageFrame().getStackItem(1)); hashInput = hub.currentFrame().frame().shadowReadMemory(offset, size); } } From acca913e9e3e83fd2a439f8f9c730eff1875255e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 22 Aug 2024 10:56:02 +0530 Subject: [PATCH 417/461] fix(hubStamp): update stamp when creating a section Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 22 ++----------------- .../module/hub/section/TraceSection.java | 19 ++++------------ .../hub/section/TxInitializationSection.java | 3 --- .../hub/section/TxPreWarmingMacroSection.java | 2 -- .../module/hub/section/TxSkippedSection.java | 1 + .../types/TransactionProcessingMetadata.java | 13 ++--------- 6 files changed, 9 insertions(+), 51 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 5b59ed05d4..e19fe0dab3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -497,9 +497,7 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { if (!txStack.current().requiresEvmExecution()) { state.setProcessingPhase(TX_SKIP); - state.stamps().incrementHubStamp(); - defers.scheduleForPostTransaction( - new TxSkippedSection(this, world, this.txStack.current(), this.transients)); + new TxSkippedSection(this, world, this.txStack.current(), this.transients); } else { if (txStack.current().requiresPrewarming()) { state.setProcessingPhase(TX_WARM); @@ -533,20 +531,7 @@ public void traceEndTransaction( // TODO: add the following resolution this.defers.resolvePostRollback(this, ... - this.txStack - .current() - .completeLineaTransaction( - this, - world, - isSuccessful, - this.state.stamps().hub(), - this.state().getProcessingPhase(), - logs, - selfDestructs); - - if (this.state.getProcessingPhase() != TX_SKIP) { - this.state.stamps().incrementHubStamp(); - } + this.txStack.current().completeLineaTransaction(this, isSuccessful, logs, selfDestructs); for (Module m : this.modules) { m.traceEndTx(txStack.current()); @@ -952,9 +937,6 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { } void processStateExec(MessageFrame frame) { - - this.state.stamps().incrementHubStamp(); - this.pch.setup(frame); this.handleStack(frame); 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 c49791e7fa..0536b1191b 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 @@ -54,23 +54,12 @@ public class TraceSection { /* A link to the next section */ @Setter public TraceSection nextSection = null; - /** - * Default creator for an empty section. Prefer the creator where we specify the max nb of rows - */ - public TraceSection(Hub hub) { - this.hub = hub; - this.commonValues = new CommonFragmentValues(hub); - this.fragments = - new ArrayList<>( - 22); // 22 is the maximum number of lines in a section (Successful reverted Modexp) - hub.addTraceSection(this); - } - /** Default creator specifying the max number of rows the section can contain. */ public TraceSection(final Hub hub, final short maxNumberOfLines) { this.hub = hub; - this.commonValues = new CommonFragmentValues(hub); - this.fragments = new ArrayList<>(maxNumberOfLines); + hub.state().stamps().incrementHubStamp(); + commonValues = new CommonFragmentValues(hub); + fragments = new ArrayList<>(maxNumberOfLines); hub.addTraceSection(this); } @@ -81,7 +70,7 @@ public TraceSection(final Hub hub, final short maxNumberOfLines) { */ public final void addFragment(TraceFragment fragment) { Preconditions.checkArgument(!(fragment instanceof CommonFragment)); - this.fragments.add(fragment); + fragments.add(fragment); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java index ba3416dc2c..8b8512b27a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxInitializationSection.java @@ -16,7 +16,6 @@ package net.consensys.linea.zktracer.module.hub.section; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; @@ -38,8 +37,6 @@ public class TxInitializationSection extends TraceSection { public TxInitializationSection(Hub hub, WorldView world) { super(hub, (short) 5); - hub.state.setProcessingPhase(TX_INIT); - hub.state.stamps().incrementHubStamp(); final TransactionProcessingMetadata tx = hub.txStack().current(); final boolean isDeployment = tx.isDeployment(); final Address toAddress = tx.getEffectiveTo(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 9b511f3f6d..142f5dc529 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -57,7 +57,6 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { final HashMap> seenKeys = new HashMap<>(); for (AccessListEntry entry : accessList) { - hub.state.stamps().incrementHubStamp(); final Address address = entry.address(); final DeploymentInfo deploymentInfo = @@ -96,7 +95,6 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { final List keys = entry.storageKeys(); for (Bytes32 k : keys) { - hub.state.stamps().incrementHubStamp(); final UInt256 key = UInt256.fromBytes(k); final EWord value = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java index c83665fb07..19395380d9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxSkippedSection.java @@ -43,6 +43,7 @@ public TxSkippedSection( Hub hub, WorldView world, TransactionProcessingMetadata txMetadata, Transients transients) { super(hub, (short) 4); this.txMetadata = txMetadata; + hub.defers().scheduleForPostTransaction(this); // From account information final Address fromAddress = txMetadata.getBesuTransaction().getSender(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 692c6cf6de..872c852ac5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -16,7 +16,6 @@ package net.consensys.linea.zktracer.types; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.*; -import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP; import static net.consensys.linea.zktracer.types.AddressUtils.effectiveToAddress; import java.math.BigInteger; @@ -32,7 +31,6 @@ import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.HubProcessingPhase; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; @@ -179,16 +177,9 @@ public void setPreFinalisationValues( } public void completeLineaTransaction( - Hub hub, - WorldView world, - final boolean statusCode, - final int hubStampTransactionEnd, - final HubProcessingPhase hubPhase, - final List logs, - final Set
selfDestructs) { + Hub hub, final boolean statusCode, final List logs, final Set
selfDestructs) { this.statusCode = statusCode; - this.hubStampTransactionEnd = - (hubPhase == TX_SKIP) ? hubStampTransactionEnd : hubStampTransactionEnd + 1; + this.hubStampTransactionEnd = hub.stamp(); this.logs = logs; for (Address address : selfDestructs) { this.destructedAccountsSnapshot.add(AccountSnapshot.canonical(hub, address)); From 78d1f96dc757b5d49678c4951296f603bbc9dd8e Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 22 Aug 2024 17:09:43 +0530 Subject: [PATCH 418/461] fix set returner info while returning from a precompile call Signed-off-by: Francois Bojarski --- .../zktracer/module/hub/section/call/CallSection.java | 5 ----- .../section/call/precompileSubsection/BlakeSubsection.java | 2 -- .../call/precompileSubsection/PrecompileSubsection.java | 7 +++++++ .../module/hub/section/copy/ReturnDataCopySection.java | 2 +- .../java/net/consensys/linea/zktracer/module/mmu/Mmu.java | 2 +- .../net/consensys/linea/zktracer/module/mmu/Trace.java | 4 ++-- zkevm-constraints | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index 8d85ac19c4..ce62b14f65 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -194,11 +194,6 @@ public CallSection(Hub hub) { precompileSubsection = ADDRESS_TO_PRECOMPILE.get(preOpcodeCalleeSnapshot.address()).apply(hub, this); - - hub.defers().scheduleForImmediateContextEntry(precompileSubsection); // gas & input data, ... - hub.defers() - .scheduleForContextReEntry( - precompileSubsection, hub.currentFrame()); // success bit & return data } else { Optional.ofNullable(world.get(calleeAddress)) .ifPresentOrElse( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java index 2ec0f52313..6e4f914da4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java @@ -41,8 +41,6 @@ public BlakeSubsection(Hub hub, CallSection callSection) { blakeCdsOobCall = new Blake2fCallDataSizeOobCall(); firstImcFragment.callOob(blakeCdsOobCall); - hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); - if (!blakeCdsOobCall.isHubSuccess()) { this.setScenario(PRC_FAILURE_KNOWN_TO_HUB); blakeSuccess = false; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java index c088bc799d..f24eb58685 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/PrecompileSubsection.java @@ -95,6 +95,10 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { this.callSection = callSection; fragments = new ArrayList<>(maxNumberOfLines()); + hub.defers().scheduleForImmediateContextEntry(this); // gas & input data, ... + hub.defers().scheduleForContextExit(this, exoModuleOperationId()); + hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); // success bit & return data + final PrecompileScenarioFragment.PrecompileFlag precompileFlag = addressToPrecompileFlag(callSection.precompileAddress.orElseThrow()); @@ -157,6 +161,9 @@ public void resolveAtContextReEntry(Hub hub, CallFrame frame) { callSuccess = bytesToBoolean(hub.messageFrame().getStackItem(0)); returnData = frame.frame().getReturnData(); + frame.returnDataContextNumber(exoModuleOperationId()); + frame.returnDataSpan(new MemorySpan(0, returnData.size())); + if (callSuccess) { hub.defers().scheduleForPostRollback(this, frame); callSection.setFinalContextFragment( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java index 9568c60e29..e30faac195 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ReturnDataCopySection.java @@ -70,7 +70,7 @@ public ReturnDataCopySection(Hub hub) { // beyond this point unexceptional final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; if (triggerMmu) { - MmuCall mmuCall = MmuCall.returnDataCopy(hub); + final MmuCall mmuCall = MmuCall.returnDataCopy(hub); imcFragment.callMmu(mmuCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java index 8a2e7c5294..b2e6fa665f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java @@ -90,7 +90,7 @@ public void commit(List buffers) { int mmuStamp = 0; int mmioStamp = 0; - for (MmuOperation mmuOp : this.mmuOperations) { + for (MmuOperation mmuOp : mmuOperations) { mmuOp.getCFI(); mmuOp.setExoBytes(exoSumDecoder); mmuOp.fillLimb(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Trace.java index 02add7735c..f6d13adbe3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Trace.java @@ -40,8 +40,8 @@ public class Trace { public static final int NB_MICRO_ROWS_TOT_RIGHT_PADDED_WORD_EXTRACTION = 0x2; public static final int NB_PP_ROWS_ANY_TO_RAM_WITH_PADDING_PURE_PADDING = 0x4; public static final int NB_PP_ROWS_ANY_TO_RAM_WITH_PADDING_PURE_PADDING_PO = 0x5; - public static final int NB_PP_ROWS_ANY_TO_RAM_WITH_PADDING_SOME_DATA = 0x1; - public static final int NB_PP_ROWS_ANY_TO_RAM_WITH_PADDING_SOME_DATA_PO = 0x2; + public static final int NB_PP_ROWS_ANY_TO_RAM_WITH_PADDING_SOME_DATA = 0xa; + public static final int NB_PP_ROWS_ANY_TO_RAM_WITH_PADDING_SOME_DATA_PO = 0xb; public static final int NB_PP_ROWS_BLAKE = 0x2; public static final int NB_PP_ROWS_BLAKE_PO = 0x3; public static final int NB_PP_ROWS_BLAKE_PT = 0x4; diff --git a/zkevm-constraints b/zkevm-constraints index 715ded201f..4c84263716 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 715ded201fc8c66838a3fedbdf2246371a1af51a +Subproject commit 4c842637167821c75bf8632653511a3f2c340a0b From 8bf9161e3ab15b621c288486c598fcf0d334525f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 22 Aug 2024 14:11:09 +0200 Subject: [PATCH 419/461] feat(trm): a new trimming test for the HUB --- .../zktracer/module/trm/TrmTracerTest.java | 57 ++++++++++++++++++- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java index 324fd9648a..8307d28847 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java @@ -22,6 +22,9 @@ import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; +import java.util.ArrayList; +import java.util.List; + public class TrmTracerTest { private final Bytes32 RANDOM_STRING_FROM_THE_INTERNET = Bytes32.fromHexString( @@ -43,8 +46,9 @@ public class TrmTracerTest { + "ffffffff" + "ffffffff" + "ffffffff" + + "ffffffff" + "ffffffff"); - private final Bytes32 EXTRACT_DISREGARDED_PREFIX_STRING = + private final Bytes32 BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___MAX_VALUE = Bytes32.fromHexString( "0x" + "ffffffff" @@ -55,6 +59,28 @@ public class TrmTracerTest { + "00000000" + "00000000" + "00000000"); + private final Bytes32 BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___ONE = + Bytes32.fromHexString( + "0x" + + "00000000" + + "00000000" + + "00000001" + + "00000000" + + "00000000" + + "00000000" + + "00000000" + + "00000000"); + private final Bytes32 BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___RANDOM = + Bytes32.fromHexString( + "0x" + + "b18cd834" + + "b6192fcf" + + "9f51322e" + + "00000000" + + "00000000" + + "00000000" + + "00000000" + + "00000000"); @Test void testNonCallTinyParamLessThan16() { @@ -65,7 +91,7 @@ void testNonCallTinyParamLessThan16() { @Test void testNonCallTinyParamAround256() { - for (int tiny = 0; tiny < 16; tiny++) { + for (int tiny = 0; tiny < 32; tiny++) { nonCall(Bytes32.leftPad(Bytes.ofUnsignedLong((long) tiny + 248))); } } @@ -75,7 +101,7 @@ void testNonCallAddressParameterTinyAfterTrimming() { for (int tiny = 0; tiny < 16; tiny++) { nonCall( RANDOM_STRING_FROM_THE_INTERNET - .and(EXTRACT_DISREGARDED_PREFIX_STRING) + .and(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___MAX_VALUE) .or(Bytes32.leftPad(Bytes.of(tiny)))); } } @@ -104,6 +130,31 @@ void nonCall(Bytes bytes) { .run(); } + @Test + void testTrimToUncoverATinyAddressAndQueryItsBalanceCodeHashAndCodeSize() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + + List opCodeList = List.of(OpCode.BALANCE, OpCode.EXTCODESIZE, OpCode.EXTCODEHASH); + + for (int i = 0; i < 11; i++) { + program + .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___MAX_VALUE) + .push(i) + .op(OpCode.OR) + .op(opCodeList.get(i % 3)) + .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___RANDOM) + .push(i) + .op(OpCode.OR) + .op(opCodeList.get((i + 1) % 3)) + .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___ONE) + .push(i) + .op(OpCode.OR) + .op(opCodeList.get((i + 2) % 3)); + } + + BytecodeRunner.of(program.compile()).run(); + } + void sevenArgCall(long rawAddr) { BytecodeRunner.of( BytecodeCompiler.newProgram() From b3af824212db62353ba3bce159d1806242fed9bc Mon Sep 17 00:00:00 2001 From: Tsvetan Dimitrov Date: Thu, 22 Aug 2024 17:19:39 +0300 Subject: [PATCH 420/461] fix: invalid code prefix MMU instruction patch --- .../linea/zktracer/module/hub/Hub.java | 1 - .../module/hub/fragment/imc/mmu/MmuCall.java | 4 ++- .../hub/section/halt/ReturnSection.java | 7 ++++-- .../zktracer/module/mmio/CallStackReader.java | 19 ++++++++------ .../linea/zktracer/module/mmu/MmuData.java | 5 ++-- .../mmu/instructions/InvalidCodePrefix.java | 4 +-- .../ContractModifyingStorageTest.java | 25 +++++-------------- 7 files changed, 30 insertions(+), 35 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index e19fe0dab3..67ec584e71 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -978,7 +978,6 @@ public int cumulatedTxCount() { } void traceOpcode(MessageFrame frame) { - switch (this.opCodeData().instructionFamily()) { case ADD, MOD, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index b0d3995374..6c3ca0babb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -287,6 +287,8 @@ public static MmuCall create2(final Hub hub, boolean failureCondition) { } public static MmuCall invalidCodePrefix(final Hub hub) { + final short currentExceptions = hub.pch().exceptions(); + return new MmuCall(hub, MMU_INST_INVALID_CODE_PREFIX) .sourceId(hub.currentFrame().contextNumber()) .sourceRamBytes( @@ -295,7 +297,7 @@ public static MmuCall invalidCodePrefix(final Hub hub) { .frame() .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) - .successBit(Exceptions.any(hub.pch().exceptions())); + .successBit(Exceptions.invalidCodePrefix(currentExceptions)); } public static MmuCall revert(final Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 1ea023e1da..9528ed9984 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -80,7 +80,7 @@ public ReturnSection(Hub hub) { this.addFragment(currentContextFragment); this.addFragment(firstImcFragment); - short exceptions = hub.pch().exceptions(); + final short exceptions = hub.pch().exceptions(); if (Exceptions.any(exceptions)) { returnScenarioFragment.setScenario(RETURN_EXCEPTION); @@ -194,7 +194,10 @@ public ReturnSection(Hub hub) { firstImcFragment.callOob(maxCodeSizeOobCall); // sanity checks - Preconditions.checkArgument(invalidCodePrefixCheckMmuCall.successBit()); + // TODO: Olivier should confirm this validation check. + Preconditions.checkArgument( + Exceptions.invalidCodePrefix(exceptions) == invalidCodePrefixCheckMmuCall.successBit()); + // Preconditions.checkArgument(invalidCodePrefixCheckMmuCall.successBit()); Preconditions.checkArgument(!maxCodeSizeOobCall.isMaxCodeSizeException()); final ImcFragment secondImcFragment = ImcFragment.empty(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java index 3cc204750a..051774fac7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/CallStackReader.java @@ -30,20 +30,23 @@ public class CallStackReader { private final CallStack callStack; - public Bytes valueFromMemory(final long contextNumber, final boolean ramIsSource) { + /** + * Performs a full copy of the memory based on the identified context. + * + * @param contextNumber + * @param ramIsSource + * @return returns either the current contents of memory of an execution context or the return + * data of a precompile or the calldata of a transaction depending on the type of the context. + */ + public Bytes fullCopyOfContextMemory(final long contextNumber, final boolean ramIsSource) { final CallFrame callFrame = callStack.getByContextNumber(contextNumber); - if (callFrame.type() == CallFrameType.TRANSACTION_CALL_DATA_HOLDER - || callFrame.type() == CallFrameType.ROOT) { + if (callFrame.type() == CallFrameType.TRANSACTION_CALL_DATA_HOLDER) { return callFrame.callDataInfo().data(); } if (callFrame.type() == CallFrameType.PRECOMPILE_RETURN_DATA) { - if (ramIsSource) { - return callFrame.outputData(); - } else { - return Bytes.EMPTY; - } + return ramIsSource ? callFrame.outputData() : Bytes.EMPTY; } final MessageFrame messageFrame = callFrame.frame(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java index 4325ce8e3b..c8fbf828ce 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuData.java @@ -111,7 +111,7 @@ public void setSourceRamBytes() { final long sourceContextNumber = mmuToMmioConstantValues.sourceContextNumber(); if (sourceContextNumber != 0) { - final Bytes sourceMemory = callStackReader.valueFromMemory(sourceContextNumber, true); + final Bytes sourceMemory = callStackReader.fullCopyOfContextMemory(sourceContextNumber, true); this.sourceRamBytes(sourceMemory); } } @@ -125,7 +125,8 @@ public void setTargetRamBytes() { final long targetContextNumber = mmuToMmioConstantValues.targetContextNumber(); if (targetContextNumber != 0) { - final Bytes targetMemory = callStackReader.valueFromMemory(targetContextNumber, false); + final Bytes targetMemory = + callStackReader.fullCopyOfContextMemory(targetContextNumber, false); this.targetRamBytes(targetMemory); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java index 7981f1fbc2..bd4e0ab462 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java @@ -61,7 +61,7 @@ public MmuData preProcess(MmuData mmuData, final CallStack callStack) { // Set mmuData.sourceRamBytes CallStackReader callStackReader = new CallStackReader(callStack); final Bytes sourceMemory = - callStackReader.valueFromMemory(mmuData.hubToMmuValues().sourceId(), true); + callStackReader.fullCopyOfContextMemory(mmuData.hubToMmuValues().sourceId(), true); mmuData.sourceRamBytes(sourceMemory); // row n°1 @@ -120,7 +120,7 @@ public MmuData setMicroInstructions(MmuData mmuData) { .sourceLimbOffset(initialSourceLimbOffset) .sourceByteOffset(initialSourceByteOffset) .targetByteOffset((short) LLARGEMO) - .limb((Bytes16) microLimb) + .limb(Bytes16.leftPad(microLimb)) .build()); return mmuData; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index 7a2eaaefb8..378e35c991 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -22,7 +22,7 @@ import com.google.common.base.Preconditions; import net.consensys.linea.testing.ToyAccount; -import net.consensys.linea.testing.ToyExecutionEnvironment; +import net.consensys.linea.testing.ToyExecutionEnvironmentV2; import net.consensys.linea.testing.ToyTransaction; import net.consensys.linea.testing.ToyWorld; import net.consensys.linea.zktracer.types.AddressUtils; @@ -91,12 +91,8 @@ void contractModifyingStorageInConstructorTest() { ToyWorld toyWorld = ToyWorld.builder().accounts(List.of(userAccount)).build(); - ToyExecutionEnvironment toyExecutionEnvironment = - ToyExecutionEnvironment.builder() - .toyWorld(toyWorld) - .transaction(tx) - .testValidator(x -> {}) - .build(); + ToyExecutionEnvironmentV2 toyExecutionEnvironment = + ToyExecutionEnvironmentV2.builder().toyWorld(toyWorld).transaction(tx).build(); toyExecutionEnvironment.run(); } @@ -127,12 +123,8 @@ void contractModifyingStorageInFunctionTest() { ToyWorld toyWorld = ToyWorld.builder().accounts(List.of(userAccount)).build(); - ToyExecutionEnvironment toyExecutionEnvironment = - ToyExecutionEnvironment.builder() - .toyWorld(toyWorld) - .transaction(tx) - .testValidator(x -> {}) - .build(); + ToyExecutionEnvironmentV2 toyExecutionEnvironment = + ToyExecutionEnvironmentV2.builder().toyWorld(toyWorld).transaction(tx).build(); // TODO: add transaction to invoke function @@ -209,12 +201,7 @@ void temporaryTest() { .value(Wei.fromEth(3)) .build()); - ToyExecutionEnvironment.builder() - .toyWorld(world.build()) - .transactions(txList) - .testValidator(x -> {}) - .build() - .run(); + ToyExecutionEnvironmentV2.builder().toyWorld(world.build()).transactions(txList).build().run(); } // Temporary support function From 38f11ae22fbcba0cf59c3fed8ebf7325d5b3b128 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 22 Aug 2024 23:18:33 +0200 Subject: [PATCH 421/461] fix(constraints): update to fix failing oob tests--no-verify --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index 4c84263716..b120efb25e 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 4c842637167821c75bf8632653511a3f2c340a0b +Subproject commit b120efb25e1ab5d8bf72fdae3ce88076869cf617 From 13c5793c3f5baf15b4e08375258adfe33c7bacd6 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Thu, 22 Aug 2024 23:45:14 +0200 Subject: [PATCH 422/461] feat(gas): update ACDC --- .../linea/zktracer/module/gas/Gas.java | 3 +- .../zktracer/module/gas/GasOperation.java | 68 ++++++++++++++----- .../zktracer/module/gas/GasParameters.java | 3 +- .../zktracer/module/oob/OobOperation.java | 1 + 4 files changed, 56 insertions(+), 19 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Gas.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Gas.java index 4d40ee9121..1dde5e89df 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Gas.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Gas.java @@ -60,7 +60,8 @@ public void tracePreOpcode(MessageFrame frame) { } private GasParameters extractGasParameters(MessageFrame frame) { - return new GasParameters(BigInteger.ZERO, BigInteger.ZERO, false); + // TODO: fill it with the actual values + return new GasParameters(0, BigInteger.ZERO, BigInteger.ZERO, false, false); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java index e242022323..bf951c61f2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java @@ -15,50 +15,84 @@ package net.consensys.linea.zktracer.module.gas; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_LT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WCP_INST_LEQ; import static net.consensys.linea.zktracer.module.gas.Trace.CT_MAX; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.booleanToInt; +import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; import java.math.BigInteger; import lombok.EqualsAndHashCode; import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.types.UnsignedByte; -import org.apache.tuweni.bytes.Bytes; @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false) public class GasOperation extends ModuleOperation { @EqualsAndHashCode.Include GasParameters gasParameters; - Bytes acc1; - Bytes acc2; + BigInteger[] wcpArg1Lo; + BigInteger[] wcpArg2Lo; + UnsignedByte[] wcpInst; + BigInteger[] wcpRes; + int CT_MAX; public GasOperation(GasParameters gasParameters) { this.gasParameters = gasParameters; - acc1 = bigIntegerToBytes(gasParameters.gasActl()); - acc2 = - bigIntegerToBytes( - (BigInteger.valueOf((2L * booleanToInt(gasParameters.oogx()) - 1)) - .multiply(gasParameters.gasCost().subtract(gasParameters.gasActl()))) - .subtract(BigInteger.valueOf(booleanToInt(gasParameters.oogx())))); + CT_MAX = gasParameters.ctMax(); + + // init arrays + wcpArg1Lo = new BigInteger[CT_MAX + 1]; + wcpArg2Lo = new BigInteger[CT_MAX + 1]; + wcpInst = new UnsignedByte[CT_MAX + 1]; + wcpRes = new BigInteger[CT_MAX + 1]; + + // row 0 + wcpArg1Lo[0] = BigInteger.ZERO; + wcpArg2Lo[0] = gasParameters.gasActual(); + wcpInst[0] = UnsignedByte.of(WCP_INST_LEQ); + wcpRes[0] = BigInteger.ONE; + + // row 1 + wcpArg1Lo[1] = BigInteger.ZERO; + wcpArg2Lo[1] = gasParameters.gasCost(); + wcpInst[1] = UnsignedByte.of(WCP_INST_LEQ); + wcpRes[1] = BigInteger.ONE; + + // row 2 + if (gasParameters.oogx()) { + wcpArg1Lo[2] = gasParameters.gasActual(); + wcpArg2Lo[2] = gasParameters.gasCost(); + wcpInst[2] = UnsignedByte.of(EVM_INST_LT); + wcpRes[2] = booleanToBigInteger(gasParameters.oogx()); + } else { + // TODO: init the lists with zeros (or something equivalent) instead + wcpArg1Lo[2] = BigInteger.ZERO; + wcpArg2Lo[2] = BigInteger.ZERO; + wcpInst[2] = UnsignedByte.of(0); + wcpRes[2] = BigInteger.ZERO; + } } @Override protected int computeLineCount() { - return CT_MAX + 1; + return gasParameters.ctMax() + 1; } public void trace(int stamp, Trace trace) { for (short i = 0; i < CT_MAX + 1; i++) { trace - .stamp(stamp) + // .inputsAndOutputsAreMeaningful(stamp != 0) ? + // .first(i == 0) .ct(i) - .gasActl(gasParameters.gasActl().longValue()) + // .ctMax(CT_MAX) + .gasActl(gasParameters.gasActual().longValue()) .gasCost(bigIntegerToBytes(gasParameters.gasCost())) + // .xahoy(gasParameters.xahoy()) .oogx(gasParameters.oogx()) - .byte1(UnsignedByte.of(acc1.get(i))) - .byte2(UnsignedByte.of(acc2.get(i))) - .acc1(acc1.slice(0, i + 1)) - .acc2(acc2.slice(0, i + 1)) + // .wcpArg1Lo(bigIntegerToBytes(wcpArg1Lo[i])) + // .wcpArg2Lo(bigIntegerToBytes(wcpArg2Lo[i])) + // .wcpInst(wcpInst[i].byteValue()) + // .wcpRes(bigIntegerToBytes(wcpRes[i])) .validateRow(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasParameters.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasParameters.java index 9106de5266..04399f6a64 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasParameters.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasParameters.java @@ -17,4 +17,5 @@ import java.math.BigInteger; -public record GasParameters(BigInteger gasActl, BigInteger gasCost, boolean oogx) {} +public record GasParameters( + int ctMax, BigInteger gasActual, BigInteger gasCost, boolean xahoy, boolean oogx) {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java index 6c7714a089..30bb795caf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/OobOperation.java @@ -1036,6 +1036,7 @@ private void setModexpLead(ModexpLeadOobCall prcModexpLeadOobCall) { noCall(3); // Note: this noCall is not explicitly indicated in the specs since not necessary // Here it is done only to initialize the corresponding array elements to fill the trace + // TODO: init the lists with zeros (or something equivalent) instead of using noCall } // Set loadLead From 37ea5583e3be91b4fb29684a1be3443fb99e6d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Thu, 22 Aug 2024 23:53:35 +0200 Subject: [PATCH 423/461] feat(modexp): new tests for MODEXP --- .../zktracer/module/trm/TrmTracerTest.java | 7 +- .../zktracer/precompiles/ModexpTests.java | 133 ++++++++++++++++++ 2 files changed, 136 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java index 8307d28847..927c720fcf 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java @@ -22,7 +22,6 @@ import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; -import java.util.ArrayList; import java.util.List; public class TrmTracerTest { @@ -119,9 +118,9 @@ void testSevenArgCall() { } @Test - void testSixArgCall() { + void testSampleDelegateCall() { for (long tiny = 0; tiny < 16; tiny++) { - sixArgCall(tiny); + sampleDelegateCall(tiny); } } @@ -170,7 +169,7 @@ void sevenArgCall(long rawAddr) { .run(); } - void sixArgCall(long rawAddr) { + void sampleDelegateCall(long rawAddr) { BytecodeRunner.of( BytecodeCompiler.newProgram() .push(Bytes.fromHexString("0xff")) // rds diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java index 9c5ae16c90..65913ebf17 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java @@ -20,8 +20,20 @@ import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; +import java.util.List; + public class ModexpTests { + // some 10 decimal digit primes in the range [256 ** 3, 256 ** 4[ + // * 1081914797 ≡ 0x407CB5AD + // * 1086173677 ≡ 0x40BDB1ED + // * 1219462969 ≡ 0x48AF8739 + // * 2198809297 ≡ 0x830F2AD1 + // * 3752945107 ≡ 0xDFB165D3 + // * 3772857469 ≡ 0xE0E13C7D + // * 3952396501 ≡ 0xEB94C8D5 + // * 4171332133 ≡ 0xF8A17A25 + @Test void basicModexpTest() { final Bytes bytecode = @@ -38,4 +50,125 @@ void basicModexpTest() { .compile(); BytecodeRunner.of(bytecode).run(); } + + @Test + void testUnpaddedModexp() { + + String hexBase = "407CB5AD"; + String hexExpn = "40BDB1ED"; + String hexModl = "48AF8739"; + + BytecodeCompiler program = preparingBaseExponentAndModulusForModexpAndRunningVariousModexps(hexBase, hexExpn, hexModl); + + BytecodeRunner.of(program.compile()).run(); + } + + @Test + void testPaddedModexp() { + + String hexBase = "00407CB5AD"; + String hexExpn = "40BDB1ED"; + String hexModl = "000048AF8739"; + + BytecodeCompiler program = preparingBaseExponentAndModulusForModexpAndRunningVariousModexps(hexBase, hexExpn, hexModl); + + BytecodeRunner.of(program.compile()).run(); + } + + int byteSize(String hexString) { + return (hexString.length() + 1) / 2; + } + + BytecodeCompiler preparingBaseExponentAndModulusForModexpAndRunningVariousModexps( String hexBase, String hexExpn, String hexModl ) { + + BytecodeCompiler program = preparingBaseExponentAndModulusForModexp( + hexBase, + hexExpn, + hexModl + ); + + int bbs = byteSize(hexBase); + int ebs = byteSize(hexExpn); + int mbs = byteSize(hexModl); + + List returnAtCapacityList = List.of(0, 1, mbs - 1, mbs, mbs + 1, 31, 32); + List callDataSizeList = List.of( + 0, 1, 31, + 32, 33, 63, + 64, 65, 95, + 96, 97, 96 + (bbs - 1), + 96 + bbs, 96 + bbs + 1, 96 + bbs + (ebs - 1), + 96 + bbs + ebs, 96 + bbs + ebs + 1, 96 + bbs + ebs + (mbs -1), + 96 + bbs + ebs + mbs, 96 + bbs + ebs + mbs + 1 + ); + + for (int returnAtCapacity : returnAtCapacityList) { + for (int callDataSize : callDataSizeList) { + parametrizedModexpCall(program, returnAtCapacity, callDataSize); + } + } + + return program; + } + + void parametrizedModexpCall(BytecodeCompiler program, int returnAtCapacity, int callDataSize) { + program + .push(returnAtCapacity) // r@c + .push(Bytes.fromHexString("0100")) // r@o + .push(callDataSize) // cds + .push(Bytes.fromHexString("")) // cdo + .push(0x04) // address (here: MODEXP) + .push(Bytes.fromHexString("ffff")) // gas + .op(OpCode.DELEGATECALL) + .op(OpCode.POP); + } + + BytecodeCompiler preparingBaseExponentAndModulusForModexp(String hexBase, String hexExpn, String hexModl) { + + int bbs = byteSize(hexBase); + int ebs = byteSize(hexExpn); + int mbs = byteSize(hexModl); + int baseOffset = 64 + bbs; + int expnOffset = 64 + bbs + ebs; + int modlOffset = 64 + bbs + ebs + mbs; + return BytecodeCompiler.newProgram() + .push(byteSize(hexBase)).push("00").op(OpCode.MSTORE) // this sets bbs = 4 + .push(byteSize(hexExpn)).push("20").op(OpCode.MSTORE) // this sets ebs = 4 + .push(byteSize(hexModl)).push("40").op(OpCode.MSTORE) // this sets mbs = 4 + // to read call data 32 + 32 + 32 + 4 + 4 + 4 = 108 bytes are sufficient + .push(hexBase).push(baseOffset).op(OpCode.MSTORE) // this sets the base + .push(hexExpn).push(expnOffset).op(OpCode.MSTORE) // this sets the exponent + .push(hexModl).push(modlOffset).op(OpCode.MSTORE) // this sets the modulus + ; + } + + + + @Test + void variationsOnEmptyCalls() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + + List callDataSizeList = List.of( + 0, 1, 31, + 32, 33, 63, + 64, 65, 95, + 96, 97, 128); + for (int callDataSize : callDataSizeList) { + appendAllZeroCallDataModexpCalls(program, callDataSize); + } + + BytecodeRunner.of(program.compile()).run(); + } + + void appendAllZeroCallDataModexpCalls(BytecodeCompiler program, int callDataSize) { + program + .push(Bytes.fromHexString("0200")) // rds 0x0200 ≡ 512 in decimal + .push(Bytes.fromHexString("0200")) // rdo + .push(callDataSize) // cds + .push(Bytes.fromHexString("00")) // cdo + .push(0x04) // i.e. MODEXP + .push(Bytes.fromHexString("ffff")) // gas + .op(OpCode.STATICCALL) + .op(OpCode.POP); + } } From 989a82d82e5fe8d97d5f53b8b9d7bf0ec84e49e0 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 23 Aug 2024 12:14:15 +0530 Subject: [PATCH 424/461] style: spotless Signed-off-by: Francois Bojarski --- .../zktracer/module/trm/TrmTracerTest.java | 68 +++++----- .../zktracer/precompiles/ModexpTests.java | 123 ++++++++++-------- 2 files changed, 105 insertions(+), 86 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java index 927c720fcf..1d0b9f2cc9 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.trm; +import java.util.List; + import net.consensys.linea.testing.BytecodeCompiler; import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; @@ -22,8 +24,6 @@ import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; -import java.util.List; - public class TrmTracerTest { private final Bytes32 RANDOM_STRING_FROM_THE_INTERNET = Bytes32.fromHexString( @@ -59,27 +59,27 @@ public class TrmTracerTest { + "00000000" + "00000000"); private final Bytes32 BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___ONE = - Bytes32.fromHexString( - "0x" - + "00000000" - + "00000000" - + "00000001" - + "00000000" - + "00000000" - + "00000000" - + "00000000" - + "00000000"); + Bytes32.fromHexString( + "0x" + + "00000000" + + "00000000" + + "00000001" + + "00000000" + + "00000000" + + "00000000" + + "00000000" + + "00000000"); private final Bytes32 BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___RANDOM = - Bytes32.fromHexString( - "0x" - + "b18cd834" - + "b6192fcf" - + "9f51322e" - + "00000000" - + "00000000" - + "00000000" - + "00000000" - + "00000000"); + Bytes32.fromHexString( + "0x" + + "b18cd834" + + "b6192fcf" + + "9f51322e" + + "00000000" + + "00000000" + + "00000000" + + "00000000" + + "00000000"); @Test void testNonCallTinyParamLessThan16() { @@ -137,18 +137,18 @@ void testTrimToUncoverATinyAddressAndQueryItsBalanceCodeHashAndCodeSize() { for (int i = 0; i < 11; i++) { program - .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___MAX_VALUE) - .push(i) - .op(OpCode.OR) - .op(opCodeList.get(i % 3)) - .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___RANDOM) - .push(i) - .op(OpCode.OR) - .op(opCodeList.get((i + 1) % 3)) - .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___ONE) - .push(i) - .op(OpCode.OR) - .op(opCodeList.get((i + 2) % 3)); + .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___MAX_VALUE) + .push(i) + .op(OpCode.OR) + .op(opCodeList.get(i % 3)) + .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___RANDOM) + .push(i) + .op(OpCode.OR) + .op(opCodeList.get((i + 1) % 3)) + .push(BYTE_STRING_OUTSIDE_OF_ADDRESS_RANGE___ONE) + .push(i) + .op(OpCode.OR) + .op(opCodeList.get((i + 2) % 3)); } BytecodeRunner.of(program.compile()).run(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java index 65913ebf17..874576bf27 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java @@ -14,14 +14,14 @@ */ package net.consensys.linea.zktracer.precompiles; +import java.util.List; + import net.consensys.linea.testing.BytecodeCompiler; import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; -import java.util.List; - public class ModexpTests { // some 10 decimal digit primes in the range [256 ** 3, 256 ** 4[ @@ -58,7 +58,8 @@ void testUnpaddedModexp() { String hexExpn = "40BDB1ED"; String hexModl = "48AF8739"; - BytecodeCompiler program = preparingBaseExponentAndModulusForModexpAndRunningVariousModexps(hexBase, hexExpn, hexModl); + BytecodeCompiler program = + preparingBaseExponentAndModulusForModexpAndRunningVariousModexps(hexBase, hexExpn, hexModl); BytecodeRunner.of(program.compile()).run(); } @@ -70,7 +71,8 @@ void testPaddedModexp() { String hexExpn = "40BDB1ED"; String hexModl = "000048AF8739"; - BytecodeCompiler program = preparingBaseExponentAndModulusForModexpAndRunningVariousModexps(hexBase, hexExpn, hexModl); + BytecodeCompiler program = + preparingBaseExponentAndModulusForModexpAndRunningVariousModexps(hexBase, hexExpn, hexModl); BytecodeRunner.of(program.compile()).run(); } @@ -79,28 +81,38 @@ int byteSize(String hexString) { return (hexString.length() + 1) / 2; } - BytecodeCompiler preparingBaseExponentAndModulusForModexpAndRunningVariousModexps( String hexBase, String hexExpn, String hexModl ) { + BytecodeCompiler preparingBaseExponentAndModulusForModexpAndRunningVariousModexps( + String hexBase, String hexExpn, String hexModl) { - BytecodeCompiler program = preparingBaseExponentAndModulusForModexp( - hexBase, - hexExpn, - hexModl - ); + BytecodeCompiler program = preparingBaseExponentAndModulusForModexp(hexBase, hexExpn, hexModl); int bbs = byteSize(hexBase); int ebs = byteSize(hexExpn); int mbs = byteSize(hexModl); List returnAtCapacityList = List.of(0, 1, mbs - 1, mbs, mbs + 1, 31, 32); - List callDataSizeList = List.of( - 0, 1, 31, - 32, 33, 63, - 64, 65, 95, - 96, 97, 96 + (bbs - 1), - 96 + bbs, 96 + bbs + 1, 96 + bbs + (ebs - 1), - 96 + bbs + ebs, 96 + bbs + ebs + 1, 96 + bbs + ebs + (mbs -1), - 96 + bbs + ebs + mbs, 96 + bbs + ebs + mbs + 1 - ); + List callDataSizeList = + List.of( + 0, + 1, + 31, + 32, + 33, + 63, + 64, + 65, + 95, + 96, + 97, + 96 + (bbs - 1), + 96 + bbs, + 96 + bbs + 1, + 96 + bbs + (ebs - 1), + 96 + bbs + ebs, + 96 + bbs + ebs + 1, + 96 + bbs + ebs + (mbs - 1), + 96 + bbs + ebs + mbs, + 96 + bbs + ebs + mbs + 1); for (int returnAtCapacity : returnAtCapacityList) { for (int callDataSize : callDataSizeList) { @@ -113,17 +125,18 @@ BytecodeCompiler preparingBaseExponentAndModulusForModexpAndRunningVariousModexp void parametrizedModexpCall(BytecodeCompiler program, int returnAtCapacity, int callDataSize) { program - .push(returnAtCapacity) // r@c - .push(Bytes.fromHexString("0100")) // r@o - .push(callDataSize) // cds - .push(Bytes.fromHexString("")) // cdo - .push(0x04) // address (here: MODEXP) - .push(Bytes.fromHexString("ffff")) // gas - .op(OpCode.DELEGATECALL) - .op(OpCode.POP); + .push(returnAtCapacity) // r@c + .push(Bytes.fromHexString("0100")) // r@o + .push(callDataSize) // cds + .push(Bytes.fromHexString("")) // cdo + .push(0x04) // address (here: MODEXP) + .push(Bytes.fromHexString("ffff")) // gas + .op(OpCode.DELEGATECALL) + .op(OpCode.POP); } - BytecodeCompiler preparingBaseExponentAndModulusForModexp(String hexBase, String hexExpn, String hexModl) { + BytecodeCompiler preparingBaseExponentAndModulusForModexp( + String hexBase, String hexExpn, String hexModl) { int bbs = byteSize(hexBase); int ebs = byteSize(hexExpn); @@ -132,27 +145,33 @@ BytecodeCompiler preparingBaseExponentAndModulusForModexp(String hexBase, String int expnOffset = 64 + bbs + ebs; int modlOffset = 64 + bbs + ebs + mbs; return BytecodeCompiler.newProgram() - .push(byteSize(hexBase)).push("00").op(OpCode.MSTORE) // this sets bbs = 4 - .push(byteSize(hexExpn)).push("20").op(OpCode.MSTORE) // this sets ebs = 4 - .push(byteSize(hexModl)).push("40").op(OpCode.MSTORE) // this sets mbs = 4 - // to read call data 32 + 32 + 32 + 4 + 4 + 4 = 108 bytes are sufficient - .push(hexBase).push(baseOffset).op(OpCode.MSTORE) // this sets the base - .push(hexExpn).push(expnOffset).op(OpCode.MSTORE) // this sets the exponent - .push(hexModl).push(modlOffset).op(OpCode.MSTORE) // this sets the modulus - ; + .push(byteSize(hexBase)) + .push("00") + .op(OpCode.MSTORE) // this sets bbs = 4 + .push(byteSize(hexExpn)) + .push("20") + .op(OpCode.MSTORE) // this sets ebs = 4 + .push(byteSize(hexModl)) + .push("40") + .op(OpCode.MSTORE) // this sets mbs = 4 + // to read call data 32 + 32 + 32 + 4 + 4 + 4 = 108 bytes are sufficient + .push(hexBase) + .push(baseOffset) + .op(OpCode.MSTORE) // this sets the base + .push(hexExpn) + .push(expnOffset) + .op(OpCode.MSTORE) // this sets the exponent + .push(hexModl) + .push(modlOffset) + .op(OpCode.MSTORE) // this sets the modulus + ; } - - @Test void variationsOnEmptyCalls() { BytecodeCompiler program = BytecodeCompiler.newProgram(); - List callDataSizeList = List.of( - 0, 1, 31, - 32, 33, 63, - 64, 65, 95, - 96, 97, 128); + List callDataSizeList = List.of(0, 1, 31, 32, 33, 63, 64, 65, 95, 96, 97, 128); for (int callDataSize : callDataSizeList) { appendAllZeroCallDataModexpCalls(program, callDataSize); } @@ -161,14 +180,14 @@ void variationsOnEmptyCalls() { } void appendAllZeroCallDataModexpCalls(BytecodeCompiler program, int callDataSize) { - program - .push(Bytes.fromHexString("0200")) // rds 0x0200 ≡ 512 in decimal - .push(Bytes.fromHexString("0200")) // rdo - .push(callDataSize) // cds - .push(Bytes.fromHexString("00")) // cdo - .push(0x04) // i.e. MODEXP - .push(Bytes.fromHexString("ffff")) // gas - .op(OpCode.STATICCALL) - .op(OpCode.POP); + program + .push(Bytes.fromHexString("0200")) // rds 0x0200 ≡ 512 in decimal + .push(Bytes.fromHexString("0200")) // rdo + .push(callDataSize) // cds + .push(Bytes.fromHexString("00")) // cdo + .push(0x04) // i.e. MODEXP + .push(Bytes.fromHexString("ffff")) // gas + .op(OpCode.STATICCALL) + .op(OpCode.POP); } } From b465ac46453982767418c519bd4fb89994af982f Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 23 Aug 2024 08:51:10 +0200 Subject: [PATCH 425/461] feat(constraints): update --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index b120efb25e..7c44dc562e 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit b120efb25e1ab5d8bf72fdae3ce88076869cf617 +Subproject commit 7c44dc562e588dbd7fbeadc81ff48337cd52ad66 From da9f8b0e5ee27be38517a691eb6c0835e7445e48 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 23 Aug 2024 10:11:12 +0200 Subject: [PATCH 426/461] feat(constraints): update --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index 7c44dc562e..8f814229bc 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 7c44dc562e588dbd7fbeadc81ff48337cd52ad66 +Subproject commit 8f814229bc2f748c25fda2aa1a1dce8b548ed0a9 From c217789707d316240e6d59a5ea322c91d9fdd0c9 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Fri, 23 Aug 2024 17:00:20 +0530 Subject: [PATCH 427/461] fix: inverted logic of triggering of mmu in callDataLoad Signed-off-by: Francois Bojarski --- .../hub/section/CallDataLoadSection.java | 2 +- .../linea/zktracer/module/mmio/Mmio.java | 3 +-- .../zktracer/module/mmio/MmioPatterns.java | 22 ++++++++++--------- .../RightPaddedWordExtraction.java | 3 ++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java index 6c23851a64..c35ae36842 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/CallDataLoadSection.java @@ -62,7 +62,7 @@ public CallDataLoadSection(Hub hub) { if (Exceptions.none(exception)) { - if (oobCall.isCdlOutOfBounds()) { + if (!oobCall.isCdlOutOfBounds()) { final EWord read = EWord.of( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java index c681e9a40b..0c88c652be 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java @@ -47,7 +47,6 @@ public class Mmio implements Module { public Mmio(Mmu mmu) { this.mmu = mmu; - // this.callStackReader = new CallStackReader(callStack); } @Override @@ -80,7 +79,7 @@ public List columnsHeaders() { public void commit(List buffers) { Trace trace = new Trace(buffers); int stamp = 0; - for (MmuOperation mmuOperation : this.mmu.mmuOperations()) { + for (MmuOperation mmuOperation : mmu.mmuOperations()) { final MmuData currentMmuData = mmuOperation.mmuData(); for (int currentMmioInstNumber = 0; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/MmioPatterns.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/MmioPatterns.java index 8733767c10..5e4e4dd951 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/MmioPatterns.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/MmioPatterns.java @@ -27,9 +27,9 @@ public class MmioPatterns { static List isolateSuffix(final Bytes16 input, final List flag) { - List output = new ArrayList<>(LLARGE); + final List output = new ArrayList<>(LLARGE); - output.add(0, flag.get(0) ? Bytes.of(input.get(0)) : Bytes.EMPTY); + output.addFirst(flag.getFirst() ? Bytes.of(input.get(0)) : Bytes.EMPTY); for (short ct = 1; ct < LLARGE; ct++) { output.add( @@ -43,9 +43,9 @@ static List isolateSuffix(final Bytes16 input, final List flag) } static List isolatePrefix(final Bytes16 input, final List flag) { - List output = new ArrayList<>(LLARGE); + final List output = new ArrayList<>(LLARGE); - output.add(0, flag.get(0) ? Bytes.EMPTY : Bytes.of(input.get(0))); + output.addFirst(flag.getFirst() ? Bytes.EMPTY : Bytes.of(input.get(0))); for (short ct = 1; ct < LLARGE; ct++) { output.add( @@ -60,9 +60,9 @@ static List isolatePrefix(final Bytes16 input, final List flag) static List isolateChunk( final Bytes16 input, final List startFlag, final List endFlag) { - List output = new ArrayList<>(LLARGE); + final List output = new ArrayList<>(LLARGE); - output.add(0, startFlag.get(0) ? Bytes.of(input.get(0)) : Bytes.EMPTY); + output.addFirst(startFlag.getFirst() ? Bytes.of(input.get(0)) : Bytes.EMPTY); for (short ct = 1; ct < LLARGE; ct++) { if (startFlag.get(ct)) { @@ -80,11 +80,13 @@ static List isolateChunk( } static List power(final List flag) { - List output = new ArrayList<>(LLARGE); + final List output = new ArrayList<>(LLARGE); - output.add(0, flag.get(0) ? Bytes.ofUnsignedShort(256) : Bytes.of(1)); + output.addFirst(flag.getFirst() ? Bytes.ofUnsignedShort(256) : Bytes.of(1)); for (short ct = 1; ct < LLARGE; ct++) { + final Bytes toPut = + flag.get(ct) ? Bytes.concatenate(output.get(ct - 1), Bytes.of(0)) : output.get(ct - 1); output.add( ct, flag.get(ct) ? Bytes.concatenate(output.get(ct - 1), Bytes.of(0)) : output.get(ct - 1)); @@ -93,9 +95,9 @@ static List power(final List flag) { } static List antiPower(final List flag) { - List output = new ArrayList<>(LLARGE); + final List output = new ArrayList<>(LLARGE); - output.add(0, flag.get(0) ? Bytes.of(1) : Bytes.ofUnsignedShort(256)); + output.addFirst(flag.getFirst() ? Bytes.of(1) : Bytes.ofUnsignedShort(256)); for (short ct = 1; ct < LLARGE; ct++) { output.add( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/RightPaddedWordExtraction.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/RightPaddedWordExtraction.java index 590dc2cc55..599e22029d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/RightPaddedWordExtraction.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/RightPaddedWordExtraction.java @@ -22,6 +22,7 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMIO_INST_RAM_TO_LIMB_TRANSPLANT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMIO_INST_RAM_TO_LIMB_TWO_SOURCE; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WORD_SIZE; +import static net.consensys.linea.zktracer.module.mmu.Trace.NB_MICRO_ROWS_TOT_RIGHT_PADDED_WORD_EXTRACTION; import static net.consensys.linea.zktracer.types.Conversions.*; import java.math.BigInteger; @@ -86,7 +87,7 @@ public MmuData preProcess(MmuData mmuData, final CallStack callStack) { mmuData.outAndBinValues(MmuOutAndBinValues.DEFAULT); // all 0 mmuData.totalLeftZeroesInitials(0); - mmuData.totalNonTrivialInitials(Trace.NB_MICRO_ROWS_TOT_RIGHT_PADDED_WORD_EXTRACTION); + mmuData.totalNonTrivialInitials(NB_MICRO_ROWS_TOT_RIGHT_PADDED_WORD_EXTRACTION); mmuData.totalRightZeroesInitials(0); return mmuData; From 71b6dd3fdfe0174f1f78636befe6685c204f82d4 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 23 Aug 2024 14:07:07 +0200 Subject: [PATCH 428/461] fix(gas): move gas in trace-files.gradle --- .../linea/zktracer/module/gas/Trace.java | 287 ++++++++++-------- gradle/trace-files.gradle | 4 +- 2 files changed, 168 insertions(+), 123 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java index c74d850528..8996ee0982 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.gas; +import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -30,44 +31,52 @@ * Please DO NOT ATTEMPT TO MODIFY this code directly. */ public class Trace { - public static final int CT_MAX = 0x7; private final BitSet filled = new BitSet(); private int currentLine = 0; - private final MappedByteBuffer acc1; - private final MappedByteBuffer acc2; - private final MappedByteBuffer byte1; - private final MappedByteBuffer byte2; private final MappedByteBuffer ct; - private final MappedByteBuffer gasActl; + private final MappedByteBuffer ctMax; + private final MappedByteBuffer exceptionsAhoy; + private final MappedByteBuffer first; + private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; - private final MappedByteBuffer oogx; - private final MappedByteBuffer stamp; + private final MappedByteBuffer inputsAndOutputsAreMeaningful; + private final MappedByteBuffer outOfGasException; + private final MappedByteBuffer wcpArg1Lo; + private final MappedByteBuffer wcpArg2Lo; + private final MappedByteBuffer wcpInst; + private final MappedByteBuffer wcpRes; static List headers(int length) { return List.of( - new ColumnHeader("gas.ACC_1", 8, length), - new ColumnHeader("gas.ACC_2", 8, length), - new ColumnHeader("gas.BYTE_1", 1, length), - new ColumnHeader("gas.BYTE_2", 1, length), new ColumnHeader("gas.CT", 1, length), - new ColumnHeader("gas.GAS_ACTL", 4, length), + new ColumnHeader("gas.CT_MAX", 1, length), + new ColumnHeader("gas.EXCEPTIONS_AHOY", 1, length), + new ColumnHeader("gas.FIRST", 1, length), + new ColumnHeader("gas.GAS_ACTUAL", 4, length), new ColumnHeader("gas.GAS_COST", 8, length), - new ColumnHeader("gas.OOGX", 1, length), - new ColumnHeader("gas.STAMP", 4, length)); + new ColumnHeader("gas.INPUTS_AND_OUTPUTS_ARE_MEANINGFUL", 1, length), + new ColumnHeader("gas.OUT_OF_GAS_EXCEPTION", 1, length), + new ColumnHeader("gas.WCP_ARG1_LO", 16, length), + new ColumnHeader("gas.WCP_ARG2_LO", 16, length), + new ColumnHeader("gas.WCP_INST", 1, length), + new ColumnHeader("gas.WCP_RES", 1, length)); } public Trace(List buffers) { - this.acc1 = buffers.get(0); - this.acc2 = buffers.get(1); - this.byte1 = buffers.get(2); - this.byte2 = buffers.get(3); - this.ct = buffers.get(4); - this.gasActl = buffers.get(5); - this.gasCost = buffers.get(6); - this.oogx = buffers.get(7); - this.stamp = buffers.get(8); + this.ct = buffers.get(0); + this.ctMax = buffers.get(1); + this.exceptionsAhoy = buffers.get(2); + this.first = buffers.get(3); + this.gasActual = buffers.get(4); + this.gasCost = buffers.get(5); + this.inputsAndOutputsAreMeaningful = buffers.get(6); + this.outOfGasException = buffers.get(7); + this.wcpArg1Lo = buffers.get(8); + this.wcpArg2Lo = buffers.get(9); + this.wcpInst = buffers.get(10); + this.wcpRes = buffers.get(11); } public int size() { @@ -78,203 +87,227 @@ public int size() { return this.currentLine; } - public Trace acc1(final Bytes b) { + public Trace ct(final long b) { if (filled.get(0)) { - throw new IllegalStateException("gas.ACC_1 already set"); + throw new IllegalStateException("gas.CT already set"); } else { filled.set(0); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 64) { - throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - acc1.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - acc1.put(bs.get(j)); - } + if(b >= 8L) { throw new IllegalArgumentException("ct has invalid value (" + b + ")"); } + ct.put((byte) b); + return this; } - public Trace acc2(final Bytes b) { + public Trace ctMax(final long b) { if (filled.get(1)) { - throw new IllegalStateException("gas.ACC_2 already set"); + throw new IllegalStateException("gas.CT_MAX already set"); } else { filled.set(1); } - // Trim array to size - Bytes bs = b.trimLeadingZeros(); - // Sanity check against expected width - if (bs.bitLength() > 64) { - throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); - } - // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - acc2.put((byte) 0); - } - // Write bytes - for (int j = 0; j < bs.size(); j++) { - acc2.put(bs.get(j)); - } + if(b >= 8L) { throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); } + ctMax.put((byte) b); + return this; } - public Trace byte1(final UnsignedByte b) { + public Trace exceptionsAhoy(final Boolean b) { if (filled.get(2)) { - throw new IllegalStateException("gas.BYTE_1 already set"); + throw new IllegalStateException("gas.EXCEPTIONS_AHOY already set"); } else { filled.set(2); } - byte1.put(b.toByte()); + exceptionsAhoy.put((byte) (b ? 1 : 0)); return this; } - public Trace byte2(final UnsignedByte b) { + public Trace first(final Boolean b) { if (filled.get(3)) { - throw new IllegalStateException("gas.BYTE_2 already set"); + throw new IllegalStateException("gas.FIRST already set"); } else { filled.set(3); } - byte2.put(b.toByte()); + first.put((byte) (b ? 1 : 0)); return this; } - public Trace ct(final long b) { + public Trace gasActual(final long b) { if (filled.get(4)) { - throw new IllegalStateException("gas.CT already set"); + throw new IllegalStateException("gas.GAS_ACTUAL already set"); } else { filled.set(4); } - if (b >= 8L) { - throw new IllegalArgumentException("ct has invalid value (" + b + ")"); - } - ct.put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("gasActual has invalid value (" + b + ")"); } + gasActual.put((byte) (b >> 24)); + gasActual.put((byte) (b >> 16)); + gasActual.put((byte) (b >> 8)); + gasActual.put((byte) b); + return this; } - public Trace gasActl(final long b) { + public Trace gasCost(final Bytes b) { if (filled.get(5)) { - throw new IllegalStateException("gas.GAS_ACTL already set"); + throw new IllegalStateException("gas.GAS_COST already set"); } else { filled.set(5); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("gasActl has invalid value (" + b + ")"); - } - gasActl.put((byte) (b >> 24)); - gasActl.put((byte) (b >> 16)); - gasActl.put((byte) (b >> 8)); - gasActl.put((byte) b); + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if(bs.bitLength() > 64) { throw new IllegalArgumentException("gasCost has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<8; i++) { gasCost.put((byte) 0); } + // Write bytes + for(int j=0; j 64) { - throw new IllegalArgumentException("gasCost has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - gasCost.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { wcpArg1Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasCost.put(bs.get(j)); - } + for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { wcpArg2Lo.put((byte) 0); } + // Write bytes + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); + wcpInst.put(b.toByte()); + + return this; + } + + public Trace wcpRes(final Boolean b) { + if (filled.get(11)) { + throw new IllegalStateException("gas.WCP_RES already set"); + } else { + filled.set(11); } - stamp.put((byte) (b >> 24)); - stamp.put((byte) (b >> 16)); - stamp.put((byte) (b >> 8)); - stamp.put((byte) b); + + wcpRes.put((byte) (b ? 1 : 0)); return this; } public Trace validateRow() { if (!filled.get(0)) { - throw new IllegalStateException("gas.ACC_1 has not been filled"); + throw new IllegalStateException("gas.CT has not been filled"); } if (!filled.get(1)) { - throw new IllegalStateException("gas.ACC_2 has not been filled"); + throw new IllegalStateException("gas.CT_MAX has not been filled"); } if (!filled.get(2)) { - throw new IllegalStateException("gas.BYTE_1 has not been filled"); + throw new IllegalStateException("gas.EXCEPTIONS_AHOY has not been filled"); } if (!filled.get(3)) { - throw new IllegalStateException("gas.BYTE_2 has not been filled"); + throw new IllegalStateException("gas.FIRST has not been filled"); } if (!filled.get(4)) { - throw new IllegalStateException("gas.CT has not been filled"); + throw new IllegalStateException("gas.GAS_ACTUAL has not been filled"); } if (!filled.get(5)) { - throw new IllegalStateException("gas.GAS_ACTL has not been filled"); + throw new IllegalStateException("gas.GAS_COST has not been filled"); } if (!filled.get(6)) { - throw new IllegalStateException("gas.GAS_COST has not been filled"); + throw new IllegalStateException("gas.INPUTS_AND_OUTPUTS_ARE_MEANINGFUL has not been filled"); } if (!filled.get(7)) { - throw new IllegalStateException("gas.OOGX has not been filled"); + throw new IllegalStateException("gas.OUT_OF_GAS_EXCEPTION has not been filled"); } if (!filled.get(8)) { - throw new IllegalStateException("gas.STAMP has not been filled"); + throw new IllegalStateException("gas.WCP_ARG1_LO has not been filled"); + } + + if (!filled.get(9)) { + throw new IllegalStateException("gas.WCP_ARG2_LO has not been filled"); + } + + if (!filled.get(10)) { + throw new IllegalStateException("gas.WCP_INST has not been filled"); + } + + if (!filled.get(11)) { + throw new IllegalStateException("gas.WCP_RES has not been filled"); } filled.clear(); @@ -285,39 +318,51 @@ public Trace validateRow() { public Trace fillAndValidateRow() { if (!filled.get(0)) { - acc1.position(acc1.position() + 8); + ct.position(ct.position() + 1); } if (!filled.get(1)) { - acc2.position(acc2.position() + 8); + ctMax.position(ctMax.position() + 1); } if (!filled.get(2)) { - byte1.position(byte1.position() + 1); + exceptionsAhoy.position(exceptionsAhoy.position() + 1); } if (!filled.get(3)) { - byte2.position(byte2.position() + 1); + first.position(first.position() + 1); } if (!filled.get(4)) { - ct.position(ct.position() + 1); + gasActual.position(gasActual.position() + 4); } if (!filled.get(5)) { - gasActl.position(gasActl.position() + 4); + gasCost.position(gasCost.position() + 8); } if (!filled.get(6)) { - gasCost.position(gasCost.position() + 8); + inputsAndOutputsAreMeaningful.position(inputsAndOutputsAreMeaningful.position() + 1); } if (!filled.get(7)) { - oogx.position(oogx.position() + 1); + outOfGasException.position(outOfGasException.position() + 1); } if (!filled.get(8)) { - stamp.position(stamp.position() + 4); + wcpArg1Lo.position(wcpArg1Lo.position() + 16); + } + + if (!filled.get(9)) { + wcpArg2Lo.position(wcpArg2Lo.position() + 16); + } + + if (!filled.get(10)) { + wcpInst.position(wcpInst.position() + 1); + } + + if (!filled.get(11)) { + wcpRes.position(wcpRes.position() + 1); } filled.clear(); diff --git a/gradle/trace-files.gradle b/gradle/trace-files.gradle index 02e615a009..0d4a27b3be 100644 --- a/gradle/trace-files.gradle +++ b/gradle/trace-files.gradle @@ -68,7 +68,7 @@ tasks.register('binreftable', TraceFilesTask) { // // Put here modules following the conventional MODULE/columns.lisp naming scheme. // -['bin', 'blockhash', 'euc', 'mmio', 'shf', 'wcp', 'rlptxn', 'rom', 'romlex', 'trm', 'stp', 'loginfo', 'logdata'].each {moduleName -> +['bin', 'blockhash', 'euc', 'mmio', 'shf', 'wcp', 'rlptxn', 'rom', 'romlex', 'trm', 'stp', 'loginfo', 'logdata', 'gas'].each {moduleName -> tasks.register(moduleName, TraceFilesTask) { group "Trace files generation" // dependsOn corsetExists @@ -81,7 +81,7 @@ tasks.register('binreftable', TraceFilesTask) { // // Put here modules following the conventional MODULE/columns.lisp, MODULE/constants.lisp naming scheme. // -['mmu', 'blake2fmodexpdata', 'blockdata', 'oob', 'exp', 'rlptxrcpt', 'rlpaddr', 'shakiradata', 'mxp', 'ecdata', 'gas'].each {moduleName -> +['mmu', 'blake2fmodexpdata', 'blockdata', 'oob', 'exp', 'rlptxrcpt', 'rlpaddr', 'shakiradata', 'mxp', 'ecdata'].each {moduleName -> tasks.register(moduleName, TraceFilesTask) { group "Trace files generation" // dependsOn corsetExists From f01ffde009177590b21fc3ddf115e6752e29fdb0 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 23 Aug 2024 14:13:06 +0200 Subject: [PATCH 429/461] fix(gas): update implementation after Trace.java update --- .../zktracer/module/gas/GasOperation.java | 34 ++++++------ .../linea/zktracer/module/gas/Trace.java | 54 +++++++++++++------ 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java index bf951c61f2..da46fd9c9d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java @@ -17,9 +17,7 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_LT; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WCP_INST_LEQ; -import static net.consensys.linea.zktracer.module.gas.Trace.CT_MAX; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; -import static net.consensys.linea.zktracer.types.Conversions.booleanToBigInteger; import java.math.BigInteger; @@ -33,7 +31,7 @@ public class GasOperation extends ModuleOperation { BigInteger[] wcpArg1Lo; BigInteger[] wcpArg2Lo; UnsignedByte[] wcpInst; - BigInteger[] wcpRes; + boolean[] wcpRes; int CT_MAX; public GasOperation(GasParameters gasParameters) { @@ -44,32 +42,32 @@ public GasOperation(GasParameters gasParameters) { wcpArg1Lo = new BigInteger[CT_MAX + 1]; wcpArg2Lo = new BigInteger[CT_MAX + 1]; wcpInst = new UnsignedByte[CT_MAX + 1]; - wcpRes = new BigInteger[CT_MAX + 1]; + wcpRes = new boolean[CT_MAX + 1]; // row 0 wcpArg1Lo[0] = BigInteger.ZERO; wcpArg2Lo[0] = gasParameters.gasActual(); wcpInst[0] = UnsignedByte.of(WCP_INST_LEQ); - wcpRes[0] = BigInteger.ONE; + wcpRes[0] = true; // row 1 wcpArg1Lo[1] = BigInteger.ZERO; wcpArg2Lo[1] = gasParameters.gasCost(); wcpInst[1] = UnsignedByte.of(WCP_INST_LEQ); - wcpRes[1] = BigInteger.ONE; + wcpRes[1] = true; // row 2 if (gasParameters.oogx()) { wcpArg1Lo[2] = gasParameters.gasActual(); wcpArg2Lo[2] = gasParameters.gasCost(); wcpInst[2] = UnsignedByte.of(EVM_INST_LT); - wcpRes[2] = booleanToBigInteger(gasParameters.oogx()); + wcpRes[2] = gasParameters.oogx(); } else { // TODO: init the lists with zeros (or something equivalent) instead wcpArg1Lo[2] = BigInteger.ZERO; wcpArg2Lo[2] = BigInteger.ZERO; wcpInst[2] = UnsignedByte.of(0); - wcpRes[2] = BigInteger.ZERO; + wcpRes[2] = false; } } @@ -81,18 +79,18 @@ protected int computeLineCount() { public void trace(int stamp, Trace trace) { for (short i = 0; i < CT_MAX + 1; i++) { trace - // .inputsAndOutputsAreMeaningful(stamp != 0) ? - // .first(i == 0) + .inputsAndOutputsAreMeaningful(stamp != 0) + .first(i == 0) .ct(i) - // .ctMax(CT_MAX) - .gasActl(gasParameters.gasActual().longValue()) + .ctMax(CT_MAX) + .gasActual(gasParameters.gasActual().longValue()) .gasCost(bigIntegerToBytes(gasParameters.gasCost())) - // .xahoy(gasParameters.xahoy()) - .oogx(gasParameters.oogx()) - // .wcpArg1Lo(bigIntegerToBytes(wcpArg1Lo[i])) - // .wcpArg2Lo(bigIntegerToBytes(wcpArg2Lo[i])) - // .wcpInst(wcpInst[i].byteValue()) - // .wcpRes(bigIntegerToBytes(wcpRes[i])) + .exceptionsAhoy(gasParameters.xahoy()) + .outOfGasException(gasParameters.oogx()) + .wcpArg1Lo(bigIntegerToBytes(wcpArg1Lo[i])) + .wcpArg2Lo(bigIntegerToBytes(wcpArg2Lo[i])) + .wcpInst(wcpInst[i]) + .wcpRes(wcpRes[i]) .validateRow(); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java index 8996ee0982..295346d56b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/Trace.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.gas; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -94,10 +93,11 @@ public Trace ct(final long b) { filled.set(0); } - if(b >= 8L) { throw new IllegalArgumentException("ct has invalid value (" + b + ")"); } + if (b >= 8L) { + throw new IllegalArgumentException("ct has invalid value (" + b + ")"); + } ct.put((byte) b); - return this; } @@ -108,10 +108,11 @@ public Trace ctMax(final long b) { filled.set(1); } - if(b >= 8L) { throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); } + if (b >= 8L) { + throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); + } ctMax.put((byte) b); - return this; } @@ -146,13 +147,14 @@ public Trace gasActual(final long b) { filled.set(4); } - if(b >= 4294967296L) { throw new IllegalArgumentException("gasActual has invalid value (" + b + ")"); } + if (b >= 4294967296L) { + throw new IllegalArgumentException("gasActual has invalid value (" + b + ")"); + } gasActual.put((byte) (b >> 24)); gasActual.put((byte) (b >> 16)); gasActual.put((byte) (b >> 8)); gasActual.put((byte) b); - return this; } @@ -166,11 +168,17 @@ public Trace gasCost(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if(bs.bitLength() > 64) { throw new IllegalArgumentException("gasCost has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 64) { + throw new IllegalArgumentException("gasCost has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<8; i++) { gasCost.put((byte) 0); } + for (int i = bs.size(); i < 8; i++) { + gasCost.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg1Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg1Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg2Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg2Lo.put((byte) 0); + } // Write bytes - for(int j=0; j Date: Fri, 23 Aug 2024 14:29:26 +0200 Subject: [PATCH 430/461] docs(gas): add comment --- .../net/consensys/linea/zktracer/module/gas/GasOperation.java | 1 + 1 file changed, 1 insertion(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java index da46fd9c9d..3bcf40c231 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/gas/GasOperation.java @@ -78,6 +78,7 @@ protected int computeLineCount() { public void trace(int stamp, Trace trace) { for (short i = 0; i < CT_MAX + 1; i++) { + // TODO: review traced values trace .inputsAndOutputsAreMeaningful(stamp != 0) .first(i == 0) From 725e377e4b2ceb683766f136f7b795b2419fb45e Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Fri, 23 Aug 2024 16:36:09 +0200 Subject: [PATCH 431/461] fix(ecdata): fill success bit correctly --- .../module/ecdata/EcDataOperation.java | 162 ++++++++---------- .../zktracer/module/ecdata/EcRecoverTest.java | 112 ++++++------ 2 files changed, 129 insertions(+), 145 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 326a5836bd..04ae3077b8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -53,7 +53,6 @@ import com.google.common.base.Preconditions; import lombok.Getter; -import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.container.ModuleOperation; import net.consensys.linea.zktracer.module.ext.Ext; @@ -73,7 +72,7 @@ public class EcDataOperation extends ModuleOperation { public static final EWord SECP256K1N = EWord.of(SECP256K1N_HI, SECP256K1N_LO); public static final int nBYTES_OF_DELTA_BYTES = 4; - @Setter private Bytes returnData; + private final Bytes returnData; private final Wcp wcp; private final Ext ext; @@ -121,14 +120,11 @@ public class EcDataOperation extends ModuleOperation { // pairing-specific private final int totalPairings; - private List notOnG2; // counter-constant - private List notOnG2Acc; // counter-constant + private final List notOnG2; // counter-constant + private final List notOnG2Acc; // counter-constant private boolean notOnG2AccMax; // index-constant - private List isInfinity; // counter-constant - private List overallTrivialPairing; // counter-constant - - // For debugging - private boolean returnDataSet = false; + private final List isInfinity; // counter-constant + private final List overallTrivialPairing; // counter-constant private EcDataOperation( Wcp wcp, @@ -191,7 +187,7 @@ private EcDataOperation( notOnG2Acc = repeat(false, nRows); // Set returnData - setReturnData(returnData); + this.returnData = returnData; } public static EcDataOperation of( @@ -212,84 +208,8 @@ public static EcDataOperation of( return ecDataOperation; } - public void setReturnData(Bytes returnData) { - switch (precompileFlag) { - case PRC_ECRECOVER -> { - EWord recoveredAddress = EWord.ZERO; - - // Extract output - if (internalChecksPassed) { - recoveredAddress = EWord.of(returnData); - } - - // Set success bit and output limb - successBit = !recoveredAddress.isZero(); - limb.set(8, recoveredAddress.hi()); - limb.set(9, recoveredAddress.lo()); - } - case PRC_ECADD -> { - EWord resX = EWord.ZERO; - EWord resY = EWord.ZERO; - - // Extract output - if (internalChecksPassed && returnData.toArray().length != 0) { - Preconditions.checkArgument(returnData.toArray().length == 64); - resX = EWord.of(returnData.slice(0, 32)); - resY = EWord.of(returnData.slice(32, 32)); - } - - // Set success bit and output limb - successBit = internalChecksPassed; - limb.set(8, resX.hi()); - limb.set(9, resX.lo()); - limb.set(10, resY.hi()); - limb.set(11, resY.lo()); - } - case PRC_ECMUL -> { - EWord resX = EWord.ZERO; - EWord resY = EWord.ZERO; - - // Extract output - if (internalChecksPassed && returnData.toArray().length != 0) { - Preconditions.checkArgument(returnData.toArray().length == 64); - resX = EWord.of(returnData.slice(0, 32)); - resY = EWord.of(returnData.slice(32, 32)); - } - - // Set success bit and output limb - successBit = internalChecksPassed; - limb.set(6, resX.hi()); - limb.set(7, resX.lo()); - limb.set(8, resY.hi()); - limb.set(9, resY.lo()); - } - case PRC_ECPAIRING -> { - EWord pairingResult = EWord.ZERO; - - // Extract output - if (internalChecksPassed) { - pairingResult = EWord.of(returnData); - } - - // Set output limb - limb.set(limb.size() - 2, pairingResult.hi()); - limb.set(limb.size() - 1, pairingResult.lo()); - - // Set callSuccess - if (!internalChecksPassed) { - successBit = false; - } else { - successBit = !notOnG2AccMax; - } - } - } - returnDataSet = true; - } - private int getTotalSize( PrecompileScenarioFragment.PrecompileFlag precompileFlag, boolean isData) { - Preconditions.checkArgument(returnDataSet, "returnData must be set before"); - if (isData) { return switch (precompileFlag) { case PRC_ECRECOVER -> TOTAL_SIZE_ECRECOVER_DATA; @@ -443,6 +363,19 @@ void handleRecover() { // Because of the hashmap in the ext module, this useless row will only be inserted one time. // Tested by TestEcRecoverWithEmptyExt ext.callADDMOD(Bytes.EMPTY, Bytes.EMPTY, Bytes.EMPTY); + + // Set result rows + EWord recoveredAddress = EWord.ZERO; + + // Extract output + if (internalChecksPassed) { + recoveredAddress = EWord.of(returnData); + } + + // Set success bit and output limb + successBit = !recoveredAddress.isZero(); + limb.set(8, recoveredAddress.hi()); + limb.set(9, recoveredAddress.lo()); } void handleAdd() { @@ -479,6 +412,24 @@ void handleAdd() { // set circuitSelectorEcadd circuitSelectorEcadd = internalChecksPassed; + + // Set result rows + EWord resX = EWord.ZERO; + EWord resY = EWord.ZERO; + + // Extract output + if (internalChecksPassed && returnData.toArray().length != 0) { + Preconditions.checkArgument(returnData.toArray().length == 64); + resX = EWord.of(returnData.slice(0, 32)); + resY = EWord.of(returnData.slice(32, 32)); + } + + // Set success bit and output limb + successBit = internalChecksPassed; + limb.set(8, resX.hi()); + limb.set(9, resX.lo()); + limb.set(10, resY.hi()); + limb.set(11, resY.lo()); } void handleMul() { @@ -509,6 +460,24 @@ void handleMul() { // Set circuitSelectorEcmul circuitSelectorEcmul = internalChecksPassed; + + // Set result rows + EWord resX = EWord.ZERO; + EWord resY = EWord.ZERO; + + // Extract output + if (internalChecksPassed && returnData.toArray().length != 0) { + Preconditions.checkArgument(returnData.toArray().length == 64); + resX = EWord.of(returnData.slice(0, 32)); + resY = EWord.of(returnData.slice(32, 32)); + } + + // Set success bit and output limb + successBit = internalChecksPassed; + limb.set(6, resX.hi()); + limb.set(7, resX.lo()); + limb.set(8, resY.hi()); + limb.set(9, resY.lo()); } void handlePairing() { @@ -615,15 +584,30 @@ void handlePairing() { // This is after all pairings have been processed - // Success bit is set in setReturnData + // Set result rows + EWord pairingResult = EWord.ZERO; + + // Extract output + if (internalChecksPassed) { + pairingResult = EWord.of(returnData); + } + + // Set output limb + limb.set(limb.size() - 2, pairingResult.hi()); + limb.set(limb.size() - 1, pairingResult.lo()); + + // Set callSuccess + if (!internalChecksPassed) { + successBit = false; + } else { + successBit = !notOnG2AccMax; + } // acceptablePairOfPointsForPairingCircuit, g2MembershipTestRequired, circuitSelectorEcpairing, // circuitSelectorG2Membership are set in the trace method } void trace(Trace trace, final int stamp, final long previousId) { - Preconditions.checkArgument(returnDataSet, "returnData must be set before"); - final Bytes deltaByte = leftPadTo(Bytes.minimalBytes(id - previousId - 1), nBYTES_OF_DELTA_BYTES); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java index b5d686de75..4688349443 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java @@ -42,6 +42,62 @@ void testEcRecoverWithEmptyExt() { .run(); } + @ParameterizedTest + @MethodSource("ecRecoverSource") + void testEcRecover( + String description, + EWord h, + EWord v, + EWord r, + EWord s, + boolean expectedInternalChecksPassed, + boolean expectedSuccessBit) { + BytecodeCompiler program = + BytecodeCompiler.newProgram() + // First place the parameters in memory + .push(h) + .push(0) + .op(OpCode.MSTORE) + .push(v) // v + .push(0x20) + .op(OpCode.MSTORE) + .push(r) // r + .push(0x40) + .op(OpCode.MSTORE) + .push(s) // s + .push(0x60) + .op(OpCode.MSTORE) + // Do the call + .push(32) // retSize + .push(0x80) // retOffset + .push(0x80) // argSize + .push(0) // argOffset + .push(1) // address + .push(Bytes.fromHexStringLenient("0xFFFFFFFF")) // gas + .op(OpCode.STATICCALL); + + BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); + bytecodeRunner.run(); + + // Retrieve recoveredAddress, internalChecksPassed, successBit + // Assert internalChecksPassed and successBit are what expected + EcDataOperation ecDataOperation = + bytecodeRunner.getHub().ecData().getOperations().stream().toList().get(0); + EWord recoveredAddress = + EWord.of( + ecDataOperation.limb().get(8).toUnsignedBigInteger(), + ecDataOperation.limb().get(9).toUnsignedBigInteger()); + boolean internalChecksPassed = ecDataOperation.internalChecksPassed(); + boolean successBit = ecDataOperation.successBit(); + + assertEquals(expectedInternalChecksPassed, internalChecksPassed); + assertEquals(expectedSuccessBit, successBit); + + System.out.println("recoveredAddress: " + recoveredAddress); + System.out.println("internalChecksPassed: " + internalChecksPassed); + System.out.println("successBit: " + successBit); + } + private static Stream ecRecoverSource() { EWord h = EWord.ofHexString("0x456e9aea5e197a1f1af7a3e85a3212fa4049a3ba34c2289b4c860fc0b0c64ef3"); @@ -171,60 +227,4 @@ private static Arguments ecRecoverArgumentsFromStrings( boolean expectedSuccessBit) { return Arguments.of(description, h, v, r, s, expectedInternalChecksPassed, expectedSuccessBit); } - - @ParameterizedTest - @MethodSource("ecRecoverSource") - void testEcRecover( - String description, - EWord h, - EWord v, - EWord r, - EWord s, - boolean expectedInternalChecksPassed, - boolean expectedSuccessBit) { - BytecodeCompiler program = - BytecodeCompiler.newProgram() - // First place the parameters in memory - .push(h) - .push(0) - .op(OpCode.MSTORE) - .push(v) // v - .push(0x20) - .op(OpCode.MSTORE) - .push(r) // r - .push(0x40) - .op(OpCode.MSTORE) - .push(s) // s - .push(0x60) - .op(OpCode.MSTORE) - // Do the call - .push(32) // retSize - .push(0x80) // retOffset - .push(0x80) // argSize - .push(0) // argOffset - .push(1) // address - .push(Bytes.fromHexStringLenient("0xFFFFFFFF")) // gas - .op(OpCode.STATICCALL); - - BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); - bytecodeRunner.run(); - - // Retrieve recoveredAddress, internalChecksPassed, successBit - // Assert internalChecksPassed and successBit are what expected - EcDataOperation ecDataOperation = - bytecodeRunner.getHub().ecData().getOperations().stream().toList().get(0); - EWord recoveredAddress = - EWord.of( - ecDataOperation.limb().get(8).toUnsignedBigInteger(), - ecDataOperation.limb().get(9).toUnsignedBigInteger()); - boolean internalChecksPassed = ecDataOperation.internalChecksPassed(); - boolean successBit = ecDataOperation.successBit(); - - assertEquals(internalChecksPassed, expectedInternalChecksPassed); - assertEquals(successBit, expectedSuccessBit); - - System.out.println("recoveredAddress: " + recoveredAddress); - System.out.println("internalChecksPassed: " + internalChecksPassed); - System.out.println("successBit: " + successBit); - } } From 5e19d0764504fe8be183daedb87584aa9933c524 Mon Sep 17 00:00:00 2001 From: FlorianHuc Date: Fri, 23 Aug 2024 17:01:00 +0200 Subject: [PATCH 432/461] change runner name --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 7b7b0aa026..395ffa2647 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -40,7 +40,7 @@ jobs: path: arithmetization/build/libs tests: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-128 steps: - uses: webfactory/ssh-agent@v0.7.0 with: From 8bf2be7bcd757a161ed6f95d1410878694bf4d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 17:45:03 +0200 Subject: [PATCH 433/461] fix(MARKED_FOR_SELFDESTRUCT): fixed typo --- .../zktracer/module/hub/fragment/account/AccountFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index f9e80a81c9..0495cac19c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -178,7 +178,7 @@ public void resolvePostTransaction( oldState.address(), oldState.deploymentNumber()); if (effectiveSelfDestructMap.containsKey(ephemeralAccount)) { final int selfDestructTime = effectiveSelfDestructMap.get(ephemeralAccount); - markedForSelfDestruct = hubStamp < selfDestructTime; + markedForSelfDestruct = hubStamp > selfDestructTime; markedForSelfDestructNew = hubStamp >= selfDestructTime; } else { markedForSelfDestruct = false; From 59ff899962cf665572e7eb01632b86ced43cc643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 17:46:12 +0200 Subject: [PATCH 434/461] fix(modexp): use safe slice method to extract bbs, ebs and mbs --- .../hub/precompiles/ModexpMetadata.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java index 7088949066..13ba0b62e9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java @@ -30,9 +30,10 @@ @Getter @Accessors(fluent = true) public class ModexpMetadata { - static final int EBS_MIN_OFFSET = 32; - static final int MBS_MIN_OFFSET = 64; - static final int BASE_MIN_OFFSET = 96; + static final int BBS_MIN_OFFSET = 0x00; + static final int EBS_MIN_OFFSET = 0x20; + static final int MBS_MIN_OFFSET = 0x40; + static final int BASE_MIN_OFFSET = 0x60; private final Bytes callData; @Setter private Bytes rawResult; @@ -57,9 +58,9 @@ private int bbsShift() { return EBS_MIN_OFFSET - Math.min(EBS_MIN_OFFSET, callData.size()); } - public Bytes rawBbs() { - return extractBbs() ? callData.slice(0, EBS_MIN_OFFSET) : Bytes.EMPTY; - } + public Bytes rawBbs() { return Util.slice(callData, BBS_MIN_OFFSET, WORD_SIZE); } + public Bytes rawEbs() { return Util.slice(callData, EBS_MIN_OFFSET, WORD_SIZE); } + public Bytes rawMbs() { return Util.slice(callData, MBS_MIN_OFFSET, WORD_SIZE); } public EWord bbs() { return EWord.of(rawBbs().shiftRight(bbsShift()).shiftLeft(bbsShift())); @@ -71,9 +72,6 @@ private int ebsShift() { : 0; } - public Bytes rawEbs() { - return extractEbs() ? callData.slice(EBS_MIN_OFFSET, WORD_SIZE) : Bytes.EMPTY; - } public EWord ebs() { return EWord.of(rawEbs().shiftRight(ebsShift()).shiftLeft(ebsShift())); @@ -85,10 +83,6 @@ private int mbsShift() { : 0; } - public Bytes rawMbs() { - return extractMbs() ? callData.slice(MBS_MIN_OFFSET, WORD_SIZE) : Bytes.EMPTY; - } - public EWord mbs() { return EWord.of(rawMbs().shiftRight(mbsShift()).shiftLeft(mbsShift())); } From ebdb8e353a012d2f9a3da3b04c203e0664af6706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 17:47:08 +0200 Subject: [PATCH 435/461] fix(modexp): extract the correct "rawLeadingWord" --- .../hub/precompiles/ModexpMetadata.java | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java index 13ba0b62e9..f3221a98d5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java @@ -22,6 +22,8 @@ import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import net.consensys.linea.zktracer.module.Util; +import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; @@ -36,10 +38,13 @@ public class ModexpMetadata { static final int BASE_MIN_OFFSET = 0x60; private final Bytes callData; + private final EWord rawLeadingWord; @Setter private Bytes rawResult; - public ModexpMetadata(final Bytes callData) { + public ModexpMetadata(final Hub hub, final Bytes callData) { this.callData = callData; + int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); + this.rawLeadingWord = EWord.of(hub.messageFrame().shadowReadMemory(exponentOffsetInCallData, WORD_SIZE)); } public boolean extractBbs() { @@ -105,20 +110,28 @@ public boolean loadRawLeadingWord() { public EWord rawLeadingWord() { - if (!loadRawLeadingWord()) { - return EWord.ZERO; - } + // if (!loadRawLeadingWord()) { + // return EWord.ZERO; + // } + + // TODO: is this precaution useless / dangerous ? + Preconditions.checkArgument(loadRawLeadingWord()); + return this.rawLeadingWord; + + // int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); + + // return EWord.of(hub.messageFrame().shadowReadMemory(exponentOffsetInCallData, WORD_SIZE)); + + // int numberOfBytesToGrabFromCallData = + // (exponentOffsetInCallData + WORD_SIZE <= callData.size()) + // ? WORD_SIZE + // : callData.size() - exponentOffsetInCallData; + // Preconditions.checkArgument(0 < numberOfBytesToGrabFromCallData); + + // return EWord.of( + // Bytes32.rightPad( + // callData.slice(BASE_MIN_OFFSET + bbsInt(), numberOfBytesToGrabFromCallData))); - int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); - int numberOfBytesToGrabFromCallData = - (exponentOffsetInCallData + WORD_SIZE <= callData.size()) - ? WORD_SIZE - : callData.size() - exponentOffsetInCallData; - Preconditions.checkArgument(0 < numberOfBytesToGrabFromCallData); - - return EWord.of( - Bytes32.rightPad( - callData.slice(BASE_MIN_OFFSET + bbsInt(), numberOfBytesToGrabFromCallData))); } public boolean extractModulus() { From e17d6e0feff0dae27c94dabe7ea961ec3ec6dd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 17:47:33 +0200 Subject: [PATCH 436/461] ras --- .../section/call/precompileSubsection/ModexpSubsection.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 90906b6a76..2e3a97f304 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -46,6 +46,7 @@ import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; +import net.consensys.linea.zktracer.types.EWord; public class ModexpSubsection extends PrecompileSubsection { @@ -56,7 +57,7 @@ public class ModexpSubsection extends PrecompileSubsection { public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); - modExpMetadata = new ModexpMetadata(callData); + modExpMetadata = new ModexpMetadata(hub, callData); if (modExpMetadata .bbs() .toUnsignedBigInteger() From acff53239ecd01929979018a35366cbb1364f1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 17:52:25 +0200 Subject: [PATCH 437/461] spotless --- .../hub/precompiles/ModexpMetadata.java | 43 +++++++------------ .../ModexpSubsection.java | 1 - .../zktracer/precompiles/ModexpTests.java | 5 ++- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java index f3221a98d5..126c93e6cb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java @@ -26,7 +26,6 @@ import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.evm.internal.Words; @Getter @@ -44,11 +43,12 @@ public class ModexpMetadata { public ModexpMetadata(final Hub hub, final Bytes callData) { this.callData = callData; int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); - this.rawLeadingWord = EWord.of(hub.messageFrame().shadowReadMemory(exponentOffsetInCallData, WORD_SIZE)); + this.rawLeadingWord = + EWord.of(hub.messageFrame().shadowReadMemory(exponentOffsetInCallData, WORD_SIZE)); } public boolean extractBbs() { - return !callData.isEmpty(); + return callData.size() > BBS_MIN_OFFSET; } public boolean extractEbs() { @@ -59,14 +59,22 @@ public boolean extractMbs() { return callData.size() > MBS_MIN_OFFSET; } + public Bytes rawBbs() { + return Util.slice(callData, BBS_MIN_OFFSET, WORD_SIZE); + } + + public Bytes rawEbs() { + return Util.slice(callData, EBS_MIN_OFFSET, WORD_SIZE); + } + + public Bytes rawMbs() { + return Util.slice(callData, MBS_MIN_OFFSET, WORD_SIZE); + } + private int bbsShift() { return EBS_MIN_OFFSET - Math.min(EBS_MIN_OFFSET, callData.size()); } - public Bytes rawBbs() { return Util.slice(callData, BBS_MIN_OFFSET, WORD_SIZE); } - public Bytes rawEbs() { return Util.slice(callData, EBS_MIN_OFFSET, WORD_SIZE); } - public Bytes rawMbs() { return Util.slice(callData, MBS_MIN_OFFSET, WORD_SIZE); } - public EWord bbs() { return EWord.of(rawBbs().shiftRight(bbsShift()).shiftLeft(bbsShift())); } @@ -77,7 +85,6 @@ private int ebsShift() { : 0; } - public EWord ebs() { return EWord.of(rawEbs().shiftRight(ebsShift()).shiftLeft(ebsShift())); } @@ -109,29 +116,9 @@ public boolean loadRawLeadingWord() { } public EWord rawLeadingWord() { - - // if (!loadRawLeadingWord()) { - // return EWord.ZERO; - // } - // TODO: is this precaution useless / dangerous ? Preconditions.checkArgument(loadRawLeadingWord()); return this.rawLeadingWord; - - // int exponentOffsetInCallData = BASE_MIN_OFFSET + bbsInt(); - - // return EWord.of(hub.messageFrame().shadowReadMemory(exponentOffsetInCallData, WORD_SIZE)); - - // int numberOfBytesToGrabFromCallData = - // (exponentOffsetInCallData + WORD_SIZE <= callData.size()) - // ? WORD_SIZE - // : callData.size() - exponentOffsetInCallData; - // Preconditions.checkArgument(0 < numberOfBytesToGrabFromCallData); - - // return EWord.of( - // Bytes32.rightPad( - // callData.slice(BASE_MIN_OFFSET + bbsInt(), numberOfBytesToGrabFromCallData))); - } public boolean extractModulus() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index 2e3a97f304..68cb990991 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -46,7 +46,6 @@ import net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata; import net.consensys.linea.zktracer.module.hub.section.call.CallSection; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; -import net.consensys.linea.zktracer.types.EWord; public class ModexpSubsection extends PrecompileSubsection { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java index 874576bf27..c68508620f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/ModexpTests.java @@ -116,14 +116,15 @@ BytecodeCompiler preparingBaseExponentAndModulusForModexpAndRunningVariousModexp for (int returnAtCapacity : returnAtCapacityList) { for (int callDataSize : callDataSizeList) { - parametrizedModexpCall(program, returnAtCapacity, callDataSize); + appendParametrizedModexpCall(program, returnAtCapacity, callDataSize); } } return program; } - void parametrizedModexpCall(BytecodeCompiler program, int returnAtCapacity, int callDataSize) { + void appendParametrizedModexpCall( + BytecodeCompiler program, int returnAtCapacity, int callDataSize) { program .push(returnAtCapacity) // r@c .push(Bytes.fromHexString("0100")) // r@o From 5408f9205cf9d69e2bf9c5465ea9022dbe396dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 17:54:11 +0200 Subject: [PATCH 438/461] fix(oob): typo --- .../main/java/net/consensys/linea/zktracer/module/oob/Oob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java index e472e95495..9f77a5ee1d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/oob/Oob.java @@ -123,7 +123,7 @@ final void traceChunk(final OobOperation oobOperation, int stamp, Trace trace) { .isEcmul(oobInstruction == OOB_INST_ECMUL) .isEcpairing(oobInstruction == OOB_INST_ECPAIRING) .isBlake2FCds(oobInstruction == OOB_INST_BLAKE_CDS) - .isBlake2FParams(oobInstruction == OOB_INST_BLAKE_CDS) + .isBlake2FParams(oobInstruction == OOB_INST_BLAKE_PARAMS) .isModexpCds(oobInstruction == OOB_INST_MODEXP_CDS) .isModexpXbs(oobInstruction == OOB_INST_MODEXP_XBS) .isModexpLead(oobInstruction == OOB_INST_MODEXP_LEAD) From ddfe11643d790ba697d0d1507f4148a47ef8b2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 22:03:17 +0200 Subject: [PATCH 439/461] fix(rollback): REVERT now also triggers the rollback mechanism --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 67ec584e71..54f5d4efe3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -705,7 +705,7 @@ public void traceContextExit(MessageFrame frame) { this.defers.resolveUponExitingContext(this, this.currentFrame()); // TODO: verify me please @Olivier - if (Exceptions.any(this.pch.exceptions())) { + if (this.currentFrame().opCode() == OpCode.REVERT || Exceptions.any(this.pch.exceptions())) { this.defers.resolvePostRollback(this, frame, this.currentFrame()); } From f249e99f22c6b9b2e747b42393ce8fdb477d359c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 22:04:34 +0200 Subject: [PATCH 440/461] fix(mmu): we only commit those MmuOperations that say "traceMe()" --- .../consensys/linea/zktracer/module/mmu/Mmu.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java index b2e6fa665f..c19bb5f601 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java @@ -91,13 +91,16 @@ public void commit(List buffers) { int mmioStamp = 0; for (MmuOperation mmuOp : mmuOperations) { - mmuOp.getCFI(); - mmuOp.setExoBytes(exoSumDecoder); - mmuOp.fillLimb(); - mmuStamp += 1; - mmuOp.trace(mmuStamp, mmioStamp, trace); - mmioStamp += mmuOp.mmuData().numberMmioInstructions(); + if (mmuOp.mmuData().mmuCall().traceMe()) { + mmuOp.getCFI(); + mmuOp.setExoBytes(exoSumDecoder); + mmuOp.fillLimb(); + + mmuStamp += 1; + mmuOp.trace(mmuStamp, mmioStamp, trace); + mmioStamp += mmuOp.mmuData().numberMmioInstructions(); + } } } From 96d656631a5079f8b4c570e210d5aa5b7b362e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Fri, 23 Aug 2024 22:05:34 +0200 Subject: [PATCH 441/461] test(mmu): added tests for MMU Note. There is a bug somewhere, REVERT opcodes don't trigger the MMU ... --- .../zktracer/module/mmu/MemoryTests.java | 68 +++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java index 220ecd426d..c39c8fa88e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java @@ -23,13 +23,15 @@ import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; +import static net.consensys.linea.testing.BytecodeCompiler.newProgram; + class MemoryTests { private final Random rnd = new Random(666); @Test void successionOverlappingMstore() { BytecodeRunner.of( - BytecodeCompiler.newProgram() + newProgram() .push(Bytes.repeat((byte) 1, 32)) .push(0) .op(OpCode.MSTORE) @@ -47,20 +49,78 @@ void successionOverlappingMstore() { @Test void fastMload() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(34).push(0).op(OpCode.MLOAD).compile()) + BytecodeRunner.of(newProgram().push(34).push(0).op(OpCode.MLOAD).compile()) .run(); } @Test void alignedMstore8() { - BytecodeRunner.of(BytecodeCompiler.newProgram().push(12).push(0).op(OpCode.MSTORE8).compile()) + BytecodeRunner.of(newProgram().push(12).push(0).op(OpCode.MSTORE8).compile()) .run(); } @Test void nonAlignedMstore8() { BytecodeRunner.of( - BytecodeCompiler.newProgram().push(66872).push(35).op(OpCode.MSTORE8).compile()) + newProgram().push(66872).push(35).op(OpCode.MSTORE8).compile()) .run(); } + + + @Test + void mstoreAndReturn() { + BytecodeCompiler program = newProgram(); + program + .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x20).op(OpCode.MSTORE) + .push(0x10).push(0x30).op(OpCode.RETURN); + BytecodeRunner.of(program.compile()).run(); + } + + @Test + void mstoreAndRevert() { + BytecodeCompiler program = newProgram(); + program + .push("deadbeef22222222deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x20).op(OpCode.MSTORE) + .push(0x10).push(0x28).op(OpCode.REVERT); + BytecodeRunner.of(program.compile()).run(); + } + + @Test + void returnAfterLog2() { + BytecodeCompiler program = newProgram(); + program + .push(0x01).push(0x11).op(OpCode.SHA3) // KECCAK("00") + .push(0x00).op(OpCode.MSTORE) + .push(0x02).push(0x31).op(OpCode.SHA3) // KECCAK("0000") + .push(0x20).op(OpCode.MSTORE) + // + .push(0x20) // size + .push(0x10) // offset + .push(0xbbbbbbbb) // topic 2 + .push(0xaaaaaaaa) // topic 1 + .op(OpCode.LOG2) + .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x40).op(OpCode.MSTORE) + .push(0x10).push(0x30).op(OpCode.RETURN); + + BytecodeRunner.of(program.compile()).run(); + } + + @Test + void simpleRevertedLog() { + BytecodeCompiler program = newProgram(); + program + .push(0x01).push(0x11).op(OpCode.SHA3) // KECCAK("00") + .push(0x00).op(OpCode.MSTORE) + .push(0x02).push(0x31).op(OpCode.SHA3) // KECCAK("0000") + .push(0x20).op(OpCode.MSTORE) + // + .push(0x20) // size + .push(0x10) // offset + .push(0xbbbbbbbb) // topic 2 + .push(0xaaaaaaaa) // topic 1 + .op(OpCode.LOG2) + .push(0x10).push(0x30).op(OpCode.REVERT); + + BytecodeRunner.of(program.compile()).run(); + } } From 7cdec09e7de89113cebe7a3c358c5e27f03b9447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 24 Aug 2024 01:39:37 +0200 Subject: [PATCH 442/461] fix(mmu): line count now discards operations that don't get traced --- .../net/consensys/linea/zktracer/module/mmu/Mmu.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java index c19bb5f601..e3008db793 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java @@ -75,7 +75,16 @@ public void popTransaction() { @Override public int lineCount() { - return this.mmuOperations.lineCount(); + int lineCount = 0; + + for (int i = 0; i < this.mmuOperations.size(); i++) { + MmuOperation mmuOperation = this.mmuOperations.get(i); + if (mmuOperation.mmuData().mmuCall().traceMe()) { + lineCount += mmuOperation.lineCount(); + } + } + + return lineCount; } @Override From bd2788881845d3805606b54f183941d565c30da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 24 Aug 2024 01:40:18 +0200 Subject: [PATCH 443/461] feat(mxp): some extra tests they don't shed light on the issue ... --- .../zktracer/module/mmu/MemoryTests.java | 7 +++-- .../linea/zktracer/module/mxp/MxpTest.java | 29 ++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java index c39c8fa88e..8cc67d71b1 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java @@ -71,7 +71,7 @@ void nonAlignedMstore8() { void mstoreAndReturn() { BytecodeCompiler program = newProgram(); program - .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x20).op(OpCode.MSTORE) + .push("deadbeef11111111deadbeef22222222deadbeef00000000deadbeefcccccccc").push(0x20).op(OpCode.MSTORE) .push(0x10).push(0x30).op(OpCode.RETURN); BytecodeRunner.of(program.compile()).run(); } @@ -80,7 +80,7 @@ void mstoreAndReturn() { void mstoreAndRevert() { BytecodeCompiler program = newProgram(); program - .push("deadbeef22222222deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x20).op(OpCode.MSTORE) + .push("deadbeef11111111deadbeef22222222deadbeef00000000deadbeefcccccccc").push(0x20).op(OpCode.MSTORE) .push(0x10).push(0x28).op(OpCode.REVERT); BytecodeRunner.of(program.compile()).run(); } @@ -106,7 +106,7 @@ void returnAfterLog2() { } @Test - void simpleRevertedLog() { + void revertAfterLog2() { BytecodeCompiler program = newProgram(); program .push(0x01).push(0x11).op(OpCode.SHA3) // KECCAK("00") @@ -119,6 +119,7 @@ void simpleRevertedLog() { .push(0xbbbbbbbb) // topic 2 .push(0xaaaaaaaa) // topic 1 .op(OpCode.LOG2) + .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x40).op(OpCode.MSTORE) .push(0x10).push(0x30).op(OpCode.REVERT); BytecodeRunner.of(program.compile()).run(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index e5cf5ab4c7..99a506a93e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -126,7 +126,7 @@ void testMxpRandomTriggerMxpx() { } @Test - void testMxpRandomTriggerRoob() { + void testRandomMxpInstructionsFollowedByTriggeringRoob() { // Testing a random program BytecodeCompiler program = BytecodeCompiler.newProgram(); final int INSTRUCTION_COUNT = 256; @@ -138,6 +138,33 @@ void testMxpRandomTriggerRoob() { BytecodeRunner.of(program.compile()).run(); } + + @Test + void testSingleLog3TriggersRoob() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + program + .push("30000003333333333333000000000000" + "00000000000000000000000000000003") // topic 3 + .push("20000000000000000000222222222222" + "20000000000000000000000000000002") // topic 2 + .push("10000000000000000000000000000000" + "00000000000001111111111111000001") // topic 1 + .push("00000000000000000000010000000000" + "00000000000000000000000000000000") // size + .push("00000000000000000000000000000000" + "00000000000000000000000000000001") // offset + .op(OpCode.LOG3); + BytecodeRunner.of(program.compile()).run(); + } + + @Test + void testSingleUnexceptionalLog3() { + BytecodeCompiler program = BytecodeCompiler.newProgram(); + program + .push("30000003333333333333000000000000" + "00000000000000000000000000000003") // topic 3 + .push("20000000000000000000222222222222" + "20000000000000000000000000000002") // topic 2 + .push("10000000000000000000000000000000" + "00000000000001111111111111000001") // topic 1 + .push("00000000000000000000000000000000" + "00000000000000000000000000000100") // size + .push("00000000000000000000000000000000" + "00000000000000000000000000000101") // offset + .op(OpCode.LOG3); + BytecodeRunner.of(program.compile()).run(); + } + @Test void testMxpxOrRoob() { final int REPETITIONS = 5; From 49ed5c8c88925a70dbd52961f295353aa9c5ba28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Sat, 24 Aug 2024 01:43:29 +0200 Subject: [PATCH 444/461] feat: traceMe() method for MmuOperation --- .../consensys/linea/zktracer/module/mmu/Mmu.java | 16 ++++++++-------- .../linea/zktracer/module/mmu/MmuOperation.java | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java index e3008db793..19d4176db3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java @@ -79,7 +79,7 @@ public int lineCount() { for (int i = 0; i < this.mmuOperations.size(); i++) { MmuOperation mmuOperation = this.mmuOperations.get(i); - if (mmuOperation.mmuData().mmuCall().traceMe()) { + if (mmuOperation.traceMe()) { lineCount += mmuOperation.lineCount(); } } @@ -99,16 +99,16 @@ public void commit(List buffers) { int mmuStamp = 0; int mmioStamp = 0; - for (MmuOperation mmuOp : mmuOperations) { + for (MmuOperation mmuOperation : mmuOperations) { - if (mmuOp.mmuData().mmuCall().traceMe()) { - mmuOp.getCFI(); - mmuOp.setExoBytes(exoSumDecoder); - mmuOp.fillLimb(); + if (mmuOperation.traceMe()) { + mmuOperation.getCFI(); + mmuOperation.setExoBytes(exoSumDecoder); + mmuOperation.fillLimb(); mmuStamp += 1; - mmuOp.trace(mmuStamp, mmioStamp, trace); - mmioStamp += mmuOp.mmuData().numberMmioInstructions(); + mmuOperation.trace(mmuStamp, mmioStamp, trace); + mmioStamp += mmuOperation.mmuData().numberMmioInstructions(); } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java index 160786d120..2f263af416 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java @@ -79,6 +79,10 @@ public class MmuOperation extends ModuleOperation { this.callStackReader = new CallStackReader(callStack); } + public boolean traceMe() { + return this.mmuData.mmuCall().traceMe(); + } + @Override protected int computeLineCount() { return 1 + mmuData.numberMmuPreprocessingRows() + mmuData.numberMmioInstructions(); From 9658d9318d7d900802c66d3b824ef87191d7eed7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 24 Aug 2024 08:56:38 +0530 Subject: [PATCH 445/461] spotless + fix untraced MMU op in mmio Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/mmio/Mmio.java | 37 +++---- .../linea/zktracer/module/mmu/Mmu.java | 11 +-- .../zktracer/module/mmu/MmuOperation.java | 13 ++- .../zktracer/module/mmu/MemoryTests.java | 99 ++++++++++++------- .../linea/zktracer/module/mxp/MxpTest.java | 25 +++-- 5 files changed, 103 insertions(+), 82 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java index 0c88c652be..e4cb282fca 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmio/Mmio.java @@ -80,23 +80,26 @@ public void commit(List buffers) { Trace trace = new Trace(buffers); int stamp = 0; for (MmuOperation mmuOperation : mmu.mmuOperations()) { - final MmuData currentMmuData = mmuOperation.mmuData(); - - for (int currentMmioInstNumber = 0; - currentMmioInstNumber < currentMmuData.numberMmioInstructions(); - currentMmioInstNumber++) { - stamp++; - - final MmioInstructions mmioInstructions = - new MmioInstructions(currentMmuData, currentMmioInstNumber); - final MmioData mmioData = - mmioInstructions.compute( - currentMmuData - .mmuToMmioInstructions() - .get(currentMmioInstNumber) - .mmioInstruction()); - - trace(trace, mmioData, stamp); + if (mmuOperation.traceMe()) { + + final MmuData currentMmuData = mmuOperation.mmuData(); + + for (int currentMmioInstNumber = 0; + currentMmioInstNumber < currentMmuData.numberMmioInstructions(); + currentMmioInstNumber++) { + stamp++; + + final MmioInstructions mmioInstructions = + new MmioInstructions(currentMmuData, currentMmioInstNumber); + final MmioData mmioData = + mmioInstructions.compute( + currentMmuData + .mmuToMmioInstructions() + .get(currentMmioInstNumber) + .mmioInstruction()); + + trace(trace, mmioData, stamp); + } } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java index 19d4176db3..fcc9bf885c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/Mmu.java @@ -75,16 +75,7 @@ public void popTransaction() { @Override public int lineCount() { - int lineCount = 0; - - for (int i = 0; i < this.mmuOperations.size(); i++) { - MmuOperation mmuOperation = this.mmuOperations.get(i); - if (mmuOperation.traceMe()) { - lineCount += mmuOperation.lineCount(); - } - } - - return lineCount; + return this.mmuOperations.lineCount(); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java index 2f263af416..9cf6ba4c67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java @@ -80,18 +80,23 @@ public class MmuOperation extends ModuleOperation { } public boolean traceMe() { - return this.mmuData.mmuCall().traceMe(); + return mmuData.mmuCall().traceMe(); } @Override protected int computeLineCount() { - return 1 + mmuData.numberMmuPreprocessingRows() + mmuData.numberMmioInstructions(); + return traceMe() + ? 1 + mmuData.numberMmuPreprocessingRows() + mmuData.numberMmioInstructions() + : 0; } public int computeMmioLineCount() { int sum = 0; - for (int i = 0; i < mmuData().numberMmioInstructions(); i++) { - sum += numberOfRowOfMmioInstruction(mmuData.mmuToMmioInstructions().get(i).mmioInstruction()); + if (traceMe()) { + for (int i = 0; i < mmuData().numberMmioInstructions(); i++) { + sum += + numberOfRowOfMmioInstruction(mmuData.mmuToMmioInstructions().get(i).mmioInstruction()); + } } return sum; } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java index 8cc67d71b1..306ef6c24e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.module.mmu; +import static net.consensys.linea.testing.BytecodeCompiler.newProgram; + import java.util.Random; import net.consensys.linea.testing.BytecodeCompiler; @@ -23,8 +25,6 @@ import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; -import static net.consensys.linea.testing.BytecodeCompiler.newProgram; - class MemoryTests { private final Random rnd = new Random(666); @@ -49,30 +49,29 @@ void successionOverlappingMstore() { @Test void fastMload() { - BytecodeRunner.of(newProgram().push(34).push(0).op(OpCode.MLOAD).compile()) - .run(); + BytecodeRunner.of(newProgram().push(34).push(0).op(OpCode.MLOAD).compile()).run(); } @Test void alignedMstore8() { - BytecodeRunner.of(newProgram().push(12).push(0).op(OpCode.MSTORE8).compile()) - .run(); + BytecodeRunner.of(newProgram().push(12).push(0).op(OpCode.MSTORE8).compile()).run(); } @Test void nonAlignedMstore8() { - BytecodeRunner.of( - newProgram().push(66872).push(35).op(OpCode.MSTORE8).compile()) - .run(); + BytecodeRunner.of(newProgram().push(66872).push(35).op(OpCode.MSTORE8).compile()).run(); } - @Test void mstoreAndReturn() { BytecodeCompiler program = newProgram(); program - .push("deadbeef11111111deadbeef22222222deadbeef00000000deadbeefcccccccc").push(0x20).op(OpCode.MSTORE) - .push(0x10).push(0x30).op(OpCode.RETURN); + .push("deadbeef11111111deadbeef22222222deadbeef00000000deadbeefcccccccc") + .push(0x20) + .op(OpCode.MSTORE) + .push(0x10) + .push(0x30) + .op(OpCode.RETURN); BytecodeRunner.of(program.compile()).run(); } @@ -80,8 +79,12 @@ void mstoreAndReturn() { void mstoreAndRevert() { BytecodeCompiler program = newProgram(); program - .push("deadbeef11111111deadbeef22222222deadbeef00000000deadbeefcccccccc").push(0x20).op(OpCode.MSTORE) - .push(0x10).push(0x28).op(OpCode.REVERT); + .push("deadbeef11111111deadbeef22222222deadbeef00000000deadbeefcccccccc") + .push(0x20) + .op(OpCode.MSTORE) + .push(0x10) + .push(0x28) + .op(OpCode.REVERT); BytecodeRunner.of(program.compile()).run(); } @@ -89,18 +92,28 @@ void mstoreAndRevert() { void returnAfterLog2() { BytecodeCompiler program = newProgram(); program - .push(0x01).push(0x11).op(OpCode.SHA3) // KECCAK("00") - .push(0x00).op(OpCode.MSTORE) - .push(0x02).push(0x31).op(OpCode.SHA3) // KECCAK("0000") - .push(0x20).op(OpCode.MSTORE) - // - .push(0x20) // size - .push(0x10) // offset - .push(0xbbbbbbbb) // topic 2 - .push(0xaaaaaaaa) // topic 1 - .op(OpCode.LOG2) - .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x40).op(OpCode.MSTORE) - .push(0x10).push(0x30).op(OpCode.RETURN); + .push(0x01) + .push(0x11) + .op(OpCode.SHA3) // KECCAK("00") + .push(0x00) + .op(OpCode.MSTORE) + .push(0x02) + .push(0x31) + .op(OpCode.SHA3) // KECCAK("0000") + .push(0x20) + .op(OpCode.MSTORE) + // + .push(0x20) // size + .push(0x10) // offset + .push(0xbbbbbbbb) // topic 2 + .push(0xaaaaaaaa) // topic 1 + .op(OpCode.LOG2) + .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111") + .push(0x40) + .op(OpCode.MSTORE) + .push(0x10) + .push(0x30) + .op(OpCode.RETURN); BytecodeRunner.of(program.compile()).run(); } @@ -109,18 +122,28 @@ void returnAfterLog2() { void revertAfterLog2() { BytecodeCompiler program = newProgram(); program - .push(0x01).push(0x11).op(OpCode.SHA3) // KECCAK("00") - .push(0x00).op(OpCode.MSTORE) - .push(0x02).push(0x31).op(OpCode.SHA3) // KECCAK("0000") - .push(0x20).op(OpCode.MSTORE) - // - .push(0x20) // size - .push(0x10) // offset - .push(0xbbbbbbbb) // topic 2 - .push(0xaaaaaaaa) // topic 1 - .op(OpCode.LOG2) - .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111").push(0x40).op(OpCode.MSTORE) - .push(0x10).push(0x30).op(OpCode.REVERT); + .push(0x01) + .push(0x11) + .op(OpCode.SHA3) // KECCAK("00") + .push(0x00) + .op(OpCode.MSTORE) + .push(0x02) + .push(0x31) + .op(OpCode.SHA3) // KECCAK("0000") + .push(0x20) + .op(OpCode.MSTORE) + // + .push(0x20) // size + .push(0x10) // offset + .push(0xbbbbbbbb) // topic 2 + .push(0xaaaaaaaa) // topic 1 + .op(OpCode.LOG2) + .push("deadbeef00000000deadbeef33333333deadbeefccccccccdeadbeef11111111") + .push(0x40) + .op(OpCode.MSTORE) + .push(0x10) + .push(0x30) + .op(OpCode.REVERT); BytecodeRunner.of(program.compile()).run(); } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index 99a506a93e..de85fd888d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -138,17 +138,16 @@ void testRandomMxpInstructionsFollowedByTriggeringRoob() { BytecodeRunner.of(program.compile()).run(); } - @Test void testSingleLog3TriggersRoob() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push("30000003333333333333000000000000" + "00000000000000000000000000000003") // topic 3 - .push("20000000000000000000222222222222" + "20000000000000000000000000000002") // topic 2 - .push("10000000000000000000000000000000" + "00000000000001111111111111000001") // topic 1 - .push("00000000000000000000010000000000" + "00000000000000000000000000000000") // size - .push("00000000000000000000000000000000" + "00000000000000000000000000000001") // offset - .op(OpCode.LOG3); + .push("30000003333333333333000000000000" + "00000000000000000000000000000003") // topic 3 + .push("20000000000000000000222222222222" + "20000000000000000000000000000002") // topic 2 + .push("10000000000000000000000000000000" + "00000000000001111111111111000001") // topic 1 + .push("00000000000000000000010000000000" + "00000000000000000000000000000000") // size + .push("00000000000000000000000000000000" + "00000000000000000000000000000001") // offset + .op(OpCode.LOG3); BytecodeRunner.of(program.compile()).run(); } @@ -156,12 +155,12 @@ void testSingleLog3TriggersRoob() { void testSingleUnexceptionalLog3() { BytecodeCompiler program = BytecodeCompiler.newProgram(); program - .push("30000003333333333333000000000000" + "00000000000000000000000000000003") // topic 3 - .push("20000000000000000000222222222222" + "20000000000000000000000000000002") // topic 2 - .push("10000000000000000000000000000000" + "00000000000001111111111111000001") // topic 1 - .push("00000000000000000000000000000000" + "00000000000000000000000000000100") // size - .push("00000000000000000000000000000000" + "00000000000000000000000000000101") // offset - .op(OpCode.LOG3); + .push("30000003333333333333000000000000" + "00000000000000000000000000000003") // topic 3 + .push("20000000000000000000222222222222" + "20000000000000000000000000000002") // topic 2 + .push("10000000000000000000000000000000" + "00000000000001111111111111000001") // topic 1 + .push("00000000000000000000000000000000" + "00000000000000000000000000000100") // size + .push("00000000000000000000000000000000" + "00000000000000000000000000000101") // offset + .op(OpCode.LOG3); BytecodeRunner.of(program.compile()).run(); } From 029cdbc8e7d3944dc06dc39eafdfb4b07b463346 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 26 Aug 2024 10:34:31 +0530 Subject: [PATCH 446/461] fix make it build Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/rlpaddr/TestRlpAddress.java | 8 ++------ .../main/java/net/consensys/linea/testing/ToyWorld.java | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index a5e102d81e..dde9eb31dc 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -23,6 +23,7 @@ import net.consensys.linea.testing.BytecodeCompiler; import net.consensys.linea.testing.ToyAccount; import net.consensys.linea.testing.ToyExecutionEnvironment; +import net.consensys.linea.testing.ToyExecutionEnvironmentV2; import net.consensys.linea.testing.ToyTransaction; import net.consensys.linea.testing.ToyWorld; import net.consensys.linea.zktracer.opcode.OpCode; @@ -68,12 +69,7 @@ void randDeployment() { .payload(initCode) .build(); - ToyExecutionEnvironment.builder() - .toyWorld(world.build()) - .transaction(tx) - .testValidator(x -> {}) - .build() - .run(); + ToyExecutionEnvironmentV2.builder().toyWorld(world.build()).transaction(tx).build().run(); } @Test diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyWorld.java b/testing/src/main/java/net/consensys/linea/testing/ToyWorld.java index e4a3d31c25..2d03b83279 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ToyWorld.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyWorld.java @@ -109,7 +109,6 @@ public MutableAccount createAccount( .balance(balance) .build(); - accounts.add(account); addressAccountMap.put(address, account); return authorizedCodeService.processMutableAccount(this, account, address); From acafb72e1d55623f9833fa3f81029492670533c1 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 26 Aug 2024 10:57:06 +0530 Subject: [PATCH 447/461] fix successBit in invalidCodePrefix MmuCall Signed-off-by: Francois Bojarski --- .../module/hub/fragment/imc/mmu/MmuCall.java | 2 +- .../module/hub/section/halt/ReturnSection.java | 5 +---- .../mmu/instructions/InvalidCodePrefix.java | 16 +++++++--------- .../ContractModifyingStorageTest.java | 11 ++++++----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java index 6c3ca0babb..005e26f9e3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/MmuCall.java @@ -297,7 +297,7 @@ public static MmuCall invalidCodePrefix(final Hub hub) { .frame() .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) .sourceOffset(EWord.of(hub.messageFrame().getStackItem(0))) - .successBit(Exceptions.invalidCodePrefix(currentExceptions)); + .successBit(!Exceptions.invalidCodePrefix(currentExceptions)); } public static MmuCall revert(final Hub hub) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java index 9528ed9984..37f3a947f8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/ReturnSection.java @@ -194,10 +194,7 @@ public ReturnSection(Hub hub) { firstImcFragment.callOob(maxCodeSizeOobCall); // sanity checks - // TODO: Olivier should confirm this validation check. - Preconditions.checkArgument( - Exceptions.invalidCodePrefix(exceptions) == invalidCodePrefixCheckMmuCall.successBit()); - // Preconditions.checkArgument(invalidCodePrefixCheckMmuCall.successBit()); + Preconditions.checkArgument(invalidCodePrefixCheckMmuCall.successBit()); Preconditions.checkArgument(!maxCodeSizeOobCall.isMaxCodeSizeException()); final ImcFragment secondImcFragment = ImcFragment.empty(hub); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java index bd4e0ab462..8f4a239bed 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/instructions/InvalidCodePrefix.java @@ -19,13 +19,13 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGEMO; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMIO_INST_RAM_TO_LIMB_ONE_SOURCE; +import static net.consensys.linea.zktracer.module.mmu.Trace.NB_PP_ROWS_INVALID_CODE_PREFIX; import java.util.ArrayList; import java.util.List; import net.consensys.linea.zktracer.module.euc.Euc; import net.consensys.linea.zktracer.module.euc.EucOperation; -import net.consensys.linea.zktracer.module.mmio.CallStackReader; import net.consensys.linea.zktracer.module.mmu.MmuData; import net.consensys.linea.zktracer.module.mmu.Trace; import net.consensys.linea.zktracer.module.mmu.values.HubToMmuValues; @@ -42,8 +42,8 @@ public class InvalidCodePrefix implements MmuInstruction { private final Euc euc; private final Wcp wcp; - private List eucCallRecords; - private List wcpCallRecords; + private final List eucCallRecords; + private final List wcpCallRecords; private long initialSourceLimbOffset; private short initialSourceByteOffset; @@ -52,21 +52,19 @@ public class InvalidCodePrefix implements MmuInstruction { public InvalidCodePrefix(Euc euc, Wcp wcp) { this.euc = euc; this.wcp = wcp; - this.eucCallRecords = new ArrayList<>(Trace.NB_PP_ROWS_INVALID_CODE_PREFIX); - this.wcpCallRecords = new ArrayList<>(Trace.NB_PP_ROWS_INVALID_CODE_PREFIX); + this.eucCallRecords = new ArrayList<>(NB_PP_ROWS_INVALID_CODE_PREFIX); + this.wcpCallRecords = new ArrayList<>(NB_PP_ROWS_INVALID_CODE_PREFIX); } @Override public MmuData preProcess(MmuData mmuData, final CallStack callStack) { // Set mmuData.sourceRamBytes - CallStackReader callStackReader = new CallStackReader(callStack); - final Bytes sourceMemory = - callStackReader.fullCopyOfContextMemory(mmuData.hubToMmuValues().sourceId(), true); + final Bytes sourceMemory = mmuData.mmuCall().sourceRamBytes().get(); mmuData.sourceRamBytes(sourceMemory); // row n°1 final long dividend1 = mmuData.hubToMmuValues().sourceOffsetLo().longValueExact(); - EucOperation eucOp = euc.callEUC(Bytes.ofUnsignedLong(dividend1), Bytes.of(16)); + final EucOperation eucOp = euc.callEUC(Bytes.ofUnsignedLong(dividend1), Bytes.of(16)); final short rem = (short) eucOp.remainder().toInt(); final long quot = eucOp.quotient().toLong(); initialSourceLimbOffset = quot; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java index 378e35c991..dd3a58cb81 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/ContractModifyingStorageTest.java @@ -103,20 +103,21 @@ void contractModifyingStorageInFunctionTest() { // arithmetization/src/test/resources/contracts/contractModifyingStorage/ContractModifyingStorageInFunction.sol // User address - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount userAccount = + final KeyPair keyPair = new SECP256K1().generateKeyPair(); + final Address userAddress = + Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + final ToyAccount userAccount = ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); // Deployment transaction - Transaction tx = + final Transaction tx = ToyTransaction.builder() .sender(userAccount) .payload( Bytes.fromHexString( "0x608060405234801561001057600080fd5b50610304806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c8063501e82121461005c5780636cc014de1461007a578063a314150f14610098578063a5d666a9146100b6578063e8af2fa5146100d4575b600080fd5b6100646100de565b60405161007191906101ca565b60405180910390f35b6100826100e4565b60405161008f91906101ca565b60405180910390f35b6100a06100ea565b6040516100ad91906101ca565b60405180910390f35b6100be6100f0565b6040516100cb91906101ca565b60405180910390f35b6100dc6100f6565b005b60005481565b60015481565b60025481565b60035481565b60008081905550600180819055506002808190555060038081905550600a60005461012191906101e5565b600081905550600b60015461013691906101e5565b600181905550600c60025461014b91906101e5565b600281905550600d60035461016091906101e5565b60038190555060008054610174919061023b565b6000819055506014600154610189919061023b565b600181905550601560025461019e919061023b565b60028190555060156003546101b3919061023b565b600381905550565b6101c481610295565b82525050565b60006020820190506101df60008301846101bb565b92915050565b60006101f082610295565b91506101fb83610295565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156102305761022f61029f565b5b828201905092915050565b600061024682610295565b915061025183610295565b9250817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561028a5761028961029f565b5b828202905092915050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fdfea26469706673582212200d443753b26ea215c94e8fd1b03e4d389ebc740d96823003d127316393455da664736f6c63430008000033")) .transactionType(TransactionType.FRONTIER) - .gasLimit(0xffffffffL) + .gasLimit(0x38444C0L) .value(Wei.ZERO) .keyPair(keyPair) .build(); From d917467f6d2924cefe21e92cc8144a1e14b06e93 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 26 Aug 2024 12:02:34 +0530 Subject: [PATCH 448/461] fix: aborting calls defers at childContextEntry Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/hub/Hub.java | 2 +- .../module/hub/section/call/CallSection.java | 2 +- .../zktracer/module/oob/OobCallTest.java | 62 ++++++++++--------- .../module/rlpaddr/TestRlpAddress.java | 3 +- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 54f5d4efe3..6d718a6358 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -953,7 +953,7 @@ void processStateExec(MessageFrame frame) { this.squashCurrentFrameOutputData(); this.squashParentFrameReturnData(); - this.addTraceSection(new StackOnlySection(this)); + new StackOnlySection(this); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index ce62b14f65..ccc42b765e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -174,6 +174,7 @@ public CallSection(Hub hub) { final boolean aborts = hub.pch().abortingConditions().any(); Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts); + hub.defers().scheduleForImmediateContextEntry(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); hub.defers().scheduleForPostTransaction(this); @@ -183,7 +184,6 @@ public CallSection(Hub hub) { } // The CALL is now unexceptional and un-aborted - hub.defers().scheduleForImmediateContextEntry(this); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java index 6b422db685..b677851996 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java @@ -42,32 +42,32 @@ public class OobCallTest { @Test void TestCallSendValueGreaterThanBalanceHiNonZero() { - EWord balanceOfCaller = EWord.of(BigInteger.ONE); - EWord amountToSend = EWord.of(BigInteger.ONE, BigInteger.ZERO); + final EWord balanceOfCaller = EWord.of(BigInteger.ONE); + final EWord amountToSend = EWord.of(BigInteger.ONE, BigInteger.ZERO); testCallSendValue(balanceOfCaller, amountToSend, 1); } @Test void TestCallSendValueGreaterThanBalanceLoNonZero() { - EWord balanceOfCaller = EWord.of(BigInteger.ONE); - EWord amountToSend = EWord.of(BigInteger.ZERO, BigInteger.TWO); + final EWord balanceOfCaller = EWord.of(BigInteger.ONE); + final EWord amountToSend = EWord.of(BigInteger.ZERO, BigInteger.TWO); testCallSendValue(balanceOfCaller, amountToSend, 1); } @Test void TestCallSendValueGreaterThanBalanceHiLoNonZero() { - EWord balanceOfCaller = EWord.of(BigInteger.ONE); - EWord amountToSend = EWord.of(BigInteger.TWO, BigInteger.TWO); + final EWord balanceOfCaller = EWord.of(BigInteger.ONE); + final EWord amountToSend = EWord.of(BigInteger.TWO, BigInteger.TWO); testCallSendValue(balanceOfCaller, amountToSend, 1); } @Test void TestCallSendValueSmallerThanBalanceLoNonZero() { - EWord balanceOfCaller = EWord.of(BigInteger.TWO); - EWord amountToSend = EWord.of(BigInteger.ZERO, BigInteger.ONE); + final EWord balanceOfCaller = EWord.of(BigInteger.TWO); + final EWord amountToSend = EWord.of(BigInteger.ZERO, BigInteger.ONE); testCallSendValue(balanceOfCaller, amountToSend); } @@ -78,25 +78,25 @@ void TestCallSendValueSmallerThanBalanceLoNonZero() { */ @Test void testRecursiveCalls1024() { - EWord iterations = EWord.of(BigInteger.valueOf(1024)); + final EWord iterations = EWord.of(BigInteger.valueOf(1024)); testRecursiveCalls(iterations); } @Test void testRecursiveCalls1025() { - EWord iterations = EWord.of(BigInteger.valueOf(1025)); + final EWord iterations = EWord.of(BigInteger.valueOf(1025)); testRecursiveCalls(iterations, 1); } @Test void TestRecursiveCallsWithBytecode() { - BytecodeRunner bytecodeRunner = + final BytecodeRunner bytecodeRunner = BytecodeRunner.of(Bytes.fromHexString("60006000600060006000305af1")); bytecodeRunner.run(Wei.fromEth(400), 0xFFFFFFFFL); - Hub hub = bytecodeRunner.getHub(); + final Hub hub = bytecodeRunner.getHub(); assertTrue(Exceptions.none(hub.pch().exceptions())); @@ -109,20 +109,21 @@ private void testCallSendValue(EWord balanceOfCaller, EWord amountToSend) { } private void testCallSendValue( - EWord balanceOfCaller, EWord amountToSend, int numberOfOnesInOobEvent1) { + final EWord balanceOfCaller, EWord amountToSend, int numberOfOnesInOobEvent1) { /* NOTE: The contracts in this method are compiled by using solc *.sol --bin-runtime --evm-version london -o compiledContracts i.e., we do not include the init code of the contracts in the bytecode */ // User address - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount userAccount = + final KeyPair keyPair = new SECP256K1().generateKeyPair(); + final Address userAddress = + Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + final ToyAccount userAccount = ToyAccount.builder().balance(Wei.fromEth(1)).nonce(1).address(userAddress).build(); // Caller - ToyAccount contractCallerAccount = + final ToyAccount contractCallerAccount = ToyAccount.builder() .balance(Wei.of(balanceOfCaller.toBigInteger())) .nonce(2) @@ -133,7 +134,7 @@ private void testCallSendValue( .build(); // Callee - ToyAccount contractCalleeAccount = + final ToyAccount contractCalleeAccount = ToyAccount.builder() .balance(Wei.fromEth(1)) .nonce(3) @@ -143,7 +144,7 @@ private void testCallSendValue( "60806040526004361061002d5760003560e01c806363acac8e14610039578063ff277a621461006257610034565b3661003457005b600080fd5b34801561004557600080fd5b50610060600480360381019061005b91906101b5565b61008b565b005b34801561006e57600080fd5b5061008960048036038101906100849190610240565b61010f565b005b600081111561010c573073ffffffffffffffffffffffffffffffffffffffff166363acac8e6001836100bd91906102af565b6040518263ffffffff1660e01b81526004016100d991906102f2565b600060405180830381600087803b1580156100f357600080fd5b505af1158015610107573d6000803e3d6000fd5b505050505b50565b60008290508073ffffffffffffffffffffffffffffffffffffffff1663671dcbd7836040518263ffffffff1660e01b81526004016000604051808303818588803b15801561015c57600080fd5b505af1158015610170573d6000803e3d6000fd5b5050505050505050565b600080fd5b6000819050919050565b6101928161017f565b811461019d57600080fd5b50565b6000813590506101af81610189565b92915050565b6000602082840312156101cb576101ca61017a565b5b60006101d9848285016101a0565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061020d826101e2565b9050919050565b61021d81610202565b811461022857600080fd5b50565b60008135905061023a81610214565b92915050565b600080604083850312156102575761025661017a565b5b60006102658582860161022b565b9250506020610276858286016101a0565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006102ba8261017f565b91506102c58361017f565b92508282039050818111156102dd576102dc610280565b5b92915050565b6102ec8161017f565b82525050565b600060208201905061030760008301846102e3565b9291505056fea2646970667358221220eeda6cd078a1e0b43b7e0e6267949ef02a8119de7d68431781e3b1ef33a616d464736f6c63430008150033")) .build(); - Transaction tx = + final Transaction tx = ToyTransaction.builder() .sender(userAccount) .to(contractCallerAccount) @@ -157,12 +158,12 @@ private void testCallSendValue( .keyPair(keyPair) .build(); - ToyWorld toyWorld = + final ToyWorld toyWorld = ToyWorld.builder() .accounts(List.of(userAccount, contractCallerAccount, contractCalleeAccount)) .build(); - ToyExecutionEnvironment toyExecutionEnvironment = + final ToyExecutionEnvironment toyExecutionEnvironment = ToyExecutionEnvironment.builder() .toyWorld(toyWorld) .transaction(tx) @@ -171,7 +172,7 @@ private void testCallSendValue( toyExecutionEnvironment.run(); - Hub hub = toyExecutionEnvironment.getHub(); + final Hub hub = toyExecutionEnvironment.getHub(); assertTrue(Exceptions.none(hub.pch().exceptions())); @@ -189,13 +190,14 @@ private void testRecursiveCalls(EWord iterations, int numberOfOnesInOobEvent1) { i.e., we do not include the init code of the contracts in the bytecode */ // User address - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address userAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount userAccount = + final KeyPair keyPair = new SECP256K1().generateKeyPair(); + final Address userAddress = + Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + final ToyAccount userAccount = ToyAccount.builder().balance(Wei.fromEth(25)).nonce(1).address(userAddress).build(); // Caller - ToyAccount contractCallerAccount = + final ToyAccount contractCallerAccount = ToyAccount.builder() .balance(Wei.fromEth(1)) .nonce(2) @@ -205,7 +207,7 @@ private void testRecursiveCalls(EWord iterations, int numberOfOnesInOobEvent1) { "60806040526004361061002d5760003560e01c806363acac8e14610039578063ff277a621461006257610034565b3661003457005b600080fd5b34801561004557600080fd5b50610060600480360381019061005b91906101b5565b61008b565b005b34801561006e57600080fd5b5061008960048036038101906100849190610240565b61010f565b005b600081111561010c573073ffffffffffffffffffffffffffffffffffffffff166363acac8e6001836100bd91906102af565b6040518263ffffffff1660e01b81526004016100d991906102f2565b600060405180830381600087803b1580156100f357600080fd5b505af1158015610107573d6000803e3d6000fd5b505050505b50565b60008290508073ffffffffffffffffffffffffffffffffffffffff1663671dcbd7836040518263ffffffff1660e01b81526004016000604051808303818588803b15801561015c57600080fd5b505af1158015610170573d6000803e3d6000fd5b5050505050505050565b600080fd5b6000819050919050565b6101928161017f565b811461019d57600080fd5b50565b6000813590506101af81610189565b92915050565b6000602082840312156101cb576101ca61017a565b5b60006101d9848285016101a0565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061020d826101e2565b9050919050565b61021d81610202565b811461022857600080fd5b50565b60008135905061023a81610214565b92915050565b600080604083850312156102575761025661017a565b5b60006102658582860161022b565b9250506020610276858286016101a0565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006102ba8261017f565b91506102c58361017f565b92508282039050818111156102dd576102dc610280565b5b92915050565b6102ec8161017f565b82525050565b600060208201905061030760008301846102e3565b9291505056fea2646970667358221220eeda6cd078a1e0b43b7e0e6267949ef02a8119de7d68431781e3b1ef33a616d464736f6c63430008150033")) .build(); - Transaction tx = + final Transaction tx = ToyTransaction.builder() .sender(userAccount) .to(contractCallerAccount) @@ -216,10 +218,10 @@ private void testRecursiveCalls(EWord iterations, int numberOfOnesInOobEvent1) { .keyPair(keyPair) .build(); - ToyWorld toyWorld = + final ToyWorld toyWorld = ToyWorld.builder().accounts(List.of(userAccount, contractCallerAccount)).build(); - ToyExecutionEnvironment toyExecutionEnvironment = + final ToyExecutionEnvironment toyExecutionEnvironment = ToyExecutionEnvironment.builder() .toyWorld(toyWorld) .transaction(tx) @@ -228,7 +230,7 @@ private void testRecursiveCalls(EWord iterations, int numberOfOnesInOobEvent1) { toyExecutionEnvironment.run(); - Hub hub = toyExecutionEnvironment.getHub(); + final Hub hub = toyExecutionEnvironment.getHub(); assertTrue(Exceptions.none(hub.pch().exceptions())); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index dde9eb31dc..9d4b438dc1 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.rlpaddr; -import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randData; import static net.consensys.linea.zktracer.module.rlpcommon.RlpRandEdgeCase.randLong; import java.util.Random; @@ -55,7 +54,7 @@ void randDeployment() { .build(); ; - final Bytes initCode = randData(true); + final Bytes initCode = BytecodeCompiler.newProgram().push(1).push(1).op(OpCode.SLT).compile(); world.account(senderAccount); From 889a04e1cd68419219203f7c52fdedf5b31fc5eb Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 26 Aug 2024 12:36:54 +0530 Subject: [PATCH 449/461] fix postOpcode acc snapshot for aborting calls Signed-off-by: Francois Bojarski --- .../consensys/linea/zktracer/module/hub/Hub.java | 5 ++--- .../module/hub/section/call/CallSection.java | 16 ++++++++++++++-- .../consensys/linea/zktracer/ReplayTests.java | 3 --- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 6d718a6358..8639f934a3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -716,8 +716,8 @@ public void traceContextExit(MessageFrame frame) { public void tracePreExecution(final MessageFrame frame) { Preconditions.checkArgument( - this.state().processingPhase != TX_SKIP, - "There can't be any execution if the HUB is in the a skip phase"); + this.state().processingPhase == TX_EXEC, + "There can't be any execution if the HUB is not in execution phase"); this.processStateExec(frame); } @@ -927,7 +927,6 @@ public void unlatchStack(MessageFrame frame, TraceSection section) { } // This works because we are certain that the stack chunks are the first. - final boolean breakHere = !(section.fragments().get(i) instanceof StackFragment); ((StackFragment) section.fragments().get(i)) .stackOps() .get(line.resultColumn() - 1) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index ccc42b765e..9dca5fbd3b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -33,6 +33,7 @@ import net.consensys.linea.zktracer.module.hub.defer.ContextExitDefer; import net.consensys.linea.zktracer.module.hub.defer.ContextReEntryDefer; import net.consensys.linea.zktracer.module.hub.defer.ImmediateContextEntryDefer; +import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; @@ -54,11 +55,13 @@ import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.evm.worldstate.WorldView; public class CallSection extends TraceSection - implements ImmediateContextEntryDefer, + implements PostOpcodeDefer, + ImmediateContextEntryDefer, ContextExitDefer, ContextReEntryDefer, PostRollbackDefer, @@ -174,16 +177,17 @@ public CallSection(Hub hub) { final boolean aborts = hub.pch().abortingConditions().any(); Preconditions.checkArgument(oobCall.isAbortingCondition() == aborts); - hub.defers().scheduleForImmediateContextEntry(this); hub.defers().scheduleForPostRollback(this, hub.currentFrame()); hub.defers().scheduleForPostTransaction(this); if (aborts) { this.abortingCall(hub); + hub.defers().scheduleForPostExecution(this); return; } // The CALL is now unexceptional and un-aborted + hub.defers().scheduleForImmediateContextEntry(this); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); final WorldUpdater world = hub.messageFrame().getWorldUpdater(); @@ -268,6 +272,14 @@ private void abortingCall(Hub hub) { finalContextFragment = ContextFragment.nonExecutionProvidesEmptyReturnData(hub); } + @Override + public void resolvePostExecution( + Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { + Preconditions.checkArgument(scenarioFragment.getScenario() == CALL_ABORT_WONT_REVERT); + postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); + postOpcodeCalleeSnapshot = canonical(hub, preOpcodeCalleeSnapshot.address()); + } + @Override public void resolveUponImmediateContextEntry(Hub hub) { postOpcodeCallerSnapshot = canonical(hub, preOpcodeCallerSnapshot.address()); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java index 023c85e089..f1fc76277a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java @@ -25,7 +25,6 @@ import lombok.extern.slf4j.Slf4j; import net.consensys.linea.testing.ToyExecutionEnvironment; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** @@ -82,7 +81,6 @@ void fatMxp() { } @Test - @Disabled void leoFailingRange() { replay("5389571-5389577.json.gz"); } @@ -108,7 +106,6 @@ void multipleFailingCallToEcrecover() { } @Test - @Disabled void incident777zkGethMainnet() { replay("7461019-7461030.json.gz"); } From 4e5f9abc2bafd59699aac637261424d3dce4b0c6 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 26 Aug 2024 13:20:25 +0530 Subject: [PATCH 450/461] cleanup Signed-off-by: Francois Bojarski --- .../hub/precompiles/PrecompileInvocation.java | 164 ------------------ 1 file changed, 164 deletions(-) delete mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java deleted file mode 100644 index b28a9ac052..0000000000 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/PrecompileInvocation.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright ConsenSys AG. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -package net.consensys.linea.zktracer.module.hub.precompiles; - -import lombok.Builder; -import lombok.experimental.Accessors; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.types.MemorySpan; -import net.consensys.linea.zktracer.types.Precompile; - -// TODO: delete me please - -@Accessors(fluent = true) -@Builder -public record PrecompileInvocation( - /* The precompile being called */ - Precompile precompile, - /* - * If applicable, some data related to the precompile required later. Only used for Blake2f for - * now. - */ - PrecompileMetadata metadata, - /* The input data for the precompile */ - MemorySpan callDataSource, - /* Where the caller wants the precompile return data to be stored */ - MemorySpan requestedReturnDataTarget, - boolean hubFailure, - boolean ramFailure, - /* The price of the *CALL itself */ - long opCodeGas, - /* The intrinsic cost of the precompile */ - long precompilePrice, - /* The available gas just before the *CALL opcode execution */ - long gasAtCall, - /* If applicable, the gas given to a precompile */ - long gasAllowance, - /* The amount of gas to be given back to the caller */ - long returnGas, - /* The HubStamp at the time of the call of the precompile*/ - int hubStamp) { - - public boolean success() { - return !this.hubFailure && !this.ramFailure; - } - - // TODO: will die - public static PrecompileInvocation of(final Hub hub, Precompile p) { - // final boolean hubFailure = - // switch (p) { - // case EC_RECOVER -> !EcRecoverEffectiveCall.hasEnoughGas(hub); - // case SHA2_256 -> !Sha256Blocks.hasEnoughGas(hub); - // case RIPEMD_160 -> !RipemdBlocks.hasEnoughGas(hub); - // case IDENTITY -> switch (hub.opCode()) { - // case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - // final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); - // if (target.equals(Address.ID)) { - // final long dataByteLength = hub.transients().op().callDataSegment().length(); - // final long wordCount = (dataByteLength + 31) / 32; - // final long gasNeeded = 15 + 3 * wordCount; - // - // yield hub.transients().op().gasAllowanceForCall() < gasNeeded; - // } else { - // throw new IllegalStateException(); - // } - // } - // default -> throw new IllegalStateException(); - // }; - // case MODEXP -> false; - // case EC_ADD -> hub.transients().op().gasAllowanceForCall() < 150; - // case EC_MUL -> hub.transients().op().gasAllowanceForCall() < 6000; - // case EC_PAIRING -> EcPairingFinalExponentiations.isHubFailure(hub); - // case BLAKE2F -> BlakeRounds.isHubFailure(hub); - // }; - // - // final boolean ramFailure = - // !hubFailure - // && switch (p) { - // case EC_RECOVER, IDENTITY, RIPEMD_160, SHA2_256 -> false; - // case MODEXP -> ModexpEffectiveCall.gasCost(hub) - // > hub.transients().op().gasAllowanceForCall(); - // case EC_ADD -> EcAddEffectiveCall.isRamFailure(hub); - // case EC_MUL -> EcMulEffectiveCall.isRamFailure(hub); - // case EC_PAIRING -> EcPairingFinalExponentiations.isRamFailure(hub); - // case BLAKE2F -> BlakeRounds.isRamFailure(hub); - // }; - // - // final long opCodeGas = Hub.GAS_PROJECTOR.of(hub.messageFrame(), hub.opCode()).total(); - // - // final long precompilePrice = - // hubFailure || ramFailure - // ? hub.transients().op().gasAllowanceForCall() - // : switch (p) { - // case EC_RECOVER -> EcRecoverEffectiveCall.gasCost(); - // case SHA2_256 -> Sha256Blocks.gasCost(hub); - // case RIPEMD_160 -> RipemdBlocks.gasCost(hub); - // case IDENTITY -> switch (hub.opCode()) { - // case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { - // final Address target = Words.toAddress(hub.messageFrame().getStackItem(1)); - // if (target.equals(Address.ID)) { - // final long dataByteLength = hub.transients().op().callDataSegment().length(); - // final long wordCount = (dataByteLength + 31) / 32; - // yield 15 + 3 * wordCount; - // } else { - // throw new IllegalStateException(); - // } - // } - // default -> throw new IllegalStateException(); - // }; - // case MODEXP -> ModexpEffectiveCall.gasCost(hub); - // case EC_ADD -> EcAddEffectiveCall.gasCost(); - // case EC_MUL -> EcMulEffectiveCall.gasCost(); - // case EC_PAIRING -> EcPairingFinalExponentiations.gasCost(hub); - // case BLAKE2F -> BlakeRounds.gasCost(hub); - // }; - // - // final long returnGas = - // hubFailure || ramFailure - // ? 0 - // : hub.transients().op().gasAllowanceForCall() - precompilePrice; - // - // PrecompileMetadata metadata = - // switch (p) { - // case EC_RECOVER -> EcRecoverMetadata.of(hub); - // case SHA2_256 -> null; - // case RIPEMD_160 -> null; - // case IDENTITY -> null; - // case MODEXP -> ModExpMetadata.of(hub); - // case EC_ADD -> null; - // case EC_MUL -> null; - // case EC_PAIRING -> null; - // case BLAKE2F -> BlakeRounds.metadata(hub); - // }; - // - // return PrecompileInvocation.builder() - // .precompile(p) - // .metadata(metadata) - // .callDataSource(hub.transients().op().callDataSegment()) - // .requestedReturnDataTarget(hub.transients().op().returnDataRequestedSegment()) - // .hubFailure(hubFailure) - // .ramFailure(ramFailure) - // .opCodeGas(opCodeGas) - // .precompilePrice(precompilePrice) - // .gasAtCall(hub.messageFrame().getRemainingGas()) - // .gasAllowance(hub.transients().op().gasAllowanceForCall()) - // .returnGas(returnGas) - // .hubStamp(hub.stamp()) - // .build(); - // - return PrecompileInvocation.builder().build(); - } -} From 88088f8fe20cd7b73589c9f188742c38023b29e7 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 26 Aug 2024 10:35:27 +0200 Subject: [PATCH 451/461] docs(hub): add comment related to creator nonce --- .../module/hub/fragment/imc/oob/opcodes/CreateOobCall.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java index e2b19df28d..4c68996901 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/oob/opcodes/CreateOobCall.java @@ -78,6 +78,8 @@ public Trace trace(Trace trace) { .pMiscOobData5(booleanToBytes(hasCode)) .pMiscOobData6(bigIntegerToBytes(callStackDepth)) .pMiscOobData7(booleanToBytes(abortingCondition)) - .pMiscOobData8(booleanToBytes(failureCondition)); + .pMiscOobData8(booleanToBytes(failureCondition)) + // TODO: add pMiscOobData9(creatorNonce) when Trace.java is updated + ; } } From e6f91fb58d28a8c88d4e2bdcac062610a43d88b5 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 26 Aug 2024 11:10:14 +0200 Subject: [PATCH 452/461] fix(ecdata): partial fix --- .../linea/zktracer/module/add/Trace.java | 102 ++--- .../linea/zktracer/module/ecdata/EcData.java | 19 +- .../module/ecdata/EcDataOperation.java | 2 + .../linea/zktracer/module/ecdata/Trace.java | 355 +++++++++++------- .../linea/zktracer/module/hub/Hub.java | 8 - 5 files changed, 249 insertions(+), 237 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java index b1df4b1234..f1bc9d03bb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.add; +import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -105,17 +106,11 @@ public Trace acc1(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - acc1.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { acc1.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - acc1.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - acc2.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { acc2.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - acc2.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - arg1Hi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { arg1Hi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg1Hi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - arg1Lo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { arg1Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg1Lo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - arg2Hi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { arg2Hi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg2Hi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - arg2Lo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { arg2Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - arg2Lo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - resHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { resHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - resHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - resLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { resLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - resLo.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); } stamp.put((byte) (b >> 24)); stamp.put((byte) (b >> 16)); stamp.put((byte) (b >> 8)); stamp.put((byte) b); + return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index 80fa4d1353..b0d5b4210b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -86,19 +86,17 @@ public void commit(List buffers) { final Trace trace = new Trace(buffers); int stamp = 0; long previousId = 0; - - // TODO: operations should come in the right order now, no need to sort them. To test. + // Sort the operations by id given the fact that the initial data structure is a stacked set List sortedOperations = this.operations.stream().sorted(Comparator.comparingLong(EcDataOperation::id)).toList(); - for (EcDataOperation op : sortedOperations) { // TODO: temporary hack, we should have only successful EcData Operations, will be fixed in PR // #748 - if (op.successBit()) { - stamp++; - op.trace(trace, stamp, previousId); - previousId = op.id(); - } + // if (op.successBit()) { + stamp++; + op.trace(trace, stamp, previousId); + previousId = op.id(); + // } } } @@ -116,7 +114,10 @@ public void callEcData( case PRC_ECMUL -> ecMulEffectiveCall.addPrecompileLimit(1); case PRC_ECRECOVER -> ecRecoverEffectiveCall.addPrecompileLimit(1); case PRC_ECPAIRING -> { - // TODO @Lorenzo + // TODO: @Lorenzo @Olivier complete + // ecPairingG2MembershipCalls.addPrecompileLimit(); + // ecPairingMillerLoops.addPrecompileLimit(); + // ecPairingFinalExponentiations.addPrecompileLimit(); } default -> throw new IllegalArgumentException("Operation not supported by EcData"); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 04ae3077b8..327d90f5bb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -48,6 +48,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.*; import static net.consensys.linea.zktracer.types.Containers.repeat; import static net.consensys.linea.zktracer.types.Utils.leftPadTo; +import static net.consensys.linea.zktracer.types.Utils.rightPadTo; import java.util.List; @@ -138,6 +139,7 @@ private EcDataOperation( this.precompileFlag = precompileFlag; final int paddedCallDataLength = this.precompileFlag == PRC_ECMUL ? 96 : 128; if (callData.size() < paddedCallDataLength) { + // TODO: this is likely right padding, not left padding this.data = leftPadTo(callData, paddedCallDataLength); } else { // TODO: why keep the entire data rather than data[0:paddedCallDataLength] ? diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java index 99208049d8..271c060af5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java @@ -48,12 +48,9 @@ public class Trace { public static final int INDEX_MAX_ECRECOVER_RESULT = 0x1; public static final int MULMOD = 0x9; public static final BigInteger P_BN_HI = new BigInteger("64323764613183177041862057485226039389"); - public static final BigInteger P_BN_LO = - new BigInteger("201385395114098847380338600778089168199"); - public static final BigInteger SECP256K1N_HI = - new BigInteger("340282366920938463463374607431768211455"); - public static final BigInteger SECP256K1N_LO = - new BigInteger("340282366920938463463374607427473243183"); + public static final BigInteger P_BN_LO = new BigInteger("201385395114098847380338600778089168199"); + public static final BigInteger SECP256K1N_HI = new BigInteger("340282366920938463463374607431768211455"); + public static final BigInteger SECP256K1N_LO = new BigInteger("340282366920938463463374607427473243183"); public static final int TOTAL_SIZE_ECADD_DATA = 0x80; public static final int TOTAL_SIZE_ECADD_RESULT = 0x40; public static final int TOTAL_SIZE_ECMUL_DATA = 0x60; @@ -131,22 +128,22 @@ static List headers(int length) { new ColumnHeader("ecdata.CIRCUIT_SELECTOR_ECPAIRING", 1, length), new ColumnHeader("ecdata.CIRCUIT_SELECTOR_ECRECOVER", 1, length), new ColumnHeader("ecdata.CIRCUIT_SELECTOR_G2_MEMBERSHIP", 1, length), - new ColumnHeader("ecdata.CT", 2, length), - new ColumnHeader("ecdata.CT_MAX", 2, length), - new ColumnHeader("ecdata.EXT_ARG1_HI", 32, length), - new ColumnHeader("ecdata.EXT_ARG1_LO", 32, length), - new ColumnHeader("ecdata.EXT_ARG2_HI", 32, length), - new ColumnHeader("ecdata.EXT_ARG2_LO", 32, length), - new ColumnHeader("ecdata.EXT_ARG3_HI", 32, length), - new ColumnHeader("ecdata.EXT_ARG3_LO", 32, length), + new ColumnHeader("ecdata.CT", 1, length), + new ColumnHeader("ecdata.CT_MAX", 1, length), + new ColumnHeader("ecdata.EXT_ARG1_HI", 16, length), + new ColumnHeader("ecdata.EXT_ARG1_LO", 16, length), + new ColumnHeader("ecdata.EXT_ARG2_HI", 16, length), + new ColumnHeader("ecdata.EXT_ARG2_LO", 16, length), + new ColumnHeader("ecdata.EXT_ARG3_HI", 16, length), + new ColumnHeader("ecdata.EXT_ARG3_LO", 16, length), new ColumnHeader("ecdata.EXT_FLAG", 1, length), new ColumnHeader("ecdata.EXT_INST", 1, length), - new ColumnHeader("ecdata.EXT_RES_HI", 32, length), - new ColumnHeader("ecdata.EXT_RES_LO", 32, length), + new ColumnHeader("ecdata.EXT_RES_HI", 16, length), + new ColumnHeader("ecdata.EXT_RES_LO", 16, length), new ColumnHeader("ecdata.G2_MEMBERSHIP_TEST_REQUIRED", 1, length), new ColumnHeader("ecdata.HURDLE", 1, length), - new ColumnHeader("ecdata.ID", 8, length), - new ColumnHeader("ecdata.INDEX", 4, length), + new ColumnHeader("ecdata.ID", 4, length), + new ColumnHeader("ecdata.INDEX", 2, length), new ColumnHeader("ecdata.INDEX_MAX", 32, length), new ColumnHeader("ecdata.INTERNAL_CHECKS_PASSED", 1, length), new ColumnHeader("ecdata.IS_ECADD_DATA", 1, length), @@ -160,20 +157,20 @@ static List headers(int length) { new ColumnHeader("ecdata.IS_INFINITY", 1, length), new ColumnHeader("ecdata.IS_LARGE_POINT", 1, length), new ColumnHeader("ecdata.IS_SMALL_POINT", 1, length), - new ColumnHeader("ecdata.LIMB", 32, length), + new ColumnHeader("ecdata.LIMB", 16, length), new ColumnHeader("ecdata.NOT_ON_G2", 1, length), new ColumnHeader("ecdata.NOT_ON_G2_ACC", 1, length), new ColumnHeader("ecdata.NOT_ON_G2_ACC_MAX", 1, length), new ColumnHeader("ecdata.OVERALL_TRIVIAL_PAIRING", 1, length), - new ColumnHeader("ecdata.PHASE", 4, length), - new ColumnHeader("ecdata.STAMP", 8, 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.WCP_ARG1_HI", 32, length), - new ColumnHeader("ecdata.WCP_ARG1_LO", 32, length), - new ColumnHeader("ecdata.WCP_ARG2_HI", 32, length), - new ColumnHeader("ecdata.WCP_ARG2_LO", 32, 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), + new ColumnHeader("ecdata.WCP_ARG2_LO", 16, length), new ColumnHeader("ecdata.WCP_FLAG", 1, length), new ColumnHeader("ecdata.WCP_INST", 1, length), new ColumnHeader("ecdata.WCP_RES", 1, length)); @@ -251,19 +248,21 @@ public Trace accPairings(final Bytes b) { filled.set(1); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - accPairings.put((byte) 0); - } - accPairings.put(b.toArrayUnsafe()); + // 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= 8L) { throw new IllegalArgumentException("ct has invalid value (" + b + ")"); } + ct.put((byte) b); + return this; } - public Trace ctMax(final short b) { + public Trace ctMax(final long b) { if (filled.get(9)) { throw new IllegalStateException("ecdata.CT_MAX already set"); } else { filled.set(9); } - ctMax.putShort(b); + if(b >= 8L) { throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); } + ctMax.put((byte) b); + return this; } @@ -376,11 +379,14 @@ public Trace extArg1Hi(final Bytes b) { filled.set(10); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - extArg1Hi.put((byte) 0); - } - extArg1Hi.put(b.toArrayUnsafe()); + // Trim array to size + Bytes bs = b.trimLeadingZeros(); + // Sanity check against expected width + if(bs.bitLength() > 128) { throw new IllegalArgumentException("extArg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extArg1Hi.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("extArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extArg1Lo.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("extArg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extArg2Hi.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("extArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extArg2Lo.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("extArg3Hi has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extArg3Hi.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("extArg3Lo has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extArg3Lo.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("extResHi has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extResHi.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("extResLo has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { extResLo.put((byte) 0); } + // Write bytes + for(int j=0; j= 4294967296L) { throw new IllegalArgumentException("id has invalid value (" + b + ")"); } + id.put((byte) (b >> 24)); + id.put((byte) (b >> 16)); + id.put((byte) (b >> 8)); + id.put((byte) b); + return this; } - public Trace index(final int b) { + public Trace index(final long b) { if (filled.get(23)) { throw new IllegalStateException("ecdata.INDEX already set"); } else { filled.set(23); } - index.putInt(b); + if(b >= 65536L) { throw new IllegalArgumentException("index has invalid value (" + b + ")"); } + index.put((byte) (b >> 8)); + index.put((byte) b); + return this; } @@ -576,11 +611,14 @@ public Trace indexMax(final Bytes b) { filled.set(24); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - indexMax.put((byte) 0); - } - indexMax.put(b.toArrayUnsafe()); + // 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 128) { throw new IllegalArgumentException("limb has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { limb.put((byte) 0); } + // Write bytes + for(int j=0; j= 65536L) { throw new IllegalArgumentException("phase has invalid value (" + b + ")"); } + phase.put((byte) (b >> 8)); + phase.put((byte) b); + return this; } @@ -812,7 +856,12 @@ public Trace stamp(final long b) { filled.set(43); } - stamp.putLong(b); + if(b >= 4294967296L) { throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); } + stamp.put((byte) (b >> 24)); + stamp.put((byte) (b >> 16)); + stamp.put((byte) (b >> 8)); + stamp.put((byte) b); + return this; } @@ -836,11 +885,14 @@ public Trace totalPairings(final Bytes b) { filled.set(45); } - final byte[] bs = b.toArrayUnsafe(); - for (int i = bs.length; i < 32; i++) { - totalPairings.put((byte) 0); - } - totalPairings.put(b.toArrayUnsafe()); + // 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 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 128) { throw new IllegalArgumentException("wcpArg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { wcpArg1Hi.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { wcpArg1Lo.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { wcpArg2Hi.put((byte) 0); } + // Write bytes + for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + // Write padding (if necessary) + for(int i=bs.size(); i<16; i++) { wcpArg2Lo.put((byte) 0); } + // Write bytes + for(int j=0; j Date: Mon, 26 Aug 2024 11:11:03 +0200 Subject: [PATCH 453/461] fix(ecdata): call data has to be right padded + 100% valid padded call data length # Conflicts: # arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java --- .../module/ecdata/EcDataOperation.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 327d90f5bb..cee0c4199d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -137,10 +137,23 @@ private EcDataOperation( Preconditions.checkArgument(precompileFlag.isEcdataPrecompile(), "invalid EC type"); this.precompileFlag = precompileFlag; - final int paddedCallDataLength = this.precompileFlag == PRC_ECMUL ? 96 : 128; + final int paddedCallDataLength = + switch (precompileFlag) { + case PRC_ECRECOVER -> 128; + case PRC_ECADD -> 128; + case PRC_ECMUL -> 96; + case PRC_ECPAIRING -> { + int callDataSize = callData.size(); + Preconditions.checkArgument(callDataSize % 192 == 0); + yield callDataSize; + } + default -> throw new IllegalArgumentException( + "EcDataOperation expects to be called on an elliptic curve precompile, not on " + + precompileFlag.name()); + }; + if (callData.size() < paddedCallDataLength) { - // TODO: this is likely right padding, not left padding - this.data = leftPadTo(callData, paddedCallDataLength); + this.data = rightPadTo(callData, paddedCallDataLength); } else { // TODO: why keep the entire data rather than data[0:paddedCallDataLength] ? this.data = callData; From 1069e3ff0d5fc8150041135c454e94bb7f3a7523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 26 Aug 2024 11:16:59 +0200 Subject: [PATCH 454/461] fix(ecdata): ensure that EcData has nonempty call data + renaming --- .../module/ecdata/EcDataOperation.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index cee0c4199d..b86cc2ba7b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -79,7 +79,7 @@ public class EcDataOperation extends ModuleOperation { private final Ext ext; @Getter private final long id; - private final Bytes data; + private final Bytes rightPaddedCallData; @Getter private final PrecompileScenarioFragment.PrecompileFlag precompileFlag; private final int nRows; @@ -137,13 +137,14 @@ private EcDataOperation( Preconditions.checkArgument(precompileFlag.isEcdataPrecompile(), "invalid EC type"); this.precompileFlag = precompileFlag; + int callDataSize = callData.size(); + Preconditions.checkArgument(callDataSize > 0, "EcDataOperation should only be called with nonempty call rightPaddedCallData"); final int paddedCallDataLength = switch (precompileFlag) { case PRC_ECRECOVER -> 128; case PRC_ECADD -> 128; case PRC_ECMUL -> 96; case PRC_ECPAIRING -> { - int callDataSize = callData.size(); Preconditions.checkArgument(callDataSize % 192 == 0); yield callDataSize; } @@ -153,10 +154,10 @@ private EcDataOperation( }; if (callData.size() < paddedCallDataLength) { - this.data = rightPadTo(callData, paddedCallDataLength); + this.rightPaddedCallData = rightPadTo(callData, paddedCallDataLength); } else { - // TODO: why keep the entire data rather than data[0:paddedCallDataLength] ? - this.data = callData; + // TODO: why keep the entire rightPaddedCallData rather than rightPaddedCallData[0:paddedCallDataLength] ? + this.rightPaddedCallData = callData; } if (precompileFlag == PRC_ECPAIRING) { @@ -322,10 +323,10 @@ private EWord callExt(int i, OpCode extInst, EWord arg1, EWord arg2, EWord arg3) void handleRecover() { // Extract inputs - final EWord h = EWord.of(data.slice(0, 32)); - final EWord v = EWord.of(data.slice(32, 32)); - final EWord r = EWord.of(data.slice(64, 32)); - final EWord s = EWord.of(data.slice(96, 32)); + final EWord h = EWord.of(rightPaddedCallData.slice(0, 32)); + final EWord v = EWord.of(rightPaddedCallData.slice(32, 32)); + final EWord r = EWord.of(rightPaddedCallData.slice(64, 32)); + final EWord s = EWord.of(rightPaddedCallData.slice(96, 32)); // Set input limb limb.set(0, h.hi()); @@ -395,10 +396,10 @@ void handleRecover() { void handleAdd() { // Extract inputs - final EWord pX = EWord.of(data.slice(0, 32)); - final EWord pY = EWord.of(data.slice(32, 32)); - final EWord qX = EWord.of(data.slice(64, 32)); - final EWord qY = EWord.of(data.slice(96, 32)); + final EWord pX = EWord.of(rightPaddedCallData.slice(0, 32)); + final EWord pY = EWord.of(rightPaddedCallData.slice(32, 32)); + final EWord qX = EWord.of(rightPaddedCallData.slice(64, 32)); + final EWord qY = EWord.of(rightPaddedCallData.slice(96, 32)); // Set limb limb.set(0, pX.hi()); @@ -449,9 +450,9 @@ void handleAdd() { void handleMul() { // Extract inputs - final EWord pX = EWord.of(data.slice(0, 32)); - final EWord pY = EWord.of(data.slice(32, 32)); - final EWord n = EWord.of(data.slice(64, 32)); + final EWord pX = EWord.of(rightPaddedCallData.slice(0, 32)); + final EWord pY = EWord.of(rightPaddedCallData.slice(32, 32)); + final EWord n = EWord.of(rightPaddedCallData.slice(64, 32)); // Set limb limb.set(0, pX.hi()); @@ -504,12 +505,12 @@ void handlePairing() { for (int accPairings = 1; accPairings <= totalPairings; accPairings++) { // Extract inputs final int bytesOffset = (accPairings - 1) * 192; - final EWord aX = EWord.of(data.slice(bytesOffset, 32)); - final EWord aY = EWord.of(data.slice(32 + bytesOffset, 32)); - final EWord bXIm = EWord.of(data.slice(64 + bytesOffset, 32)); - final EWord bXRe = EWord.of(data.slice(96 + bytesOffset, 32)); - final EWord bYIm = EWord.of(data.slice(128 + bytesOffset, 32)); - final EWord bYRe = EWord.of(data.slice(160 + bytesOffset, 32)); + final EWord aX = EWord.of(rightPaddedCallData.slice(bytesOffset, 32)); + final EWord aY = EWord.of(rightPaddedCallData.slice(32 + bytesOffset, 32)); + final EWord bXIm = EWord.of(rightPaddedCallData.slice(64 + bytesOffset, 32)); + final EWord bXRe = EWord.of(rightPaddedCallData.slice(96 + bytesOffset, 32)); + final EWord bYIm = EWord.of(rightPaddedCallData.slice(128 + bytesOffset, 32)); + final EWord bYRe = EWord.of(rightPaddedCallData.slice(160 + bytesOffset, 32)); // Set limb final int rowsOffset = (accPairings - 1) * (INDEX_MAX_ECPAIRING_DATA_MIN + 1); // 12 From e8aea36e7763d112204ae555caadb37dcc176f86 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 26 Aug 2024 12:10:39 +0200 Subject: [PATCH 455/461] spotless --- .../linea/zktracer/module/ecdata/EcDataOperation.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index b86cc2ba7b..325e232237 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -138,7 +138,9 @@ private EcDataOperation( this.precompileFlag = precompileFlag; int callDataSize = callData.size(); - Preconditions.checkArgument(callDataSize > 0, "EcDataOperation should only be called with nonempty call rightPaddedCallData"); + Preconditions.checkArgument( + callDataSize > 0, + "EcDataOperation should only be called with nonempty call rightPaddedCallData"); final int paddedCallDataLength = switch (precompileFlag) { case PRC_ECRECOVER -> 128; @@ -156,7 +158,8 @@ private EcDataOperation( if (callData.size() < paddedCallDataLength) { this.rightPaddedCallData = rightPadTo(callData, paddedCallDataLength); } else { - // TODO: why keep the entire rightPaddedCallData rather than rightPaddedCallData[0:paddedCallDataLength] ? + // TODO: why keep the entire rightPaddedCallData rather than + // rightPaddedCallData[0:paddedCallDataLength] ? this.rightPaddedCallData = callData; } From 3fe62a897b43d633a806c6c785e1fee014059787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Mon, 26 Aug 2024 13:01:11 +0200 Subject: [PATCH 456/461] feat(ecrecover): ultra simple failing test --- .../zktracer/module/ecdata/EcRecoverTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java index 4688349443..f76eb2d831 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java @@ -227,4 +227,34 @@ private static Arguments ecRecoverArgumentsFromStrings( boolean expectedSuccessBit) { return Arguments.of(description, h, v, r, s, expectedInternalChecksPassed, expectedSuccessBit); } + + @Test + void testSingleInternalChecksFailEcrecover() { + BytecodeCompiler program = + BytecodeCompiler.newProgram() + // First place the parameters in memory + .push("1111111111111111111111111111111111111111111111111111111111111111") // h + .push(0) + .op(OpCode.MSTORE) + .push("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") // v + .push(0x20) + .op(OpCode.MSTORE) + .push("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc") // r + .push(0x40) + .op(OpCode.MSTORE) + .push("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc") // s + .push(0x60) + .op(OpCode.MSTORE) + // Do the call + .push(32) // retSize + .push(0x80) // retOffset + .push(0x80) // argSize + .push(0) // argOffset + .push(1) // address + .push(Bytes.fromHexStringLenient("0xFFFFFFFF")) // gas + .op(OpCode.STATICCALL); + + BytecodeRunner bytecodeRunner = BytecodeRunner.of(program.compile()); + bytecodeRunner.run(); + } } From 99f62a39e2ac2d0361fd577135c760867560a1e9 Mon Sep 17 00:00:00 2001 From: Lorenzo Gentile Date: Mon, 26 Aug 2024 13:26:03 +0200 Subject: [PATCH 457/461] fix(ecdata): re-enable tracing and line counting disregarding success bit value --- .../linea/zktracer/module/ecdata/EcData.java | 4 - .../module/ecdata/EcDataOperation.java | 6 +- .../linea/zktracer/module/ecdata/Trace.java | 265 +++++++++++++----- .../zktracer/module/ecdata/EcDataTest.java | 4 + .../zktracer/module/ecdata/EcRecoverTest.java | 46 +-- 5 files changed, 224 insertions(+), 101 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java index b0d5b4210b..53c9e23062 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcData.java @@ -90,13 +90,9 @@ public void commit(List buffers) { List sortedOperations = this.operations.stream().sorted(Comparator.comparingLong(EcDataOperation::id)).toList(); for (EcDataOperation op : sortedOperations) { - // TODO: temporary hack, we should have only successful EcData Operations, will be fixed in PR - // #748 - // if (op.successBit()) { stamp++; op.trace(trace, stamp, previousId); previousId = op.id(); - // } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index 325e232237..e8fb6c0533 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -111,8 +111,6 @@ public class EcDataOperation extends ModuleOperation { private final List extResLo; private final List extInst; - // TODO: this bit should be useless we should have only successful EcData Operations, will be - // fixed in PR #748 @Getter private boolean successBit; private boolean circuitSelectorEcrecover; private boolean circuitSelectorEcadd; @@ -759,9 +757,7 @@ void trace(Trace trace, final int stamp, final long previousId) { @Override protected int computeLineCount() { - // TODO: temporary hack, we should have only successful EcData Operations, will be fixed in PR - // #748 - return successBit ? nRowsData + nRowsResult : 0; + return nRowsData + nRowsResult; } private Pair callToC1Membership(int k, EWord pX, EWord pY) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java index 271c060af5..36062466b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java @@ -48,9 +48,12 @@ public class Trace { public static final int INDEX_MAX_ECRECOVER_RESULT = 0x1; public static final int MULMOD = 0x9; public static final BigInteger P_BN_HI = new BigInteger("64323764613183177041862057485226039389"); - public static final BigInteger P_BN_LO = new BigInteger("201385395114098847380338600778089168199"); - public static final BigInteger SECP256K1N_HI = new BigInteger("340282366920938463463374607431768211455"); - public static final BigInteger SECP256K1N_LO = new BigInteger("340282366920938463463374607427473243183"); + public static final BigInteger P_BN_LO = + new BigInteger("201385395114098847380338600778089168199"); + public static final BigInteger SECP256K1N_HI = + new BigInteger("340282366920938463463374607431768211455"); + public static final BigInteger SECP256K1N_LO = + new BigInteger("340282366920938463463374607427473243183"); public static final int TOTAL_SIZE_ECADD_DATA = 0x80; public static final int TOTAL_SIZE_ECADD_RESULT = 0x40; public static final int TOTAL_SIZE_ECMUL_DATA = 0x60; @@ -251,18 +254,26 @@ public Trace accPairings(final Bytes b) { // 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)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + accPairings.put((byte) 0); + } // Write bytes - for(int j=0; j= 8L) { throw new IllegalArgumentException("ct has invalid value (" + b + ")"); } + if (b >= 8L) { + throw new IllegalArgumentException("ct has invalid value (" + b + ")"); + } ct.put((byte) b); - return this; } @@ -365,10 +377,11 @@ public Trace ctMax(final long b) { filled.set(9); } - if(b >= 8L) { throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); } + if (b >= 8L) { + throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); + } ctMax.put((byte) b); - return this; } @@ -382,11 +395,18 @@ public Trace extArg1Hi(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if(bs.bitLength() > 128) { throw new IllegalArgumentException("extArg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg1Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg1Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg1Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg1Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg1Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg2Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg2Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg2Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg2Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg2Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg3Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg3Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg3Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg3Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg3Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg3Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg3Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg3Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extResHi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("extResHi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extResHi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extResHi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extResLo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("extResLo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extResLo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extResLo.put((byte) 0); + } // Write bytes - for(int j=0; j= 4294967296L) { throw new IllegalArgumentException("id has invalid value (" + b + ")"); } + if (b >= 4294967296L) { + throw new IllegalArgumentException("id has invalid value (" + b + ")"); + } id.put((byte) (b >> 24)); id.put((byte) (b >> 16)); id.put((byte) (b >> 8)); id.put((byte) b); - return this; } @@ -596,11 +664,12 @@ public Trace index(final long b) { filled.set(23); } - if(b >= 65536L) { throw new IllegalArgumentException("index has invalid value (" + b + ")"); } + if (b >= 65536L) { + throw new IllegalArgumentException("index has invalid value (" + b + ")"); + } index.put((byte) (b >> 8)); index.put((byte) b); - return this; } @@ -614,11 +683,17 @@ public Trace indexMax(final Bytes b) { // 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)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + indexMax.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("limb has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("limb has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { limb.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + limb.put((byte) 0); + } // Write bytes - for(int j=0; j= 65536L) { throw new IllegalArgumentException("phase has invalid value (" + b + ")"); } + if (b >= 65536L) { + throw new IllegalArgumentException("phase has invalid value (" + b + ")"); + } phase.put((byte) (b >> 8)); phase.put((byte) b); - return this; } @@ -856,13 +938,14 @@ public Trace stamp(final long b) { filled.set(43); } - if(b >= 4294967296L) { throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); } + if (b >= 4294967296L) { + throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); + } stamp.put((byte) (b >> 24)); stamp.put((byte) (b >> 16)); stamp.put((byte) (b >> 8)); stamp.put((byte) b); - return this; } @@ -888,11 +971,18 @@ public Trace totalPairings(final Bytes b) { // 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)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + totalPairings.put((byte) 0); + } // Write bytes - for(int j=0; j 256) { throw new IllegalArgumentException("totalSize has invalid width (" + bs.bitLength() + "bits)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + totalSize.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg1Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg1Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg1Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg1Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg1Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg2Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg2Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg2Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg2Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg2Lo.put((byte) 0); + } // Write bytes - for(int j=0; j Date: Mon, 26 Aug 2024 13:29:02 +0200 Subject: [PATCH 458/461] spotless --- .../linea/zktracer/module/add/Trace.java | 102 +++++++++++++----- 1 file changed, 75 insertions(+), 27 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java index f1bc9d03bb..b1df4b1234 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.add; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -106,11 +105,17 @@ public Trace acc1(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if(bs.bitLength() > 128) { throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { acc1.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + acc1.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { acc2.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + acc2.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg1Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg1Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg1Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg1Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg2Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg2Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg2Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg2Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { resHi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + resHi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { resLo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + resLo.put((byte) 0); + } // Write bytes - for(int j=0; j= 4294967296L) { throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); } + if (b >= 4294967296L) { + throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); + } stamp.put((byte) (b >> 24)); stamp.put((byte) (b >> 16)); stamp.put((byte) (b >> 8)); stamp.put((byte) b); - return this; } From 89fabc4e13787f2241198a324c01be02470695b5 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 26 Aug 2024 17:23:57 +0530 Subject: [PATCH 459/461] feat(txndata): inmplement EIP2681 Signed-off-by: Francois Bojarski --- .../linea/zktracer/module/add/Trace.java | 102 +++++-- .../module/constants/GlobalConstants.java | 3 +- .../module/ecdata/EcDataOperation.java | 7 +- .../linea/zktracer/module/ecdata/Trace.java | 265 +++++++++++++----- .../linea/zktracer/module/txndata/Trace.java | 16 +- .../module/txndata/TxndataOperation.java | 29 +- gradle/trace-files.gradle | 2 +- zkevm-constraints | 2 +- 8 files changed, 311 insertions(+), 115 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java index f1bc9d03bb..b1df4b1234 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Trace.java @@ -15,7 +15,6 @@ package net.consensys.linea.zktracer.module.add; -import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.BitSet; import java.util.List; @@ -106,11 +105,17 @@ public Trace acc1(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if(bs.bitLength() > 128) { throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("acc1 has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { acc1.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + acc1.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("acc2 has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { acc2.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + acc2.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg1Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg1Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg1Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg1Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg1Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg2Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg2Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg2Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("arg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { arg2Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + arg2Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("resHi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { resHi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + resHi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("resLo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { resLo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + resLo.put((byte) 0); + } // Write bytes - for(int j=0; j= 4294967296L) { throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); } + if (b >= 4294967296L) { + throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); + } stamp.put((byte) (b >> 24)); stamp.put((byte) (b >> 16)); stamp.put((byte) (b >> 8)); stamp.put((byte) b); - return this; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/constants/GlobalConstants.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/constants/GlobalConstants.java index 32c7e0c6e2..5f7e3c9365 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/constants/GlobalConstants.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/constants/GlobalConstants.java @@ -26,12 +26,13 @@ public class GlobalConstants { public static final int BLOCKHASH_MAX_HISTORY = 0x100; public static final int CREATE2_SHIFT = 0xff; + public static final long EIP2681_MAX_NONCE = 0xffffffffffffffffL; public static final int EIP_3541_MARKER = 0xef; public static final BigInteger EMPTY_KECCAK_HI = new BigInteger("262949717399590921288928019264691438528"); public static final BigInteger EMPTY_KECCAK_LO = new BigInteger("304396909071904405792975023732328604784"); - public static final long EMPTY_RIPEMD_HI = 0x9c1185a5L; + public static final int EMPTY_RIPEMD_HI = 0x9c1185a5; public static final BigInteger EMPTY_RIPEMD_LO = new BigInteger("263072838190121256777638892741499129137"); public static final BigInteger EMPTY_SHA2_HI = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java index b86cc2ba7b..325e232237 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/EcDataOperation.java @@ -138,7 +138,9 @@ private EcDataOperation( this.precompileFlag = precompileFlag; int callDataSize = callData.size(); - Preconditions.checkArgument(callDataSize > 0, "EcDataOperation should only be called with nonempty call rightPaddedCallData"); + Preconditions.checkArgument( + callDataSize > 0, + "EcDataOperation should only be called with nonempty call rightPaddedCallData"); final int paddedCallDataLength = switch (precompileFlag) { case PRC_ECRECOVER -> 128; @@ -156,7 +158,8 @@ private EcDataOperation( if (callData.size() < paddedCallDataLength) { this.rightPaddedCallData = rightPadTo(callData, paddedCallDataLength); } else { - // TODO: why keep the entire rightPaddedCallData rather than rightPaddedCallData[0:paddedCallDataLength] ? + // TODO: why keep the entire rightPaddedCallData rather than + // rightPaddedCallData[0:paddedCallDataLength] ? this.rightPaddedCallData = callData; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java index 271c060af5..36062466b9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ecdata/Trace.java @@ -48,9 +48,12 @@ public class Trace { public static final int INDEX_MAX_ECRECOVER_RESULT = 0x1; public static final int MULMOD = 0x9; public static final BigInteger P_BN_HI = new BigInteger("64323764613183177041862057485226039389"); - public static final BigInteger P_BN_LO = new BigInteger("201385395114098847380338600778089168199"); - public static final BigInteger SECP256K1N_HI = new BigInteger("340282366920938463463374607431768211455"); - public static final BigInteger SECP256K1N_LO = new BigInteger("340282366920938463463374607427473243183"); + public static final BigInteger P_BN_LO = + new BigInteger("201385395114098847380338600778089168199"); + public static final BigInteger SECP256K1N_HI = + new BigInteger("340282366920938463463374607431768211455"); + public static final BigInteger SECP256K1N_LO = + new BigInteger("340282366920938463463374607427473243183"); public static final int TOTAL_SIZE_ECADD_DATA = 0x80; public static final int TOTAL_SIZE_ECADD_RESULT = 0x40; public static final int TOTAL_SIZE_ECMUL_DATA = 0x60; @@ -251,18 +254,26 @@ public Trace accPairings(final Bytes b) { // 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)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + accPairings.put((byte) 0); + } // Write bytes - for(int j=0; j= 8L) { throw new IllegalArgumentException("ct has invalid value (" + b + ")"); } + if (b >= 8L) { + throw new IllegalArgumentException("ct has invalid value (" + b + ")"); + } ct.put((byte) b); - return this; } @@ -365,10 +377,11 @@ public Trace ctMax(final long b) { filled.set(9); } - if(b >= 8L) { throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); } + if (b >= 8L) { + throw new IllegalArgumentException("ctMax has invalid value (" + b + ")"); + } ctMax.put((byte) b); - return this; } @@ -382,11 +395,18 @@ public Trace extArg1Hi(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if(bs.bitLength() > 128) { throw new IllegalArgumentException("extArg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg1Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg1Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg1Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg1Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg1Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg2Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg2Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg2Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg2Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg2Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg3Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg3Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg3Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg3Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extArg3Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "extArg3Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extArg3Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extArg3Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extResHi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("extResHi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extResHi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extResHi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("extResLo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("extResLo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { extResLo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + extResLo.put((byte) 0); + } // Write bytes - for(int j=0; j= 4294967296L) { throw new IllegalArgumentException("id has invalid value (" + b + ")"); } + if (b >= 4294967296L) { + throw new IllegalArgumentException("id has invalid value (" + b + ")"); + } id.put((byte) (b >> 24)); id.put((byte) (b >> 16)); id.put((byte) (b >> 8)); id.put((byte) b); - return this; } @@ -596,11 +664,12 @@ public Trace index(final long b) { filled.set(23); } - if(b >= 65536L) { throw new IllegalArgumentException("index has invalid value (" + b + ")"); } + if (b >= 65536L) { + throw new IllegalArgumentException("index has invalid value (" + b + ")"); + } index.put((byte) (b >> 8)); index.put((byte) b); - return this; } @@ -614,11 +683,17 @@ public Trace indexMax(final Bytes b) { // 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)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + indexMax.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("limb has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException("limb has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { limb.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + limb.put((byte) 0); + } // Write bytes - for(int j=0; j= 65536L) { throw new IllegalArgumentException("phase has invalid value (" + b + ")"); } + if (b >= 65536L) { + throw new IllegalArgumentException("phase has invalid value (" + b + ")"); + } phase.put((byte) (b >> 8)); phase.put((byte) b); - return this; } @@ -856,13 +938,14 @@ public Trace stamp(final long b) { filled.set(43); } - if(b >= 4294967296L) { throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); } + if (b >= 4294967296L) { + throw new IllegalArgumentException("stamp has invalid value (" + b + ")"); + } stamp.put((byte) (b >> 24)); stamp.put((byte) (b >> 16)); stamp.put((byte) (b >> 8)); stamp.put((byte) b); - return this; } @@ -888,11 +971,18 @@ public Trace totalPairings(final Bytes b) { // 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)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + totalPairings.put((byte) 0); + } // Write bytes - for(int j=0; j 256) { throw new IllegalArgumentException("totalSize has invalid width (" + bs.bitLength() + "bits)"); } + 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); } + for (int i = bs.size(); i < 32; i++) { + totalSize.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg1Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg1Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg1Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg1Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg1Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg1Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg1Lo.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Hi has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg2Hi has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg2Hi.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg2Hi.put((byte) 0); + } // Write bytes - for(int j=0; j 128) { throw new IllegalArgumentException("wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); } + if (bs.bitLength() > 128) { + throw new IllegalArgumentException( + "wcpArg2Lo has invalid width (" + bs.bitLength() + "bits)"); + } // Write padding (if necessary) - for(int i=bs.size(); i<16; i++) { wcpArg2Lo.put((byte) 0); } + for (int i = bs.size(); i < 16; i++) { + wcpArg2Lo.put((byte) 0); + } // Write bytes - for(int j=0; j callsToEucAndWcp = new ArrayList<>(N_ROWS_TX_MAX); @@ -72,37 +74,42 @@ public TxndataOperation(Wcp wcp, Euc euc, TransactionProcessingMetadata tx) { } private void setCallsToEucAndWcp() { - // i+0 - final Bytes row0arg1 = bigIntegerToBytes(tx.getInitialBalance()); + // i + nonce_row_offset + final Bytes nonce = Bytes.minimalBytes(tx.getBesuTransaction().getNonce()); + wcp.callLT(nonce, EIP_2681_MAX_NONCE); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(nonce, EIP_2681_MAX_NONCE, true)); + + // i + initial_balance_row_offset + final Bytes initBalance = bigIntegerToBytes(tx.getInitialBalance()); final BigInteger value = tx.getBesuTransaction().getValue().getAsBigInteger(); final Bytes row0arg2 = bigIntegerToBytes( value.add( outgoingLowRow6() .multiply(BigInteger.valueOf(tx.getBesuTransaction().getGasLimit())))); - wcp.callLT(row0arg1, row0arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row0arg1, row0arg2, false)); + wcp.callLT(initBalance, row0arg2); + this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(initBalance, row0arg2, false)); - // i+1 + // i + sufficient_gas_row_offset final Bytes row1arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getGasLimit()); final Bytes row1arg2 = Bytes.minimalBytes(tx.getUpfrontGasCost()); wcp.callLT(row1arg1, row1arg2); this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row1arg1, row1arg2, false)); - // i+2 + // i + upper_limit_refunds_row_offset final Bytes row2arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas()); final Bytes row2arg2 = Bytes.of(MAX_REFUND_QUOTIENT); final Bytes refundLimit = euc.callEUC(row2arg1, row2arg2).quotient(); this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToEuc(row2arg1, row2arg2, refundLimit)); - // i+3 + // i + effective_refund_row_offset final Bytes refundCounterMax = Bytes.minimalBytes(tx.getRefundCounterMax()); final boolean getFullRefund = wcp.callLT(refundCounterMax, refundLimit); this.callsToEucAndWcp.add( TxnDataComparisonRecord.callToLt(refundCounterMax, refundLimit, getFullRefund)); - // i+4 + // i + detecting_empty_call_data_row_offset final Bytes row4arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getPayload().size()); final boolean nonZeroDataSize = wcp.callISZERO(row4arg1); this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToIsZero(row4arg1, nonZeroDataSize)); @@ -119,21 +126,21 @@ private void setCallsToEucAndWcp() { } } case EIP1559 -> { - // i+5 + // i + max_fee_and_basefee_row_offset final Bytes maxFee = bigIntegerToBytes(tx.getBesuTransaction().getMaxFeePerGas().get().getAsBigInteger()); final Bytes row5arg2 = Bytes.minimalBytes(tx.getBaseFee()); wcp.callLT(maxFee, row5arg2); this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row5arg2, false)); - // i+6 + // i + maxfee_and_max_priority_fee_row_offset final Bytes row6arg2 = bigIntegerToBytes( tx.getBesuTransaction().getMaxPriorityFeePerGas().get().getAsBigInteger()); wcp.callLT(maxFee, row6arg2); this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row6arg2, false)); - // i+7 + // i + computing_effective_gas_price_row_offset final Bytes row7arg2 = bigIntegerToBytes( tx.getBesuTransaction() diff --git a/gradle/trace-files.gradle b/gradle/trace-files.gradle index 0d4a27b3be..d97e8785f6 100644 --- a/gradle/trace-files.gradle +++ b/gradle/trace-files.gradle @@ -98,7 +98,7 @@ tasks.register('binreftable', TraceFilesTask) { ['txndata'].each {moduleName -> tasks.register(moduleName, TraceFilesTask) { group "Trace files generation" - dependsOn corsetExists + // dependsOn corsetExists module = moduleName files = ["${moduleName}/columns.lisp", "constants/constants.lisp", "${moduleName}/constants.lisp"] diff --git a/zkevm-constraints b/zkevm-constraints index 8f814229bc..b6bf989a5a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 8f814229bc2f748c25fda2aa1a1dce8b548ed0a9 +Subproject commit b6bf989a5a381258f217c160a9ea3ef2d802fde2 From 8a1abd505f9913e59fd34b567db2127f155fe7f7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 26 Aug 2024 21:55:17 +0530 Subject: [PATCH 460/461] fix(txndata): trivial fix Signed-off-by: Francois Bojarski --- .../module/txndata/TxndataOperation.java | 83 ++++++++++--------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java index 28f69e8fe1..f2de616d0a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txndata/TxndataOperation.java @@ -61,6 +61,7 @@ public class TxndataOperation extends ModuleOperation { private static final Bytes EIP_2681_MAX_NONCE = Bytes.minimalBytes(EIP2681_MAX_NONCE); private static final int N_ROWS_TX_MAX = Math.max(Math.max(NB_ROWS_TYPE_0, NB_ROWS_TYPE_1), NB_ROWS_TYPE_2); + private static final int NB_WCP_EUC_ROWS_FRONTIER_ACCESS_LIST = 6; private final List callsToEucAndWcp = new ArrayList<>(N_ROWS_TX_MAX); private final ArrayList valuesToRlptxn = new ArrayList<>(N_ROWS_TX_MAX); private final ArrayList valuesToRlpTxrcpt = new ArrayList<>(N_ROWS_TX_MAX); @@ -88,41 +89,41 @@ private void setCallsToEucAndWcp() { outgoingLowRow6() .multiply(BigInteger.valueOf(tx.getBesuTransaction().getGasLimit())))); wcp.callLT(initBalance, row0arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(initBalance, row0arg2, false)); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(initBalance, row0arg2, false)); // i + sufficient_gas_row_offset final Bytes row1arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getGasLimit()); final Bytes row1arg2 = Bytes.minimalBytes(tx.getUpfrontGasCost()); wcp.callLT(row1arg1, row1arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row1arg1, row1arg2, false)); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(row1arg1, row1arg2, false)); // i + upper_limit_refunds_row_offset final Bytes row2arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getGasLimit() - tx.getLeftoverGas()); final Bytes row2arg2 = Bytes.of(MAX_REFUND_QUOTIENT); final Bytes refundLimit = euc.callEUC(row2arg1, row2arg2).quotient(); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToEuc(row2arg1, row2arg2, refundLimit)); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToEuc(row2arg1, row2arg2, refundLimit)); // i + effective_refund_row_offset final Bytes refundCounterMax = Bytes.minimalBytes(tx.getRefundCounterMax()); final boolean getFullRefund = wcp.callLT(refundCounterMax, refundLimit); - this.callsToEucAndWcp.add( + callsToEucAndWcp.add( TxnDataComparisonRecord.callToLt(refundCounterMax, refundLimit, getFullRefund)); // i + detecting_empty_call_data_row_offset final Bytes row4arg1 = Bytes.minimalBytes(tx.getBesuTransaction().getPayload().size()); final boolean nonZeroDataSize = wcp.callISZERO(row4arg1); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToIsZero(row4arg1, nonZeroDataSize)); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToIsZero(row4arg1, nonZeroDataSize)); switch (tx.getBesuTransaction().getType()) { case FRONTIER -> { - for (int i = 5; i < NB_ROWS_TYPE_0; i++) { - this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); + for (int i = NB_WCP_EUC_ROWS_FRONTIER_ACCESS_LIST; i < NB_ROWS_TYPE_0; i++) { + callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); } } case ACCESS_LIST -> { - for (int i = 5; i < NB_ROWS_TYPE_1; i++) { - this.callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); + for (int i = NB_WCP_EUC_ROWS_FRONTIER_ACCESS_LIST; i < NB_ROWS_TYPE_1; i++) { + callsToEucAndWcp.add(TxnDataComparisonRecord.empty()); } } case EIP1559 -> { @@ -131,14 +132,14 @@ private void setCallsToEucAndWcp() { bigIntegerToBytes(tx.getBesuTransaction().getMaxFeePerGas().get().getAsBigInteger()); final Bytes row5arg2 = Bytes.minimalBytes(tx.getBaseFee()); wcp.callLT(maxFee, row5arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row5arg2, false)); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row5arg2, false)); // i + maxfee_and_max_priority_fee_row_offset final Bytes row6arg2 = bigIntegerToBytes( tx.getBesuTransaction().getMaxPriorityFeePerGas().get().getAsBigInteger()); wcp.callLT(maxFee, row6arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row6arg2, false)); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row6arg2, false)); // i + computing_effective_gas_price_row_offset final Bytes row7arg2 = @@ -149,7 +150,7 @@ private void setCallsToEucAndWcp() { .getAsBigInteger() .add(BigInteger.valueOf(tx.getBaseFee()))); final boolean result = wcp.callLT(maxFee, row7arg2); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row7arg2, result)); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToLt(maxFee, row7arg2, result)); } } } @@ -168,41 +169,41 @@ protected int computeLineCount() { private void setRlptxnValues() { // i+0 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) COMMON_RLP_TXN_PHASE_NUMBER_0, Bytes.EMPTY, Bytes.ofUnsignedInt(getTxTypeAsInt(tx.getBesuTransaction().getType())))); // i+1 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) COMMON_RLP_TXN_PHASE_NUMBER_1, tx.isDeployment() ? Bytes.EMPTY : tx.getEffectiveTo().slice(0, 4), tx.isDeployment() ? Bytes.EMPTY : lowPart(tx.getEffectiveTo()))); // i+2 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) COMMON_RLP_TXN_PHASE_NUMBER_2, Bytes.EMPTY, Bytes.ofUnsignedLong(tx.getBesuTransaction().getNonce()))); // i+3 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) COMMON_RLP_TXN_PHASE_NUMBER_3, tx.isDeployment() ? Bytes.of(1) : Bytes.EMPTY, bigIntegerToBytes(tx.getBesuTransaction().getValue().getAsBigInteger()))); // i+4 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) COMMON_RLP_TXN_PHASE_NUMBER_4, Bytes.ofUnsignedLong(tx.getDataCost()), Bytes.ofUnsignedLong(tx.getBesuTransaction().getPayload().size()))); // i+5 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) COMMON_RLP_TXN_PHASE_NUMBER_5, Bytes.EMPTY, @@ -211,38 +212,38 @@ private void setRlptxnValues() { switch (tx.getBesuTransaction().getType()) { case FRONTIER -> { // i+6 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) TYPE_0_RLP_TXN_PHASE_NUMBER_6, Bytes.EMPTY, Bytes.minimalBytes(tx.getEffectiveGasPrice()))); for (int i = 7; i < NB_ROWS_TYPE_0 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); + valuesToRlptxn.add(RlptxnOutgoing.empty()); } } case ACCESS_LIST -> { // i+6 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) TYPE_1_RLP_TXN_PHASE_NUMBER_6, Bytes.EMPTY, Bytes.minimalBytes(tx.getEffectiveGasPrice()))); // i+7 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) TYPE_1_RLP_TXN_PHASE_NUMBER_7, Bytes.ofUnsignedInt(tx.numberWarmedKey()), Bytes.ofUnsignedInt(tx.numberWarmedAddress()))); for (int i = 8; i < NB_ROWS_TYPE_1 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); + valuesToRlptxn.add(RlptxnOutgoing.empty()); } } case EIP1559 -> { // i+6 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) TYPE_2_RLP_TXN_PHASE_NUMBER_6, bigIntegerToBytes( @@ -250,14 +251,14 @@ private void setRlptxnValues() { bigIntegerToBytes(outgoingLowRow6()))); // i+7 - this.valuesToRlptxn.add( + valuesToRlptxn.add( RlptxnOutgoing.set( (short) TYPE_2_RLP_TXN_PHASE_NUMBER_7, Bytes.ofUnsignedInt(tx.numberWarmedKey()), Bytes.ofUnsignedInt(tx.numberWarmedAddress()))); for (int i = 8; i < NB_ROWS_TYPE_2 + 1; i++) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); + valuesToRlptxn.add(RlptxnOutgoing.empty()); } } } @@ -284,8 +285,8 @@ public void setRlptxrcptValues() { public void setCallWcpLastTxOfBlock(final Bytes blockGasLimit) { final Bytes arg1 = Bytes.minimalBytes(tx.getAccumulatedGasUsedInBlock()); - this.wcp.callLEQ(arg1, blockGasLimit); - this.callsToEucAndWcp.add(TxnDataComparisonRecord.callToLeq(arg1, blockGasLimit, true)); + wcp.callLEQ(arg1, blockGasLimit); + callsToEucAndWcp.add(TxnDataComparisonRecord.callToLeq(arg1, blockGasLimit, true)); } private BigInteger outgoingLowRow6() { @@ -305,8 +306,8 @@ public void traceTx(Trace trace, BlockSnapshot block, int absTxNumMax) { final boolean isLastTxOfTheBlock = tx.getRelativeTransactionNumber() == block.getNbOfTxsInBlock(); if (isLastTxOfTheBlock) { - this.valuesToRlptxn.add(RlptxnOutgoing.empty()); - this.valuesToRlpTxrcpt.add(RlptxrcptOutgoing.emptyValue()); + valuesToRlptxn.add(RlptxnOutgoing.empty()); + valuesToRlpTxrcpt.add(RlptxrcptOutgoing.emptyValue()); } final long fromHi = highPart(tx.getSender()); @@ -370,17 +371,17 @@ public void traceTx(Trace trace, BlockSnapshot block, int absTxNumMax) { .gasCumulative(cumulativeGas) .statusCode(tx.statusCode()) .codeFragmentIndex(tx.getCodeFragmentIndex()) - .phaseRlpTxn(UnsignedByte.of(this.valuesToRlptxn.get(ct).phase())) - .outgoingHi(this.valuesToRlptxn.get(ct).outGoingHi()) - .outgoingLo(this.valuesToRlptxn.get(ct).outGoingLo()) - .eucFlag(this.callsToEucAndWcp.get(ct).eucFlag()) - .wcpFlag(this.callsToEucAndWcp.get(ct).wcpFlag()) - .inst(UnsignedByte.of(this.callsToEucAndWcp.get(ct).instruction())) - .argOneLo(this.callsToEucAndWcp.get(ct).arg1()) - .argTwoLo(this.callsToEucAndWcp.get(ct).arg2()) - .res(this.callsToEucAndWcp.get(ct).result()) - .phaseRlpTxnrcpt(UnsignedByte.of(this.valuesToRlpTxrcpt.get(ct).phase())) - .outgoingRlpTxnrcpt(Bytes.ofUnsignedLong(this.valuesToRlpTxrcpt.get(ct).outgoing())) + .phaseRlpTxn(UnsignedByte.of(valuesToRlptxn.get(ct).phase())) + .outgoingHi(valuesToRlptxn.get(ct).outGoingHi()) + .outgoingLo(valuesToRlptxn.get(ct).outGoingLo()) + .eucFlag(callsToEucAndWcp.get(ct).eucFlag()) + .wcpFlag(callsToEucAndWcp.get(ct).wcpFlag()) + .inst(UnsignedByte.of(callsToEucAndWcp.get(ct).instruction())) + .argOneLo(callsToEucAndWcp.get(ct).arg1()) + .argTwoLo(callsToEucAndWcp.get(ct).arg2()) + .res(callsToEucAndWcp.get(ct).result()) + .phaseRlpTxnrcpt(UnsignedByte.of(valuesToRlpTxrcpt.get(ct).phase())) + .outgoingRlpTxnrcpt(Bytes.ofUnsignedLong(valuesToRlpTxrcpt.get(ct).outgoing())) .validateRow(); } } From 8668d70c909687d1b16e501f28cedfb1e0876276 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 27 Aug 2024 09:20:48 +0530 Subject: [PATCH 461/461] fix: wrong data cost calculation that contains the deployement cost Signed-off-by: Francois Bojarski --- .../zktracer/types/TransactionProcessingMetadata.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 872c852ac5..fa92f47582 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -146,10 +146,11 @@ public TransactionProcessingMetadata( this.initialBalance = getInitialBalance(world); - // Note: Besu's dataCost computation contains the 21_000 transaction cost + // Note: Besu's dataCost computation contains + // - the 21_000 transaction cost (we deduce it) + // - the contract creation cost in case of deployment (we set deployment to false to not add it) this.dataCost = - ZkTracer.gasCalculator.transactionIntrinsicGasCost( - besuTransaction.getPayload(), isDeployment) + ZkTracer.gasCalculator.transactionIntrinsicGasCost(besuTransaction.getPayload(), false) - GAS_CONST_G_TRANSACTION; this.accessListCost = besuTransaction.getAccessList().map(ZkTracer.gasCalculator::accessListGasCost).orElse(0L);